root/src/haikuimage.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. haiku_can_use_native_image_api
  2. haiku_load_image
  3. syms_of_haikuimage

     1 /* Haiku window system support.
     2    Copyright (C) 2021-2023 Free Software Foundation, Inc.
     3 
     4 This file is part of GNU Emacs.
     5 
     6 GNU Emacs is free software: you can redistribute it and/or modify
     7 it under the terms of the GNU General Public License as published by
     8 the Free Software Foundation, either version 3 of the License, or (at
     9 your option) any later version.
    10 
    11 GNU Emacs is distributed in the hope that it will be useful,
    12 but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14 GNU General Public License for more details.
    15 
    16 You should have received a copy of the GNU General Public License
    17 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    18 
    19 #include <config.h>
    20 
    21 #include "lisp.h"
    22 #include "dispextern.h"
    23 #include "haikuterm.h"
    24 #include "coding.h"
    25 
    26 #include "haiku_support.h"
    27 
    28 bool
    29 haiku_can_use_native_image_api (Lisp_Object type)
    30 {
    31   const char *mime_type = NULL;
    32 
    33   if (EQ (type, Qnative_image))
    34     return 1;
    35 
    36 #ifdef HAVE_RSVG
    37   if (EQ (type, Qsvg))
    38     return 0;
    39 #endif
    40 
    41   if (EQ (type, Qjpeg))
    42     mime_type = "image/jpeg";
    43   else if (EQ (type, Qpng))
    44     mime_type = "image/png";
    45 #ifndef HAVE_GIF
    46   else if (EQ (type, Qgif))
    47     mime_type = "image/gif";
    48 #endif
    49   else if (EQ (type, Qtiff))
    50     mime_type = "image/tiff";
    51   else if (EQ (type, Qbmp))
    52     mime_type = "image/bmp";
    53   else if (EQ (type, Qsvg))
    54     mime_type = "image/svg";
    55   else if (EQ (type, Qpbm))
    56     mime_type = "image/pbm";
    57   /* Don't use native image APIs for image types that have animations,
    58      since those aren't supported by the Translation Kit.  */
    59 #ifndef HAVE_WEBP
    60   else if (EQ (type, Qwebp))
    61     mime_type = "image/webp";
    62 #endif
    63 
    64   if (!mime_type)
    65     return 0;
    66 
    67   return be_can_translate_type_to_bitmap_p (mime_type);
    68 }
    69 
    70 extern int
    71 haiku_load_image (struct frame *f, struct image *img,
    72                   Lisp_Object spec_file, Lisp_Object spec_data)
    73 {
    74   eassert (valid_image_p (img->spec));
    75 
    76   void *pixmap = NULL;
    77 
    78   if (STRINGP (spec_file))
    79     {
    80       pixmap = be_translate_bitmap_from_file_name
    81         (SSDATA (ENCODE_UTF_8 (spec_file)));
    82     }
    83   else if (STRINGP (spec_data))
    84     {
    85       pixmap = be_translate_bitmap_from_memory
    86         (SSDATA (spec_data), SBYTES (spec_data));
    87     }
    88 
    89   void *conv = NULL;
    90 
    91   if (!pixmap || !BBitmap_convert (pixmap, &conv))
    92     {
    93       add_to_log ("Unable to load image %s", img->spec);
    94       return 0;
    95     }
    96 
    97   if (conv)
    98     {
    99       BBitmap_free (pixmap);
   100       pixmap = conv;
   101     }
   102 
   103   int left, top, right, bottom, stride, mono_p;
   104   BBitmap_dimensions (pixmap, &left, &top, &right, &bottom, &stride, &mono_p);
   105 
   106   img->width = (1 + right - left);
   107   img->height = (1 + bottom - top);
   108   img->pixmap = pixmap;
   109 
   110   return 1;
   111 }
   112 
   113 void
   114 syms_of_haikuimage (void)
   115 {
   116 }

/* [<][>][^][v][top][bottom][index][help] */