Skip to content

Commit 0f35eb1

Browse files
author
Evgeniy Sidenko
committed
optimizations
added correct OutOfMemory processing
1 parent 6f91e51 commit 0f35eb1

File tree

5 files changed

+49
-35
lines changed

5 files changed

+49
-35
lines changed

pom.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.aspose</groupId>
88
<artifactId>aspose-imaging-heic-adapter</artifactId>
9-
<version>25.4</version>
9+
<version>25.8</version>
1010
<name>Aspose.Imaging.HEIC.Adapter for Java</name>
1111
<description>Aspose.Imaging.HEIC.Adapter Combines 2 products Aspose.Imaging and Openize.HEIC, this allows to use the functions of both libraries as a single whole and expand export between formats HEIC format can be exported to all formats supported by Imaging, for example Png, Tiff, Pdf, Svg, Jpeg, Gif, Bmp, Emf, Wmf, J2k, Webp etc.</description>
1212
<url>https://products.aspose.com/imaging/java</url>
@@ -32,7 +32,7 @@
3232
<repositories>
3333
<repository>
3434
<id>aspose-maven-repository</id>
35-
<url>https://repository.aspose.com/repo/</url>
35+
<url>https://releases.aspose.com/java/repo/</url>
3636
</repository>
3737
</repositories>
3838

@@ -53,18 +53,19 @@
5353
<dependency>
5454
<groupId>com.aspose</groupId>
5555
<artifactId>aspose-imaging</artifactId>
56-
<version>25.4</version>
56+
<version>25.7</version>
5757
</dependency>
5858
<dependency>
5959
<groupId>com.aspose</groupId>
6060
<artifactId>aspose-imaging</artifactId>
61-
<version>25.4</version>
61+
<version>25.7</version>
6262
<classifier>javadoc</classifier>
6363
</dependency>
6464
<dependency>
65-
<groupId>com.aspose</groupId>
65+
<!-- <groupId>com.aspose</groupId> -->
66+
<groupId>openize</groupId>
6667
<artifactId>openize-heic</artifactId>
67-
<version>25.4</version>
68+
<version>25.8</version>
6869
</dependency>
6970
</dependencies>
7071

src/main/java/com/aspose/imaging/heic/adapter/HEICDataLoader.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
package com.aspose.imaging.heic.adapter;
66

77
import com.aspose.imaging.*;
8-
import com.aspose.imaging.internal.Exceptions.NotSupportedException;
98
import openize.heic.decoder.HeicImageFrame;
109

10+
import java.util.Collections;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
1114
/**
1215
* <p>
1316
* The Heic data loader of {@code IRasterImageArgb32PixelLoader}
@@ -44,12 +47,12 @@ public HEICDataLoader(HeicImageFrame image)
4447
* @param rectangle The rectangle to load raw data from.
4548
* @param rawDataSettings The raw data settings to use for loaded data. Note if data is not in the format specified then data conversion will be performed.
4649
* @param rawDataLoader The raw data loader.
47-
* @throws NotSupportedException It does not support.
50+
* @throws UnsupportedOperationException It does not support.
4851
*/
4952
@Override
5053
public final void loadRawData(Rectangle rectangle, RawDataSettings rawDataSettings, IPartialRawDataLoader rawDataLoader)
5154
{
52-
throw new NotSupportedException();
55+
throw new UnsupportedOperationException();
5356
}
5457

5558
/**
@@ -91,8 +94,21 @@ public final RawDataSettings getRawDataSettings()
9194
@Override
9295
public final void loadPartialArgb32Pixels(Rectangle rectangle, IPartialArgb32PixelLoader partialPixelLoader)
9396
{
94-
partialPixelLoader.process(rectangle, this.image.getInt32Array(openize.heic.decoder.PixelFormat.Argb32,
95-
new openize.heic.decoder.Rectangle(rectangle.getX(), rectangle.getY(), rectangle.getWidth(), rectangle.getHeight())),
97+
final long threadID = Thread.currentThread().getId();
98+
Rectangle rec = maps.get(threadID);
99+
if (rec != null && (rectangle.getWidth() != image.getWidth() || rectangle.getHeight() != image.getHeight()))
100+
{
101+
maps.remove(threadID);
102+
throw new UnsupportedOperationException("OutOfMemory: HEIC Adapter does not support the partial processing.");
103+
}
104+
maps.put(threadID, rectangle);
105+
106+
int[] argbPixels = this.image.getInt32Array(openize.heic.decoder.PixelFormat.Argb32,
107+
new openize.heic.decoder.Rectangle(rectangle.getX(), rectangle.getY(), rectangle.getWidth(), rectangle.getHeight()), null);
108+
partialPixelLoader.process(rectangle, argbPixels,
96109
rectangle.getLocation(), new Point(rectangle.getRight(), rectangle.getBottom()));
110+
maps.remove(threadID);
97111
}
112+
113+
private final Map<Long, Rectangle> maps = Collections.synchronizedMap(new HashMap<>());
98114
}

src/main/java/com/aspose/imaging/heic/adapter/HEICImage.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.aspose.imaging.*;
88
import com.aspose.imaging.heic.adapter.loader.HEICImageLoaderDescriptor;
99
import com.aspose.imaging.heic.io.ImageStream;
10-
import com.aspose.imaging.internal.Exceptions.NotSupportedException;
1110
import com.aspose.imaging.system.io.Stream;
1211
import openize.heic.decoder.HeicImage;
1312
import openize.heic.decoder.HeicImageFrame;
@@ -220,8 +219,6 @@ public static void register()
220219
* <p>
221220
* Caches the data private.
222221
* </p>
223-
*
224-
* @throws NotSupportedException Not supported.
225222
*/
226223
@Override
227224
public /*override*/ void cacheData()
@@ -235,12 +232,12 @@ public static void register()
235232
* </p>
236233
*
237234
* @param stream The stream to save data to.
238-
* @throws NotSupportedException Not supported.
235+
* @throws UnsupportedOperationException Not supported.
239236
*/
240237
@Override
241238
protected /*override*/ void saveData(Stream stream)
242239
{
243-
throw new NotSupportedException();
240+
throw new UnsupportedOperationException();
244241
}
245242

246243
/**
@@ -250,11 +247,11 @@ public static void register()
250247
*
251248
* @param newWidth The new image width.
252249
* @param newHeight The new image height.
253-
* @throws NotSupportedException Not supported.
250+
* @throws UnsupportedOperationException Not supported.
254251
*/
255252
@Override
256253
protected /*override*/ void updateDimensions(int newWidth, int newHeight)
257254
{
258-
throw new NotSupportedException();
255+
throw new UnsupportedOperationException();
259256
}
260257
}

src/main/java/com/aspose/imaging/heic/adapter/HEICImagePage.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
package com.aspose.imaging.heic.adapter;
66

7-
import com.aspose.imaging.DataStreamSupporter;
8-
import com.aspose.imaging.IColorPalette;
9-
import com.aspose.imaging.Image;
10-
import com.aspose.imaging.RasterImage;
11-
import com.aspose.imaging.internal.Exceptions.NotSupportedException;
7+
import com.aspose.imaging.*;
128
import com.aspose.imaging.system.io.Stream;
139
import openize.heic.decoder.HeicImageFrame;
1410

@@ -119,23 +115,22 @@ public HEICImagePage(HeicImageFrame frame, Image container)
119115
* <p>
120116
* Updates the image dimensions.
121117
* </p>
122-
* @exception NotSupportedException The resizing is unsupported feature.
123-
* @param newWidth The new image width.
118+
*
119+
* @param newWidth The new image width.
124120
* @param newHeight The new image height.
121+
* @throws UnsupportedOperationException The resizing is unsupported feature.
125122
*/
126123
@Override
127124
protected void updateDimensions(int newWidth, int newHeight)
128125
{
129-
throw new NotSupportedException();
126+
throw new UnsupportedOperationException();
130127
}
131128

132129
/**
133130
* <p>
134131
* Caches the data and ensures no additional data loading will be performed from the underlying
135132
* {@link DataStreamSupporter#getDataStreamContainer()}.
136133
* </p>
137-
*
138-
* @throws NotSupportedException Not supported!
139134
*/
140135
@Override
141136
public /*override*/ void cacheData()
@@ -149,13 +144,12 @@ protected void updateDimensions(int newWidth, int newHeight)
149144
* </p>
150145
*
151146
* @param rotateFlipType Type of the rotate flip.
152-
* @throws NotSupportedException Not supported!
153147
* @see com.aspose.imaging.RotateFlipType
154148
*/
155149
@Override
156150
public /*override*/ void rotateFlip(int rotateFlipType)
157151
{
158-
throw new NotSupportedException();
152+
throw new UnsupportedOperationException();
159153
}
160154

161155
/**
@@ -166,13 +160,13 @@ protected void updateDimensions(int newWidth, int newHeight)
166160
* @param ditheringMethod The dithering method.
167161
* @param bitsCount The final bits count for dithering.
168162
* @param customPalette The custom palette for dithering.
169-
* @throws NotSupportedException Not supported!
163+
* @throws UnsupportedOperationException Not supported!
170164
* @see com.aspose.imaging.DitheringMethod
171165
*/
172166
@Override
173167
public /*override*/ void dither(int ditheringMethod, int bitsCount, IColorPalette customPalette)
174168
{
175-
throw new NotSupportedException();
169+
throw new UnsupportedOperationException();
176170
}
177171

178172
/**
@@ -181,11 +175,11 @@ protected void updateDimensions(int newWidth, int newHeight)
181175
* </p>
182176
*
183177
* @param stream The stream to save data to.
184-
* @throws NotSupportedException Not supported!
178+
* @throws UnsupportedOperationException Not supported!
185179
*/
186180
@Override
187181
protected /*override*/ void saveData(Stream stream)
188182
{
189-
throw new NotSupportedException();
183+
throw new UnsupportedOperationException();
190184
}
191185
}

src/main/java/com/aspose/imaging/heic/io/ImageStream.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class ImageStream implements IOStream, IDisposable
2525
*/
2626
private final Stream stream;
2727

28+
private long streamLength;
29+
2830
/**
2931
* <p>
3032
* Creates an instance.
@@ -34,6 +36,7 @@ public class ImageStream implements IOStream, IDisposable
3436
public ImageStream(Stream stream)
3537
{
3638
this.stream = stream;
39+
this.streamLength = stream.getLength();
3740
}
3841

3942
/**
@@ -74,6 +77,7 @@ public int read(byte[] bytes, int offset, int length)
7477
public void write(byte[] bytes)
7578
{
7679
stream.write(bytes, 0, bytes.length);
80+
this.streamLength = stream.getLength();
7781
}
7882

7983
/**
@@ -88,6 +92,7 @@ public void write(byte[] bytes)
8892
public void write(byte[] bytes, int offset, int length)
8993
{
9094
stream.write(bytes, offset, length);
95+
this.streamLength = stream.getLength();
9196
}
9297

9398
/**
@@ -139,7 +144,7 @@ public void seek(long newPosition, IOSeekMode mode)
139144
@Override
140145
public long getLength()
141146
{
142-
return stream.getLength();
147+
return this.streamLength;
143148
}
144149

145150
/**
@@ -152,6 +157,7 @@ public long getLength()
152157
public void setLength(long newLength)
153158
{
154159
stream.setLength(newLength);
160+
this.streamLength = stream.getLength();
155161
}
156162

157163
/**

0 commit comments

Comments
 (0)