java – 我可以使用libjpeg来读取带Alpha通道的JPEG吗?

前端之家收集整理的这篇文章主要介绍了java – 我可以使用libjpeg来读取带Alpha通道的JPEG吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有关Alpha通道的JPEG是否有效的似乎有一些争论.我一直认为是正确的答案是 that in the JPEG FAQ,这本质上是“否”. (这是在07年1月重申的)

然而,Sun的ImageIO库中的Java JPEGImageWriter将很乐意地使用Alpha通道编写和读取灰度和RGB图像,尽管在Linux上几乎没有任何应用程序,我已经尝试过,将正确加载这样的JPEG.过去曾经报道过这个bug,但是Sun的回应是these are valid files

This is not an Image I/O bug,but rather a deficiency in the other applications
the submitter mentions. The IIO JPEGImageWriter is able to write images with
a color model that contains an alpha channel (referred to in the IJG native
source code as the “NIFTY” color spaces,such as RGBA,YCbCrA,etc.),but many applications are not aware of these color spaces. So even though these images
written by the IIO JPEG writer are compliant with the JPEG specification (which
is blind to the varIoUs color space possiblities),some applications may not
recognize color spaces that contain an alpha channel and may throw an
error or render a corrupted image,as the submitter describes.

Developers wishing to maintain compatibility with these other alpha-unaware
applications should write images that do not contain an alpha channel (such as
TYPE_INT_RGB). Developers who want the capability of writing/reading an image
containing an alpha channel in the JPEG format can do so using the Image I/O
API,but need to be aware that many native applications out there are not quite
compliant with the YCbCrA and RGBA formats.

For more information,see the Image I/O JPEG Metadata Format Specification and Usage Notes:
07003

Closing as “not a bug”.
xxxxx@xxxxx 2003-03-24

我正在使用一个Java应用程序来创建这样的文件,并且想要编写一些尽可能快地加载它们的C代码. (本质上,问题是解压缩这些文件时,Java ImageIO库非常慢,我们希望通过JNI替换加载程序的本机代码,从而改善这一点 – 这是目前的性能瓶颈.)

这里有一些示例文件 – 向任何coulrophobic的人道歉:

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

在这里,您可以看到尝试查看使用libjpeg的各种Linux软件的灰度alpha和RGB alpha图像的结果:

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

所以看起来好像在每种情况下颜色空间都被误解了. jpeglib.h中唯一允许的值为:

/* 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;

…看起来不太有希望

如果我使用libjpeg的一个稍微修改版本的example.c加载这些图像,读取标题后每个图像的cinfo.jpeg_color_space和cinfo.out_color_space的值如下所示:

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

所以我的问题是:

>可以使用libjpeg来正确读取这些文件吗?
>如果没有,是否有可以使用的替代C库可以处理它们?

显而易见,至少有两个其他的@R_301_463@案是更普遍的问题:

>更改软件以输出普通JPEG代表Alpha通道的PNG文件
>以某种方式提高Sun的ImageIO的性能

…但第一个将涉及很多代码更改,并不清楚如何去做后者.在任何情况下,我认为如何使用libjpeg加载这样的文件的问题可能是更普遍的兴趣.

任何建议将不胜感激.

解决方法

你有没有试过 libjpeg-turbo?它应该能够解码RGBA,并且已经有一个Java包装器.
原文链接:https://www.f2er.com/java/124003.html

猜你在找的Java相关文章