# Image Compression

This topic is 3676 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Dear all, I need help for developing image compression program. Do anyone know any sample source code for it (compressing bitmap to jpeg or anything else)? Sorry if it is not right topic, but I really really need help.. Thank you very much guyz... Regards, Mcloud

##### Share on other sites
What formats do you need to compress to? JPEG and PNG both have reference implementations you can use, libjpeg and libpng. However they're not exactly the easiest to use. You may want to use a library that has many different encoders available, like GDI+.

##### Share on other sites

A source code for jpeg decoder is available here
http://www.users.voicenet.com/~richgel/

This jpeg decoder is developed according to formal standards laid out by international standards.

I can answer any further clarifications in jpeg decoder.

##### Share on other sites
I want to compress BITMAP(24-bit), I loaded the image using DIB (if Im right) and retrieve the image info. I want to get the RGB value for each pixel. but I dunno how to get it, and I want to convert RGB to YUV. anybody know?

Thank you for your reference, rajesh_nest, I'll try to read the code.
lots of thank, guyz...

##### Share on other sites
Simplest thing would be to take an image library such as DevIL, Corona or FreeImage. These libraries can load and save images in various formats and it's easy to get access to the pixels.

To access pixels in a windows HBITMAP, you need to use GetDIBits() which requires that the bitmap is actually a DIB section. Only worth the trouble if you actually need to have the image data as a HBITMAP for use on dialogs or printing.

As an example, using Corona, it would work like this:

corona::Image *myImage = corona::OpenImage(  "Input.bmp", corona::PF_R8G8B8A8);void *pixels = myImage->getPixels();for(int y = 0; y < myImage->getHeight(); ++y) {  for(int x = 0; x < myImage->getWidth(); ++x) {    int pixelOffset = (myImage->getWidth() * y + x) * 4;    char *pixelAddress = reinterpret_cast<char *>(pixels) + pixelOffset;    // convert RGBA pixel at pixelAddress to YUV here  }}corona::SaveImage("Output.jpg", corona::FF_JPEG, myImage);delete myImage;

I think some of the other image libraries might even be able to convert to YUV themselves, but I haven't used them in a long time ;)

##### Share on other sites
Assuming you just want to get it done - use python and PIL.

1. 1
2. 2
3. 3
frob
15
4. 4
5. 5

• 20
• 12
• 13
• 14
• 80
• ### Forum Statistics

• Total Topics
632144
• Total Posts
3004413

×