Skip to content

Commit b6f0976

Browse files
committed
change functionality according to SVG Feature PR
merge new API (flag parameter) into existing API ImageDataProvider functionality is ignored for now.
1 parent f6c46ae commit b6f0976

File tree

8 files changed

+48
-51
lines changed

8 files changed

+48
-51
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@ public static ImageData load(String filename) {
3737
return data[0];
3838
}
3939

40-
public static ElementAtZoom<ImageData> load(InputStream stream, int fileZoom, int targetZoom) {
41-
List<ElementAtZoom<ImageData>> data = new ImageLoader().load(stream, fileZoom, targetZoom);
40+
public static ElementAtZoom<ImageData> load(InputStream stream, int fileZoom, int targetZoom, int flag) {
41+
List<ElementAtZoom<ImageData>> data = new ImageLoader().load(stream, fileZoom, targetZoom, flag);
4242
if (data.isEmpty()) SWT.error(SWT.ERROR_INVALID_IMAGE);
4343
return data.get(0);
4444
}
4545

46-
public static ElementAtZoom<ImageData> load(String filename, int fileZoom, int targetZoom) {
47-
List<ElementAtZoom<ImageData>> data = new ImageLoader().load(filename, fileZoom, targetZoom);
46+
public static ElementAtZoom<ImageData> load(String filename, int fileZoom, int targetZoom, int flag) {
47+
List<ElementAtZoom<ImageData>> data = new ImageLoader().load(filename, fileZoom, targetZoom, flag);
4848
if (data.isEmpty()) SWT.error(SWT.ERROR_INVALID_IMAGE);
4949
return data.get(0);
5050
}
51-
5251
}

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataProvider.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ public interface ImageDataProvider {
4343
*/
4444
ImageData getImageData (int zoom);
4545

46-
/**
47-
* @since 4.0
48-
*/
49-
default ImageData getCustomizedImageData(int zoom, int flag) {
50-
throw new UnsupportedOperationException();
51-
}
52-
53-
/**
54-
* @since 4.0
55-
*/
56-
default boolean supportsRasterizationFlag(int flag) {
57-
return false;
58-
}
46+
// /**
47+
// * @since 4.0
48+
// */
49+
// default ImageData getCustomizedImageData(int zoom, int flag) {
50+
// throw new UnsupportedOperationException();
51+
// }
52+
//
53+
// /**
54+
// * @since 4.0
55+
// */
56+
// default boolean supportsRasterizationFlag(int flag) {
57+
// return false;
58+
// }
5959
}

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ void reset() {
150150
* </ul>
151151
*/
152152
public ImageData[] load(InputStream stream) {
153-
load(stream, FileFormat.DEFAULT_ZOOM, FileFormat.DEFAULT_ZOOM);
153+
load(stream, FileFormat.DEFAULT_ZOOM, FileFormat.DEFAULT_ZOOM, SWT.IMAGE_COPY);
154154
return data;
155155
}
156156

157-
List<ElementAtZoom<ImageData>> load(InputStream stream, int fileZoom, int targetZoom) {
157+
List<ElementAtZoom<ImageData>> load(InputStream stream, int fileZoom, int targetZoom, int flag) {
158158
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
159159
reset();
160-
List<ElementAtZoom<ImageData>> images = InternalImageLoader.load(stream, this, fileZoom, targetZoom);
160+
List<ElementAtZoom<ImageData>> images = InternalImageLoader.load(stream, this, fileZoom, targetZoom, flag);
161161
data = images.stream().map(ElementAtZoom::element).toArray(ImageData[]::new);
162162
return images;
163163
}
@@ -181,14 +181,14 @@ List<ElementAtZoom<ImageData>> load(InputStream stream, int fileZoom, int target
181181
* </ul>
182182
*/
183183
public ImageData[] load(String filename) {
184-
load(filename, FileFormat.DEFAULT_ZOOM, FileFormat.DEFAULT_ZOOM);
184+
load(filename, FileFormat.DEFAULT_ZOOM, FileFormat.DEFAULT_ZOOM, SWT.IMAGE_COPY);
185185
return data;
186186
}
187187

188-
List<ElementAtZoom<ImageData>> load(String filename, int fileZoom, int targetZoom) {
188+
List<ElementAtZoom<ImageData>> load(String filename, int fileZoom, int targetZoom, int flag) {
189189
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
190190
try (InputStream stream = new FileInputStream(filename)) {
191-
return load(stream, fileZoom, targetZoom);
191+
return load(stream, fileZoom, targetZoom, flag);
192192
} catch (IOException e) {
193193
SWT.error(SWT.ERROR_IO, e);
194194
}

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static abstract class StaticImageFileFormat extends FileFormat {
8282
abstract ImageData[] loadFromByteStream();
8383

8484
@Override
85-
List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom) {
85+
List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom, int flag) {
8686
return Arrays.stream(loadFromByteStream()).map(d -> new ElementAtZoom<>(d, fileZoom)).toList();
8787
}
8888
}
@@ -102,16 +102,16 @@ List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom)
102102
* Format that do not implement {@link StaticImageFileFormat} MUST return
103103
* {@link ImageData} with the specified {@code targetZoom}.
104104
*/
105-
abstract List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom);
105+
abstract List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom, int flag);
106106

107107
/**
108108
* Read the specified input stream, and return the
109109
* device independent image array represented by the stream.
110110
*/
111-
public List<ElementAtZoom<ImageData>> loadFromStream(LEDataInputStream stream, int fileZoom, int targetZoom) {
111+
public List<ElementAtZoom<ImageData>> loadFromStream(LEDataInputStream stream, int fileZoom, int targetZoom, int flag) {
112112
try {
113113
inputStream = stream;
114-
return loadFromByteStream(fileZoom, targetZoom);
114+
return loadFromByteStream(fileZoom, targetZoom, flag);
115115
} catch (Exception e) {
116116
if (e instanceof IOException) {
117117
SWT.error(SWT.ERROR_IO, e);
@@ -126,14 +126,14 @@ public List<ElementAtZoom<ImageData>> loadFromStream(LEDataInputStream stream, i
126126
* Read the specified input stream using the specified loader, and
127127
* return the device independent image array represented by the stream.
128128
*/
129-
public static List<ElementAtZoom<ImageData>> load(InputStream is, ImageLoader loader, int fileZoom, int targetZoom) {
129+
public static List<ElementAtZoom<ImageData>> load(InputStream is, ImageLoader loader, int fileZoom, int targetZoom, int flag) {
130130
LEDataInputStream stream = new LEDataInputStream(is);
131131
FileFormat fileFormat = determineFileFormat(stream).orElseGet(() -> {
132132
SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
133133
return null;
134134
});
135135
fileFormat.loader = loader;
136-
return fileFormat.loadFromStream(stream, fileZoom, targetZoom);
136+
return fileFormat.loadFromStream(stream, fileZoom, targetZoom, flag);
137137
}
138138

139139
/**

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/SVGFileFormat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ boolean isFileFormat(LEDataInputStream stream) throws IOException {
4343
}
4444

4545
@Override
46-
List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom) {
46+
List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom, int flag) {
4747
if (RASTERIZER == null) {
4848
SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT, null, " [No SVG rasterizer found]");
4949
}
5050
if (targetZoom <= 0) {
5151
SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, " [Cannot rasterize SVG for zoom <= 0]");
5252
}
5353
try {
54-
ImageData rasterizedImageData = RASTERIZER.rasterizeSVG(inputStream, 100 * targetZoom / fileZoom);
54+
ImageData rasterizedImageData = RASTERIZER.rasterizeSVG(inputStream, 100 * targetZoom / fileZoom, flag);
5555
return List.of(new ElementAtZoom<>(rasterizedImageData, targetZoom));
5656
} catch (IOException e) {
5757
SWT.error(SWT.ERROR_INVALID_IMAGE, e);

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ ImageData loadIcon(int[] iconHeader) {
133133
StaticImageFileFormat png = new PNGFileFormat();
134134
if (png.isFileFormat(inputStream)) {
135135
png.loader = this.loader;
136-
return png.loadFromStream(inputStream, DEFAULT_ZOOM, DEFAULT_ZOOM).get(0).element();
136+
return png.loadFromStream(inputStream, DEFAULT_ZOOM, DEFAULT_ZOOM, SWT.IMAGE_COPY).get(0).element();
137137
}
138138
} catch (Exception e) {
139139
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -310,24 +310,22 @@ public Image(Device device, Image srcImage, int flag) {
310310
}
311311

312312
private boolean createWithSVG(Device device, int flag) {
313-
ImageData data = null;
314-
Image customizedImage = null;
315313
if (imageProvider.getProvider() instanceof ImageFileNameProvider imageFileNameProvider) {
316314
ElementAtZoom<String> fileName = DPIUtil.validateAndGetImagePathAtZoom(imageFileNameProvider, getZoom());
317315
if (fileName.element().endsWith(".svg")) {
318-
customizedImage = new Image(device, imageFileNameProvider, flag);
319-
}
320-
} else if (imageProvider.getProvider() instanceof ImageDataProvider imageDataProvider) {
321-
if (imageDataProvider.supportsRasterizationFlag(flag)) {
322-
customizedImage = new Image(device, imageDataProvider, flag);
316+
ElementAtZoom<ImageData> imageData = ImageDataLoader.load(fileName.element(), fileName.zoom(), getZoom(), flag);
317+
init(imageData.element(), getZoom());
318+
return true;
323319
}
324320
}
325-
if(customizedImage != null) {
326-
data = customizedImage.getImageData(customizedImage.getZoom());
327-
init(data, getZoom());
328-
customizedImage.dispose();
329-
return true;
330-
}
321+
// else if (imageProvider.getProvider() instanceof ImageDataProvider imageDataProvider) {
322+
// if (imageDataProvider.supportsRasterizationFlag(flag)) {
323+
// ImageData data = imageDataProvider.getCustomizedImageData(getZoom(), flag);
324+
// ElementAtZoom<ImageData> imageData = new ElementAtZoom<>(data, getZoom());
325+
// init(imageData.element(), getZoom());
326+
// return true;
327+
// }
328+
// }
331329
return false;
332330
}
333331

@@ -512,7 +510,7 @@ public Image (Device device, InputStream stream) {
512510
super(device);
513511
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
514512
int deviceZoom = getZoom();
515-
ElementAtZoom<ImageData> imageCandidate = ImageDataLoader.load(stream, FileFormat.DEFAULT_ZOOM, deviceZoom);
513+
ElementAtZoom<ImageData> imageCandidate = ImageDataLoader.load(stream, FileFormat.DEFAULT_ZOOM, deviceZoom, SWT.IMAGE_COPY);
516514
ImageData data = scaleImageData(imageCandidate.element(), deviceZoom, imageCandidate.zoom());
517515
init(data, deviceZoom);
518516
init();
@@ -556,7 +554,7 @@ public Image (Device device, String filename) {
556554
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
557555
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
558556
int deviceZoom = getZoom();
559-
ElementAtZoom<ImageData> imageCandidate = ImageDataLoader.load(filename, FileFormat.DEFAULT_ZOOM, deviceZoom);
557+
ElementAtZoom<ImageData> imageCandidate = ImageDataLoader.load(filename, FileFormat.DEFAULT_ZOOM, deviceZoom, SWT.IMAGE_COPY);
560558
ImageData data = scaleImageData(imageCandidate.element(), deviceZoom, imageCandidate.zoom());
561559
init(data, deviceZoom);
562560
init();
@@ -2128,7 +2126,7 @@ ImageData getImageData(int zoom) {
21282126

21292127
ElementAtZoom<ImageData> imageDataAtZoom;
21302128
if (nativeInitializedImage == null) {
2131-
imageDataAtZoom = ImageDataLoader.load(fileForZoom.element(), fileForZoom.zoom(), zoom);
2129+
imageDataAtZoom = ImageDataLoader.load(fileForZoom.element(), fileForZoom.zoom(), zoom, SWT.IMAGE_COPY);
21322130
} else {
21332131
imageDataAtZoom = new ElementAtZoom<>(nativeInitializedImage.getImageData(), fileForZoom.zoom());
21342132
destroyHandleForZoom(zoom);

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/InternalImageLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
class InternalImageLoader {
2323

24-
static List<ElementAtZoom<ImageData>> load(InputStream stream, ImageLoader imageLoader, int fileZoom, int targetZoom) {
25-
return FileFormat.load(stream, imageLoader, fileZoom, targetZoom);
24+
static List<ElementAtZoom<ImageData>> load(InputStream stream, ImageLoader imageLoader, int fileZoom, int targetZoom, int flag) {
25+
return FileFormat.load(stream, imageLoader, fileZoom, targetZoom, flag);
2626
}
2727

2828
static void save(OutputStream stream, int format, ImageLoader imageLoader) {

0 commit comments

Comments
 (0)