Java – can I use libjpeg to read JPEG with alpha channel?

There seems to be some debate about whether JPEG of alpha channel is effective I always think the correct answer is that in the JPEG FAQ, which is essentially "no" (this was reiterated in January 2007)

However, the Java jpegimagewriter in sun's imageio library will be happy to write and read grayscale and RGB images using the alpha channel. Although there are few applications on Linux, I have tried to load such JPEG correctly This bug has been reported in the past, but sun's response is these are valid files:

I am using a Java application to create such files and want to write some C code to load them as soon as possible (in essence, the problem is that the Java imageio library is very slow when decompressing these files. We hope to improve this by replacing the native code of the loader through JNI - this is the current performance bottleneck.)

Here are some sample files – apologize to anyone who could rophobic:

> http://mythic-beasts.com/ ~mark/example-jpegs/

Here, you can see the results of trying to view gray alpha and RGB alpha images of various linux software using libjpeg:

grayscale image with alpha channel view with various programs http://mythic-beasts.com/ ~mark/all-alpha-bridges. png

RGB image with alpha channel view with various programs http://mythic-beasts.com/ ~mark/all-alpha-clowns. png

So it seems that color space is misunderstood in every case jpeglib. The only allowed values in H are:

/* KNown color spaces. */

typedef enum {
        JCS_UNKNowN,/* error/unspecified */
        JCS_GRAYSCALE,/* monochrome */
        JCS_RGB,/* red/green/blue */
        JCS_YCbCr,/* Y/Cb/Cr (also kNown as YUV) */
        JCS_CMYK,/* C/M/Y/K */
        JCS_YCCK                /* Y/Cb/Cr/K */
} J_COLOR_SPACE;

... doesn't look promising

If I use a slightly modified version of libjpeg, example C load these images and read the Cinfo of each image after the title jpeg_ color_ Space and Cinfo out_ color_ The value of space is as follows:

gray-normal.jpg: jpeg_color_space is JCS_GRAYSCALE,out_color_space is JCS_GRAYSCALE
gray-alpha.jpg: jpeg_color_space is JCS_CMYK,out_color_space is JCS_CMYK

rgb-normal.jpg: jpeg_color_space is JCS_YCbCr,out_color_space is JCS_RGB
rgb-alpha.jpg: jpeg_color_space is JCS_CMYK,out_color_space is JCS_CMYK

So my question is:

>Can I use libjpeg to read these files correctly? > If not, is there an alternative C library available to handle them?

Obviously, at least two other solutions are more common problems:

>Change the software to output PNG files of normal JPEG representing alpha channel > improve the performance of sun's imageio in some way

... but the first one will involve a lot of code changes, and it's not clear how to do the latter In any case, I think the problem of how to load such files using libjpeg may be of more general interest

Any suggestions would be appreciated

Solution

Have you ever tried libjpeg turbo? It should be able to decode RGBA and already have a Java wrapper

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>