imagej / imagej2

Open scientific N-dimensional image processing :microscope: :sparkler:
https://imagej.net/
BSD 2-Clause "Simplified" License
1.2k stars 337 forks source link

better APNG support #193

Open oeway opened 6 years ago

oeway commented 6 years ago

As an alternative to animated GIF format, APNG has the advantage of being lossless, small in size, support more color depth(16-bit grayscale for example) and supported by most modern browsers etc.

APNG vs GIF (please use a supported browser to see)

Many of these advantages make APNG a light-weight alternative to tif format in some applications, for example sometimes we want to exchange image data between an ImageJ backend and a web browser user interface.

Since ImageJ2 uses SCIFIO by default to open images, we can already import and export multi-frame APNG images (With "Import->Image..." menu and "Export-> Image..." menu).

So now, would it be possible to consider the following features in ImageJ2?

  1. add a menu entry called "Animated PNG" in "Save As"
  2. when applying "Save As -> png" for a image stack, save the whole stack as a APNG image by default. (currently, it will convert the first frame to RGB mode and only save the first frame as a png image)
  3. load all frames when opening a APNG file (already the case when enabling "Use SCIFIO when opening files" option)
ctrueden commented 6 years ago

Thanks for your report, @oeway, and very sorry for the long delay in reply.

add a menu entry called "Animated PNG" in "Save As"

Why is a dedicated menu item necessary? Is File > Export > Image... not enough?

when applying "Save As -> png" for a image stack, save the whole stack as a APNG image by default. (currently, it will convert the first frame to RGB mode and only save the first frame as a png image)

That is an ImageJ1 command, so would require changes to ImageJ1. Or (more fragile) some hackery in the ImageJ Legacy component to override how IJ1 normally works. I'd prefer to leave the IJ1 functionality alone, since hacking on IJ1 compatibility/enhancements consumes valuable developer time that is more effectively spent on making the IJ2 code better.

load all frames when opening a APNG file (already the case when enabling "Use SCIFIO when opening files" option)

Some day, I hope to have "Use SCIFIO" on by default. The reason it is not on by default now is because the performance of TIFF is too slow compared to IJ1. And no one currently has time to remedy the situation. But eventually, it will happen!

oeway commented 6 years ago

Hi, Thanks for your reply.

Why is a dedicated menu item necessary? Is File > Export > Image... not enough?

It's actually a bit confusing to me about the difference with "Save as" and "Export". Since most of the file formats have an entry in the "Save as" entry, and for GIF format, there are even two (Gif and Animated Gif), I think it's logical to place "Animated png" together with "Animated Gif".