unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#21714: 25.0.50; image-metadata using Emacs --with-ns prevents *.gif animation.
@ 2015-10-19 16:29 Keith David Bershatsky
  2015-10-19 23:40 ` Xue Fuqiao
  2017-08-13  0:58 ` bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714) Alan Third
  0 siblings, 2 replies; 9+ messages in thread
From: Keith David Bershatsky @ 2015-10-19 16:29 UTC (permalink / raw)
  To: 21714

When using Emacs built --with-ns on OSX 10.6.8, the function `image-metadata` returns `nil` when trying to animate a *.gif file with the built-in image-mode by pressing the return key.  I suspect it is because `valid_image_p` returns `nil`, but I do not know how to test that internal function.

When opening a *.gif image, Emacs successfully displays the first image in the series of multiple images.  Pressing the return key yields:  "No image animation."

OSX has its own built-in image support when building --with-ns, which is why I am able to see the first of the *.gif images.

(image-type-available-p 'gif) returns t, so I am fairly certain I have image support.

Animation works on Emacs for Windows, but not OSX.

Thanks,

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

In GNU Emacs 25.0.50.1 (x86_64-apple-darwin10.8.0, NS appkit-1038.36 Version 10.6.8 (Build 10K549))
 of 2015-10-13
Repository revision: 6d6bf466477b004035a4314886e35214c6f8603b
Windowing system distributor 'Apple', version 10.3.1038
Configured using:
 'configure --with-ns --without-imagemagick --enable-checking=glyphs'

Configured features:
RSVG DBUS ACL LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS

Important settings:
  locale-coding-system: utf-8-unix

Major mode: C

Minor modes in effect:
  tb-mode: t
  sb-mode: t
  ml-mode: t
  sd-mode: t
  fl-mode: t
  bc-mode: t
  +-mode: t
  buffer-read-only: t
  abbrev-mode: t

Recent messages:
Type C-c C-c to view the image as text.
Wrote /Users/HOME/.0.data/.0.emacs/.lock
Emacs:  image-metadata
*beep*
if: End of buffer

Load-path shadows:
None found.

Features:
(shadow emacsbug sendmail lawlist-ztree lawlist-ys lawlist-ws
lawlist-wl elmo-imap4 elmo-localdir modb-standard modb-legacy
elmo-internal elmo-flag mmelmo-imap mmelmo-buffer elsp-generic mel-u
ps-print ps-def lpr epg-config enriched lawlist-w3m doc-view jka-compr
image-mode ccl lawlist-vl lawlist-view lawlist-undo lawlist-txt
lawlist-tm lawlist-tex compare-w lawlist-tabbar lawlist-speedbar
lawlist-shell info esh-groups ehelp ange-ftp lawlist-sgml lawlist-sb
lawlist-saveplace lawlist-ruler lawlist-replace lawlist-rectangle
lawlist-re-builder lawlist-python skeleton lawlist-profiler
lawlist-print lawlist-php cl-seq cc-langs lawlist-perl lawlist-parens
lawlist-org lawlist-calendar org-agenda org org-macro org-footnote
org-pcomplete org-list org-faces org-entities org-version
ob-emacs-lisp ob ob-tangle ob-ref ob-lob ob-table ob-exp org-src
ob-keys ob-comint ob-core ob-eval org-compat org-macs org-loaddefs
find-func holidays hol-loaddefs cal-menu calendar cal-loaddefs
lawlist-neotree lawlist-movement lawlist-mouse lawlist-ml lawlist-misc
lawlist-messages lawlist-mc rect lawlist-markdown noutline outline
lawlist-lorem lawlist-ln lawlist-keymap lawlist-js cc-mode cc-fonts
cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs
lawlist-ispell lawlist-isearch lawlist-imenu lawlist-ibuffer
lawlist-hl lawlist-grep lawlist-git ido seq vc-git vc vc-dispatcher
thingatpt time-stamp subr-x server nntp gnus-group gnus-undo
gnus-start gnus-cloud nnimap nnmail mail-source tls utf7 netrc
parse-time gnus-spec gnus-int gnus-range gnus-win nnoo mm-view
mml-smime smime dig mailcap log-edit message mml mml-sec mm-decode
mm-bodies mm-encode gmm-utils mailheader pcvs-util add-log ldap json
find-lisp ediff-merg ediff-wind ediff-diff ediff-mult ediff-help
ediff-init ediff-util ediff diff-mode conf-mode autorevert filenotify
lawlist-framebufs lawlist-frame lawlist-fm lawlist-files zeroconf dbus
xml lawlist-env lawlist-elscreen lawlist-elisp lawlist-dv
lawlist-image lawlist-ds lawlist-dired dired format-spec lawlist-diff
lawlist-desktop frameset lawlist-debug lawlist-window debug
lawlist-css smie lawlist-compile rx lawlist-color lawlist-cm
lawlist-cc lawlist-font-lock cl-macs lawlist-calc lawlist-calc+
lawlist-bk lawlist-bc lawlist-bbdb gnus gnus-ems nnheader mail-utils
wid-edit mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mailabbrev
mail-extr rfc822 timezone lawlist-minibuffer gv lawlist-auth gnus-util
mm-util help-fns mail-prsvr password-cache lawlist-as lawlist-archive
lawlist-+ lawlist-lcl byte-opt bytecomp byte-compile cl-extra cconv
lawlist-help disp-table easy-mmode edmacro kmacro quail help-mode
easymenu cl-loaddefs cl-lib pcase derived advice shell pcomplete
comint ansi-color ring savehist time-date mule-util tooltip eldoc
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel ns-win
term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese
eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese charscript case-table epa-hook jka-cmpr-hook
help simple abbrev minibuffer cl-preloaded nadvice loaddefs button
faces cus-face macroexp files text-properties overlay sha1 md5 base64
format env code-pages mule custom widget hashtable-print-readable
backquote dbusbind cocoa ns multi-tty make-network-process emacs)

Memory information:
((conses 16 2395843 198980)
 (symbols 48 89769 0)
 (miscs 40 1373 1067)
 (strings 32 212905 17549)
 (string-bytes 1 7685690)
 (vectors 16 44361)
 (vector-slots 8 1091868 14715)
 (floats 8 4334 755)
 (intervals 56 1101 110)
 (buffers 976 15))





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#21714: 25.0.50; image-metadata using Emacs --with-ns prevents *.gif animation.
  2015-10-19 16:29 bug#21714: 25.0.50; image-metadata using Emacs --with-ns prevents *.gif animation Keith David Bershatsky
@ 2015-10-19 23:40 ` Xue Fuqiao
  2017-08-13  0:58 ` bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714) Alan Third
  1 sibling, 0 replies; 9+ messages in thread
