I am writing a C ++ program to convert a BMP image to JPEG.
Here is the basic algorithm I'm trying to execute:
- Convert RGB color space to Y, Cb, Cr ..
- Down sample of Cb and Cr by 2 (this means that for each square block 2 * 2 there are 4 different values โโof Y, but 1 Cb and 1 Cr value
- Apply DCT to data units of each 8 * 8 pixels ...
- Then apply DCT coefficient quantization using the standard Cb and Cr quantization table.
- Make a zigzag order.
- Encode DC and AC ratios separately using huffman encoding.
- Write the correct header and write the value in huffman encoding ...
I have verified that I am doing this correctly, but I still have the following problems:
- Generated JPEG does not display correctly.
- I made a small file with a size of 8 * 8 24 bits (color depth) bmp, completely filled with the color value R = 10 B = 10 and G = 100 ... all 64 pixels are the same color ..
- The data that I get at each step is as follows:
- BMP 40 Header Size
- header size 40
- width 8
- height 8
- no planes 1
- no bits per pixel 24
- image size 194
- x pixel resolution per meter 2834
- y pixel resolution per meter 2834
- no colors 0
- no colors imp 0
- The conversion of Y Cb Cr (R, B, G) = (10,10,100) is (62, -29, -37)
So first, consider the component Y.
DCT coefficient for component Y:
495 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
After quantization, the zig zag order for the single data block that I get is for component Y.
30 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
Now Huffman encoding over an array of order zig zag order:
8, 1.
0011111010101100001001110101110011111111 Length 40.
0 1 , , JPEG, , 8 10 1- .
- - , ?
Umang