|
Copyright 2013-01-06 Werner Randelshofer | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.monte.media.image.BitmapImage
public class BitmapImage
A BitmapImage is comprised of a ColorModel and an accessible byte array of image data.
The image data is expressed in several layers of rectangular regions called bit-planes. To determine the bits that form a single pixel one must combine all data-bits at the same x,y position in each bit-plane. This is known as a "planar" storage layout as it was used on Commodore Amiga Computers.
The bit-planes can be stored contiguously or can be interleaved at each scanline of the image.
Fig 1. A sample image:
.+++..@...@.+..###...+++. This sample uses 4 colors: +...+.@@.@@.+.#.....+...+ . = color 0 (all bits clear) +++++:@.@.@.+.#..##.+++++ + = color 1 (bit 0 set, bit 1 clear) +...+.@...@.+.#...#.+...+ @ = color 2 (bit 0 clear, bit 1 set) +...+.@...@.+..####.+...+ # = color 3 (all bits set)
Fig 2. Contiguous bit-plane storage layout.
01110000 00001001 11000111 0....... This is the first bit-plane. 10001000 00001010 00001000 1....... Each number represents a bit 11111000 00001010 01101111 1....... in the storage layout. Eight 10001000 00001010 00101000 1....... bits are grouped into one byte. 10001000 00001001 11101000 1....... Dots indicate unused bits.Fig 3. Interleaved bit-plane storage layout.00000010 00100001 11000000 0....... This is the second bit-plane. 00000011 01100010 00000000 0....... 00000010 10100010 01100000 0....... 00000010 00100010 00100000 0....... 00000010 00100001 11100000 0.......
01110000 00001001 11000111 0....... This is the first bit-plane. 00000010 00100001 11000000 0....... This is the second bit-plane.For more details refer to "Amiga ROM Kernel Reference Manual: Libraries, Addison Wesley"10001000 00001010 00001000 1....... The bit-planes are interleaved 00000011 01100010 00000000 0....... at every scanline of the image.
11111000 00001010 01101111 1....... 00000010 10100010 01100000 0.......
10001000 00001010 00101000 1....... 00000010 00100010 00100000 0.......
10001000 00001001 11101000 1....... 00000010 00100001 11100000 0.......
Responsibility
Gives clients direct access to the image data of the bitmap. Knows how to convert the bitmap into chunky image data according to the current color model. Supports indexed color model, direct color model, 6 and 8 bit HAM color model.
Field Summary | |
---|---|
static int |
BYTE_PIXEL
Tag for byte pixel data. |
static int |
INT_PIXEL
Tag for integer pixel data. |
static int |
NO_PIXEL
Tag indicating that no pixel data is available. |
static int |
SHORT_PIXEL
Tag for short pixel data. |
Constructor Summary | |
---|---|
BitmapImage(int width,
int height,
int depth,
java.awt.image.ColorModel colorModel)
Construct an interleaved bitmap with the specified size, depth and color model. |
|
BitmapImage(int width,
int height,
int depth,
java.awt.image.ColorModel colorModel,
boolean isInterleaved)
Construct a bitmap with the specified size, depth and color model and with optional interleave. |
|
BitmapImage(int width,
int height,
int depth,
java.awt.image.ColorModel colorModel,
int bitStride,
int scanlineStride)
Construct a bitmap with the specified size, depth, color model and interleave. |
Method Summary | |
---|---|
BitmapImage |
clone()
Creates a clone. |
void |
convertFromChunky(java.awt.image.BufferedImage image)
Converts the indicated area of the bitmap data into pixel data. |
int |
convertToChunky()
Converts the planar image data into chunky pixel data. |
int |
convertToChunky(int top,
int left,
int bottom,
int right)
Converts the indicated area of the bitmap data into pixel data. |
void |
flushPixels()
Frees the memory allocated for the pixel data. |
byte[] |
getBitmap()
Gives you direct access to the bitmap data array. |
int |
getBitplaneStride()
Returns the number of bytes that you must add to a bitmap address to advance to the next bit of a scanline. |
byte[] |
getBytePixels()
Returns a reference to the byte pixel data that has been generated by a previous call to #converToChunky. |
java.awt.image.ColorModel |
getChunkyColorModel()
Returns the current color model of the chunky image in this bitmap. |
int |
getDepth()
Returns the depth of the image. |
int |
getHeight()
Returns the height of the image. |
int[] |
getIntPixels()
Returns a reference to the integer pixel data that has been generated by a previous call to #converToChunky. |
int |
getPixelType()
Returns the available type of pixel data. |
java.awt.image.ColorModel |
getPlanarColorModel()
Returns the current color model of the planar image in this bitmap. |
int |
getScanlineStride()
Returns the numer of bytes you must add to a given address in the bitmap to advance to the next scanline of the image. |
short[] |
getShortPixels()
Returns a reference to the byte pixel data that has been generated by a previous call to #converToChunky. |
int |
getWidth()
Returns the width of the image. |
boolean |
isEnforceDirectColors()
If this returns true, then convertToChunky always generates chunky pixels using a DirectColorModel. |
void |
setBytePixels(byte[] buf)
|
void |
setEnforceDirectColors(boolean b)
If you set this to true, then convertToChunky always generates chunky pixels using a DirectColorModel. |
void |
setIntPixels(int[] buf)
|
void |
setPlanarColorModel(java.awt.image.ColorModel colorModel)
Replaces the color model used for conversions from/to chunky pixels. |
void |
setPreferredChunkyColorModel(java.awt.image.ColorModel colorModel)
Sets the preferred color model used for to chunky pixels. |
void |
setShortPixels(short[] buf)
|
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int BYTE_PIXEL
public static final int INT_PIXEL
public static final int SHORT_PIXEL
public static final int NO_PIXEL
Constructor Detail |
---|
public BitmapImage(int width, int height, int depth, java.awt.image.ColorModel colorModel)
Pre condition: -
Post condition: Interleaved bitmap constructed.
Obligation: -
width
- Width in pixels.height
- Height in pixels.depth
- Number of bits per pixel.colorModel
- Color model to be used for conversions from/to chunky pixels.public BitmapImage(int width, int height, int depth, java.awt.image.ColorModel colorModel, boolean isInterleaved)
Pre condition: -
Post condition: BitmapImage constructed.
Obligation: -
width
- Width in pixels.height
- Height in pixels.depth
- Number of bits per pixel.colorModel
- Color model to be used for conversions from/to chunky pixels.isInterleaved
- Indicator for contiguous or interleaved bit-planes.public BitmapImage(int width, int height, int depth, java.awt.image.ColorModel colorModel, int bitStride, int scanlineStride)
Pre condition: ScanlineStride must be a multiple of BitplaneStride or vice versa.
Post condition: BitmapImage constructed.
Obligation: -
width
- Width in pixels.height
- Height in pixels.depth
- Number of bits per pixel.colorModel
- Color model to be used for conversions from/to chunky pixels.bitStride
- Number of data array elements between two bits of the same image pixel.scanlineStride
- Number of data array elements between a given pixel and the pixel in the same column of
the next scanline.Method Detail |
---|
public void setEnforceDirectColors(boolean b)
public boolean isEnforceDirectColors()
public int getWidth()
Pre condition: -
Post condition: -
Obligation: -
public int getHeight()
Pre condition: -
Post condition: -
Obligation: -
public int getDepth()
The depth indicates how many bits are used to form a single pixel.
Pre condition: -
Post condition: -
Obligation: -
public int getScanlineStride()
Pre condition: -
Post condition: -
Obligation: -
public int getBitplaneStride()
Pre condition: -
Post condition: -
Obligation: -
public void setPlanarColorModel(java.awt.image.ColorModel colorModel)
Pre condition: The new color model must correspond with the depth of the bitmap.
Post condition: Color model changed.
Obligation: -
colorModel
- The new color model.public java.awt.image.ColorModel getPlanarColorModel()
Pre condition: -
Post condition: -
Obligation: -
public void setPreferredChunkyColorModel(java.awt.image.ColorModel colorModel)
Pre condition: -
Post condition: Color model changed.
Obligation: -
colorModel
- The new color model.public java.awt.image.ColorModel getChunkyColorModel()
Pre condition: -
Post condition: -
Obligation: -
public byte[] getBitmap()
Pre condition: -.
Post condition: -
Obligation: The bitmap data array remains property of the BitmapImage and will be used at the next conversion to chunky. You can access it as you like (even during conversion) since this class does never change the contents of the bitmap.
public byte[] getBytePixels()
Pre condition: -
Post condition: -
Obligation: You may modify the contents of the array as you like to get some nice effects for the next call to #convertToChunky. Note whovewer that #convertToChunky will not reuse this array when the colorModel has been changed to a color format that requires pixels in integer format.
public short[] getShortPixels()
Pre condition: -
Post condition: -
Obligation: You may modify the contents of the array as you like to get some nice effects for the next call to #convertToChunky. Note whovewer that #convertToChunky will not reuse this array when the colorModel has been changed to a color format that requires pixels in integer format.
public int[] getIntPixels()
Pre condition: -
Post condition: -
Obligation: You may modify the contents of the array as you like to get some nice effects for the next call to #convertToChunky. Note however that #convertToChunky will not reuse this array when the colorModel has been changed to a color format that requires pixels in byte format.
public int getPixelType()
Pre condition: -
Post condition: -
Obligation: -
public BitmapImage clone()
Pre condition: -
Post condition: Clone created.
clone
in class java.lang.Object
public int convertToChunky()
This method will either generate byte pixel data or integer pixel data (depending on the color model).
The pixel array that resulted to a prior call to this method will be reused when the image dimension and the color model allows for it.
Pre condition: -
Post condition: Chunky pixels generated.
Obligation: -
public int convertToChunky(int top, int left, int bottom, int right)
This method will either generate byte pixel data or integer pixel data (depending on the color model).
Note that the size of the generated pixel data always corresponds to the size of the complete image. You do only specify a subset of the image to be converted not a subset to be extracted. Note also that the pixel data that resulted from prior calls to this method will be reused when the generated pixel array was of the same size and type.
Pre condition: -
Post condition: The indicated part of the bitmap has been converted into chunky pixels.
Obligation: -
public void convertFromChunky(java.awt.image.BufferedImage image)
This method will either generate byte pixel data or integer pixel data (depending on the color model).
Note that the size of the generated pixel data always corresponds to the size of the complete image. You do only specify a subset of the image to be converted not a subset to be extracted. Note also that the pixel data that resulted from prior calls to this method will be reused when the generated pixel array was of the same size and type.
Pre condition: -
Post condition: The indicated part of the bitmap has been converted into chunky pixels.
Obligation: -
public void flushPixels()
Pre condition: -
Post condition: The bitmap has given up all its references to the pixel data.
Obligation: The pixel data will not be reused at the next call to #convertToChunky.
public void setIntPixels(int[] buf)
public void setBytePixels(byte[] buf)
public void setShortPixels(short[] buf)
|
Copyright 2013-01-06 Werner Randelshofer | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |