From 27fa1a479b0fef2dfddb33f4b566cb68f572c3c5 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Thu, 30 Jan 2025 20:58:56 +0100 Subject: [PATCH] Prepare the implementation of dynamically sized image file-formats Co-authored-by: Heiko Klare --- .../swt/graphics/InternalImageLoader.java | 6 +- .../org/eclipse/swt/graphics/ImageLoader.java | 19 +++++- .../swt/internal/image/FileFormat.java | 62 ++++++++++++++----- .../swt/internal/image/GIFFileFormat.java | 22 +++---- .../swt/internal/image/JPEGFileFormat.java | 20 +++--- .../swt/internal/image/OS2BMPFileFormat.java | 17 +++-- .../swt/internal/image/PNGFileFormat.java | 15 +++-- .../swt/internal/image/TIFFFileFormat.java | 16 +++-- .../swt/internal/image/WinBMPFileFormat.java | 18 +++--- .../swt/internal/image/WinICOFileFormat.java | 19 +++--- .../swt/graphics/InternalImageLoader.java | 18 ++++-- .../swt/graphics/InternalImageLoader.java | 6 +- 12 files changed, 146 insertions(+), 92 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/InternalImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/InternalImageLoader.java index 18cdc24f651..e925542c18a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/InternalImageLoader.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/InternalImageLoader.java @@ -14,13 +14,15 @@ package org.eclipse.swt.graphics; import java.io.*; +import java.util.*; +import org.eclipse.swt.internal.DPIUtil.*; import org.eclipse.swt.internal.image.*; class InternalImageLoader { - static ImageData[] load(InputStream stream, ImageLoader imageLoader) { - return FileFormat.load(stream, imageLoader); + static List> load(InputStream stream, ImageLoader imageLoader, int fileZoom, int targetZoom) { + return FileFormat.load(stream, imageLoader, fileZoom, targetZoom); } static void save(OutputStream stream, int format, ImageLoader imageLoader) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java index 2196ae6d6f8..a1de14f5fe4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java @@ -18,6 +18,8 @@ import java.util.*; import org.eclipse.swt.*; +import org.eclipse.swt.internal.DPIUtil.*; +import org.eclipse.swt.internal.image.*; /** * Instances of this class are used to load images from, @@ -148,10 +150,16 @@ void reset() { * */ public ImageData[] load(InputStream stream) { + load(stream, FileFormat.DEFAULT_ZOOM, FileFormat.DEFAULT_ZOOM); + return data; +} + +List> load(InputStream stream, int fileZoom, int targetZoom) { if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); reset(); - data = InternalImageLoader.load(stream, this); - return data; + List> images = InternalImageLoader.load(stream, this, fileZoom, targetZoom); + data = images.stream().map(ElementAtZoom::element).toArray(ImageData[]::new); + return images; } /** @@ -173,9 +181,14 @@ public ImageData[] load(InputStream stream) { * */ public ImageData[] load(String filename) { + load(filename, FileFormat.DEFAULT_ZOOM, FileFormat.DEFAULT_ZOOM); + return data; +} + +List> load(String filename, int fileZoom, int targetZoom) { if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); try (InputStream stream = new FileInputStream(filename)) { - return load(stream); + return load(stream, fileZoom, targetZoom); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java index c3b58ea14c8..ea524de8fd0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java @@ -20,6 +20,7 @@ import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.DPIUtil.*; /** * Abstract factory class for loading/unloading images from files or streams @@ -54,27 +55,60 @@ public abstract class FileFormat { } catch (NoClassDefFoundError e) { } // ignore format } + public static final int DEFAULT_ZOOM = 100; + + private static Optional determineFileFormat(LEDataInputStream stream) { + return FORMAT_FACTORIES.stream().skip(1).map(Supplier::get).filter(f -> { + try { + return f.isFileFormat(stream); + } catch (IOException e) { + return false; + } + }).findFirst(); + } + + private static final int MAX_SIGNATURE_BYTES = 18 + 2; // e.g. Win-BMP or OS2-BMP plus a safety-margin + + public static boolean isDynamicallySizableFormat(InputStream is) { + Optional format = determineFileFormat(new LEDataInputStream(is, MAX_SIGNATURE_BYTES)); + return format.isPresent() && !(format.get() instanceof StaticImageFileFormat); + } + + static abstract class StaticImageFileFormat extends FileFormat { + + abstract ImageData[] loadFromByteStream(); + + @Override + List> loadFromByteStream(int fileZoom, int targetZoom) { + return Arrays.stream(loadFromByteStream()).map(d -> new ElementAtZoom<>(d, fileZoom)).toList(); + } + } + LEDataInputStream inputStream; LEDataOutputStream outputStream; ImageLoader loader; int compression; -/** - * Return whether or not the specified input stream - * represents a supported file format. - */ -abstract boolean isFileFormat(LEDataInputStream stream); + /** + * Return whether or not the specified input stream represents a supported file + * format. + */ + abstract boolean isFileFormat(LEDataInputStream stream) throws IOException; -abstract ImageData[] loadFromByteStream(); + /** + * Format that do not implement {@link StaticImageFileFormat} MUST return + * {@link ImageData} with the specified {@code targetZoom}. + */ + abstract List> loadFromByteStream(int fileZoom, int targetZoom); /** * Read the specified input stream, and return the * device independent image array represented by the stream. */ -public ImageData[] loadFromStream(LEDataInputStream stream) { +public List> loadFromStream(LEDataInputStream stream, int fileZoom, int targetZoom) { try { inputStream = stream; - return loadFromByteStream(); + return loadFromByteStream(fileZoom, targetZoom); } catch (Exception e) { if (e instanceof IOException) { SWT.error(SWT.ERROR_IO, e); @@ -89,14 +123,14 @@ public ImageData[] loadFromStream(LEDataInputStream stream) { * Read the specified input stream using the specified loader, and * return the device independent image array represented by the stream. */ -public static ImageData[] load(InputStream is, ImageLoader loader) { +public static List> load(InputStream is, ImageLoader loader, int fileZoom, int targetZoom) { LEDataInputStream stream = new LEDataInputStream(is); - FileFormat fileFormat = FORMAT_FACTORIES.stream().skip(1) // - .map(Supplier::get).filter(f -> f.isFileFormat(stream)) // - .findFirst().orElse(null); - if (fileFormat == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); + FileFormat fileFormat = determineFileFormat(stream).orElseGet(() -> { + SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); + return null; + }); fileFormat.loader = loader; - return fileFormat.loadFromStream(stream); + return fileFormat.loadFromStream(stream, fileZoom, targetZoom); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java index fa995f752c2..a5a5971dfcd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,11 +14,13 @@ package org.eclipse.swt.internal.image; +import java.io.*; + import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; -import java.io.*; +import org.eclipse.swt.internal.image.FileFormat.*; -public final class GIFFileFormat extends FileFormat { +public final class GIFFileFormat extends StaticImageFileFormat { String signature; int screenWidth, screenHeight, backgroundPixel, bitsPerPixel, defaultDepth; int disposalMethod = 0; @@ -51,15 +53,11 @@ static PaletteData grayRamp(int numGrays) { } @Override - boolean isFileFormat(LEDataInputStream stream) { - try { - byte[] signature = new byte[3]; - stream.read(signature); - stream.unread(signature); - return signature[0] == 'G' && signature[1] == 'I' && signature[2] == 'F'; - } catch (Exception e) { - return false; - } + boolean isFileFormat(LEDataInputStream stream) throws IOException { + byte[] signature = new byte[3]; + stream.read(signature); + stream.unread(signature); + return signature[0] == 'G' && signature[1] == 'I' && signature[2] == 'F'; } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java index fcd51e70169..9c34c8b2310 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -18,11 +18,13 @@ package org.eclipse.swt.internal.image; +import java.io.*; + import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; -import java.io.*; +import org.eclipse.swt.internal.image.FileFormat.*; -public final class JPEGFileFormat extends FileFormat { +public final class JPEGFileFormat extends StaticImageFileFormat { int restartInterval; JPEGFrameHeader frameHeader; int imageWidth, imageHeight; @@ -1362,16 +1364,14 @@ void inverseDCT(int[] dataUnit) { } } } -@Override -boolean isFileFormat(LEDataInputStream stream) { - try { + + @Override + boolean isFileFormat(LEDataInputStream stream) throws IOException { JPEGStartOfImage soi = new JPEGStartOfImage(stream); stream.unread(soi.reference); - return soi.verify(); // we no longer check for appN - } catch (Exception e) { - return false; + return soi.verify(); // we no longer check for appN } -} + boolean isZeroInColumn(int[] dataUnit, int col) { return dataUnit[col + 8] == 0 && dataUnit[col + 16] == 0 && dataUnit[col + 24] == 0 && dataUnit[col + 32] == 0 diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/OS2BMPFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/OS2BMPFileFormat.java index 130484a3f25..01a0db1dea2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/OS2BMPFileFormat.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/OS2BMPFileFormat.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,27 +14,26 @@ package org.eclipse.swt.internal.image; +import java.io.*; + import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; -import java.io.*; +import org.eclipse.swt.internal.image.FileFormat.*; -public final class OS2BMPFileFormat extends FileFormat { +public final class OS2BMPFileFormat extends StaticImageFileFormat { static final int BMPFileHeaderSize = 14; static final int BMPHeaderFixedSize = 12; int width, height, bitCount; -@Override -boolean isFileFormat(LEDataInputStream stream) { - try { + @Override + boolean isFileFormat(LEDataInputStream stream) throws IOException { byte[] header = new byte[18]; stream.read(header); stream.unread(header); int infoHeaderSize = (header[14] & 0xFF) | ((header[15] & 0xFF) << 8) | ((header[16] & 0xFF) << 16) | ((header[17] & 0xFF) << 24); return header[0] == 0x42 && header[1] == 0x4D && infoHeaderSize == BMPHeaderFixedSize; - } catch (Exception e) { - return false; } -} + byte[] loadData(byte[] infoHeader) { int stride = (width * bitCount + 7) / 8; stride = (stride + 3) / 4 * 4; // Round up to 4 byte multiple diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java index 66914c1b3da..e960f6327f3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -19,8 +19,9 @@ import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.image.FileFormat.*; -public final class PNGFileFormat extends FileFormat { +public final class PNGFileFormat extends StaticImageFileFormat { static final int SIGNATURE_LENGTH = 8; static final int PRIME = 65521; PngIhdrChunk headerChunk; @@ -151,9 +152,9 @@ void unloadIntoByteStream(ImageLoader loader) { PngEncoder encoder = new PngEncoder(loader); encoder.encode(outputStream); } -@Override -boolean isFileFormat(LEDataInputStream stream) { - try { + + @Override + boolean isFileFormat(LEDataInputStream stream) throws IOException { byte[] signature = new byte[SIGNATURE_LENGTH]; stream.read(signature); stream.unread(signature); @@ -166,10 +167,8 @@ boolean isFileFormat(LEDataInputStream stream) { if ((signature[6] & 0xFF) != 26) return false; // if ((signature[7] & 0xFF) != 10) return false; // return true; - } catch (Exception e) { - return false; } -} + /** * SWT does not support 16-bit depths. If this image uses * 16-bit depths, convert the data to an 8-bit depth. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java index 56112ba7a4f..469431578ab 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,19 +14,20 @@ package org.eclipse.swt.internal.image; +import java.io.*; + import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; -import java.io.*; +import org.eclipse.swt.internal.image.FileFormat.*; /** * Baseline TIFF decoder revision 6.0 * Extension T4-encoding CCITT T.4 1D */ -public final class TIFFFileFormat extends FileFormat { +public final class TIFFFileFormat extends StaticImageFileFormat { -@Override -boolean isFileFormat(LEDataInputStream stream) { - try { + @Override + boolean isFileFormat(LEDataInputStream stream) throws IOException { byte[] header = new byte[4]; stream.read(header); stream.unread(header); @@ -36,10 +37,7 @@ boolean isFileFormat(LEDataInputStream stream) { return false; } return true; - } catch (Exception e) { - return false; } -} @Override ImageData[] loadFromByteStream() { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java index 3032c548446..1efb4e7c192 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,11 +14,13 @@ package org.eclipse.swt.internal.image; +import java.io.*; + import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; -import java.io.*; +import org.eclipse.swt.internal.image.FileFormat.*; -public final class WinBMPFileFormat extends FileFormat { +public final class WinBMPFileFormat extends StaticImageFileFormat { static final int BMPFileHeaderSize = 14; static final int BMPHeaderFixedSize = 40; @@ -415,18 +417,16 @@ int decompressRLE8Data(byte[] src, int numBytes, int stride, byte[] dest, int de } return 1; } -@Override -boolean isFileFormat(LEDataInputStream stream) { - try { + + @Override + boolean isFileFormat(LEDataInputStream stream) throws IOException { byte[] header = new byte[18]; stream.read(header); stream.unread(header); int infoHeaderSize = (header[14] & 0xFF) | ((header[15] & 0xFF) << 8) | ((header[16] & 0xFF) << 16) | ((header[17] & 0xFF) << 24); return header[0] == 0x42 && header[1] == 0x4D && infoHeaderSize >= BMPHeaderFixedSize; - } catch (Exception e) { - return false; } -} + boolean isPaletteBMP(PaletteData pal, int depth) { switch(depth) { case 32: diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java index 6d6a981dcd5..9ab08b78877 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -18,8 +18,9 @@ import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.image.FileFormat.*; -public final class WinICOFileFormat extends FileFormat { +public final class WinICOFileFormat extends StaticImageFileFormat { byte[] bitInvertData(byte[] data, int startIndex, int endIndex) { // Destructively bit invert data in the given byte array. @@ -54,17 +55,15 @@ int iconSize(ImageData i) { int paletteSize = i.palette.colors != null ? i.palette.colors.length * 4 : 0; return WinBMPFileFormat.BMPHeaderFixedSize + paletteSize + dataSize; } -@Override -boolean isFileFormat(LEDataInputStream stream) { - try { + + @Override + boolean isFileFormat(LEDataInputStream stream) throws IOException { byte[] header = new byte[4]; stream.read(header); stream.unread(header); return header[0] == 0 && header[1] == 0 && header[2] == 1 && header[3] == 0; - } catch (Exception e) { - return false; } -} + boolean isValidIcon(ImageData i) { switch (i.depth) { case 1: @@ -131,10 +130,10 @@ ImageData[] loadFromByteStream() { */ ImageData loadIcon(int[] iconHeader) { try { - FileFormat png = new PNGFileFormat(); + StaticImageFileFormat png = new PNGFileFormat(); if (png.isFileFormat(inputStream)) { png.loader = this.loader; - return png.loadFromStream(inputStream)[0]; + return png.loadFromStream(inputStream, DEFAULT_ZOOM, DEFAULT_ZOOM).get(0).element(); } } catch (Exception e) { } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/InternalImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/InternalImageLoader.java index afe3e2aacec..0aee61a7c4f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/InternalImageLoader.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/InternalImageLoader.java @@ -21,6 +21,7 @@ import org.eclipse.swt.*; import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.DPIUtil.*; import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.internal.image.*; import org.eclipse.swt.widgets.*; @@ -32,7 +33,7 @@ class InternalImageLoader { // --- loading --- - static ImageData[] load(InputStream stream, ImageLoader imageLoader) { + static List> load(InputStream stream, ImageLoader imageLoader, int fileZoom, int targetZoom) { // 1) Load InputStream into byte array byte[] data_buffer; try (stream) { @@ -41,11 +42,20 @@ static ImageData[] load(InputStream stream, ImageLoader imageLoader) { SWT.error(SWT.ERROR_IO); return null; } - long loader = GDK.gdk_pixbuf_loader_new(); - List imgDataList = new ArrayList<>(); if (data_buffer.length == 0) { SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); // empty stream } + InputStream stream2 = new ByteArrayInputStream(data_buffer); + if (FileFormat.isDynamicallySizableFormat(stream2)) { + try { + stream2.reset(); + } catch (IOException e) { + SWT.error(SWT.ERROR_IO); + } + return FileFormat.load(stream2, imageLoader, fileZoom, targetZoom); + } + List imgDataList = new ArrayList<>(); + long loader = GDK.gdk_pixbuf_loader_new(); // 2) Copy byte array to C memory, write to GdkPixbufLoader long buffer_ptr = OS.g_malloc(data_buffer.length); C.memmove(buffer_ptr, data_buffer, data_buffer.length); @@ -128,7 +138,7 @@ static ImageData[] load(InputStream stream, ImageLoader imageLoader) { } OS.g_free(buffer_ptr); OS.g_object_unref(loader); - return imgDataArray; + return Arrays.stream(imgDataArray).map(data -> new ElementAtZoom<>(data, fileZoom)).toList(); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/InternalImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/InternalImageLoader.java index 18cdc24f651..e925542c18a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/InternalImageLoader.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/InternalImageLoader.java @@ -14,13 +14,15 @@ package org.eclipse.swt.graphics; import java.io.*; +import java.util.*; +import org.eclipse.swt.internal.DPIUtil.*; import org.eclipse.swt.internal.image.*; class InternalImageLoader { - static ImageData[] load(InputStream stream, ImageLoader imageLoader) { - return FileFormat.load(stream, imageLoader); + static List> load(InputStream stream, ImageLoader imageLoader, int fileZoom, int targetZoom) { + return FileFormat.load(stream, imageLoader, fileZoom, targetZoom); } static void save(OutputStream stream, int format, ImageLoader imageLoader) {