# Image Libarary - Load Part of an Image

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

## Recommended Posts

I was hoping I could find a C or C++ image loading library that would let me load only a portion of an image from disk at a time. Something like:
myImg = ReadImageHeader("rofl.bmp");
imgData = ReadImageRegion( myImg, rectInsideImg );
//...

I've taken a look at DevIL (which looks really nice) and ImageMagick, but they don't seem to indicate if this is possible. It's kind of a strange operation to want to perform, so I wouldn't be surprised if it was unsupported. Does anyone know of an image loading library that has this capability? Thanks in advance for any help.

##### Share on other sites
	ILuint width = ilGetInteger(IL_IMAGE_WIDTH);	ILuint height = ilGetInteger(IL_IMAGE_HEIGHT);	ILubyte* data = ilGetData();	Pixel* pixels = reinterpret_cast<Pixel*>(data);

then you can treat image pixels as a array, copy or edit that

##### Share on other sites
If all you want is a small part of a normal-sized image, then you can still use any given image library. If you're feeding the (cropped) data into something that's expecting a stride as well as a width and a height, it's particularly simple: in that case, just find the first pixel of the cropped image, pass that in as the address of the image data, pass the stride of the full image as the stride of the cropped image, and pass in the desired width and height. If you aren't feeding it into something that has a stride, you'll need to manually copy the cropped image to a new buffer. It all depends on what library is expecting the image data, and what format it's expecting it in.

If you have an incredibly huge image and you don't want to spend time loading all of it into memory, more difficult and format-specific methods will be needed, and I doubt either DevIL or ImageMagick will help you.

##### Share on other sites
Quote:
 Original post by SneftelIf all you want is a small part of a normal-sized image, then you can still use any given image library. If you're feeding the (cropped) data into something that's expecting a stride as well as a width and a height, it's particularly simple: in that case, just find the first pixel of the cropped image, pass that in as the address of the image data, pass the stride of the full image as the stride of the cropped image, and pass in the desired width and height. If you aren't feeding it into something that has a stride, you'll need to manually copy the cropped image to a new buffer. It all depends on what library is expecting the image data, and what format it's expecting it in.If you have an incredibly huge image and you don't want to spend time loading all of it into memory, more difficult and format-specific methods will be needed, and I doubt either DevIL or ImageMagick will help you.

Yeah, I should have been more specific. I need to read the data from the image while it is on disk, because the image can be gihugic [embarrass].

I figured it was a long shot, especially when you consider compressed/encoded image data, but I thought I'd check just in case. I'll probably write some simple code that allows me to do this with BMPs or un-encoded TGAs, and wait until I need to conserve disk space before I support a more robust image type.

##### Share on other sites
Note that certain formats, such as EXR, are specifically built to allow easy access to small parts of the image. If you have control over the format, choose one of those.

##### Share on other sites
OpenEXR looks like it fits the bill (from the OpenEXR documentation):
 void    readRgba1 (const char fileName[],               Array2D<Rgba> &pixels,               int &width,               int &height)    {        RgbaInputFile file (fileName);        Box2i dw = file.dataWindow();        width  = dw.max.x - dw.min.x + 1;        height = dw.max.y - dw.min.y + 1;        pixels.resizeErase (height, width);        /* awesome! */        file.setFrameBuffer (&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width);        file.readPixels (dw.min.y, dw.max.y);    }

The OpenEXR format also has a lot of features that might come in handy for me.

Thanks a bunch!

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632961
• Total Posts
3009484
• ### Who's Online (See full list)

There are no registered users currently online

×