![]() |
![]() |
![]() |
![]() |
An image can be very large, much larger than the available memory, so you can’t just access pixels with a pointer *.
Instead, you read pixels from an image with a region. This is a rectangular sub-area of an image. In C, the API looks like:
VipsImage *image = vips_image_new_from_file( filename, NULL ); VipsRegion *region = vips_region_new( image ); // ask for a 100x100 pixel region at 0x0 (top left) VipsRect r = { left: 0, top: 0, width: 100, height: 100 }; if( vips_region_prepare( region, &r ) ) vips_error( ... ); // get a pointer to the pixel at x, y, where x, y must // be within the region // as long as you stay within the valid area for the region, // you can address pixels with regular pointer arithmetic // compile with -DDEBUG and the macro will check bounds for you // add VIPS_REGION_LSKIP() to move down a line VipsPel *pixel = VIPS_REGION_ADDR( region, x, y ); // you can call vips_region_prepare() many times // everything in libvips is a GObject ... when you're done, // just free with g_object_unref( region );
The action that
takes varies with the type of image. If the image is a file on disc, for example, then VIPS will arrange for a section of the file to be read in.
vips_region_prepare()
(* there is an image access mode where you can just use a pointer, but it’s rarely used)