Skip to content

Commit bfd3979

Browse files
committed
ImageIO bypass (default) to not use spi classes for GIF, PNG, and JPEG.
Also Tiff, though.
1 parent eca95a7 commit bfd3979

File tree

2 files changed

+53
-47
lines changed

2 files changed

+53
-47
lines changed

sources/net.sf.j2s.java.core/src/com/sun/imageio/plugins/png/PNGImageWriter.java

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
import javax.imageio.stream.ImageOutputStream;
5252
import javax.imageio.stream.ImageOutputStreamImpl;
5353

54-
import swingjs.jzlib.JZlib;
55-
5654
class CRC {
5755

5856
private static int[] crcTable = new int[256];
@@ -110,20 +108,24 @@ public ChunkStream(int type, ImageOutputStream stream) throws IOException {
110108
writeInt(type);
111109
}
112110

113-
public int read() throws IOException {
111+
@Override
112+
public int read() throws IOException {
114113
throw new RuntimeException("Method not available");
115114
}
116115

117-
public int read(byte[] b, int off, int len) throws IOException {
116+
@Override
117+
public int read(byte[] b, int off, int len) throws IOException {
118118
throw new RuntimeException("Method not available");
119119
}
120120

121-
public void write(byte[] b, int off, int len) throws IOException {
121+
@Override
122+
public void write(byte[] b, int off, int len) throws IOException {
122123
crc.update(b, off, len);
123124
stream.write(b, off, len);
124125
}
125126

126-
public void write(int b) throws IOException {
127+
@Override
128+
public void write(int b) throws IOException {
127129
crc.update(b);
128130
stream.write(b);
129131
}
@@ -142,7 +144,8 @@ public void finish() throws IOException {
142144
stream.flushBefore(pos);
143145
}
144146

145-
protected void finalize() throws Throwable {
147+
@Override
148+
protected void finalize() throws Throwable {
146149
// Empty finalizer (for improved performance; no need to call
147150
// super.finalize() in this case)
148151
}
@@ -198,29 +201,27 @@ private void finishChunk() throws IOException {
198201
stream.flushBefore(pos);
199202
}
200203

201-
public int read() throws IOException {
204+
@Override
205+
public int read() throws IOException {
202206
throw new RuntimeException("Method not available");
203207
}
204208

205-
public int read(byte[] b, int off, int len) throws IOException {
209+
@Override
210+
public int read(byte[] b, int off, int len) throws IOException {
206211
throw new RuntimeException("Method not available");
207212
}
208213

209-
public void write(byte[] b, int off, int len) throws IOException {
214+
@Override
215+
public void write(byte[] b, int off, int len) throws IOException {
210216
if (len == 0) {
211217
return;
212218
}
213219

214220
if (!def.finished()) {
215-
def.setInput(b, off, len, true);
216-
while (def.avail_in > 0) {
217-
int err = deflate();
218-
if (err == JZlib.Z_STREAM_END)
219-
break;
220-
}
221-
// while (!def.needsInput()) {
222-
// deflate();
223-
// }
221+
def.setInput(b, off, len);
222+
while (!def.needsInput()) {
223+
deflate();
224+
}
224225
}
225226
}
226227

@@ -244,7 +245,8 @@ public void deflate() throws IOException {
244245
}
245246
}
246247

247-
public void write(int b) throws IOException {
248+
@Override
249+
public void write(int b) throws IOException {
248250
byte[] wbuf = new byte[1];
249251
wbuf[0] = (byte)b;
250252
write(wbuf, 0, 1);
@@ -264,7 +266,8 @@ public void finish() throws IOException {
264266
}
265267
}
266268

267-
protected void finalize() throws Throwable {
269+
@Override
270+
protected void finalize() throws Throwable {
268271
// Empty finalizer (for improved performance; no need to call
269272
// super.finalize() in this case)
270273
}
@@ -331,7 +334,8 @@ public PNGImageWriter(ImageWriterSpi originatingProvider) {
331334
super(originatingProvider);
332335
}
333336

334-
public void setOutput(Object output) {
337+
@Override
338+
public void setOutput(Object output) {
335339
super.setOutput(output);
336340
if (output != null) {
337341
if (!(output instanceof ImageOutputStream)) {
@@ -345,27 +349,32 @@ public void setOutput(Object output) {
345349

346350
private static int[] allowedProgressivePasses = { 1, 7 };
347351

348-
public ImageWriteParam getDefaultWriteParam() {
352+
@Override
353+
public ImageWriteParam getDefaultWriteParam() {
349354
return new PNGImageWriteParam(getLocale());
350355
}
351356

352-
public IIOMetadata getDefaultStreamMetadata(ImageWriteParam param) {
357+
@Override
358+
public IIOMetadata getDefaultStreamMetadata(ImageWriteParam param) {
353359
return null;
354360
}
355361

356-
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
362+
@Override
363+
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
357364
ImageWriteParam param) {
358365
PNGMetadata m = new PNGMetadata();
359366
m.initialize(imageType, imageType.getSampleModel().getNumBands());
360367
return m;
361368
}
362369

363-
public IIOMetadata convertStreamMetadata(IIOMetadata inData,
370+
@Override
371+
public IIOMetadata convertStreamMetadata(IIOMetadata inData,
364372
ImageWriteParam param) {
365373
return null;
366374
}
367375

368-
public IIOMetadata convertImageMetadata(IIOMetadata inData,
376+
@Override
377+
public IIOMetadata convertImageMetadata(IIOMetadata inData,
369378
ImageTypeSpecifier imageType,
370379
ImageWriteParam param) {
371380
// TODO - deal with imageType
@@ -1025,7 +1034,8 @@ private void initializeScaleTables(int[] sampleSize) {
10251034
}
10261035
}
10271036

1028-
public void write(IIOMetadata streamMetadata,
1037+
@Override
1038+
public void write(IIOMetadata streamMetadata,
10291039
IIOImage image,
10301040
ImageWriteParam param) throws IIOException {
10311041
if (stream == null) {

sources/net.sf.j2s.java.core/src/javax/imageio/ImageIO.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -905,25 +905,21 @@ public static Iterator<ImageReader> getImageReaders(Object input) {
905905
private static Method writerFileSuffixesMethod;
906906
private static Method writerMIMETypesMethod;
907907

908-
static {
909-
try {
910-
readerFormatNamesMethod =
911-
ImageReaderSpi.class.getMethod("getFormatNames");
912-
readerFileSuffixesMethod =
913-
ImageReaderSpi.class.getMethod("getFileSuffixes");
914-
readerMIMETypesMethod =
915-
ImageReaderSpi.class.getMethod("getMIMETypes");
916-
917-
writerFormatNamesMethod =
918-
ImageWriterSpi.class.getMethod("getFormatNames");
919-
writerFileSuffixesMethod =
920-
ImageWriterSpi.class.getMethod("getFileSuffixes");
921-
writerMIMETypesMethod =
922-
ImageWriterSpi.class.getMethod("getMIMETypes");
923-
} catch (NoSuchMethodException e) {
924-
e.printStackTrace();
925-
}
926-
}
908+
static {
909+
try {
910+
if (useSPI) {
911+
readerFormatNamesMethod = ImageReaderSpi.class.getMethod("getFormatNames");
912+
readerFileSuffixesMethod = ImageReaderSpi.class.getMethod("getFileSuffixes");
913+
readerMIMETypesMethod = ImageReaderSpi.class.getMethod("getMIMETypes");
914+
915+
writerFormatNamesMethod = ImageWriterSpi.class.getMethod("getFormatNames");
916+
writerFileSuffixesMethod = ImageWriterSpi.class.getMethod("getFileSuffixes");
917+
writerMIMETypesMethod = ImageWriterSpi.class.getMethod("getMIMETypes");
918+
}
919+
} catch (NoSuchMethodException e) {
920+
e.printStackTrace();
921+
}
922+
}
927923

928924
/**
929925
* Returns an <code>Iterator</code> containing all currently

0 commit comments

Comments
 (0)