From: Alan Third <alan@idiocy.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: juanjose.garciaripoll@gmail.com, emacs-devel@gnu.org
Subject: Re: GDI+ take 3
Date: Tue, 14 Apr 2020 23:19:45 +0100 [thread overview]
Message-ID: <20200414221945.GA96666@breton.holly.idiocy.org> (raw)
In-Reply-To: <83v9m2gdyf.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 964 bytes --]
On Tue, Apr 14, 2020 at 08:43:52PM +0300, Eli Zaretskii wrote:
> > Date: Tue, 14 Apr 2020 18:33:59 +0300
> > From: Eli Zaretskii <eliz@gnu.org>
> > Cc: emacs-devel@gnu.org
> >
> > Thanks, I've installed this now on the master branch, with some
> > changes to enable switching this feature on and off at runtime.
> > Building with this feature available is now ON by default, but to
> > actually use the feature, one needs to turn it on at runtime by
> > setting the new variable w32-use-native-image-API to a non-nil value.
>
> One more thing: Alan, as you asked, I tried to keep the changes
> extensible to NS native image display, I hope I succeeded. Please
> take a look; if something else needs to be done to make NS use the
> framework, let's talk.
Looks good, I’ve implemented the NS equivalent. The only thing missing
is the ability to force the native API off at run‐time, but I’m not
sure it’s important.
--
Alan Third
[-- Attachment #2: 0001-Use-native-image-API-for-NS.patch --]
[-- Type: text/plain, Size: 12858 bytes --]
From b21f001a21fa3f5ea6f6ffb0a2c4a753faf420b4 Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Tue, 14 Apr 2020 22:56:06 +0100
Subject: [PATCH] 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.
---
configure.ac | 25 +++++++++------
src/image.c | 89 +++++++++++++++------------------------------------
src/nsimage.m | 49 ++++++++++++++++++++++++++++
src/nsterm.h | 1 +
4 files changed, 91 insertions(+), 73 deletions(-)
diff --git a/configure.ac b/configure.ac
index b0a2cc466b..cdb8378abe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1910,6 +1910,8 @@ AC_DEFUN
bitmapdir=${bmd_acc#:}
fi
+NATIVE_IMAGE_API=no
+
test "${with_ns}" = maybe && test "${opsys}" != darwin && with_ns=no
HAVE_NS=no
NS_GNUSTEP_CONFIG=no
@@ -2021,6 +2023,11 @@ AC_DEFUN
AC_MSG_ERROR([Mac OS X 10.6 or newer is required]);
fi
fi
+
+ if test "${with_native_image_api}" = yes; then
+ AC_DEFINE(HAVE_NATIVE_IMAGE_API, 1, [Define to use native OS APIs for images.])
+ NATIVE_IMAGE_API="yes (ns)"
+ fi
fi
AC_SUBST(LIBS_GNUSTEP)
@@ -2127,7 +2134,6 @@ AC_DEFUN
NTLIB=
CM_OBJ="cm.o"
XARGS_LIMIT=
-NATIVE_IMAGE_API=no
if test "${HAVE_W32}" = "yes"; then
AC_DEFINE(HAVE_NTGUI, 1, [Define to use native MS Windows GUI.])
if test "$with_toolkit_scroll_bars" = "no"; then
@@ -3575,9 +3581,8 @@ AC_DEFUN
### Use -ljpeg if available, unless '--with-jpeg=no'.
HAVE_JPEG=no
LIBJPEG=
-if test "${NS_IMPL_COCOA}" = yes; then
- : # Cocoa provides its own jpeg support, so do nothing.
-elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes"; then
+if test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes" \
+ || test "${HAVE_NS}" = "yes"; then
if test "${with_jpeg}" != "no"; then
AC_CACHE_CHECK([for jpeglib 6b or later],
[emacs_cv_jpeglib],
@@ -3726,13 +3731,12 @@ AC_DEFUN
HAVE_PNG=no
LIBPNG=
PNG_CFLAGS=
-if test "${NS_IMPL_COCOA}" = yes; then
- : # Cocoa provides its own png support, so do nothing.
-elif test "${with_png}" != no; then
+if test "${with_png}" != no; then
# mingw32 loads the library dynamically.
if test "$opsys" = mingw32; then
AC_CHECK_HEADER([png.h], [HAVE_PNG=yes])
- elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes"; then
+ elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes" \
+ || test "${HAVE_NS}" = "yes"; then
EMACS_CHECK_MODULES([PNG], [libpng >= 1.0.0])
if test $HAVE_PNG = yes; then
LIBPNG=$PNG_LIBS
@@ -3806,7 +3810,8 @@ AC_DEFUN
if test "${HAVE_TIFF}" = "yes"; then
AC_DEFINE(HAVE_TIFF, 1, [Define to 1 if you have the tiff library (-ltiff).])
fi
-elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes"; then
+elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes" \
+ || test "${HAVE_NS}" = "yes"; then
if test "${with_tiff}" != "no"; then
AC_CHECK_HEADER(tiffio.h,
[tifflibs="-lz -lm"
@@ -3835,7 +3840,7 @@ AC_DEFUN
AC_DEFINE(HAVE_GIF, 1, [Define to 1 if you have a gif (or ungif) library.])
fi
elif test "${HAVE_X11}" = "yes" && test "${with_gif}" != "no" \
- || test "${HAVE_W32}" = "yes"; then
+ || test "${HAVE_W32}" = "yes" || test "${HAVE_NS}" = "yes"; then
AC_CHECK_HEADER(gif_lib.h,
# EGifPutExtensionLast only exists from version libungif-4.1.0b1.
# Earlier versions can crash Emacs, but version 5.0 removes EGifPutExtensionLast.
diff --git a/src/image.c b/src/image.c
index aacaf0b734..210c83a5fe 100644
--- a/src/image.c
+++ b/src/image.c
@@ -24,7 +24,7 @@ Copyright (C) 1989, 1992-2020 Free Software Foundation, Inc.
/* Include this before including <setjmp.h> to work around bugs with
older libpng; see Bug#17429. */
-#if defined HAVE_PNG && !defined HAVE_NS
+#if defined HAVE_PNG
# include <png.h>
#endif
@@ -125,6 +125,7 @@ #define PUT_PIXEL XPutPixel
#define NO_PIXMAP 0
#define PIX_MASK_RETAIN 0
+#define PIX_MASK_DRAW 1
#endif /* HAVE_NS */
@@ -6242,6 +6243,8 @@ image_can_use_native_api (Lisp_Object type)
#if HAVE_NATIVE_IMAGE_API
# ifdef HAVE_NTGUI
return w32_can_use_native_image_api (type);
+# elif defined HAVE_NS
+ return ns_can_use_native_image_api (type);
# else
return false;
# endif
@@ -6315,6 +6318,10 @@ native_image_load (struct frame *f, struct image *img)
return w32_load_image (f, img,
image_spec_value (img->spec, QCfile, NULL),
image_spec_value (img->spec, QCdata, NULL));
+# elif defined HAVE_NS
+ return ns_load_image (f, img,
+ image_spec_value (img->spec, QCfile, NULL),
+ image_spec_value (img->spec, QCdata, NULL));
# else
return 0;
# endif
@@ -6327,7 +6334,7 @@ native_image_load (struct frame *f, struct image *img)
PNG
***********************************************************************/
-#if defined (HAVE_PNG) || defined (HAVE_NS)
+#if defined (HAVE_PNG)
/* Indices of image specification fields in png_format, below. */
@@ -6378,10 +6385,10 @@ png_image_p (Lisp_Object object)
return fmt[PNG_FILE].count + fmt[PNG_DATA].count == 1;
}
-#endif /* HAVE_PNG || HAVE_NS */
+#endif /* HAVE_PNG */
-#if defined HAVE_PNG && !defined HAVE_NS
+#ifdef HAVE_PNG
# ifdef WINDOWSNT
/* PNG library details. */
@@ -6971,17 +6978,7 @@ png_load (struct frame *f, struct image *img)
return png_load_body (f, img, &c);
}
-#elif defined HAVE_NS
-
-static bool
-png_load (struct frame *f, struct image *img)
-{
- return ns_load_image (f, img,
- image_spec_value (img->spec, QCfile, NULL),
- image_spec_value (img->spec, QCdata, NULL));
-}
-
-#endif /* HAVE_NS */
+#endif /* HAVE_PNG */
\f
@@ -6989,7 +6986,7 @@ png_load (struct frame *f, struct image *img)
JPEG
***********************************************************************/
-#if defined (HAVE_JPEG) || defined (HAVE_NS)
+#if defined (HAVE_JPEG)
/* Indices of image specification fields in gs_format, below. */
@@ -7041,7 +7038,7 @@ jpeg_image_p (Lisp_Object object)
return fmt[JPEG_FILE].count + fmt[JPEG_DATA].count == 1;
}
-#endif /* HAVE_JPEG || HAVE_NS */
+#endif /* HAVE_JPEG */
#ifdef HAVE_JPEG
@@ -7543,18 +7540,6 @@ jpeg_load (struct frame *f, struct image *img)
return jpeg_load_body (f, img, &mgr);
}
-#else /* HAVE_JPEG */
-
-#ifdef HAVE_NS
-static bool
-jpeg_load (struct frame *f, struct image *img)
-{
- return ns_load_image (f, img,
- image_spec_value (img->spec, QCfile, NULL),
- image_spec_value (img->spec, QCdata, NULL));
-}
-#endif /* HAVE_NS */
-
#endif /* !HAVE_JPEG */
@@ -7563,7 +7548,7 @@ jpeg_load (struct frame *f, struct image *img)
TIFF
***********************************************************************/
-#if defined (HAVE_TIFF) || defined (HAVE_NS)
+#if defined (HAVE_TIFF)
/* Indices of image specification fields in tiff_format, below. */
@@ -7616,7 +7601,7 @@ tiff_image_p (Lisp_Object object)
return fmt[TIFF_FILE].count + fmt[TIFF_DATA].count == 1;
}
-#endif /* HAVE_TIFF || HAVE_NS */
+#endif /* HAVE_TIFF */
#ifdef HAVE_TIFF
@@ -7984,16 +7969,6 @@ tiff_load (struct frame *f, struct image *img)
return 1;
}
-#elif defined HAVE_NS
-
-static bool
-tiff_load (struct frame *f, struct image *img)
-{
- return ns_load_image (f, img,
- image_spec_value (img->spec, QCfile, NULL),
- image_spec_value (img->spec, QCdata, NULL));
-}
-
#endif
@@ -8002,7 +7977,7 @@ tiff_load (struct frame *f, struct image *img)
GIF
***********************************************************************/
-#if defined (HAVE_GIF) || defined (HAVE_NS)
+#if defined (HAVE_GIF)
/* Indices of image specification fields in gif_format, below. */
@@ -8064,7 +8039,7 @@ gif_image_p (Lisp_Object object)
return fmt[GIF_FILE].count + fmt[GIF_DATA].count == 1;
}
-#endif /* HAVE_GIF || HAVE_NS */
+#endif /* HAVE_GIF */
#ifdef HAVE_GIF
@@ -8581,18 +8556,6 @@ gif_load (struct frame *f, struct image *img)
return 1;
}
-#else /* !HAVE_GIF */
-
-#ifdef HAVE_NS
-static bool
-gif_load (struct frame *f, struct image *img)
-{
- return ns_load_image (f, img,
- image_spec_value (img->spec, QCfile, NULL),
- image_spec_value (img->spec, QCdata, NULL));
-}
-#endif /* HAVE_NS */
-
#endif /* HAVE_GIF */
@@ -10259,19 +10222,19 @@ initialize_image_type (struct image_type const *type)
{ SYMBOL_INDEX (Qsvg), svg_image_p, svg_load, image_clear_image,
IMAGE_TYPE_INIT (init_svg_functions) },
#endif
-#if defined HAVE_PNG || defined HAVE_NS
+#if defined HAVE_PNG
{ SYMBOL_INDEX (Qpng), png_image_p, png_load, image_clear_image,
IMAGE_TYPE_INIT (init_png_functions) },
#endif
-#if defined HAVE_GIF || defined HAVE_NS
+#if defined HAVE_GIF
{ SYMBOL_INDEX (Qgif), gif_image_p, gif_load, gif_clear_image,
IMAGE_TYPE_INIT (init_gif_functions) },
#endif
-#if defined HAVE_TIFF || defined HAVE_NS
+#if defined HAVE_TIFF
{ SYMBOL_INDEX (Qtiff), tiff_image_p, tiff_load, image_clear_image,
IMAGE_TYPE_INIT (init_tiff_functions) },
#endif
-#if defined HAVE_JPEG || defined HAVE_NS
+#if defined HAVE_JPEG
{ SYMBOL_INDEX (Qjpeg), jpeg_image_p, jpeg_load, image_clear_image,
IMAGE_TYPE_INIT (init_jpeg_functions) },
#endif
@@ -10421,22 +10384,22 @@ syms_of_image (void)
add_image_type (Qxpm);
#endif
-#if defined (HAVE_JPEG) || defined (HAVE_NS) || defined (HAVE_NATIVE_IMAGE_API)
+#if defined (HAVE_JPEG) || defined (HAVE_NATIVE_IMAGE_API)
DEFSYM (Qjpeg, "jpeg");
add_image_type (Qjpeg);
#endif
-#if defined (HAVE_TIFF) || defined (HAVE_NS) || defined (HAVE_NATIVE_IMAGE_API)
+#if defined (HAVE_TIFF) || defined (HAVE_NATIVE_IMAGE_API)
DEFSYM (Qtiff, "tiff");
add_image_type (Qtiff);
#endif
-#if defined (HAVE_GIF) || defined (HAVE_NS) || defined (HAVE_NATIVE_IMAGE_API)
+#if defined (HAVE_GIF) || defined (HAVE_NATIVE_IMAGE_API)
DEFSYM (Qgif, "gif");
add_image_type (Qgif);
#endif
-#if defined (HAVE_PNG) || defined (HAVE_NS) || defined(HAVE_NATIVE_IMAGE_API)
+#if defined (HAVE_PNG) || defined (HAVE_NATIVE_IMAGE_API)
DEFSYM (Qpng, "png");
add_image_type (Qpng);
#endif
diff --git a/src/nsimage.m b/src/nsimage.m
index 3cccc984ca..07750de95f 100644
--- a/src/nsimage.m
+++ b/src/nsimage.m
@@ -45,6 +45,55 @@ Updated by Christian Limpach (chris@nice.ch)
========================================================================== */
+bool
+ns_can_use_native_image_api (Lisp_Object type)
+{
+ NSString *imageType = @"unknown";
+ NSArray *types;
+
+ NSTRACE ("ns_can_use_native_image_api");
+
+ if (EQ (type, Qnative_image))
+ return YES;
+
+#ifdef NS_IMPL_COCOA
+ /* Work out the UTI of the image type. */
+ if (EQ (type, Qjpeg))
+ imageType = @"public.jpeg";
+ else if (EQ (type, Qpng))
+ imageType = @"public.png";
+ else if (EQ (type, Qgif))
+ imageType = @"com.compuserve.gif";
+ else if (EQ (type, Qtiff))
+ imageType = @"public.tiff";
+ else if (EQ (type, Qsvg))
+ imageType = @"public.svg-image";
+
+ /* NSImage also supports a host of other types such as PDF and BMP,
+ but we don't yet support these in image.c. */
+
+ types = [NSImage imageTypes];
+#else
+ /* Work out the image type. */
+ if (EQ (type, Qjpeg))
+ imageType = @"jpeg";
+ else if (EQ (type, Qpng))
+ imageType = @"png";
+ else if (EQ (type, Qgif))
+ imageType = @"gif";
+ else if (EQ (type, Qtiff))
+ imageType = @"tiff";
+
+ types = [NSImage imageFileTypes];
+#endif
+
+ /* Check if the type is supported on this system. */
+ if ([types indexOfObject:imageType] != NSNotFound)
+ return YES;
+ else
+ return NO;
+}
+
void *
ns_image_from_XBM (char *bits, int width, int height,
unsigned long fg, unsigned long bg)
diff --git a/src/nsterm.h b/src/nsterm.h
index f5d3c32b8b..8d5371c8f2 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -1189,6 +1189,7 @@ #define NSAPP_DATA2_RUNFILEDIALOG 11
/* From nsimage.m, needed in image.c */
struct image;
+extern bool ns_can_use_native_image_api (Lisp_Object type);
extern void *ns_image_from_XBM (char *bits, int width, int height,
unsigned long fg, unsigned long bg);
extern void *ns_image_for_XPM (int width, int height, int depth);
--
2.26.1
next prev parent reply other threads:[~2020-04-14 22:19 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-04 21:25 GDI+ take 3 Juan José García-Ripoll
2020-04-05 12:58 ` Eli Zaretskii
2020-04-13 6:19 ` Eli Zaretskii
2020-04-13 10:04 ` Juan José García-Ripoll
2020-04-14 15:33 ` Eli Zaretskii
2020-04-14 17:43 ` Eli Zaretskii
2020-04-14 22:19 ` Alan Third [this message]
2020-04-16 18:39 ` Eli Zaretskii
2020-04-14 18:38 ` Dmitry Gutov
2020-04-14 18:43 ` Eli Zaretskii
2020-04-14 19:38 ` Dmitry Gutov
2020-04-14 19:08 ` Basil L. Contovounesios
2020-04-14 19:24 ` Eli Zaretskii
2020-04-14 21:57 ` Basil L. Contovounesios
2020-04-15 6:18 ` Eli Zaretskii
2020-04-15 13:40 ` Juanma Barranquero
2020-04-15 14:00 ` Eli Zaretskii
2020-04-15 14:12 ` Juanma Barranquero
2020-04-15 14:17 ` Juanma Barranquero
2020-04-15 14:28 ` Eli Zaretskii
2020-04-15 14:35 ` Juanma Barranquero
2020-04-15 14:43 ` Eli Zaretskii
2020-04-15 14:47 ` Juanma Barranquero
2020-04-15 15:00 ` Juanma Barranquero
2020-04-15 15:02 ` Juanma Barranquero
2020-04-15 15:10 ` Eli Zaretskii
2020-04-15 15:31 ` Juanma Barranquero
2020-04-15 15:46 ` Eli Zaretskii
2020-04-15 15:56 ` Eli Zaretskii
2020-04-15 16:08 ` Eli Zaretskii
2020-04-15 16:50 ` Juanma Barranquero
2020-04-15 16:59 ` Eli Zaretskii
2020-04-15 17:24 ` Juanma Barranquero
2020-04-15 17:34 ` Eli Zaretskii
2020-04-15 17:49 ` Juanma Barranquero
2020-04-15 18:13 ` Eli Zaretskii
2020-04-15 18:45 ` Juanma Barranquero
2020-04-15 20:21 ` Eli Zaretskii
2020-04-15 20:31 ` Juanma Barranquero
2020-04-16 10:04 ` Eli Zaretskii
2020-04-16 23:49 ` Juanma Barranquero
2020-04-17 6:55 ` Eli Zaretskii
2020-04-17 7:27 ` Juan José García-Ripoll
2020-04-17 8:36 ` Juanma Barranquero
2020-04-17 9:52 ` Eli Zaretskii
2020-04-18 8:41 ` Juan José García-Ripoll
2020-04-18 10:00 ` Eli Zaretskii
2020-04-18 10:09 ` Juanma Barranquero
2020-04-18 12:38 ` Juan José García-Ripoll
2020-04-18 13:38 ` Eli Zaretskii
2020-04-18 15:56 ` Juanma Barranquero
2020-04-18 16:15 ` Eli Zaretskii
2020-04-18 17:51 ` Juan José García-Ripoll
2020-04-18 18:01 ` Eli Zaretskii
2020-04-18 18:04 ` Eli Zaretskii
2020-04-18 18:49 ` Juanma Barranquero
2020-04-18 19:15 ` Eli Zaretskii
2020-04-18 20:19 ` Alan Third
2020-04-19 10:20 ` Juan José García-Ripoll
2020-04-19 20:08 ` Juan José García-Ripoll
2020-04-20 13:37 ` Eli Zaretskii
2020-04-21 7:35 ` Juan José García-Ripoll
2020-04-21 14:15 ` Eli Zaretskii
2020-04-21 18:17 ` Alan Third
2020-04-21 18:34 ` Eli Zaretskii
2020-04-25 16:51 ` Alan Third
2020-04-20 20:16 ` Alan Third
2020-04-21 6:25 ` Juan José García-Ripoll
2020-04-25 16:23 ` Alan Third
2020-04-25 13:42 ` Eli Zaretskii
2020-04-26 15:14 ` Juan José García-Ripoll
2020-04-19 18:16 ` Eli Zaretskii
2020-04-19 20:28 ` Juan José García-Ripoll
2020-04-20 13:54 ` Eli Zaretskii
2020-04-21 6:44 ` Juan José García-Ripoll
2020-04-21 14:13 ` Eli Zaretskii
2020-04-21 16:20 ` Juan José García-Ripoll
2020-04-15 16:50 ` Eli Zaretskii
2020-04-15 14:27 ` Eli Zaretskii
[not found] <617217672.240027.1586079490291@mail1.libero.it>
2020-04-15 14:07 ` Angelo Graziosi
2020-04-15 14:15 ` Eli Zaretskii
2020-04-15 14:22 ` Angelo Graziosi
2020-04-15 14:26 ` Eli Zaretskii
2020-04-15 15:25 ` Angelo Graziosi
2020-04-15 15:27 ` Eli Zaretskii
2020-04-15 15:46 ` Angelo Graziosi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200414221945.GA96666@breton.holly.idiocy.org \
--to=alan@idiocy.org \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=juanjose.garciaripoll@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.