all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Can I avoid using `clear-image-cache'?
@ 2005-05-06  9:27 Mathias Dahl
  2005-05-06 10:35 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 3+ messages in thread
From: Mathias Dahl @ 2005-05-06  9:27 UTC (permalink / raw)


I am currently developing a little package, tumme.el, to browse images
in Emacs. It is similar to thumbs.el but quite different too.

I have code that inserts thumbnail versions of images into a buffer,
like this:

  (defun tumme-ins-img (file original-file-name
                             associated-dired-buffer)
    "Insert thumbnail image."
    (let (beg end tags
              (i `(image :type ,'jpeg
                         :file ,file
                         :relief ,tumme-thumb-relief
                         :margin ,tumme-thumb-margin)))
      (setq beg (point))
      (insert-image i)
      (setq end (point))
      (add-text-properties
       beg end
       (list 'original-file-name original-file-name
             'associated-dired-buffer associated-dired-buffer
             'tags (tumme-list-tags original-file-name)))))

The problem is that if I rotate the thumbnail image (using the tools
from ImageMagick), removes and inserts the image again, the image is
fetched from Emacs' image cache. Therefor I need to clear the cache
using `clear-image-cache' so that it loads the file from disk.

Now, I know that this can be done in other ways. For example
`insert-image-file' does not have this problem as it puts the image
bytes into the text properties, while they way I use `insert-image'
will insert the file name. I probably can change the code to work the
way `insert-image-file' does, but I would rather like to, in some way,
be able to flush one particular image from the image cache.

Can this be done or do I need to write a more advanced piece of code?

For now I will use `clear-image-cache' although it feels "ugly".

/Mathias

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

* Re: Can I avoid using `clear-image-cache'?
  2005-05-06  9:27 Can I avoid using `clear-image-cache'? Mathias Dahl
@ 2005-05-06 10:35 ` Thien-Thi Nguyen
  2005-05-09  6:01   ` Mathias Dahl
  0 siblings, 1 reply; 3+ messages in thread
From: Thien-Thi Nguyen @ 2005-05-06 10:35 UTC (permalink / raw)


Mathias Dahl <brakjoller.rem0veth1s@gmail.com> writes:

> I probably can change the code to work the way
> `insert-image-file' does, but I would rather like to, in some
> way, be able to flush one particular image from the image cache.
>
> Can this be done or do I need to write a more advanced piece of code?

yes. ;-)

> For now I will use `clear-image-cache' although it feels "ugly".

i just looked at image.c:1661 (lookup_image), which sez:

  /* If not found, create a new image and cache it.  */
  if (img == NULL)

probably immediately prior to this block is the best place to add
a file timestamp check.  that's not as pretty a solution as fully
generalizing the check to some kind of `:volatile VOLATILE-SPEC':

  :volatile VOLATILE-SPEC

  If VOLATILE-SPEC is t, take extra steps to check for "image
  change" so that image-cache lookup can DTRT [obviously this
  documentation can be improved ;-].  If :file is specified,
  use the timestamp of the file.  Otherwise, compute a hash of
  the data and use that to detect change.

  VOLATILE-SPEC may also be a function that takes one argument,
  either the file timestamp or the data (as a string), and returns
  non-nil to indicate that the image has changed.

i was all fired up and ready to do some quick munging and post
code (thereby procrastinating on other emacs munging for vms :-),
but then i saw how image.c leaves file loading to each image type
(not enough abstraction for my tastes) so all the gumption seeped
away...

perhaps post-release i (or someone else) will do the requisite
refactoring so that :volatile or like can be added more easily.

thi

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

* Re: Can I avoid using `clear-image-cache'?
  2005-05-06 10:35 ` Thien-Thi Nguyen
@ 2005-05-09  6:01   ` Mathias Dahl
  0 siblings, 0 replies; 3+ messages in thread
From: Mathias Dahl @ 2005-05-09  6:01 UTC (permalink / raw)


Thien-Thi Nguyen <ttn@glug.org> writes:

> i just looked at image.c:1661 (lookup_image), which sez:
>
>   /* If not found, create a new image and cache it.  */
>   if (img == NULL)
>
> probably immediately prior to this block is the best place to add
> a file timestamp check.  that's not as pretty a solution as fully
> generalizing the check to some kind of `:volatile VOLATILE-SPEC':
>
>   :volatile VOLATILE-SPEC
>
>   If VOLATILE-SPEC is t, take extra steps to check for "image
>   change" so that image-cache lookup can DTRT [obviously this
>   documentation can be improved ;-].  If :file is specified,
>   use the timestamp of the file.  Otherwise, compute a hash of
>   the data and use that to detect change.
>
>   VOLATILE-SPEC may also be a function that takes one argument,
>   either the file timestamp or the data (as a string), and returns
>   non-nil to indicate that the image has changed.
>
> i was all fired up and ready to do some quick munging and post
> code (thereby procrastinating on other emacs munging for vms :-),
> but then i saw how image.c leaves file loading to each image type
> (not enough abstraction for my tastes) so all the gumption seeped
> away...
>
> perhaps post-release i (or someone else) will do the requisite
> refactoring so that :volatile or like can be added more easily.

Sounds like a good idea. I can wait, my hack is working quite nicely
for now.

/Mathias

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

end of thread, other threads:[~2005-05-09  6:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-06  9:27 Can I avoid using `clear-image-cache'? Mathias Dahl
2005-05-06 10:35 ` Thien-Thi Nguyen
2005-05-09  6:01   ` Mathias Dahl

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.