Package bdsup2sub.bitmap
Class Bitmap
java.lang.Object
bdsup2sub.bitmap.Bitmap
Class to handle byte based bitmaps with a separate palette up to 256 colors.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate int[]
createHistogram
(int colorIndexCount) crop
(int xOffset, int yOffset, int croppedBitmapWidth, int croppedBitmapHeight) void
fillRectangularWithColorIndex
(int rectX, int rectY, int rectWidth, int rectHeight, byte colorIndex) private void
fillWithColorIndexValue
(byte colorIndex) getBitmapWithNormalizedPalette
(byte[] alphaValues, int alphaThreshold, byte[] lumaValues, int[] lumaThreshold) Convert a palettized Bitmap (where each palette entry has individual alpha) to a Bitmap with N color palette, where: index0 = transparent (background), index1 = light color (pattern), ...private int
getColorIndexWithTheHighestValue
(int[] histogram) getCroppingBounds
(byte[] alpha, int alphaThreshold) int
int
getHighestVisibleColorIndex
(byte[] alphaValues) getImage
(ColorModel colorModel) byte[]
private byte
getPixel
(int x, int y) int
getPrimaryColorIndex
(byte[] alpha, int alphaThreshold, byte[] luma) int
getWidth()
private boolean
isColorAboveAlphaThreshold
(int bufferIndex, byte[] alpha, int alphaThreshold) private boolean
isColumnWithColorAboveAlphaThreshold
(int x, int yMin, int yMax, byte[] alpha, int alphaThreshold) private boolean
isRowWithColorAboveAlphaThreshold
(int yOfs, byte[] alpha, int alphaThreshold) scaleBilinear
(int sizeX, int sizeY, Palette pal) Scales a palettized Bitmap to a Bitmap with the same palette using bilinear filtering.scaleBilinear
(int sizeX, int sizeY, Palette pal, boolean dither) Scales a palettized Bitmap to a Bitmap with a new quantized Palette using bilinear filtering.scaleBilinearLm
(int sizeX, int sizeY, Palette pal, int alphaThr, int[] lumThr) Scales a palettized Bitmap (where each palette entry has individual alpha) using bilinear filtering to a Bitmap with N color palette, where: index0 = transparent, index1 = light color, ...scaleFilter
(int sizeX, int sizeY, Palette pal, com.mortennobel.imagescaling.ResampleFilter f) Scales a palettized Bitmap to a Bitmap with the same Palette using a given scaling filter.scaleFilter
(int sizeX, int sizeY, Palette pal, com.mortennobel.imagescaling.ResampleFilter f, boolean dither) Scales a palettized Bitmap to a Bitmap with a new quantized Palette using a given scaling filter.scaleFilterLm
(int sizeX, int sizeY, Palette pal, int alphaThr, int[] lumThr, com.mortennobel.imagescaling.ResampleFilter f) Scales a palettized Bitmap (where each palette entry has individual alpha) using a given scaling filter to a Bitmap with N color palette, where: index0 = transparent, index1 = light color, ...private void
setPixel
(int x, int y, byte color) int[]
private void
weightHistogramWithAlphaAndLumaValues
(int[] histogram, byte[] alphaValues, int alphaThreshold, byte[] lumaValues)
-
Field Details
-
logger
-
width
private final int width -
height
private final int height -
buffer
private final byte[] buffer
-
-
Constructor Details
-
Bitmap
public Bitmap(int width, int height) -
Bitmap
public Bitmap(int width, int height, byte fillerColorIndex) -
Bitmap
public Bitmap(int width, int height, byte[] buffer) -
Bitmap
-
-
Method Details
-
fillWithColorIndexValue
private void fillWithColorIndexValue(byte colorIndex) -
fillRectangularWithColorIndex
public void fillRectangularWithColorIndex(int rectX, int rectY, int rectWidth, int rectHeight, byte colorIndex) -
getImage
-
getPrimaryColorIndex
public int getPrimaryColorIndex(byte[] alpha, int alphaThreshold, byte[] luma) -
createHistogram
private int[] createHistogram(int colorIndexCount) -
weightHistogramWithAlphaAndLumaValues
private void weightHistogramWithAlphaAndLumaValues(int[] histogram, byte[] alphaValues, int alphaThreshold, byte[] lumaValues) -
getColorIndexWithTheHighestValue
private int getColorIndexWithTheHighestValue(int[] histogram) -
getHighestVisibleColorIndex
public int getHighestVisibleColorIndex(byte[] alphaValues) -
getBitmapWithNormalizedPalette
public Bitmap getBitmapWithNormalizedPalette(byte[] alphaValues, int alphaThreshold, byte[] lumaValues, int[] lumaThreshold) Convert a palettized Bitmap (where each palette entry has individual alpha) to a Bitmap with N color palette, where: index0 = transparent (background), index1 = light color (pattern), ... , indexN-2 = dark color, indexN-1 = black. For N-1 luminances, N-2 thresholds are needed lumaThreshold[0] is the threshold for the lightest color (-> index 1) lumaThreshold[N-2] is the threshold for the darkest color (-> index N-1) -
scaleBilinearLm
Scales a palettized Bitmap (where each palette entry has individual alpha) using bilinear filtering to a Bitmap with N color palette, where: index0 = transparent, index1 = light color, ... , indexN-2 = dark color, indexN-1 = black.- Parameters:
sizeX
- Target widthsizeY
- Target heightpal
- Palette of the source BitmapalphaThr
- Threshold for alpha (transparency), lower = more transparentlumThr
- Threshold for luminances. For N-1 luminances, N-2 thresholds are needed lumThr[0] is the threshold for the lightest color (-> idx 1) lumThr[N-2] is the threshold for the darkest color (-> idx N-1)- Returns:
- Scaled Bitmap which uses a fixed frame Palette.
-
scaleFilterLm
public Bitmap scaleFilterLm(int sizeX, int sizeY, Palette pal, int alphaThr, int[] lumThr, com.mortennobel.imagescaling.ResampleFilter f) Scales a palettized Bitmap (where each palette entry has individual alpha) using a given scaling filter to a Bitmap with N color palette, where: index0 = transparent, index1 = light color, ... , indexN-2 = dark color, indexN-1 = black- Parameters:
sizeX
- Target widthsizeY
- Target heightpal
- Palette of the source BitmapalphaThr
- Threshold for alpha (transparency), lower = more transparentlumThr
- Threshold for luminances. For N-1 luminances, N-2 thresholds are needed lumThr[0] is the threshold for the lightest color (-> idx 1) lumThr[N-2] is the threshold for the darkest color (-> idx N-1)f
- Filter for scaling- Returns:
- Scaled Bitmap which uses a fixed frame Palette.
-
scaleBilinear
Scales a palettized Bitmap to a Bitmap with the same palette using bilinear filtering.- Parameters:
sizeX
- Target widthsizeY
- Target heightpal
- Palette of the source Bitmap- Returns:
- Scaled Bitmap which uses the same Palette as the source Bitmap.
-
scaleBilinear
Scales a palettized Bitmap to a Bitmap with a new quantized Palette using bilinear filtering.- Parameters:
sizeX
- Target widthsizeY
- Target heightpal
- Palette of the source Bitmapdither
- True: apply dithering- Returns:
- Scaled Bitmap and new Palette
-
scaleFilter
public Bitmap scaleFilter(int sizeX, int sizeY, Palette pal, com.mortennobel.imagescaling.ResampleFilter f) Scales a palettized Bitmap to a Bitmap with the same Palette using a given scaling filter.- Parameters:
sizeX
- Target widthsizeY
- Target heightpal
- Palette of the source Bitmapf
- Filter for scaling- Returns:
- Scaled Bitmap which uses the same Palette as the source Bitmap.
-
scaleFilter
public BitmapWithPalette scaleFilter(int sizeX, int sizeY, Palette pal, com.mortennobel.imagescaling.ResampleFilter f, boolean dither) Scales a palettized Bitmap to a Bitmap with a new quantized Palette using a given scaling filter.- Parameters:
sizeX
- Target widthsizeY
- Target heightpal
- Palette of the source Bitmapf
- Filter for scalingdither
- True: apply dithering- Returns:
- Scaled Bitmap and new Palette
-
toARGB
-
crop
-
getCroppingBounds
-
isRowWithColorAboveAlphaThreshold
private boolean isRowWithColorAboveAlphaThreshold(int yOfs, byte[] alpha, int alphaThreshold) -
isColumnWithColorAboveAlphaThreshold
private boolean isColumnWithColorAboveAlphaThreshold(int x, int yMin, int yMax, byte[] alpha, int alphaThreshold) -
isColorAboveAlphaThreshold
private boolean isColorAboveAlphaThreshold(int bufferIndex, byte[] alpha, int alphaThreshold) -
getWidth
public int getWidth() -
getHeight
public int getHeight() -
getInternalBuffer
public byte[] getInternalBuffer() -
getPixel
private byte getPixel(int x, int y) -
setPixel
private void setPixel(int x, int y, byte color)
-