简体   繁体   English

我可以将使用libjpeg的jpeg解压的output设置为一定的宽度和高度吗?

[英]Can I set the output of jpeg decompression using libjpeg to certain width and height?

I want to decode a jpeg image and I am using libjpeg to do so.我想解码一个 jpeg 图像,我正在使用 libjpeg 这样做。 The flow is: Input image -> Option 1.Resize+decode, Option 2.decode+resize- >output流程为:Input image -> Option 1.Resize+decode, Option 2.decode+resize->output

In the above flow, what option should I go for?在上面的流程中,我应该选择什么 go ?

Can I resize my output decompressed image to specific width and height, for example 416x416?我可以将我的 output 解压缩图像的大小调整为特定的宽度和高度,例如 416x416?

Side note: While going through the doc, I came across the the parameters output_width and output_height, can I modify these?旁注:在浏览文档时,我遇到了参数 output_width 和 output_height,我可以修改这些吗? The documentation I am referring: DOC Lines: 631-641我指的文档: DOC Lines: 631-641

You can't resize a JPEG without decoding it first.不先解码就无法调整 JPEG 的大小。 So option 2 is your only option.所以选项2是你唯一的选择。 After decoding with libjpeg, you need to resize the image.使用 libjpeg 解码后,需要调整图像大小。 You need to write an algorithm for that yourself, or use another library.你需要自己写一个算法,或者使用另一个库。 libjpeg doesn't do that. libjpeg 不这样做。

If you want to store it in the new size, you can use libjpeg again to encode the resulting image.如果您想以新的大小存储它,您可以再次使用 libjpeg 对生成的图像进行编码。 In that case, you can (and must) set output_width and output_height .在这种情况下,您可以(并且必须)设置output_widthoutput_height This doesn't actually change the size - it tells libjpeg how large the image you want to encode is.这实际上并没有改变大小 - 它告诉 libjpeg 你要编码的图像有多大。

Yes, you can scale the image while decompressing it, but only by multiples (or sub-multiples) of its real dimensions.是的,您可以在解压缩图像缩放图像,但只能通过其实际尺寸的倍数(或子倍数)。

It can be useful anyway, and I used it that way.无论如何它可能很有用,我就是这样使用它的。 I wanted to generate miniatures (thumbs) of bigger pictures, so I chose the smallest dimension available;我想生成更大图片的缩影(拇指),所以我选择了可用的最小尺寸; the output is smaller, less memory, less pixels to process in order to resize, and depending of the situation even the decoding step can be faster. output 更小,memory 更少,为了调整大小而要处理的像素更少,并且根据情况甚至解码步骤可以更快。

I don't have those sources at hand, but I can search this night to provide more details.我手头没有这些资源,但我可以在今晚搜索以提供更多详细信息。

-- UPDATE -- I've found, in my old sources (pascal), the following: -- 更新 -- 我在我的旧资源(pascal)中发现了以下内容:

  cinfo.scale_num := 1;
  cinfo.scale_denom := 1;   { 1:1 scaling }
  ...
  cinfo.two_pass_quantize := TRUE;

  { Step 5: Start decompressor }

  jpeg_start_decompress(@cinfo);

As you see, there is a scaling facility applied while decompressing ;如您所见,解压缩时应用了缩放工具; for what I remember, it works perfectly when asking for 1/2, 1/4, 1/8 and so on of the original image.据我所知,它在要求原始图像的 1/2、1/4、1/8 等时效果很好。

In another program, I've found:在另一个程序中,我发现:

  sc := round(width/IconRect.right/(fmOptions.cbThumbQuality.ItemIndex+1));
  if sc>ord(jsEighth) then sc := ord(jsEighth);
  scale := TJpegScale(sc);

The snippet above calculates how much to scale down the original image to get the "icon" (or miniature) width, but limits the scaling to 1/8: I remember, but I am not sure, that this limitation comes from the jpeg library.上面的代码片段计算了将原始图像缩小多少以获得“图标”(或微型)宽度,但将缩放限制为 1/8:我记得,但我不确定,这个限制来自 jpeg 库. On the other hand, the jpeg library has evolved and maybe it has now more features.另一方面,jpeg 库已经发展,也许它现在具有更多功能。

So, to conclude, you can set a scaling mode but not the final dimension;因此,总而言之,您可以设置缩放模式,但不能设置最终尺寸; after having set the scale, output_width will reflect the final width, and this is anyway necessary to allocate memory for the decompression routines of the library.设置比例后, output_width将反映最终宽度,无论如何这是为库的解压缩例程分配 memory 所必需的。

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM