1 /*
2 * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1217 // MODE_EXPLICIT is not allowed
1218 default:
1219 }
1220 }
1221
1222 // Initialize bitDepth and colorType
1223 metadata.initialize(new ImageTypeSpecifier(im), numBands);
1224
1225 // Overwrite IHDR width and height values with values from image
1226 metadata.IHDR_width = destWidth;
1227 metadata.IHDR_height = destHeight;
1228
1229 this.bpp = numBands*((metadata.IHDR_bitDepth == 16) ? 2 : 1);
1230
1231 // Initialize scaling tables for this image
1232 initializeScaleTables(sampleModel.getSampleSize());
1233
1234 clearAbortRequest();
1235
1236 processImageStarted(0);
1237
1238 try {
1239 write_magic();
1240 write_IHDR();
1241
1242 write_cHRM();
1243 write_gAMA();
1244 write_iCCP();
1245 write_sBIT();
1246 write_sRGB();
1247
1248 write_PLTE();
1249
1250 write_hIST();
1251 write_tRNS();
1252 write_bKGD();
1253
1254 write_pHYs();
1255 write_sPLT();
1256 write_tIME();
1257 write_tEXt();
1258 write_iTXt();
1259 write_zTXt();
1260
1261 writeUnknownChunks();
1262
1263 write_IDAT(im, deflaterLevel);
1264
1265 if (abortRequested()) {
1266 processWriteAborted();
1267 } else {
1268 // Finish up and inform the listeners we are done
1269 writeIEND();
1270 processImageComplete();
1271 }
1272 } catch (IOException e) {
1273 throw new IIOException("I/O error writing PNG file!", e);
1274 }
1275 }
1276 }
|
1 /*
2 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1217 // MODE_EXPLICIT is not allowed
1218 default:
1219 }
1220 }
1221
1222 // Initialize bitDepth and colorType
1223 metadata.initialize(new ImageTypeSpecifier(im), numBands);
1224
1225 // Overwrite IHDR width and height values with values from image
1226 metadata.IHDR_width = destWidth;
1227 metadata.IHDR_height = destHeight;
1228
1229 this.bpp = numBands*((metadata.IHDR_bitDepth == 16) ? 2 : 1);
1230
1231 // Initialize scaling tables for this image
1232 initializeScaleTables(sampleModel.getSampleSize());
1233
1234 clearAbortRequest();
1235
1236 processImageStarted(0);
1237 if (abortRequested()) {
1238 processWriteAborted();
1239 } else {
1240 try {
1241 write_magic();
1242 write_IHDR();
1243
1244 write_cHRM();
1245 write_gAMA();
1246 write_iCCP();
1247 write_sBIT();
1248 write_sRGB();
1249
1250 write_PLTE();
1251
1252 write_hIST();
1253 write_tRNS();
1254 write_bKGD();
1255
1256 write_pHYs();
1257 write_sPLT();
1258 write_tIME();
1259 write_tEXt();
1260 write_iTXt();
1261 write_zTXt();
1262
1263 writeUnknownChunks();
1264
1265 write_IDAT(im, deflaterLevel);
1266
1267 if (abortRequested()) {
1268 processWriteAborted();
1269 } else {
1270 // Finish up and inform the listeners we are done
1271 writeIEND();
1272 processImageComplete();
1273 }
1274 } catch (IOException e) {
1275 throw new IIOException("I/O error writing PNG file!", e);
1276 }
1277 }
1278 }
1279 }
|