Skip to content

Commit

Permalink
add support for palette-based image formats
Browse files Browse the repository at this point in the history
  • Loading branch information
mstr2 committed Oct 17, 2024
1 parent 60b92b2 commit e23a756
Show file tree
Hide file tree
Showing 19 changed files with 1,455 additions and 721 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public final class ImageFrame {
private final int width;
private final int height;
private final int stride;
private final byte[][] palette;
private final int[] palette;
private final int paletteIndexBits;
private final ImageMetadata metadata;
private float pixelScale;

Expand All @@ -50,18 +51,31 @@ public final class ImageFrame {
* @param width The image width.
* @param height The image height.
* @param stride The stride from a pixel position in one row to the same
* horizontal position in the next row, in bytes
* @param palette The image palette. This is ignored unless the type is
* one of the palette types.
* horizontal position in the next row.
* @param metadata The image metadata.
*/
public ImageFrame(ImageType imageType, Buffer imageData,
int width, int height, int stride, byte[][] palette,
ImageMetadata metadata)
{
this(imageType, imageData,
width, height, stride, palette,
1.0f, metadata);
int width, int height, int stride,
ImageMetadata metadata) {
this(imageType, imageData, width, height, stride, 1.0f, metadata);
}

/**
* Create an <code>ImageFrame</code>.
*
* @param imageType The type of image data. The value of this field also implies the number of bands.
* @param imageData The image data.
* @param width The image width.
* @param height The image height.
* @param stride The stride from a pixel position in one row to the same horizontal position in the next row.
* @param pixelScale The scale of a 72DPI virtual pixel in the resolution of the image
* (1.0f for 72DPI images, 2.0f for 144DPI images, etc.).
* @param metadata The image metadata.
*/
public ImageFrame(ImageType imageType, Buffer imageData,
int width, int height, int stride,
float pixelScale, ImageMetadata metadata) {
this(imageType, imageData, width, height, stride, null, -1, pixelScale, metadata);
}

/**
Expand All @@ -72,24 +86,23 @@ public ImageFrame(ImageType imageType, Buffer imageData,
* @param imageData The image data.
* @param width The image width.
* @param height The image height.
* @param stride The stride from a pixel position in one row to the same
* horizontal position in the next row, in bytes
* @param palette The image palette. This is ignored unless the type is
* one of the palette types.
* @param stride The stride from a pixel position in one row to the same horizontal position in the next row.
* @param palette The image palette. This is ignored unless the type is one of the palette types.
* @param paletteIndexBits The size of a palette index, in bits.
* @param pixelScale The scale of a 72DPI virtual pixel in the resolution
* of the image (1.0f for 72DPI images, 2.0f for 144DPI images, etc.).
* @param metadata The image metadata.
*/
public ImageFrame(ImageType imageType, Buffer imageData,
int width, int height, int stride, byte[][] palette,
float pixelScale, ImageMetadata metadata)
{
int width, int height, int stride, int[] palette,
int paletteIndexBits, float pixelScale, ImageMetadata metadata) {
this.imageType = imageType;
this.imageData = imageData;
this.width = width;
this.height = height;
this.stride = stride;
this.palette = palette;
this.paletteIndexBits = paletteIndexBits;
this.pixelScale = pixelScale;
this.metadata = metadata;
}
Expand All @@ -114,10 +127,14 @@ public int getStride() {
return this.stride;
}

public byte[][] getPalette() {
public int[] getPalette() {
return this.palette;
}

public int getPaletteIndexBits() {
return paletteIndexBits;
}

public void setPixelScale(float pixelScale) {
this.pixelScale = pixelScale;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,24 @@ public static enum ImageType {
*/
GRAY_ALPHA_PRE,
/**
* An image with one 8-bit channel of indexes into a 24-bit
* An image with one channel of indexes into a 24-bit
* lookup table which maps the indexes to 8-bit RGB components.
*/
PALETTE,
/**
* An image with one 8-bit channel of indexes into a 32-bit
* An image with one channel of indexes into a 32-bit
* lookup table which maps the indexes to 8-bit RGBA components
* wherein the opacity is not-premultiplied.
*/
PALETTE_ALPHA,
/**
* An image with one 8-bit channel of indexes into a 32-bit
* An image with one channel of indexes into a 32-bit
* lookup table which maps the indexes to 8-bit RGBA components
* wherein the opacity is premultiplied.
*/
PALETTE_ALPHA_PRE,
/**
* An image with one 8-bit channel of indexes into a 24-bit
* An image with one channel of indexes into a 24-bit
* lookup table which maps the indexes to 8-bit RGB components, and
* a single transparent index to indicate the location of transparent
* pixels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public ImageFrame load(int imageIndex, double w, double h,
}

return new ImageFrame(ImageStorage.ImageType.RGB, img,
width, height, width * bpp, null, imagePixelScale, imageMetadata);
width, height, width * bpp, imagePixelScale, imageMetadata);
}
}

Expand Down
Loading

0 comments on commit e23a756

Please sign in to comment.