Class AmigaBitmapImage
- All Implemented Interfaces:
Cloneable
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. 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.......
Fig 3. Interleaved bit-plane storage layout.
01110000 00001001 11000111 0....... This is the first bit-plane. 00000010 00100001 11000000 0....... This is the second bit-plane. 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.......For more details refer to "Amiga ROM Kernel Reference Manual: Libraries, Addison Wesley"
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.
- Author:
- Werner Randelshofer, Hausmatt 10, CH-6405 Goldau, Switzerland
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intTag for byte pixel data.static final intTag for integer pixel data.static final intTag indicating that no pixel data is available.static final intTag for short pixel data. -
Constructor Summary
ConstructorsConstructorDescriptionAmigaBitmapImage(int width, int height, int depth, ColorModel colorModel) Construct an interleaved bitmap with the specified size, depth and color model.AmigaBitmapImage(int width, int height, int depth, ColorModel colorModel, boolean isInterleaved) Construct a bitmap with the specified size, depth and color model and with optional interleave.AmigaBitmapImage(int width, int height, int depth, ColorModel colorModel, int bitStride, int scanlineStride) Construct a bitmap with the specified size, depth, color model and interleave. -
Method Summary
Modifier and TypeMethodDescriptionclone()Creates a clone.voidconvertFromChunky(BufferedImage image) Converts the indicated area of the bitmap data into pixel data.intConverts the planar image data into chunky pixel data.intconvertToChunky(int top, int left, int bottom, int right) Converts the indicated area of the bitmap data into pixel data.voidFrees the memory allocated for the pixel data.byte[]Gives you direct access to the bitmap data array.intReturns the number of bytes that you must add to a bitmap address to advance to the next bit of a scanline.byte[]Returns a reference to the byte pixel data that has been generated by a previous call to #converToChunky.Returns the current color model of the chunky image in this bitmap.intgetDepth()Returns the depth of the image.intReturns the height of the image.int[]Returns a reference to the integer pixel data that has been generated by a previous call to #converToChunky.intReturns the available type of pixel data.Returns the current color model of the planar image in this bitmap.intReturns the numer of bytes you must add to a given address in the bitmap to advance to the next scanline of the image.short[]Returns a reference to the byte pixel data that has been generated by a previous call to #converToChunky.intgetWidth()Returns the width of the image.booleanIf this returns true, then convertToChunky always generates chunky pixels using a DirectColorModel.voidsetBytePixels(byte[] buf) voidsetEnforceDirectColors(boolean b) If you set this to true, then convertToChunky always generates chunky pixels using a DirectColorModel.voidsetIntPixels(int[] buf) voidsetPlanarColorModel(ColorModel colorModel) Replaces the color model used for conversions from/to chunky pixels.voidsetPreferredChunkyColorModel(ColorModel colorModel) Sets the preferred color model used for to chunky pixels.voidsetShortPixels(short[] buf)
-
Field Details
-
BYTE_PIXEL
public static final int BYTE_PIXELTag for byte pixel data.- See Also:
-
INT_PIXEL
public static final int INT_PIXELTag for integer pixel data.- See Also:
-
SHORT_PIXEL
public static final int SHORT_PIXELTag for short pixel data.- See Also:
-
NO_PIXEL
public static final int NO_PIXELTag indicating that no pixel data is available.- See Also:
-
-
Constructor Details
-
AmigaBitmapImage
Construct an interleaved bitmap with the specified size, depth and color model. BitplaneStride and ScanlineStride are rounded up to the next even number of bytes.Pre condition: -
Post condition: Interleaved bitmap constructed.
Obligation: -
- Parameters:
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.
-
AmigaBitmapImage
public AmigaBitmapImage(int width, int height, int depth, ColorModel colorModel, boolean isInterleaved) Construct a bitmap with the specified size, depth and color model and with optional interleave. BitplaneStride and ScanlineStride are rounded up to the next even number of bytes.Pre condition: -
Post condition: BitmapImage constructed.
Obligation: -
- Parameters:
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.
-
AmigaBitmapImage
public AmigaBitmapImage(int width, int height, int depth, ColorModel colorModel, int bitStride, int scanlineStride) Construct a bitmap with the specified size, depth, color model and interleave.Pre condition: ScanlineStride must be a multiple of BitplaneStride or vice versa.
Post condition: BitmapImage constructed.
Obligation: -
- Parameters:
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 Details
-
setEnforceDirectColors
public void setEnforceDirectColors(boolean b) If you set this to true, then convertToChunky always generates chunky pixels using a DirectColorModel. -
isEnforceDirectColors
public boolean isEnforceDirectColors()If this returns true, then convertToChunky always generates chunky pixels using a DirectColorModel. -
getWidth
public int getWidth()Returns the width of the image.Pre condition: -
Post condition: -
Obligation: -
- Returns:
- The width in pixels.
-
getHeight
public int getHeight()Returns the height of the image.Pre condition: -
Post condition: -
Obligation: -
- Returns:
- The height in pixels.
-
getDepth
public int getDepth()Returns the depth of the image.The depth indicates how many bits are used to form a single pixel.
Pre condition: -
Post condition: -
Obligation: -
- Returns:
- The number of bitplanes used to form a single pixel.
-
getScanlineStride
public 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.Pre condition: -
Post condition: -
Obligation: -
- Returns:
- The scansize.
-
getBitplaneStride
public int getBitplaneStride()Returns the number of bytes that you must add to a bitmap address to advance to the next bit of a scanline.Pre condition: -
Post condition: -
Obligation: -
- Returns:
- The interleave of the bitmap.
-
setPlanarColorModel
Replaces the color model used for conversions from/to chunky pixels.Pre condition: The new color model must correspond with the depth of the bitmap.
Post condition: Color model changed.
Obligation: -
- Parameters:
colorModel- The new color model.
-
getPlanarColorModel
Returns the current color model of the planar image in this bitmap.Pre condition: -
Post condition: -
Obligation: -
- Returns:
- The color model.
-
setPreferredChunkyColorModel
Sets the preferred color model used for to chunky pixels.Pre condition: -
Post condition: Color model changed.
Obligation: -
- Parameters:
colorModel- The new color model.
-
getChunkyColorModel
Returns the current color model of the chunky image in this bitmap.Pre condition: -
Post condition: -
Obligation: -
- Returns:
- The color model.
-
getBitmap
public byte[] getBitmap()Gives you direct access to the bitmap data array.Pre condition: -.
Post condition: -
Obligation: The bitmap data array remains property of the AmigaBitmapImage 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.
- Returns:
- A reference to the bitmap data.
-
getBytePixels
public byte[] getBytePixels()Returns a reference to the byte pixel data that has been generated by a previous call to #converToChunky.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.
- Returns:
- byte array or NULL when no byte pixels have been generated by #convertToChunky.
-
getShortPixels
public short[] getShortPixels()Returns a reference to the byte pixel data that has been generated by a previous call to #converToChunky.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.
- Returns:
- byte array or NULL when no byte pixels have been generated by #convertToChunky.
-
getIntPixels
public int[] getIntPixels()Returns a reference to the integer pixel data that has been generated by a previous call to #converToChunky.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.
- Returns:
- byte array or NULL when no int pixels have been generated by #convertToChunky.
-
getPixelType
public int getPixelType()Returns the available type of pixel data.Pre condition: -
Post condition: -
Obligation: -
- Returns:
- A constant that specifies the current type of pixel data.
-
clone
Creates a clone.Pre condition: -
Post condition: Clone created.
-
convertToChunky
public int convertToChunky()Converts the planar image data into chunky pixel data.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: -
- Returns:
- The type of generated pixel data.
-
convertToChunky
public int convertToChunky(int top, int left, int bottom, int right) Converts the indicated area of the bitmap data into pixel data.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: -
- Returns:
- The type of generated pixel data.
-
convertFromChunky
Converts the indicated area of the bitmap data into pixel data.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: -
-
flushPixels
public void flushPixels()Frees the memory allocated for the pixel data.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.
-
setIntPixels
public void setIntPixels(int[] buf) -
setBytePixels
public void setBytePixels(byte[] buf) -
setShortPixels
public void setShortPixels(short[] buf)
-