Jpeg file size optimization

Jpeg file size optimization

Hello,

We bought from Intel license for Intel C++ Composer XE for Mac OS X with IPPv7.
For jpeg image encodding we are using UIC jpeg encoder.
Before using this to save file in jpeg/jfif format we were using Graphics Magic libarary.

Problem is that with UIC jpeg encoder the file size is bigger than with Graphics Magic library fot the same quality.
Passed parameters for UIC jpeg encoder are:

params_jpeg.mode = JPEG_BASELINE;
params_jpeg.comment_size = 0;
params_jpeg.huffman_opt = 0;
params_jpeg.nthreads = 2;
params_jpeg.point_transform = 0;
params_jpeg.predictor = 1;
params_jpeg.quality = 20;
params_jpeg.restart_interval = 0;
params_jpeg.sampling = IS_411;
params_jpeg.tmode = 0;

The question is which parameters shall we setup to have at least the same size jpeg file as with Graphics Magic library.

I attached the files:
ananas_001.JPG - original image file
ipp_uic_20.jpg - image saved with Intel ipp uic - quality 20
graphics_magic_20.jpg - image saved with Graphics Magic library - quality 20

After running linux command line tool for jpeg optimisation (jpegoptim) on ipp_uic_20.jpg,
the size is reduced to 36653 bytes (13.44%) - without modyfing compression quality level.
Running the same command on graphics_magic_20.jpg gives no more optimisation gain.
As written in jpegoptim manual: jpegoptim is used to optimize/compress jpeg files.
Program supports lossless optimization, which is based on optimizing the Huffman tables.
And so called "lossy" optimization where in addition to optimizing Huffman tables user can specify upperlimit for image quality.

For our application the jpeg file size is extremely importand.

Regards

Krzysztof Rataj

17 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

Hello Krzysztof,

Thanks for your interest to IPP product.

There are two points you may want to pay attention to in order to minimize resulting file size when use UIC JPEG encoder.

1. UIC JPEG encoder insert comment string in JPEG file, in your case it is "Intel IPP JPEG encoder [7.0.998] - Sep 1 2010",to identify itself. At the current version there is no interface function to control that behaviour, but as you have whole UIC sources you can easely make these changes at your side. For that you will need to add "return JPEG_OK;" at line 918 of file jpegenc.cpp (located at ipp_samples\uic\src\codec\image\jpeg\enc\src folder). I think it make sense in future to add function which will enable or disable that behaviour.

2. It is possible to generate optimal huffman tables, which fromone hand will optimize entropy coding and minimize resulting data size but from other hand it will cost you in encoder speed. As IPP (and UIC codecs) are mostly focused on performance aspect we usestandard huffman tables by default, theywork for any image but do not provide the optimal bit packing.Please set huff_opt parameter to 1 in your call of SetParams of JPEGEncoder class, that will instruct encoder to not use standard huffman tables but generate tables which are optimal for this particular image.

ExcStatus SetParams(
JMODE mode,
JCOLOR color,
JSS sampling,
int restart_interval,
int huff_opt, // should set 1 forgenerating optimal huffman tables
int quality);

Regards,
Vladimir

Hello Vladimir,

Thank you for your answer.

1. I added the line "return JPEG_OK;" to the file jpegenc.cpp at 918 and the comment disappear.

2. I changed huff_opt to one, but the output image was the same size. After that I compiled uic sample code uic_transcoder_con.app from intel website into two versions: with huff_opt set to zero and huff_opt set to one.
With the same input uic_test_image.jpg and parameters the outputed two images were the same size. We check this two images with file binary checking tool and there were no differences.

What can i do more to optimize encoded jpeg file with uic jpeg encoder?.

Regards
Krzysztof

Hi,

you are right, after careful check we found out that generating optimal huffmant tables did not work in baseline encoding mode. We will investigate how toenable this and get back recommendation to you. Please stay tuned.

Regards,
Vladimir

Hi Krzysztof,i investigate this problem and found what it is no big problem to add optimal huffmant tablessupport to baseline encoding. In attached file you can found updated encoder.cpp with needed changes .