From: Xue Fuqiao @ 2015-10-19 23:40 UTC (permalink / raw)
  To: Keith David Bershatsky; +Cc: 21714

On Tue, Oct 20, 2015 at 12:29 AM, Keith David Bershatsky
<esq@lawlist.com> wrote:
> When opening a *.gif image, Emacs successfully displays the first image in the series of multiple images.  Pressing the return key yields:  "No image animation."

Yes, I can reproduce this problem on OS X 10.11 with Emacs master.

Configured features:
ACL LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714)
  2015-10-19 16:29 bug#21714: 25.0.50; image-metadata using Emacs --with-ns prevents *.gif animation Keith David Bershatsky
  2015-10-19 23:40 ` Xue Fuqiao
@ 2017-08-13  0:58 ` Alan Third
  2017-08-13 13:21   ` npostavs
  2017-08-14 16:02   ` Charles A. Roelli
  1 sibling, 2 replies; 9+ messages in thread
From: Alan Third @ 2017-08-13  0:58 UTC (permalink / raw)
  To: Keith David Bershatsky; +Cc: 21714

* src/nsimage.m (image_spec_value): New function.
(ns_load_image): Handle multiple frames.
(EmacsImage::getMetadata, EmacsImage::setFrame): New function.
* src/nsterm.h (EmacsImage::getMetadata, EmacsImage::setFrame): New
function prototypes.
---
 src/nsimage.m | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/nsterm.h  |  2 ++
 2 files changed, 81 insertions(+)

