# Need help on bmp to jpeg conversion

July 13, 2009 at 10:35:24
Specs: Windows Vista, 1gb
 I am writing a c++ code for converting bmp file into jpeg....The algorithm i have followed is:1)Convert RGB color space to Y,Cb,Cr..2)Down sample Cb and Cr by 2..that means for each square block of 2*2 there is 4 different Yvalue but 1 Cb and 1 Cr value..3)Apply DCT to data units of each 8*8 pixels...4)Then apply quantization on DCT coefficient by using standard quantization table of Cb and Cr.5)Do zigzag ordering.6)Encode the DC and AC coefficient separately using huffman encoding.7)Write proper header and write huffman encoded value to the file...By doing all this things correctly(cross checked for various imaged and values) I am still not gettingthe jpeg image correctly displayed.Then i made a small 8*8 24 bit(color depth) bmp file completly filled with color value R=10 B=10and G=100...all 64 pixels are of same color..The data that i m getting at every step is as follows...Bmp Image Header:size of header 40width 8height 8no of planes 1no of bits per pixel 24image size 194x resolution pixel per meter 2834y resolution pixel per meter 2834no of colors 0no of imp colors 0The Y Cb Cr conversion of (R,B,G)=(10,10,100) is (62,-29,-37)so lets consider Y component first..The DCT coefficient for Y component is :495 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 0After Quantization, the zig zag ordering of single data unit that i m getting is this, for Y component.30 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0Now the huffman coding of above zig zag order array is :Y dc coding: 00111110Y ac coding: 1010 (for ac huffman table(luminance Y) EOB value is 1010)Similary huffman coding of Cb and Cr components is as follows:cb dc coding: 11000010cb ac coding: 01 (for ac huffman table(chrominance Cb,Cr) EOB value is 01)cr dc coding: 110101110cr ac coding: 01Final Huffman code that i get is:001111101010110000100111010111001 Length 33so to make it divisible by 8 padding of 1 is done.0011111010101100001001110101110011111111 Length 40.Here each single 0 or 1 is actually a bit that needs to be stored as it is in the jpeg file but since wecant write bit by bit into file, a total of 8 bit is taken and converted into a integer value in base 10and stored that into a character which now takes 1 byte.So this is all procedure and some specific data that i have shown here...but still i m not getting myimage shown correctly..can somebody help me out on this!!!!!!!!!

See More: Need help on bmp to jpeg conversion

#1
July 15, 2009 at 09:55:41
 This is probably too specialized for a general programming forum like this one. I would suggest finding a graphics programming specialist forum.

Report •
Related Solutions