Menu

Home

Vladimir Antonenko

F.A.Q

Several questions about the code and its behavior that I have so far:

Q: The executable do not want to process my BMP file, can you fix this?

A: I can but I will not. BMP format is not very complex one but its full support may took a considerable effort that I do not want to make. My goal was to write JPEG encoder not BMP parser so the parser is very basic and can read only true color (24 bit) BGR images with a lot of other restrictions. So just open your file in image editor like Windows Paint and save it as 24-bit (true color) BMP file.

Q: I have used the .exe compiled for Windows and a test bitmap but the encoding isn't good (it is kind of skewed). Could you please explain this for me?

A: This issue was fixed in 1.1 release. And keep in mind that image width/height should be multiple of 16 or it will be clipped on the left/down side. JPEG encoder processes images by 16x16 pixel blocks (if chroma subsampling is used) - read doc/Readme file. I skipped this case to keep the code small and easy to understand.

Q: You said that the code is pure C then what is C++ file (main.cpp) is doing there?

A: The JPEG encoder itself cannot make a working application, it processes images with correct pixel format and the images should be procured somewhere and jpeg output should be written back. These functions an application must provide. For this case C++ was more suitable.

Q: How to change the JPEG compression degree?

A: You have to use different quantization tables or several of them for each compression level or construct them on-the-fly. There are two tables - one for luminance and another for chrominance pixels:

qtable_0_lum[64];
qtable_0_chrom[64];

and their inverted versions

qtable_lum[64];
qtable_chrom[64];

The easiest way is to "steal" them from another jpeg file (if its compression ratio suits you).

Q: Сan you tell me if jpegant will run on Arduino Nano / Pro Mini (Microcontroller: ATmega328P SRAM 2KB, EEPROM 1KB, Flash: 32KB)? I'm not sure if jpegant can run on the ATmega328P with just 2KB ram if it's compressing a bitmat with resolution 320x240 pixels etc, as the bitmap could not it into memory. Can jpegant compress a bitmap larger that available MCU ram?

A: Unfortunately this code will not work on 8/16 bit microcontrollers, it requires 32-bit int type. In my opinion it has no point to try to do image compression on such systems - too slow for the realtime and too few memory for any practical use. In your case you have to fit 16 rows of image into RAM because jpeg compresses images by 16x16 pixel blocks (when chroma subsampling is used), so you need 320x16 = 5120 pixels = 15360 bytes just for RGB/YUV image to compress. Unless you re-arrange the data somehow, in that case you will need just around 200 bytes for jpeg context and its buffer plus output buffer for storage of a compressed bitstream. My advise for you - use something like ARM Cortex-M0 or higher.


Monday.com Logo