2362N/A * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A // Initialize CRC table 0N/A for (
int n =
0; n <
256; n++) {
0N/A for (
int k =
0; k <
8; k++) {
0N/A c =
0xedb88320 ^ (c >>>
1);
0N/A for (
int n =
0; n <
len; n++) {
0N/A // Return to end of chunk and flush to minimize buffering 0N/A // Empty finalizer (for improved performance; no need to call 0N/A // super.finalize() in this case) 0N/A// Compress output and write as a series of 'IDAT' chunks of 0N/A (
byte)
'I', (
byte)
'D', (
byte)
'A', (
byte)
'T' 0N/A // Return to end of chunk and flush to minimize buffering 0N/A // Empty finalizer (for improved performance; no need to call 0N/A // super.finalize() in this case) 0N/A // Factors from the ImageWriteParam 0N/A // Per-band scaling tables 0N/A // After the first call to initializeScaleTables, either scale and scale0 0N/A // will be valid, or scaleh and scalel will be valid, but not both. 0N/A // The tables will be designed for use with a set of input but depths 0N/A // given by sampleSize, and an output bit depth given by scalingBitDepth. 0N/A // Tables for 1, 2, 4, or 8 bit output 0N/A // Tables for 16 bit output 0N/A int totalPixels;
// Total number of pixels to be written by write_IDAT 0N/A // TODO - deal with imageType 0N/A byte[]
magic = { (
byte)
137,
80,
78,
71,
13,
10,
26,
10 };
0N/A"Only compression method 0 is defined in PNG 1.1");
0N/A"Only filter method 0 is defined in PNG 1.1");
0N/A"Only interlace methods 0 (node) and 1 (adam7) are defined in PNG 1.1");
0N/A"sBIT metadata has wrong color type.\n" +
0N/A"The chunk will not be written.");
0N/A // PLTE cannot occur in a gray image 0N/A"A PLTE chunk may not appear in a gray or gray alpha image.\n" +
0N/A"The chunk will not be written");
0N/A // Special case: image is RGB and chunk is Gray 0N/A // Promote chunk contents to RGB 0N/A"tRNS metadata has incompatible color type.\n" +
0N/A"The chunk will not be written.");
0N/A // Special case: image is RGB(A) and chunk is Gray 0N/A // Promote chunk contents to RGB 0N/A // Make a gray bKGD chunk look like RGB 0N/A // Ignore status of alpha in colorType 0N/A"bKGD metadata has incompatible color type.\n" +
0N/A"The chunk will not be written.");
0N/A }
else {
// colorType == PNGImageReader.PNG_COLOR_RGB || 0N/A // colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA 0N/A }
else {
// sampleDepth == 16 0N/A // Adjust offsets and skips based on source subsampling factors 0N/A // Early exit if no data for this pass 0N/A // Convert X offset and skip from pixels to samples 0N/A // Create row buffers 0N/A // reserve space for alpha samples 0N/A // will be used to calculate alpha value for the pixel 0N/A // Reorder palette data if necessary 0N/A case 1:
case 2:
case 4:
0N/A // Image can only have a single band 0N/A // Left shift the last byte 0N/A // Perform filtering 0N/A // Swap current and previous rows 0N/A // If write has been aborted, just return; 0N/A // processWriteAborted will be called later 0N/A // Use sourceXOffset, etc. 751N/A for (
int i =
0; i <
7; i++) {
0N/A // Check two int arrays for value equality, always returns false 0N/A // if either array is null 0N/A // hold the results of scaling an input value to the desired 0N/A // If the existing tables are still valid, just return 0N/A // Compute new tables 0N/A }
else {
// bitDepth == 16 0N/A // Divide scaling table into high and low bytes 0N/A // Set source region and subsampling to default values 0N/A // Get source region and subsampling factors 0N/A // Clip to actual image bounds 0N/A // Adjust for subsampling offsets 0N/A // Get subsampling factors 0N/A // Compute output dimensions 0N/A // Compute total number of pixels for progress notification 0N/A // Use Adam7 interlacing if set in write param 0N/A // MODE_COPY_FROM_METADATA should alreay be taken care of 0N/A // MODE_EXPLICIT is not allowed 0N/A // Initialize bitDepth and colorType 0N/A // Overwrite IHDR width and height values with values from image 0N/A // Initialize scaling tables for this image 0N/A // Finish up and inform the listeners we are done