Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having abit of a brainfart and I can't quite grasp what I'm doing wrong. It's quite simple, I am importing an image with FreeImage ( which has a method FreeImage_GetBits that returns a pointer to the first byte of the image data. I then try to load all the data into memory using (bitsperpixel / 8) * pixelsWidth ' pixelHeight, like this:

uint32_t bitsPerPixel           = FreeImage_GetBPP(bitmap);   // resolves to 24
uint32_t widthInPixels          = FreeImage_GetWidth(bitmap);  // resolves to 1024
uint32_t heightInPixels         = FreeImage_GetHeight(bitmap);  // resolves to 1024

// container is a std::vector<uint8_t>
pkgMaterial.mTextureData.insert(pkgMaterial.mTextureData.begin(), FreeImage_GetBits(bitmap), FreeImage_GetBits(bitmap) + ((bitsPerPixel/8) * widthInPixels * heightInPixels));

I have a jpg which is 31 kilobytes in size on disc. Yet when I load it using the above formula, I see the vector is then filled with 3145728 bytes, which is approx 3145 kilobytes. What am I doing wrong?

share|improve this question
Jpegs are compressed data types, is the jpeg being uncompressed when you load it in? – Evan Apr 28 '13 at 21:12
I cannot find any information if it loads the jpeg compressed or uncompressed. Why would it try to uncompress a jpg image though... isnt it just a one-way compression? – KaiserJohaan Apr 28 '13 at 21:45
It will have to uncompress the data before it can be used as an image, if it uncompresses it at the time it is loaded, then it doesn't have to waste clock cycles when the image is being drawn. One way or another, drawing an image requires access to per pixel color data. – Evan Apr 28 '13 at 22:16
OpenGL as probably every other graphics API only understands an image if it is uncompressed - that means one block of memory (24 or 32 bit) is one pixel. JPEG files does not provide the image data in that manner, it must be uncompressed. – Adam S Oct 6 '13 at 18:51
@AdamS Bit of a nitpick, but GPUs and graphics APIs do understand some compressed formats - it's just that JPEG isn't one of them. :) The DXT and BC compression formats are supported by the graphics hardware, though, and are almost universally used in games. – Nathan Reed Nov 5 '13 at 21:47

You are doing nothing wrong.
FreeImage simply decompresses the image, so you can easily read from it and/or modify it.
You cannot render an image or read any pixel values from it without decompressing it first.
And obviously the memory consumption increases if you decompress the image.

You can try to compare the file size of a BMP image before and after loading it. It should roughly be the same, because BMP images are not compressed.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.