硬汉嵌入式论坛

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

[LibJPEG] 【LibJPEG专题系列三】JPEG 图像压缩: JPEG和GIF的选择使用

[复制链接]

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
发表于 2015-4-7 17:48:30 | 显示全部楼层 |阅读模式
                   Section - [3] When should I use JPEG,
                      and when should I stick with GIF?

JPEG is *not* going to displace GIF entirely; for some types of images, GIF is superior in image quality,
file size, or both.  One of the first things to learn about JPEG is which kinds of images to apply it to.


Generally speaking, JPEG is superior to GIF for storing full-color or gray-scale images of "realistic" scenes;
that means scanned photographs, continuous-tone artwork, and similar material.  Any smooth variation in
color, such as occurs in highlighted or shaded areas, will be represented more faithfully and in less space by
JPEG than by GIF.


GIF does significantly better on images with only a few distinct colors, such as line drawings and simple carto
-ons.  Not only is GIF lossless for such images, but it often compresses them more than JPEG can.  For
example, large areas of pixels that are all *exactly*the same color are compressed very efficiently indeed by
GIF.  JPEG can't squeeze such data as much as GIF does without introducing visible defects.  (One implication
of this is that large single-color borders are quite cheap in GIF files, while they are best avoided in JPEG files.)


Computer-drawn images, such as ray-traced scenes, usually fall between photographs and cartoons in terms
of complexity.The more complex and subtly rendered the image, the more likely that JPEG will do well on it.
The same goes for semi-realistic artwork (fantasy drawings and such). But icons that use only a few colors are
handled better by GIF.


JPEG has a hard time with very sharp edges: a row of pure-black pixels adjacent to a row of pure-white pixels,
for example. Sharp edges tend to come out blurred unless you use a very high quality setting.  Edges this sharp
are rare in scanned photographs, but are fairly common in GIF files: consider borders, overlaid text, etc.  The
blurriness is particularly objectionable with text that's only a few pixels high.  If you have a GIF with a lot of small
-size overlaid text, don't JPEG it.  (If you want to attach descriptive text to a JPEG image, put it in as a comment
rather than trying to overlay it on the image.  Most recent JPEG software can deal with textual comments in a
JPEG file, although older viewers may just ignore the comments.)


Plain black-and-white (two level) images should never be converted to JPEG; they violate all of the conditions
given above.  You need at least about 16 gray levels before JPEG is useful for gray-scale images.  It should also
be noted that GIF is lossless for gray-scale images of up to 256 levels, while JPEG is not.


If you have a large library of GIF images, you may want to save space by converting the GIFs to JPEG.  This
is trickier than it may seem --- even when the GIFs contain photographic images, they are actually very poor
source material for JPEG, because the images have been color-reduced. Non-photographic images should
generally be left in GIF form.  Good-quality photographic GIFs can often be converted with no visible quality
loss, but only if you know what you are doing and you take the time to work on each image individually.  
Otherwise you're likely to lose a lot of image quality or waste a lot of disk space ... quite possibly both.  Read
sections 8 and 9 if you want to convert GIFs to JPEG.
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2015-4-7 17:55:33 | 显示全部楼层
                            Section 3JPEG和GIF选择使用

    JPEG并不会完全取代GIF;对于某些格式的图像,在图像质量或文件大小方面,亦或同时考虑两者的情况下,
GIF更有优越性。了解JPEG的首要事情之一就是知道哪些图像应该使用这种格式。
     
    一般来说,JPEG在存储“真实世界”场景(也就是指扫描的照片、色调连续的艺术品或是相似的材料)的全
彩或灰度图像方面,比GIF更具有优越性。颜色方面任何平滑的变化,比如发生在高亮区或是阴影区域的,JPEG
会更真实的表现出来,而且较之GIF,其占用的空间更小。
   
     GIF显著作用于只有少数不同颜色的图像中,比如说线条图或是简单的漫画。对于此类图像,不仅仅GIF是无损
的,而且它的压缩程度往往比JPEG更多。举例来说,由几乎完全相同颜色组成的一大片像素,将会被GIF进行确
实有效的压缩。没有肉眼可见的缺陷,JPEG却不能像GIF一样压缩如此多的数据。(这其中一个含义就是指单一
色彩的边界在GIF文件中是很廉价的,同时应避免出现在JPEG文件中。)
     
    电脑绘制的图像,比如光线追踪的场景,在复杂性方面通常会下降在照片和漫画之间。图像越复杂、渲染的越
微妙,JPEG将会做的越好。这同样适用于半写实的作品(幻想的图纸等)。但是,只使用几种颜色的图标由GIF
理得会更好。
   
    JPEG有一个很长的时间以及非常清晰的边缘:比如,临近于一行纯白像素的一行纯黑的像素。除非你使用一个
常高的质量设置,清晰的边缘才会表现的模糊。清晰的边缘罕见于扫描的照片中,但是在GIF文件中是相当常见
的:考虑到边缘、覆盖文本等。模糊程度是特别令人反感的,再加上只有几个高像素的文字。如果你有一个包含很
多小尺寸文本覆盖的GIF,不要使用JPEG。(如果你想添加描述性的文本到一个JPEG图像中,就把它作为评论去
添加,而不是试图覆盖在图像上。最近的很多JPEG软件可以在一个JPEG文件中处理文本注释,尽管其他查看器可
能会忽略这些注释。)
     
    纯黑白(二级)图像不应该转化为JPEG;它们违反上面给出的所有条件。在JPEG用于灰度图像之前,至少需
16级灰度。还应当指出的是GIF用于多达256级灰度的图像时仍是无损的,但JPEG还是不行。

    如果你有大量的GIF图像,你可能希望将这些转化为JPEG来节省空间。这比它看起来更棘手——甚至当这些GIF
像包含摄影图像,实际上它们是用于JPEG时很差的原材料,因为图像早已褪色。非摄影图像一般应保留GIF格式。
质量的摄影GIF图像可以被转化并且没有可见的质量损失,但是只有在你知道自己正在做什么并且肯花时间单独的
去处理每个图像。否则,你有可能会失去大量的图像质量或者浪费大量的磁盘空间,抑或两者兼有。如果你想将GIF
图像转化为JPEG,读读Section 8Section 9
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-12 01:52 , Processed in 0.210491 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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