diff options
| author | Alan Third | 2020-04-14 22:56:06 +0100 |
|---|---|---|
| committer | Alan Third | 2020-04-16 19:11:05 +0100 |
| commit | e105d01c952aab93de1607ebcfed7860837288fb (patch) | |
| tree | 2cd99422ab26545ba76215f95ce851a91d0115a2 /src | |
| parent | c019f03e38850b3ba3a2bcbcc84960d5b8d9663f (diff) | |
| download | emacs-e105d01c952aab93de1607ebcfed7860837288fb.tar.gz emacs-e105d01c952aab93de1607ebcfed7860837288fb.zip | |
Use native image API for NS
* configure.ac (NATIVE_IMAGE_API): Move above NS definitions.
(HAVE_NATIVE_IMAGE_API): Set for NS.
(HAVE_PNG, HAVE_JPEG, HAVE_GIF, HAVE_TIFF): Enable on NS builds.
* src/image.c (HAVE_NS): Fix a number of #if's so they no longer rely
on HAVE_NS.
(PIX_MASK_DRAW): Add for HAVE_NS so libpng support will compile.
(image_can_use_native_api):
(native_image_load): Add NS support.
(png_load):
(jpeg_load):
(tiff_load):
(gif_load): Remove NS specific definitions.
* src/nsimage.m (ns_can_use_native_image_api): New function.
* src/nsterm.h: (ns_can_use_native_image_api): New function.
Diffstat (limited to 'src')
| -rw-r--r-- | src/image.c | 89 | ||||
| -rw-r--r-- | src/nsimage.m | 49 | ||||
| -rw-r--r-- | src/nsterm.h | 1 |
3 files changed, 76 insertions, 63 deletions
diff --git a/src/image.c b/src/image.c index acb1e9d23d8..ffe2f607e52 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -24,7 +24,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 24 | 24 | ||
| 25 | /* Include this before including <setjmp.h> to work around bugs with | 25 | /* Include this before including <setjmp.h> to work around bugs with |
| 26 | older libpng; see Bug#17429. */ | 26 | older libpng; see Bug#17429. */ |
| 27 | #if defined HAVE_PNG && !defined HAVE_NS | 27 | #if defined HAVE_PNG |
| 28 | # include <png.h> | 28 | # include <png.h> |
| 29 | #endif | 29 | #endif |
| 30 | 30 | ||
| @@ -125,6 +125,7 @@ typedef struct ns_bitmap_record Bitmap_Record; | |||
| 125 | #define NO_PIXMAP 0 | 125 | #define NO_PIXMAP 0 |
| 126 | 126 | ||
| 127 | #define PIX_MASK_RETAIN 0 | 127 | #define PIX_MASK_RETAIN 0 |
| 128 | #define PIX_MASK_DRAW 1 | ||
| 128 | 129 | ||
| 129 | #endif /* HAVE_NS */ | 130 | #endif /* HAVE_NS */ |
| 130 | 131 | ||
| @@ -6242,6 +6243,8 @@ image_can_use_native_api (Lisp_Object type) | |||
| 6242 | { | 6243 | { |
| 6243 | # ifdef HAVE_NTGUI | 6244 | # ifdef HAVE_NTGUI |
| 6244 | return w32_can_use_native_image_api (type); | 6245 | return w32_can_use_native_image_api (type); |
| 6246 | # elif defined HAVE_NS | ||
| 6247 | return ns_can_use_native_image_api (type); | ||
| 6245 | # else | 6248 | # else |
| 6246 | return false; | 6249 | return false; |
| 6247 | # endif | 6250 | # endif |
| @@ -6310,6 +6313,10 @@ native_image_load (struct frame *f, struct image *img) | |||
| 6310 | return w32_load_image (f, img, | 6313 | return w32_load_image (f, img, |
| 6311 | image_spec_value (img->spec, QCfile, NULL), | 6314 | image_spec_value (img->spec, QCfile, NULL), |
| 6312 | image_spec_value (img->spec, QCdata, NULL)); | 6315 | image_spec_value (img->spec, QCdata, NULL)); |
| 6316 | # elif defined HAVE_NS | ||
| 6317 | return ns_load_image (f, img, | ||
| 6318 | image_spec_value (img->spec, QCfile, NULL), | ||
| 6319 | image_spec_value (img->spec, QCdata, NULL)); | ||
| 6313 | # else | 6320 | # else |
| 6314 | return 0; | 6321 | return 0; |
| 6315 | # endif | 6322 | # endif |
| @@ -6322,7 +6329,7 @@ native_image_load (struct frame *f, struct image *img) | |||
| 6322 | PNG | 6329 | PNG |
| 6323 | ***********************************************************************/ | 6330 | ***********************************************************************/ |
| 6324 | 6331 | ||
| 6325 | #if defined (HAVE_PNG) || defined (HAVE_NS) | 6332 | #if defined (HAVE_PNG) |
| 6326 | 6333 | ||
| 6327 | /* Indices of image specification fields in png_format, below. */ | 6334 | /* Indices of image specification fields in png_format, below. */ |
| 6328 | 6335 | ||
| @@ -6373,10 +6380,10 @@ png_image_p (Lisp_Object object) | |||
| 6373 | return fmt[PNG_FILE].count + fmt[PNG_DATA].count == 1; | 6380 | return fmt[PNG_FILE].count + fmt[PNG_DATA].count == 1; |
| 6374 | } | 6381 | } |
| 6375 | 6382 | ||
| 6376 | #endif /* HAVE_PNG || HAVE_NS */ | 6383 | #endif /* HAVE_PNG */ |
| 6377 | 6384 | ||
| 6378 | 6385 | ||
| 6379 | #if defined HAVE_PNG && !defined HAVE_NS | 6386 | #ifdef HAVE_PNG |
| 6380 | 6387 | ||
| 6381 | # ifdef WINDOWSNT | 6388 | # ifdef WINDOWSNT |
| 6382 | /* PNG library details. */ | 6389 | /* PNG library details. */ |
| @@ -6966,17 +6973,7 @@ png_load (struct frame *f, struct image *img) | |||
| 6966 | return png_load_body (f, img, &c); | 6973 | return png_load_body (f, img, &c); |
| 6967 | } | 6974 | } |
| 6968 | 6975 | ||
| 6969 | #elif defined HAVE_NS | 6976 | #endif /* HAVE_PNG */ |
| 6970 | |||
| 6971 | static bool | ||
| 6972 | png_load (struct frame *f, struct image *img) | ||
| 6973 | { | ||
| 6974 | return ns_load_image (f, img, | ||
| 6975 | image_spec_value (img->spec, QCfile, NULL), | ||
| 6976 | image_spec_value (img->spec, QCdata, NULL)); | ||
| 6977 | } | ||
| 6978 | |||
| 6979 | #endif /* HAVE_NS */ | ||
| 6980 | 6977 | ||
| 6981 | 6978 | ||
| 6982 | 6979 | ||
| @@ -6984,7 +6981,7 @@ png_load (struct frame *f, struct image *img) | |||
| 6984 | JPEG | 6981 | JPEG |
| 6985 | ***********************************************************************/ | 6982 | ***********************************************************************/ |
| 6986 | 6983 | ||
| 6987 | #if defined (HAVE_JPEG) || defined (HAVE_NS) | 6984 | #if defined (HAVE_JPEG) |
| 6988 | 6985 | ||
| 6989 | /* Indices of image specification fields in gs_format, below. */ | 6986 | /* Indices of image specification fields in gs_format, below. */ |
| 6990 | 6987 | ||
| @@ -7036,7 +7033,7 @@ jpeg_image_p (Lisp_Object object) | |||
| 7036 | return fmt[JPEG_FILE].count + fmt[JPEG_DATA].count == 1; | 7033 | return fmt[JPEG_FILE].count + fmt[JPEG_DATA].count == 1; |
| 7037 | } | 7034 | } |
| 7038 | 7035 | ||
| 7039 | #endif /* HAVE_JPEG || HAVE_NS */ | 7036 | #endif /* HAVE_JPEG */ |
| 7040 | 7037 | ||
| 7041 | #ifdef HAVE_JPEG | 7038 | #ifdef HAVE_JPEG |
| 7042 | 7039 | ||
| @@ -7538,18 +7535,6 @@ jpeg_load (struct frame *f, struct image *img) | |||
| 7538 | return jpeg_load_body (f, img, &mgr); | 7535 | return jpeg_load_body (f, img, &mgr); |
| 7539 | } | 7536 | } |
| 7540 | 7537 | ||
| 7541 | #else /* HAVE_JPEG */ | ||
| 7542 | |||
| 7543 | #ifdef HAVE_NS | ||
| 7544 | static bool | ||
| 7545 | jpeg_load (struct frame *f, struct image *img) | ||
| 7546 | { | ||
| 7547 | return ns_load_image (f, img, | ||
| 7548 | image_spec_value (img->spec, QCfile, NULL), | ||
| 7549 | image_spec_value (img->spec, QCdata, NULL)); | ||
| 7550 | } | ||
| 7551 | #endif /* HAVE_NS */ | ||
| 7552 | |||
| 7553 | #endif /* !HAVE_JPEG */ | 7538 | #endif /* !HAVE_JPEG */ |
| 7554 | 7539 | ||
| 7555 | 7540 | ||
| @@ -7558,7 +7543,7 @@ jpeg_load (struct frame *f, struct image *img) | |||
| 7558 | TIFF | 7543 | TIFF |
| 7559 | ***********************************************************************/ | 7544 | ***********************************************************************/ |
| 7560 | 7545 | ||
| 7561 | #if defined (HAVE_TIFF) || defined (HAVE_NS) | 7546 | #if defined (HAVE_TIFF) |
| 7562 | 7547 | ||
| 7563 | /* Indices of image specification fields in tiff_format, below. */ | 7548 | /* Indices of image specification fields in tiff_format, below. */ |
| 7564 | 7549 | ||
| @@ -7611,7 +7596,7 @@ tiff_image_p (Lisp_Object object) | |||
| 7611 | return fmt[TIFF_FILE].count + fmt[TIFF_DATA].count == 1; | 7596 | return fmt[TIFF_FILE].count + fmt[TIFF_DATA].count == 1; |
| 7612 | } | 7597 | } |
| 7613 | 7598 | ||
| 7614 | #endif /* HAVE_TIFF || HAVE_NS */ | 7599 | #endif /* HAVE_TIFF */ |
| 7615 | 7600 | ||
| 7616 | #ifdef HAVE_TIFF | 7601 | #ifdef HAVE_TIFF |
| 7617 | 7602 | ||
| @@ -7979,16 +7964,6 @@ tiff_load (struct frame *f, struct image *img) | |||
| 7979 | return 1; | 7964 | return 1; |
| 7980 | } | 7965 | } |
| 7981 | 7966 | ||
| 7982 | #elif defined HAVE_NS | ||
| 7983 | |||
| 7984 | static bool | ||
| 7985 | tiff_load (struct frame *f, struct image *img) | ||
| 7986 | { | ||
| 7987 | return ns_load_image (f, img, | ||
| 7988 | image_spec_value (img->spec, QCfile, NULL), | ||
| 7989 | image_spec_value (img->spec, QCdata, NULL)); | ||
| 7990 | } | ||
| 7991 | |||
| 7992 | #endif | 7967 | #endif |
| 7993 | 7968 | ||
| 7994 | 7969 | ||
| @@ -7997,7 +7972,7 @@ tiff_load (struct frame *f, struct image *img) | |||
| 7997 | GIF | 7972 | GIF |
| 7998 | ***********************************************************************/ | 7973 | ***********************************************************************/ |
| 7999 | 7974 | ||
| 8000 | #if defined (HAVE_GIF) || defined (HAVE_NS) | 7975 | #if defined (HAVE_GIF) |
| 8001 | 7976 | ||
| 8002 | /* Indices of image specification fields in gif_format, below. */ | 7977 | /* Indices of image specification fields in gif_format, below. */ |
| 8003 | 7978 | ||
| @@ -8059,7 +8034,7 @@ gif_image_p (Lisp_Object object) | |||
| 8059 | return fmt[GIF_FILE].count + fmt[GIF_DATA].count == 1; | 8034 | return fmt[GIF_FILE].count + fmt[GIF_DATA].count == 1; |
| 8060 | } | 8035 | } |
| 8061 | 8036 | ||
| 8062 | #endif /* HAVE_GIF || HAVE_NS */ | 8037 | #endif /* HAVE_GIF */ |
| 8063 | 8038 | ||
| 8064 | #ifdef HAVE_GIF | 8039 | #ifdef HAVE_GIF |
| 8065 | 8040 | ||
| @@ -8576,18 +8551,6 @@ gif_load (struct frame *f, struct image *img) | |||
| 8576 | return 1; | 8551 | return 1; |
| 8577 | } | 8552 | } |
| 8578 | 8553 | ||
| 8579 | #else /* !HAVE_GIF */ | ||
| 8580 | |||
| 8581 | #ifdef HAVE_NS | ||
| 8582 | static bool | ||
| 8583 | gif_load (struct frame *f, struct image *img) | ||
| 8584 | { | ||
| 8585 | return ns_load_image (f, img, | ||
| 8586 | image_spec_value (img->spec, QCfile, NULL), | ||
| 8587 | image_spec_value (img->spec, QCdata, NULL)); | ||
| 8588 | } | ||
| 8589 | #endif /* HAVE_NS */ | ||
| 8590 | |||
| 8591 | #endif /* HAVE_GIF */ | 8554 | #endif /* HAVE_GIF */ |
| 8592 | 8555 | ||
| 8593 | 8556 | ||
| @@ -10256,19 +10219,19 @@ static struct image_type const image_types[] = | |||
| 10256 | { SYMBOL_INDEX (Qsvg), svg_image_p, svg_load, image_clear_image, | 10219 | { SYMBOL_INDEX (Qsvg), svg_image_p, svg_load, image_clear_image, |
| 10257 | IMAGE_TYPE_INIT (init_svg_functions) }, | 10220 | IMAGE_TYPE_INIT (init_svg_functions) }, |
| 10258 | #endif | 10221 | #endif |
| 10259 | #if defined HAVE_PNG || defined HAVE_NS | 10222 | #if defined HAVE_PNG |
| 10260 | { SYMBOL_INDEX (Qpng), png_image_p, png_load, image_clear_image, | 10223 | { SYMBOL_INDEX (Qpng), png_image_p, png_load, image_clear_image, |
| 10261 | IMAGE_TYPE_INIT (init_png_functions) }, | 10224 | IMAGE_TYPE_INIT (init_png_functions) }, |
| 10262 | #endif | 10225 | #endif |
| 10263 | #if defined HAVE_GIF || defined HAVE_NS | 10226 | #if defined HAVE_GIF |
| 10264 | { SYMBOL_INDEX (Qgif), gif_image_p, gif_load, gif_clear_image, | 10227 | { SYMBOL_INDEX (Qgif), gif_image_p, gif_load, gif_clear_image, |
| 10265 | IMAGE_TYPE_INIT (init_gif_functions) }, | 10228 | IMAGE_TYPE_INIT (init_gif_functions) }, |
| 10266 | #endif | 10229 | #endif |
| 10267 | #if defined HAVE_TIFF || defined HAVE_NS | 10230 | #if defined HAVE_TIFF |
| 10268 | { SYMBOL_INDEX (Qtiff), tiff_image_p, tiff_load, image_clear_image, | 10231 | { SYMBOL_INDEX (Qtiff), tiff_image_p, tiff_load, image_clear_image, |
| 10269 | IMAGE_TYPE_INIT (init_tiff_functions) }, | 10232 | IMAGE_TYPE_INIT (init_tiff_functions) }, |
| 10270 | #endif | 10233 | #endif |
| 10271 | #if defined HAVE_JPEG || defined HAVE_NS | 10234 | #if defined HAVE_JPEG |
| 10272 | { SYMBOL_INDEX (Qjpeg), jpeg_image_p, jpeg_load, image_clear_image, | 10235 | { SYMBOL_INDEX (Qjpeg), jpeg_image_p, jpeg_load, image_clear_image, |
| 10273 | IMAGE_TYPE_INIT (init_jpeg_functions) }, | 10236 | IMAGE_TYPE_INIT (init_jpeg_functions) }, |
| 10274 | #endif | 10237 | #endif |
| @@ -10418,22 +10381,22 @@ non-numeric, there is no explicit limit on the size of images. */); | |||
| 10418 | add_image_type (Qxpm); | 10381 | add_image_type (Qxpm); |
| 10419 | #endif | 10382 | #endif |
| 10420 | 10383 | ||
| 10421 | #if defined (HAVE_JPEG) || defined (HAVE_NS) || defined (HAVE_NATIVE_IMAGE_API) | 10384 | #if defined (HAVE_JPEG) || defined (HAVE_NATIVE_IMAGE_API) |
| 10422 | DEFSYM (Qjpeg, "jpeg"); | 10385 | DEFSYM (Qjpeg, "jpeg"); |
| 10423 | add_image_type (Qjpeg); | 10386 | add_image_type (Qjpeg); |
| 10424 | #endif | 10387 | #endif |
| 10425 | 10388 | ||
| 10426 | #if defined (HAVE_TIFF) || defined (HAVE_NS) || defined (HAVE_NATIVE_IMAGE_API) | 10389 | #if defined (HAVE_TIFF) || defined (HAVE_NATIVE_IMAGE_API) |
| 10427 | DEFSYM (Qtiff, "tiff"); | 10390 | DEFSYM (Qtiff, "tiff"); |
| 10428 | add_image_type (Qtiff); | 10391 | add_image_type (Qtiff); |
| 10429 | #endif | 10392 | #endif |
| 10430 | 10393 | ||
| 10431 | #if defined (HAVE_GIF) || defined (HAVE_NS) || defined (HAVE_NATIVE_IMAGE_API) | 10394 | #if defined (HAVE_GIF) || defined (HAVE_NATIVE_IMAGE_API) |
| 10432 | DEFSYM (Qgif, "gif"); | 10395 | DEFSYM (Qgif, "gif"); |
| 10433 | add_image_type (Qgif); | 10396 | add_image_type (Qgif); |
| 10434 | #endif | 10397 | #endif |
| 10435 | 10398 | ||
| 10436 | #if defined (HAVE_PNG) || defined (HAVE_NS) || defined(HAVE_NATIVE_IMAGE_API) | 10399 | #if defined (HAVE_PNG) || defined (HAVE_NATIVE_IMAGE_API) |
| 10437 | DEFSYM (Qpng, "png"); | 10400 | DEFSYM (Qpng, "png"); |
| 10438 | add_image_type (Qpng); | 10401 | add_image_type (Qpng); |
| 10439 | #endif | 10402 | #endif |
diff --git a/src/nsimage.m b/src/nsimage.m index 3cccc984ca9..07750de95fe 100644 --- a/src/nsimage.m +++ b/src/nsimage.m | |||
| @@ -45,6 +45,55 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu) | |||
| 45 | 45 | ||
| 46 | ========================================================================== */ | 46 | ========================================================================== */ |
| 47 | 47 | ||
| 48 | bool | ||
| 49 | ns_can_use_native_image_api (Lisp_Object type) | ||
| 50 | { | ||
| 51 | NSString *imageType = @"unknown"; | ||
| 52 | NSArray *types; | ||
| 53 | |||
| 54 | NSTRACE ("ns_can_use_native_image_api"); | ||
| 55 | |||
| 56 | if (EQ (type, Qnative_image)) | ||
| 57 | return YES; | ||
| 58 | |||
| 59 | #ifdef NS_IMPL_COCOA | ||
| 60 | /* Work out the UTI of the image type. */ | ||
| 61 | if (EQ (type, Qjpeg)) | ||
| 62 | imageType = @"public.jpeg"; | ||
| 63 | else if (EQ (type, Qpng)) | ||
| 64 | imageType = @"public.png"; | ||
| 65 | else if (EQ (type, Qgif)) | ||
| 66 | imageType = @"com.compuserve.gif"; | ||
| 67 | else if (EQ (type, Qtiff)) | ||
| 68 | imageType = @"public.tiff"; | ||
| 69 | else if (EQ (type, Qsvg)) | ||
| 70 | imageType = @"public.svg-image"; | ||
| 71 | |||
| 72 | /* NSImage also supports a host of other types such as PDF and BMP, | ||
| 73 | but we don't yet support these in image.c. */ | ||
| 74 | |||
| 75 | types = [NSImage imageTypes]; | ||
| 76 | #else | ||
| 77 | /* Work out the image type. */ | ||
| 78 | if (EQ (type, Qjpeg)) | ||
| 79 | imageType = @"jpeg"; | ||
| 80 | else if (EQ (type, Qpng)) | ||
| 81 | imageType = @"png"; | ||
| 82 | else if (EQ (type, Qgif)) | ||
| 83 | imageType = @"gif"; | ||
| 84 | else if (EQ (type, Qtiff)) | ||
| 85 | imageType = @"tiff"; | ||
| 86 | |||
| 87 | types = [NSImage imageFileTypes]; | ||
| 88 | #endif | ||
| 89 | |||
| 90 | /* Check if the type is supported on this system. */ | ||
| 91 | if ([types indexOfObject:imageType] != NSNotFound) | ||
| 92 | return YES; | ||
| 93 | else | ||
| 94 | return NO; | ||
| 95 | } | ||
| 96 | |||
| 48 | void * | 97 | void * |
| 49 | ns_image_from_XBM (char *bits, int width, int height, | 98 | ns_image_from_XBM (char *bits, int width, int height, |
| 50 | unsigned long fg, unsigned long bg) | 99 | unsigned long fg, unsigned long bg) |
diff --git a/src/nsterm.h b/src/nsterm.h index f5d3c32b8b3..8d5371c8f24 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -1189,6 +1189,7 @@ extern void syms_of_nsselect (void); | |||
| 1189 | 1189 | ||
| 1190 | /* From nsimage.m, needed in image.c */ | 1190 | /* From nsimage.m, needed in image.c */ |
| 1191 | struct image; | 1191 | struct image; |
| 1192 | extern bool ns_can_use_native_image_api (Lisp_Object type); | ||
| 1192 | extern void *ns_image_from_XBM (char *bits, int width, int height, | 1193 | extern void *ns_image_from_XBM (char *bits, int width, int height, |
| 1193 | unsigned long fg, unsigned long bg); | 1194 | unsigned long fg, unsigned long bg); |
| 1194 | extern void *ns_image_for_XPM (int width, int height, int depth); | 1195 | extern void *ns_image_for_XPM (int width, int height, int depth); |