Need help converting BMP to JPEG

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:

  • Encoding Y dc: 00111110
  • Encoding Y ac: 1010 (for the ac huffman table (brightness Y), the EOB value is 1010)
  • Similary huffman Cb Cr :
  • cb dc : 11000010
  • cb ac code: 01 ( ac huffman ( Cb, Cr) EOB 01)
  • cr dc : 110101110
  • cr ac code: 01
  • , , :

    001111101010110000100111010111001 33

8, 1.

0011111010101100001001110101110011111111 Length 40.

0 1 , , JPEG, , 8 10 1- .

- - , ?

+3
2

, , , - Pennebaker/Mitchel JPEG.

:

1) 2) FDCT 3) Quantize 4) 5)

- , .

a) ? b) A/C w.r.t. ? c) " " ? d) ? 0x80, ? e) MCU ?

+2

. ImageMagick, Magick ++ CImg, .

-1

Source: https://habr.com/ru/post/1712483/


All Articles