Package de.gsi.chart.utils
Class WriteFxImage
- java.lang.Object
-
- de.gsi.chart.utils.WriteFxImage
-
public final class WriteFxImage extends java.lang.ObjectWrites a JavaFx Image into a ByteBuffer or file possible improvements: - use multiple IDAT chunks to use fixed buffer size and limit memory footprint - implement filtering of lines before compression for smaller file sizes - Optionally add tEXT chunks for metadata (EXIF)- Author:
- Alexander Krimm
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static javafx.scene.image.WritableImageclone(javafx.scene.image.Image image)copy the given Image to a WritableImagestatic voidcopyImageDataToPixelBuffer(javafx.scene.image.Image image, int[] uncompressedImageData)static java.nio.ByteBufferencode(javafx.scene.image.Image image)Encodes a JavaFx image as an RGB png image with fastest (lossless) compressionstatic java.nio.ByteBufferencode(javafx.scene.image.Image image, java.nio.ByteBuffer byteBuffer, boolean alpha, int compressionLevel, ar.com.hjg.pngj.FilterType filterType)Encodes a JavaFx image as an RGB png image.static java.nio.ByteBufferencodeAlt(javafx.scene.image.Image image, java.nio.ByteBuffer byteBuffer, boolean alpha, int compressionLevel, java.util.Map<java.lang.String,java.lang.Object> metaInfo)Encodes a JavaFx image as an RGB png image.static java.nio.ByteBufferencodePalette(javafx.scene.image.Image image, java.nio.ByteBuffer byteBuffer, boolean alpha, int compressionLevel, ar.com.hjg.pngj.FilterType filterType, PaletteQuantizer... userPalette)static PaletteQuantizerestimatePalette(int[] pixelArray, int width, int heigth, boolean alpha, int nColors)static PaletteQuantizerestimatePalette(javafx.scene.image.Image image, boolean alpha, int nColors)static intgetCompressedSizeBound(int width, int height, boolean alpha)Returns the conservative upper bound for the compressed image size.static voidsavePng(javafx.scene.image.Image image, java.io.File file)Saves the given image as a png file.
-
-
-
Method Detail
-
clone
public static javafx.scene.image.WritableImage clone(javafx.scene.image.Image image)
copy the given Image to a WritableImage- Parameters:
image- the input image- Returns:
- clone of image
-
copyImageDataToPixelBuffer
public static void copyImageDataToPixelBuffer(javafx.scene.image.Image image, int[] uncompressedImageData)
-
encode
public static java.nio.ByteBuffer encode(javafx.scene.image.Image image)
Encodes a JavaFx image as an RGB png image with fastest (lossless) compression- Parameters:
image- The input image to be encoded- Returns:
- a byte buffer with the encoded image
- See Also:
- rfc2083
-
encode
public static java.nio.ByteBuffer encode(javafx.scene.image.Image image, java.nio.ByteBuffer byteBuffer, boolean alpha, int compressionLevel, ar.com.hjg.pngj.FilterType filterType)Encodes a JavaFx image as an RGB png image. If you pass in a ByteBuffer to use, please make sure that it has enough capacity to fit the encoded image or handle errors (IndexOutOfBoundsException) accordingly. If you want to be on the safe side, usegetCompressedSizeBound(width, height, alpha)to get an upper bound for the output size.- Parameters:
image- The input image to be encodedbyteBuffer- optional byte buffer to store the output in, pass null to return a new one.alpha- whether to include alpha information in the imagecompressionLevel-Deflater.BEST_COMPRESSION(9) toDeflater.BEST_SPEED(0)filterType- filter as outlines in https://tools.ietf.org/html/rfc2083#section-6 plus some custom additional options implemented in the undelying PNG encode implementation- Returns:
- a byte buffer with the encoded image
- See Also:
- "https://tools.ietf.org/html/rfc2083"
-
encodeAlt
public static java.nio.ByteBuffer encodeAlt(javafx.scene.image.Image image, java.nio.ByteBuffer byteBuffer, boolean alpha, int compressionLevel, java.util.Map<java.lang.String,java.lang.Object> metaInfo)Encodes a JavaFx image as an RGB png image. If you pass in a ByteBuffer to use, please make sure that it has enough capacity to fit the encoded image or handle errors (IndexOutOfBoundsException) accordingly. If you want to be on the safe side, usegetCompressedSizeBound(width, height, alpha)to get an upper bound for the output size.- Parameters:
image- The input image to be encodedbyteBuffer- optional byte buffer to store the output in, pass null to return a new one.alpha- whether to include alpha information in the imagecompressionLevel-Deflater.BEST_COMPRESSION(9) toDeflater.BEST_SPEED(0)metaInfo- an optional map which will be filled with debugging information like compression efficiency- Returns:
- a byte buffer with the encoded image
- See Also:
- "https://tools.ietf.org/html/rfc2083"
-
encodePalette
public static java.nio.ByteBuffer encodePalette(javafx.scene.image.Image image, java.nio.ByteBuffer byteBuffer, boolean alpha, int compressionLevel, ar.com.hjg.pngj.FilterType filterType, PaletteQuantizer... userPalette)
-
estimatePalette
public static PaletteQuantizer estimatePalette(javafx.scene.image.Image image, boolean alpha, int nColors)
-
estimatePalette
public static PaletteQuantizer estimatePalette(int[] pixelArray, int width, int heigth, boolean alpha, int nColors)
-
getCompressedSizeBound
public static int getCompressedSizeBound(int width, int height, boolean alpha)Returns the conservative upper bound for the compressed image size.- Parameters:
width- Image widthheight- Image heightalpha- Alpha enabled- Returns:
- the upper bound for the size of the resulting png in bytes
- See Also:
- zlib sourcefor deflate upper bound
-
savePng
public static void savePng(javafx.scene.image.Image image, java.io.File file) throws java.io.IOExceptionSaves the given image as a png file.- Parameters:
image- The image to savefile- The filename to save the image to.- Throws:
java.io.IOException- if the file cannot be written
-
-