Hi Sergey,

thank you very much for your help. I attached your file, recompiled the application and the generated jpeg files were realy smaller :o). Now with ipp uic the outputed jpeg file size is acceptable for us, however with open source jpegoptim the jpeg file size is still smaller than with ipp uic :o).
Maybe in the future you can reimplement jpeg encoder in uic to have more optimal jpeg files.
For us using IPP library is crucial, because it has a lot of advantages than any other solution, but the jpeg file sizes are very important too.

Regards
Krzysztof

Thanks for update, yes we can look in future to understand what might be the difference in encoding. If you can attach some source image, and images encoded with IPP and with jpegoptim that may help us to understand how much difference still be there. One of potential sources might be quantization tables used at encoding stage. In IPP UIC we use default quantization tables compatible with libjpeg implementation. It is also possible to apply custom quantization tables to UIC. So if your appllication is able to construct quantization tables by its own algorithm (possible depending on image content) then it is possible to use them in UIC JPEG encoder

Regards,
Vladimir

Hi Vladimir,

Thanks for info. The files prepared by us are in an attachment. The file uic_test_image.jpg is an orginal image.
The files with prefix ipp_uic_a are generated with IPP UIC jpeg library with quality level 50, sampling 411, and huff_opt set to one. This files are inputs to jpegoptim application. Output files from jpegoptim are with prefix jpegoptim_a.
I hope it will help you.

Regards,
Krzysztof

Anexos: 

Thanks a lot, we will look at the differences (I would not promise when exactly we can target this in product but we definetely will use your input for consideration)

Regards,
Vladimir

Hi again,

our customer gave us a feedback that jpeg files written with uic jpeg encoder (corrected jpegenc.cpp for size optimization) are not opened with Adobe Photoshop CS3 or Elements 8. I attached the message box from Photoshop CS3.

I downloaded and installed updated version of IPP ( 7.0.2.154 ) and uic ( ipp-samples 7.0.2.048 ) - result is the same.

Without size optimization (huffman_opt = 0) the files are opened correctly.

Colud you check the jpegenc.cpp file attached in Sergey Ryadno reply
post written in this thread.

I will be gratefull for suggestions what to do.

Regards
Krzysztof

Anexos: 

AnexoTamanho
Download jpg_error.jpg28.01 KB

Hi Krzysztof,

I think I understand what is the problem. Sergey should change SOF marker from baseline (0xC0)to extended baseline (0xC1) when more than2 huffman tables used. He will review his modification and provide you corrected version soon.

Regards,
Vladimir

Hi Vladimir,

thank you for your help.
I will wait for corrected version impatiently :o)

Regards
Krzysztof

Hi Vladimir,

thank you for your help.
I will wait for corrected version impatiently :o)

Regards
Krzysztof

HiKrzysztof,Please try new variant of jpegenc.cpp. I think i correct all wrong places according previous one. Unfortunatly i dont have Photoshop CS3 in quick access butI tested encoded images withPhotoshop CS2 and it opened it successfully.

Anexos: 

AnexoTamanho
Download jpegenc.cpp124.55 KB

Hi Sergey,

thank you for your support. On my Photoshop Elements 8 jpeg files are opened correctly. We will pass our application with corrected jpeg encoder to our customer. I hope this time there will be no problem with his Photoshop.

One more time thank you for your help.

Regards
Krzysztof

Hi Sergey Ryadno :

I have the same problem and try to download " jpegenc.cpp" that you uploaded, but it seems this file is no longer available.
I would appreciate if you can check this download problem,

Thank you,
Brad

Hi Brad,

The code (I mean changes) is still in the UIC's jpegenc.cpp file. It is activated if you in uic_transcoder_con.cpp/line 381 set params_jpeg.huffman_opt = 1 instead of 0. Try it. May be there's a sense to create a new option for transcoder's command line? We'll investigate this option, the optimized Huffman may be not so performing.

Regards,
Sergey

Regards,
Sergey

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!