. If there are less items than this an
ArrayIndexOutOfBoundsException will be generated. The integer values
are represented according to the number of components. If the integer
contains values in bytes that are not used by the number of components
for that image, the values are ignored.
1 Component Images
The integer has the intensity value stored in the lowest byte and can be
obtained:
intensity = pixel[i] & 0xFF;
2 Component Images
The integer has the intensity value stored in the lowest byte and the
transparency in the top byte:
intensity = pixel[i] & 0xFF;
alpha = (pixel[i] >> 24) & 0xFF00;
Note that this is different to the VRML representation of the image
which would store the values in the text file as
alpha = pixel[i] >> 8) & 0xFF. The reason for the difference
is to maintain as much compatibility with the java image model as
possible. Java does not contain a separate intensity only image model,
instead it sets all three colour components to the same value. This way,
the user of SFImages can take a full colour image and turn it to B&W by
just setting the number of components to 2 - particularly if the three
colour components are the same (which they are for an intensity only
image) which will result in the correct intepretation of the image.
3 Component Images
The three colour components are stored in the integer array as follows:
red = (pixel[i] >> 16) & 0xFF;
green = (pixel[i] >> 8) & 0xFF;
blue = (pixel[i] ) & 0xFF;
4 Component Images
The integer has the value stored in the array as follows:
alpha = (pixel >> 24) & 0xff;
red = (pixel >> 16) & 0xff;
green = (pixel >> 8) & 0xff;
blue = (pixel ) & 0xff;
The width and height values must be greater than or equal to zero. The
number of components is between 1 and 4. Any value outside of these
bounds will generate an IllegalArgumentException.
- Parameters:
width - The width of the image in pixelsheight - The height of the image in pixelscomponents - The number of colour components [1-4]pixels - The array of pixel values as specified above.
- Throws:
java.lang.IllegalArgumentException - The number of components or width/
height are illegal values.
java.lang.ArrayIndexOutOfBoundsException - The number of pixels provided by the
caller is not enough for the width * height.