硬汉嵌入式论坛

 找回密码
 立即注册
查看: 5531|回复: 1
收起左侧

[LibJPEG] 【LibJPEG专题系列十二】透明JPEG可否存在

[复制链接]

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
发表于 2015-4-30 16:10:30 | 显示全部楼层 |阅读模式
                                  Section 12透明JPEG可否存在?
    答案是否定的。JPEG不支持透明度,而且任何时候也不会很快实现。事实证明,给JPEG添加透明度
不是一个简单的事情,想了解更多细节,请继续阅读。


    正如在GIF以及其他文件格式中所展示的,透明度的传统做法是选择一个未使用过的不同的颜色值来
表示一个透明的像素。由于JPEG是有损的(处理后的像素不一定正好是它最开始的颜色),因而这种做
法不能在JPEG中实现。通常情况下,一个像素上的小误差是可以的,是因为它只是轻微的影响整个图像。
但是,如果将像素从透明改成一般颜色或相反,误差将会非常明显且令人讨厌,特别是当实际背景和透明
色相差甚远的时候。


    一个更合理的做法是存储alpha通道(透明度百分比)作为JPEG图像的单独色彩分量。这种方法行得通,
是因为alpha中的小误差只会对结果造成很小的差别。而问题在于,一个典型的alpha通道正好是JPEG最不
擅长的图像类型:很多大的平坦区域以及突然的跳跃。你需使用一个非常高的质量参数到alpha通道。可以
这样做,但代价就是文件将会很大。这种方式做的透明JPEG将很容易是非透明JPEG的两倍大小。对于大
多数透明度的使用来说,代价实在是太大了。


    唯一可行的解决办法是将图像的有损JPEG存储以及使用一些其他算法的透明掩码的无损存储结合起来。
这样做所需要的开发、规范以及推广文件格式的能力不是一个小事。至少在我看来,没有比这样做更严肃
的了,而且透明度并不值得那么大的精力。
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2015-4-30 16:12:23 | 显示全部楼层
                       Section - [12] Can I make a transparent JPEG?

No.  JPEG does not support transparency and is not likely to do so any time soon.  It turns out that adding transparency
to JPEG would not be a simple task; read on if you want the gory details.


The traditional approach to transparency, as found in GIF and some other file formats, is to choose one otherwise-unused
color value to denote a transparent pixel.  That can't work in JPEG because JPEG is lossy: a pixel won't necessarily come
out *exactly* the same color that it started as. Normally, a small error in a pixel value is OK because it affects the image
only slightly.  But if it changes the pixel from transparent to normal or vice versa, the error would be highly visible and
annoying, especially if the actual background were quite different from the transparent color.


A more reasonable approach is to store an alpha channel (transparency percentage) as a separate color component in a
JPEG image.  That could work since a small error in alpha makes only a small difference in the result. The problem is that
a typical alpha channel is exactly the sort of image that JPEG does very badly on: lots of large flat areas and sudden jumps.
You'd have to use a very high quality setting for the alpha channel.  It could be done, but the penalty in file size is large.  A
transparent JPEG done this way could easily be double the size of a non-transparent JPEG. That's too high a price to pay
for most uses of transparency.


The only real solution is to combine lossy JPEG storage of the image with lossless storage of a transparency mask using
some other algorithm. Developing, standardizing, and popularizing a file format capable of doing that is not a small task.  
As far as I know, no serious work is being done on it; transparency doesn't seem worth that much effort.
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-11 18:28 , Processed in 0.149687 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表