fongoses / leptonica

Automatically exported from code.google.com/p/leptonica
0 stars 0 forks source link

Alpha channel in color maps #82

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I'm not sure this is the right place to report this, but I could not find a 
group or something similar for Leptonica.

I'm currently developing a project to serve responsive images with Node.js: 
https://github.com/ngryman/ribs. I've chosen Leptonica as a "backend" because 
it provides all I need in on place, and is pretty easy to use.

I want to expose pixel's data through my API, I need it to be normalized as 
ARGB. The Pix structure already does that, this is great. But this is not the 
case with color mapped images (either 8-bit PNGs or GIF). To normalize them, I 
use pixRemoveColormap with REMOVE_CMAP_TO_FULL_COLOR. The problem is that alpha 
information does not seems to be retrieved during this conversion.

As I was navigating through the docs, I saw: "The returned alpha channel value 
is zero, because it is not used in leptonica colormaps." for pixcmapGetColor32.

Does this means that if a colormap contains alpha information, this is not 
supported by Leptonica? Or is there a workaround to retrieve this information 
somehow?

This is really important for me as losing alpha won't be option for users.

Thanks very much.

Original issue reported on code.google.com by ngry...@gmail.com on 8 Sep 2013 at 8:43

GoogleCodeExporter commented 9 years ago
Some additional information:
 - Here is my test suite: https://github.com/ngryman/ribs/blob/master/test/unit/operations/open.js#L79. The commented tests fail.
 - Here is where I use Leptonica to read images: https://github.com/ngryman/ribs/blob/master/src/image_decoder.cc#L146

Not that I also set l_pngSetStripAlpha(0) to support alpha, here: 
https://github.com/ngryman/ribs/blob/master/src/image_decoder.cc#L41

Original comment by ngry...@gmail.com on 8 Sep 2013 at 8:49

GoogleCodeExporter commented 9 years ago
Ngry,

You've made a reasonable request.   Support of colormaps in leptonica has 
gradually been improved over the past few years.  leptonica now supports all 
the png alpha formats for reading, and handles images with alpha in a more 
uniform and logical way: spp = 4 indicates a valid alpha channel, and this is 
used in several operations, such as affine transforms.

There is no reason why we can't support the conversion to 32 bpp rgba.  This 
would take another flag, REMOVE_CMAP_WITH_ALPHA, for pixRemoveColormap().  And 
it seems we'd need new functions: pixcmapGetRGBA(), pixcmapGetRGBA32() and 
composeRGBAPixel(), in analogy with the existing 'Color' functions.  

But note that the order of samples in the 32-bit word, as defined in pix.h, is 
RGBA, not ARGB, for leptonica operations that depend on the byte order.

If you believe that would resolve your issue, I'll add this and send you a beta 
1.70 distribution.

Original comment by dbloomb...@google.com on 9 Sep 2013 at 12:15

GoogleCodeExporter commented 9 years ago
Thanks for your quick response.

This would be awesome :)

Original comment by ngry...@gmail.com on 9 Sep 2013 at 4:12

GoogleCodeExporter commented 9 years ago
Just wanted to let you know that alpha support with colormaps has been 
implemented and will go out in 1.70, around 20 Jan 14.  You will be able to see 
how it works in the regression test prog/alpha_ops.reg.

Thanks for the good suggestion.

Original comment by dan.bloo...@gmail.com on 17 Jan 2014 at 1:42

GoogleCodeExporter commented 9 years ago
1.70 is out.  YOu can get it at:  leptonica.org/download.html

Original comment by dan.bloo...@gmail.com on 23 Jan 2014 at 8:50