Skip to content

Commit

Permalink
8306707: Support pluggable image loading via javax.imageio
Browse files Browse the repository at this point in the history
Reviewed-by: jhendrikx, kcr, jdv
  • Loading branch information
Michael Strauß committed Nov 13, 2024
1 parent 688f7fa commit 72af9e2
Show file tree
Hide file tree
Showing 36 changed files with 3,203 additions and 799 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,20 +27,20 @@

import com.sun.javafx.iio.ImageStorage.ImageType;
import java.nio.Buffer;
import java.nio.ByteBuffer;

/**
* A class representing the data and metadata of a single image.
*/
public class ImageFrame {
private ImageType imageType;
private ByteBuffer imageData;
private int width;
private int height;
private int stride;
public final class ImageFrame {
private final ImageType imageType;
private final Buffer imageData;
private final int width;
private final int height;
private final int stride;
private final int[] palette;
private final int paletteIndexBits;
private final ImageMetadata metadata;
private float pixelScale;
private byte[][] palette;
private ImageMetadata metadata;

/**
* Create an <code>ImageFrame</code> with a default 72DPI pixel scale.
Expand All @@ -50,19 +50,33 @@ public class ImageFrame {
* @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 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,
* in data elements (not necessarily bytes).
* @param metadata The image metadata.
*/
public ImageFrame(ImageType imageType, ByteBuffer imageData,
int width, int height, int stride, byte[][] palette,
ImageMetadata metadata)
{
this(imageType, imageData,
width, height, stride, palette,
1.0f, metadata);
public ImageFrame(ImageType imageType, Buffer imageData,
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,
* in data elements (not necessarily bytes).
* @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 @@ -73,24 +87,24 @@ public ImageFrame(ImageType imageType, ByteBuffer 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.
* @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,
* in data elements (not necessarily bytes).
* @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, ByteBuffer imageData,
int width, int height, int stride, byte[][] palette,
float pixelScale, ImageMetadata metadata)
{
public ImageFrame(ImageType imageType, Buffer imageData,
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 @@ -115,10 +129,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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -72,8 +72,11 @@ public interface ImageLoader {
* @param preserveAspectRatio whether to preserve the width-to-height ratio
* of the image.
* @param smooth whether to use a smooth downscaling algorithm.
* @param screenPixelScale screen pixel scale (used for variable-density images)
* @param imagePixelScale image pixel scale (used for fixed-density images)
* @return the image at the specified index or <code>null</code> on error.
*/
public ImageFrame load(int imageIndex, int width, int height,
boolean preserveAspectRatio, boolean smooth) throws IOException;
ImageFrame load(int imageIndex, double width, double height,
boolean preserveAspectRatio, boolean smooth,
float screenPixelScale, float imagePixelScale) throws IOException;
}
Loading

3 comments on commit 72af9e2

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinrushforth
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/skara tag 24+17

@openjdk
Copy link

@openjdk openjdk bot commented on 72af9e2 Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinrushforth The tag 24+17 was successfully created.

Please sign in to comment.