I want to decode a jpeg image and I am using libjpeg to do so. The flow is: Input image -> Option 1.Resize+decode, Option 2.decode+resize- >output
In the above flow, what option should I go for?
Can I resize my output decompressed image to specific width and height, for example 416x416?
Side note: While going through the doc, I came across the the parameters output_width and output_height, can I modify these? The documentation I am referring: DOC Lines : 631-641
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.
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:
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.
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. On the other hand, the jpeg library has evolved and maybe it has now more features.
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.
Hope it helps.