diff --git a/src/nsimage.m b/src/nsimage.m
index fb2322afc3..6717202199 100644
--- a/src/nsimage.m
+++ b/src/nsimage.m
@@ -70,12 +70,38 @@ Updated by Christian Limpach (chris@nice.ch)
   return [EmacsImage allocInitFromFile: file];
 }
 
+static Lisp_Object
+image_spec_value (Lisp_Object spec, Lisp_Object key, bool *found)
+{
+  Lisp_Object tail;
+
+  eassert (valid_image_p (spec));
+
+  for (tail = XCDR (spec);
+       CONSP (tail) && CONSP (XCDR (tail));
+       tail = XCDR (XCDR (tail)))
+    {
+      if (EQ (XCAR (tail), key))
+	{
+	  if (found)
+	    *found = 1;
+	  return XCAR (XCDR (tail));
+	}
+    }
+
+  if (found)
+    *found = 0;
+  return Qnil;
+}
+
 bool
 ns_load_image (struct frame *f, struct image *img,
                Lisp_Object spec_file, Lisp_Object spec_data)
 {
   EmacsImage *eImg = nil;
   NSSize size;
+  Lisp_Object lisp_index = image_spec_value (img->spec, QCindex, NULL);
+  unsigned int index = INTEGERP (lisp_index) ? XFASTINT (lisp_index) : 0;
 
   NSTRACE ("ns_load_image");
 
@@ -99,12 +125,20 @@ Updated by Christian Limpach (chris@nice.ch)
       return 0;
     }
 
+  if (index < 0 || ![eImg setFrame: index])
+    {
+      add_to_log ("Unable to set index %d for image %s", index, img->spec);
+      return 0;
+    }
+
   size = [eImg size];
   img->width = size.width;
   img->height = size.height;
 
   /* 4) set img->pixmap = emacsimage */
   img->pixmap = eImg;
+
+  img->lisp_data = [eImg getMetadata];
   return 1;
 }
 
@@ -435,4 +469,49 @@ - (NSColor *)stippleMask
   return stippleMask;
 }
 
+/* If the image has multiple frames, get a count of them and the
+   animation delay, if available. */
+- (Lisp_Object)getMetadata
+{
+  Lisp_Object metadata = Qnil;
+
+  for (NSImageRep * r in [self representations])
+    {
+      if ([r isKindOfClass:[NSBitmapImageRep class]])
+        {
+          NSBitmapImageRep * bm = (NSBitmapImageRep *)r;
+          int frames = [[bm valueForProperty: NSImageFrameCount] intValue];
+          float delay = [[bm valueForProperty: NSImageCurrentFrameDuration]
+                          floatValue];
+
+          if (frames > 1)
+            metadata = Fcons (Qcount, Fcons (make_number (frames), metadata));
+          if (delay > 0)
+            metadata = Fcons (Qdelay, Fcons (make_float (delay), metadata));
+          break;
+        }
+    }
+  return metadata;
+}
+
+/* Attempt to set the animation frame to be displayed. */
+- (BOOL)setFrame: (unsigned int) index
+{
+  for (NSImageRep * r in [self representations])
+    {
+      if ([r isKindOfClass:[NSBitmapImageRep class]])
+        {
+          NSBitmapImageRep * bm = (NSBitmapImageRep *)r;
+          if ([[bm valueForProperty: NSImageFrameCount] intValue] <= index)
+            continue;
+
+          [bm setProperty: NSImageCurrentFrame
+                withValue: [NSNumber numberWithUnsignedInt: index]];
+          return YES;
+        }
+    }
+
+  return NO;
+}
+
 @end
diff --git a/src/nsterm.h b/src/nsterm.h
index 0f1b36db7b..67c0d42ac1 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -668,6 +668,8 @@ typedef id instancetype;
               alpha:(unsigned char)a;
 - (void)setAlphaAtX: (int)x Y: (int)y to: (unsigned char)a;
 - (NSColor *)stippleMask;
+- (Lisp_Object)getMetadata;
+- (BOOL)setFrame: (unsigned int) index;
 @end
 
 
-- 

Animated gif support, and I expect it to handle tiff with multiple
layers, or whatever.

-- 
Alan Third





^ permalink raw reply related	[flat|nested] 9+ messages in thread

* bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714)
  2017-08-13  0:58 ` bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714) Alan Third
@ 2017-08-13 13:21   ` npostavs
  2017-08-13 13:37     ` Alan Third
  2017-08-14 16:02   ` Charles A. Roelli
  1 sibling, 1 reply; 9+ messages in thread
From: npostavs @ 2017-08-13 13:21 UTC (permalink / raw)
  To: Alan Third; +Cc: Keith David Bershatsky, 21714

Alan Third <alan@idiocy.org> writes:
 
> +static Lisp_Object
> +image_spec_value (Lisp_Object spec, Lisp_Object key, bool *found)
> +{
> +  Lisp_Object tail;
> +
> +  eassert (valid_image_p (spec));
> +
> +  for (tail = XCDR (spec);
> +       CONSP (tail) && CONSP (XCDR (tail));
> +       tail = XCDR (XCDR (tail)))
> +    {
> +      if (EQ (XCAR (tail), key))
> +	{
> +	  if (found)
> +	    *found = 1;
> +	  return XCAR (XCDR (tail));
> +	}
> +    }

Wouldn't it be clearer to call Fplist_get here?





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714)
  2017-08-13 13:21   ` npostavs
@ 2017-08-13 13:37     ` Alan Third
  2017-08-13 13:54       ` npostavs
  0 siblings, 1 reply; 9+ messages in thread
From: Alan Third @ 2017-08-13 13:37 UTC (permalink / raw)
  To: npostavs; +Cc: Keith David Bershatsky, 21714

On Sun, Aug 13, 2017 at 09:21:44AM -0400, npostavs@users.sourceforge.net wrote:
> Alan Third <alan@idiocy.org> writes:
>  
> > +static Lisp_Object
> > +image_spec_value (Lisp_Object spec, Lisp_Object key, bool *found)
> > +{
> > +  Lisp_Object tail;
> > +
> > +  eassert (valid_image_p (spec));
> > +
> > +  for (tail = XCDR (spec);
> > +       CONSP (tail) && CONSP (XCDR (tail));
> > +       tail = XCDR (XCDR (tail)))
> > +    {
> > +      if (EQ (XCAR (tail), key))
> > +	{
> > +	  if (found)
> > +	    *found = 1;
> > +	  return XCAR (XCDR (tail));
> > +	}
> > +    }
> 
> Wouldn't it be clearer to call Fplist_get here?

Yes I think it would. I actually just copied the code from image.c, so
would it maybe be worth tidying up that code too?

Thanks!
-- 
Alan Third





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714)
  2017-08-13 13:37     ` Alan Third
@ 2017-08-13 13:54       ` npostavs
  2017-08-13 14:56         ` Alan Third
  0 siblings, 1 reply; 9+ messages in thread
From: npostavs @ 2017-08-13 13:54 UTC (permalink / raw)
  To: Alan Third; +Cc: Keith David Bershatsky, 21714

Alan Third <alan@idiocy.org> writes:

> On Sun, Aug 13, 2017 at 09:21:44AM -0400, npostavs@users.sourceforge.net wrote:
>> Alan Third <alan@idiocy.org> writes:
>>  
>> > +static Lisp_Object
>> > +image_spec_value (Lisp_Object spec, Lisp_Object key, bool *found)
>> > +{
>> > +  Lisp_Object tail;
>> > +
>> > +  eassert (valid_image_p (spec));
>> > +
>> > +  for (tail = XCDR (spec);
>> > +       CONSP (tail) && CONSP (XCDR (tail));
>> > +       tail = XCDR (XCDR (tail)))
>> > +    {
>> > +      if (EQ (XCAR (tail), key))
>> > +	{
>> > +	  if (found)
>> > +	    *found = 1;
>> > +	  return XCAR (XCDR (tail));
>> > +	}
>> > +    }
>> 
>> Wouldn't it be clearer to call Fplist_get here?

Actually we would need Fplist_member to set the 'found' parameter
correctly in case the value is Qnil.  Hmm, that one can signal an error,
so potentially it's not the right thing.

> Yes I think it would. I actually just copied the code from image.c, so
> would it maybe be worth tidying up that code too?

Oh, maybe we should make it non-static and call it rather than copying
then?





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714)
  2017-08-13 13:54       ` npostavs
@ 2017-08-13 14:56         ` Alan Third
  0 siblings, 0 replies; 9+ messages in thread
From: Alan Third @ 2017-08-13 14:56 UTC (permalink / raw)
  To: npostavs; +Cc: Keith David Bershatsky, 21714

On Sun, Aug 13, 2017 at 09:54:39AM -0400, npostavs@users.sourceforge.net wrote:
> Alan Third <alan@idiocy.org> writes:
> 
> > On Sun, Aug 13, 2017 at 09:21:44AM -0400, npostavs@users.sourceforge.net wrote:
> >> Alan Third <alan@idiocy.org> writes:
> >>  
> >> > +static Lisp_Object
> >> > +image_spec_value (Lisp_Object spec, Lisp_Object key, bool *found)
> >> > +{
> >> > +  Lisp_Object tail;
> >> > +
> >> > +  eassert (valid_image_p (spec));
> >> > +
> >> > +  for (tail = XCDR (spec);
> >> > +       CONSP (tail) && CONSP (XCDR (tail));
> >> > +       tail = XCDR (XCDR (tail)))
> >> > +    {
> >> > +      if (EQ (XCAR (tail), key))
> >> > +	{
> >> > +	  if (found)
> >> > +	    *found = 1;
> >> > +	  return XCAR (XCDR (tail));
> >> > +	}
> >> > +    }
> >> 
> >> Wouldn't it be clearer to call Fplist_get here?
> 
> Actually we would need Fplist_member to set the 'found' parameter
> correctly in case the value is Qnil.  Hmm, that one can signal an error,
> so potentially it's not the right thing.

In this particular case I’m not using the found parameter anyway so
Fplist_get will work fine.

-- 
Alan Third





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714)
  2017-08-13  0:58 ` bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714) Alan Third
  2017-08-13 13:21   ` npostavs
@ 2017-08-14 16:02   ` Charles A. Roelli
  2017-08-16 20:27     ` Alan Third
  1 sibling, 1 reply; 9+ messages in thread
From: Charles A. Roelli @ 2017-08-14 16:02 UTC (permalink / raw)
  To: Alan Third; +Cc: esq, 21714

Thanks for adding this feature.  It's working on my end.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714)
  2017-08-14 16:02   ` Charles A. Roelli
@ 2017-08-16 20:27     ` Alan Third
  0 siblings, 0 replies; 9+ messages in thread
From: Alan Third @ 2017-08-16 20:27 UTC (permalink / raw)
  To: Charles A. Roelli; +Cc: esq, 21714-done

On Mon, Aug 14, 2017 at 06:02:26PM +0200, Charles A. Roelli wrote:
> Thanks for adding this feature.  It's working on my end.

Thanks. It’s pushed to master now.
-- 
Alan Third





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-08-16 20:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-19 16:29 bug#21714: 25.0.50; image-metadata using Emacs --with-ns prevents *.gif animation Keith David Bershatsky
2015-10-19 23:40 ` Xue Fuqiao
2017-08-13  0:58 ` bug#21714: [PATCH] Add multiframe image support to NS port (bug#21714) Alan Third
2017-08-13 13:21   ` npostavs
2017-08-13 13:37     ` Alan Third
2017-08-13 13:54       ` npostavs
2017-08-13 14:56         ` Alan Third
2017-08-14 16:02   ` Charles A. Roelli
2017-08-16 20:27     ` Alan Third

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).