FAQ

From VipsWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 13:13, 29 September 2006
Kirk (Talk | contribs)

← Previous diff
Revision as of 13:16, 29 September 2006
Kirk (Talk | contribs)

Next diff →
Line 1: Line 1:
- 
== will arithmetic overflow? == == will arithmetic overflow? ==
Line 11: Line 10:
When you cast a 16 bit image down to an 8 bit image VIPS will warn When you cast a 16 bit image down to an 8 bit image VIPS will warn
about overflows (eg. "35698756 pixels overflowed in 16->8 bit cast") about overflows (eg. "35698756 pixels overflowed in 16->8 bit cast")
 +
 +
 +== How do I access the pixel data myself? ==
 +
 +VImage fred = whatever ...
 +
 + void *p = fred.data();
 +
 +This will allocate enough RAM to hold the whole of fred, render pixel
 +data into the RAM buffer, and return a pointer to the start of the
 +data. fred is changed to become a RAM image, so calling .data() again
 +is quick, and if you use fred later:
 +
 + jim = fred * 2;
 +
 +jim will work off the RAM data. The memory will be freed for you when
 +it's no longer needed.
 +
 +It's up to you to cast the result to the correct type. If fred is an
 +8-bit unsigned char image, you need to do:
 +
 + unsigned char *p = (unsigned char *) fred.data();
 +
 +Images are laid out top to bottom, left to right, pixel-packed (ie.
 +RGBRGBRGB ..), with no line padding.

Revision as of 13:16, 29 September 2006

will arithmetic overflow?


VIPS does automatic value-preserving conversion/casting. So 8 bit unsigned plus 8 bit unsigned makes 16 bit unsigned. There are two ways to do the /2: either rightshift (which will give you 16 bit unsigned) or /2.0, which will give you a float. There isn't a divide-by-integer-constant operation (maybe there should be).

When you cast a 16 bit image down to an 8 bit image VIPS will warn about overflows (eg. "35698756 pixels overflowed in 16->8 bit cast")


How do I access the pixel data myself?

VImage fred = whatever ...

void *p = fred.data();

This will allocate enough RAM to hold the whole of fred, render pixel data into the RAM buffer, and return a pointer to the start of the data. fred is changed to become a RAM image, so calling .data() again is quick, and if you use fred later:

jim = fred * 2;

jim will work off the RAM data. The memory will be freed for you when it's no longer needed.

It's up to you to cast the result to the correct type. If fred is an 8-bit unsigned char image, you need to do:

unsigned char *p = (unsigned char *) fred.data();

Images are laid out top to bottom, left to right, pixel-packed (ie. RGBRGBRGB ..), with no line padding.

Personal tools