Skip to content

Commit 6a24351

Browse files
committed
merge new API (flag parameter) into existing API
1 parent 39a849c commit 6a24351

File tree

7 files changed

+8
-81
lines changed

7 files changed

+8
-81
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,8 @@ 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);
42-
if (data.isEmpty()) SWT.error(SWT.ERROR_INVALID_IMAGE);
43-
return data.get(0);
44-
}
45-
46-
public static ElementAtZoom<ImageData> load(String filename, int fileZoom, int targetZoom) {
47-
List<ElementAtZoom<ImageData>> data = new ImageLoader().load(filename, 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);
4842
if (data.isEmpty()) SWT.error(SWT.ERROR_INVALID_IMAGE);
4943
return data.get(0);
5044
}
@@ -54,5 +48,4 @@ public static ElementAtZoom<ImageData> load(String filename, int fileZoom, int t
5448
if (data.isEmpty()) SWT.error(SWT.ERROR_INVALID_IMAGE);
5549
return data.get(0);
5650
}
57-
5851
}

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,10 @@ 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) {
158-
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
159-
reset();
160-
List<ElementAtZoom<ImageData>> images = InternalImageLoader.load(stream, this, fileZoom, targetZoom);
161-
data = images.stream().map(ElementAtZoom::element).toArray(ImageData[]::new);
162-
return images;
163-
}
164-
165157
List<ElementAtZoom<ImageData>> load(InputStream stream, int fileZoom, int targetZoom, int flag) {
166158
if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
167159
reset();
@@ -189,20 +181,10 @@ List<ElementAtZoom<ImageData>> load(InputStream stream, int fileZoom, int target
189181
* </ul>
190182
*/
191183
public ImageData[] load(String filename) {
192-
load(filename, FileFormat.DEFAULT_ZOOM, FileFormat.DEFAULT_ZOOM);
184+
load(filename, FileFormat.DEFAULT_ZOOM, FileFormat.DEFAULT_ZOOM, SWT.IMAGE_COPY);
193185
return data;
194186
}
195187

196-
List<ElementAtZoom<ImageData>> load(String filename, int fileZoom, int targetZoom) {
197-
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
198-
try (InputStream stream = new FileInputStream(filename)) {
199-
return load(stream, fileZoom, targetZoom);
200-
} catch (IOException e) {
201-
SWT.error(SWT.ERROR_IO, e);
202-
}
203-
return null;
204-
}
205-
206188
List<ElementAtZoom<ImageData>> load(String filename, int fileZoom, int targetZoom, int flag) {
207189
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
208190
try (InputStream stream = new FileInputStream(filename)) {

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ static abstract class StaticImageFileFormat extends FileFormat {
8383

8484
abstract ImageData[] loadFromByteStream();
8585

86-
@Override
87-
List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom) {
88-
return Arrays.stream(loadFromByteStream()).map(d -> new ElementAtZoom<>(d, fileZoom)).toList();
89-
}
90-
9186
@Override
9287
List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom, int flag) {
9388
switch (flag) {
@@ -242,12 +237,6 @@ private ImageData applyGrayImageData(ImageData data, int pHeight, int pWidth) {
242237
*/
243238
abstract boolean isFileFormat(LEDataInputStream stream) throws IOException;
244239

245-
/**
246-
* Format that do not implement {@link StaticImageFileFormat} MUST return
247-
* {@link ImageData} with the specified {@code targetZoom}.
248-
*/
249-
abstract List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom);
250-
251240
/**
252241
* Format that do not implement {@link StaticImageFileFormat} MUST return
253242
* {@link ImageData} with the specified {@code targetZoom}.
@@ -258,20 +247,6 @@ private ImageData applyGrayImageData(ImageData data, int pHeight, int pWidth) {
258247
* Read the specified input stream, and return the
259248
* device independent image array represented by the stream.
260249
*/
261-
public List<ElementAtZoom<ImageData>> loadFromStream(LEDataInputStream stream, int fileZoom, int targetZoom) {
262-
try {
263-
inputStream = stream;
264-
return loadFromByteStream(fileZoom, targetZoom);
265-
} catch (Exception e) {
266-
if (e instanceof IOException) {
267-
SWT.error(SWT.ERROR_IO, e);
268-
} else {
269-
SWT.error(SWT.ERROR_INVALID_IMAGE, e);
270-
}
271-
return null;
272-
}
273-
}
274-
275250
public List<ElementAtZoom<ImageData>> loadFromStream(LEDataInputStream stream, int fileZoom, int targetZoom, int flag) {
276251
try {
277252
inputStream = stream;
@@ -286,20 +261,6 @@ public List<ElementAtZoom<ImageData>> loadFromStream(LEDataInputStream stream, i
286261
}
287262
}
288263

289-
/**
290-
* Read the specified input stream using the specified loader, and
291-
* return the device independent image array represented by the stream.
292-
*/
293-
public static List<ElementAtZoom<ImageData>> load(InputStream is, ImageLoader loader, int fileZoom, int targetZoom) {
294-
LEDataInputStream stream = new LEDataInputStream(is);
295-
FileFormat fileFormat = determineFileFormat(stream).orElseGet(() -> {
296-
SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
297-
return null;
298-
});
299-
fileFormat.loader = loader;
300-
return fileFormat.loadFromStream(stream, fileZoom, targetZoom);
301-
}
302-
303264
/**
304265
* Read the specified input stream using the specified loader, and
305266
* return the device independent image array represented by the stream.

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ boolean isFileFormat(LEDataInputStream stream) throws IOException {
4242
return header.startsWith("<?xml") || header.startsWith("<svg");
4343
}
4444

45-
@Override
46-
List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom) {
47-
return loadFromByteStream(fileZoom, targetZoom, SWT.IMAGE_COPY);
48-
}
49-
5045
@Override
5146
List<ElementAtZoom<ImageData>> loadFromByteStream(int fileZoom, int targetZoom, int flag) {
5247
if (RASTERIZER == null) {

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ public Image (Device device, InputStream stream) {
513513
super(device);
514514
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
515515
int deviceZoom = getZoom();
516-
ElementAtZoom<ImageData> imageCandidate = ImageDataLoader.load(stream, FileFormat.DEFAULT_ZOOM, deviceZoom);
516+
ElementAtZoom<ImageData> imageCandidate = ImageDataLoader.load(stream, FileFormat.DEFAULT_ZOOM, deviceZoom, SWT.IMAGE_COPY);
517517
ImageData data = scaleImageData(imageCandidate.element(), deviceZoom, imageCandidate.zoom());
518518
init(data, deviceZoom);
519519
init();
@@ -557,7 +557,7 @@ public Image (Device device, String filename) {
557557
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
558558
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
559559
int deviceZoom = getZoom();
560-
ElementAtZoom<ImageData> imageCandidate = ImageDataLoader.load(filename, FileFormat.DEFAULT_ZOOM, deviceZoom);
560+
ElementAtZoom<ImageData> imageCandidate = ImageDataLoader.load(filename, FileFormat.DEFAULT_ZOOM, deviceZoom, SWT.IMAGE_COPY);
561561
ImageData data = scaleImageData(imageCandidate.element(), deviceZoom, imageCandidate.zoom());
562562
init(data, deviceZoom);
563563
init();
@@ -2129,7 +2129,7 @@ ImageData getImageData(int zoom) {
21292129

21302130
ElementAtZoom<ImageData> imageDataAtZoom;
21312131
if (nativeInitializedImage == null) {
2132-
imageDataAtZoom = ImageDataLoader.load(fileForZoom.element(), fileForZoom.zoom(), zoom);
2132+
imageDataAtZoom = ImageDataLoader.load(fileForZoom.element(), fileForZoom.zoom(), zoom, SWT.IMAGE_COPY);
21332133
} else {
21342134
imageDataAtZoom = new ElementAtZoom<>(nativeInitializedImage.getImageData(), fileForZoom.zoom());
21352135
destroyHandleForZoom(zoom);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
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);
26-
}
27-
2824
static List<ElementAtZoom<ImageData>> load(InputStream stream, ImageLoader imageLoader, int fileZoom, int targetZoom, int flag) {
2925
return FileFormat.load(stream, imageLoader, fileZoom, targetZoom, flag);
3026
}

0 commit comments

Comments
 (0)