Class Bitmap

java.lang.Object
bdsup2sub.bitmap.Bitmap

public class Bitmap extends Object
Class to handle byte based bitmaps with a separate palette up to 256 colors.
  • Field Details

    • logger

      private static final Logger 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

      public Bitmap(Bitmap bitmap)
  • Method Details

    • fillWithColorIndexValue

      private void fillWithColorIndexValue(byte colorIndex)
    • fillRectangularWithColorIndex

      public void fillRectangularWithColorIndex(int rectX, int rectY, int rectWidth, int rectHeight, byte colorIndex)
    • getImage

      public BufferedImage getImage(ColorModel colorModel)
    • 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

      public Bitmap 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, ... , indexN-2 = dark color, indexN-1 = black.
      Parameters:
      sizeX - Target width
      sizeY - Target height
      pal - Palette of the source Bitmap
      alphaThr - Threshold for alpha (transparency), lower = more transparent
      lumThr - 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 width
      sizeY - Target height
      pal - Palette of the source Bitmap
      alphaThr - Threshold for alpha (transparency), lower = more transparent
      lumThr - 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

      public Bitmap scaleBilinear(int sizeX, int sizeY, Palette pal)
      Scales a palettized Bitmap to a Bitmap with the same palette using bilinear filtering.
      Parameters:
      sizeX - Target width
      sizeY - Target height
      pal - Palette of the source Bitmap
      Returns:
      Scaled Bitmap which uses the same Palette as the source Bitmap.
    • scaleBilinear

      public BitmapWithPalette scaleBilinear(int sizeX, int sizeY, Palette pal, boolean dither)
      Scales a palettized Bitmap to a Bitmap with a new quantized Palette using bilinear filtering.
      Parameters:
      sizeX - Target width
      sizeY - Target height
      pal - Palette of the source Bitmap
      dither - 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 width
      sizeY - Target height
      pal - Palette of the source Bitmap
      f - 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 width
      sizeY - Target height
      pal - Palette of the source Bitmap
      f - Filter for scaling
      dither - True: apply dithering
      Returns:
      Scaled Bitmap and new Palette
    • toARGB

      public int[] toARGB(Palette pal)
    • crop

      public Bitmap crop(int xOffset, int yOffset, int croppedBitmapWidth, int croppedBitmapHeight)
    • getCroppingBounds

      public BitmapBounds getCroppingBounds(byte[] alpha, int alphaThreshold)
    • 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)