/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class CRC {
static {
// Initialize CRC table
for (int n = 0; n < 256; n++) {
int c = n;
for (int k = 0; k < 8; k++) {
if ((c & 1) == 1) {
c = 0xedb88320 ^ (c >>> 1);
} else {
c >>>= 1;
}
crcTable[n] = c;
}
}
}
public CRC() {}
public void reset() {
crc = 0xffffffff;
}
for (int n = 0; n < len; n++) {
}
}
}
public int getValue() {
return crc ^ 0xffffffff;
}
}
private long startPos;
}
throw new RuntimeException("Method not available");
}
throw new RuntimeException("Method not available");
}
}
}
// Write CRC
// Write length
// Return to end of chunk and flush to minimize buffering
}
// Empty finalizer (for improved performance; no need to call
// super.finalize() in this case)
}
}
// Compress output and write as a series of 'IDAT' chunks of
// fixed length.
private static byte[] chunkType = {
(byte)'I', (byte)'D', (byte)'A', (byte)'T'
};
private int chunkLength;
private long startPos;
private int bytesRemaining;
throws IOException {
this.chunkLength = chunkLength;
startChunk();
}
this.bytesRemaining = chunkLength;
}
// Write CRC
// Write length
// Return to end of chunk and flush to minimize buffering
}
throw new RuntimeException("Method not available");
}
throw new RuntimeException("Method not available");
}
if (len == 0) {
return;
}
while (!def.needsInput()) {
deflate();
}
}
}
int off = 0;
while (len > 0) {
if (bytesRemaining == 0) {
finishChunk();
startChunk();
}
bytesRemaining -= nbytes;
}
}
byte[] wbuf = new byte[1];
wbuf[0] = (byte)b;
}
try {
deflate();
}
}
finishChunk();
} finally {
}
}
// Empty finalizer (for improved performance; no need to call
// super.finalize() in this case)
}
}
super();
this.canWriteProgressive = true;
}
}
/**
*/
// Factors from the ImageWriteParam
int numBands;
int bpp;
// Per-band scaling tables
//
// After the first call to initializeScaleTables, either scale and scale0
// will be valid, or scaleh and scalel will be valid, but not both.
//
// The tables will be designed for use with a set of input but depths
// given by sampleSize, and an output bit depth given by scalingBitDepth.
//
// Tables for 1, 2, 4, or 8 bit output
// Tables for 16 bit output
super(originatingProvider);
}
if (!(output instanceof ImageOutputStream)) {
throw new IllegalArgumentException("output not an ImageOutputStream!");
}
} else {
}
}
return new PNGImageWriteParam(getLocale());
}
return null;
}
PNGMetadata m = new PNGMetadata();
return m;
}
return null;
}
// TODO - deal with imageType
if (inData instanceof PNGMetadata) {
} else {
return new PNGMetadata(inData);
}
}
// Write signature
}
// Write IHDR chunk
throw new IIOException(
"Only compression method 0 is defined in PNG 1.1");
}
throw new IIOException(
"Only filter method 0 is defined in PNG 1.1");
}
throw new IIOException(
"Only interlace methods 0 (node) and 1 (adam7) are defined in PNG 1.1");
}
}
if (metadata.cHRM_present) {
}
}
if (metadata.gAMA_present) {
}
}
if (metadata.iCCP_present) {
}
}
if (metadata.sBIT_present) {
"sBIT metadata has wrong color type.\n" +
"The chunk will not be written.");
return;
}
}
}
}
}
if (metadata.sRGB_present) {
}
}
if (metadata.PLTE_present) {
// PLTE cannot occur in a gray image
"A PLTE chunk may not appear in a gray or gray alpha image.\n" +
"The chunk will not be written");
return;
}
int index = 0;
for (int i = 0; i < numEntries; i++) {
}
}
}
if (metadata.hIST_present) {
if (!metadata.PLTE_present) {
throw new IIOException("hIST chunk without PLTE chunk!");
}
}
}
if (metadata.tRNS_present) {
// Special case: image is RGB and chunk is Gray
// Promote chunk contents to RGB
}
"tRNS metadata has incompatible color type.\n" +
"The chunk will not be written.");
return;
}
if (!metadata.PLTE_present) {
throw new IIOException("tRNS chunk without PLTE chunk!");
}
} else {
throw new IIOException("tRNS chunk for color type 4 or 6!");
}
}
}
if (metadata.bKGD_present) {
// Special case: image is RGB(A) and chunk is Gray
// Promote chunk contents to RGB
// Make a gray bKGD chunk look like RGB
}
// Ignore status of alpha in colorType
"bKGD metadata has incompatible color type.\n" +
"The chunk will not be written.");
return;
}
} else { // colorType == PNGImageReader.PNG_COLOR_RGB ||
// colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA
}
}
}
if (metadata.pHYs_present) {
}
}
if (metadata.sPLT_present) {
for (int i = 0; i < numEntries; i++) {
}
} else { // sampleDepth == 16
for (int i = 0; i < numEntries; i++) {
}
}
}
}
if (metadata.tIME_present) {
}
}
while (keywordIter.hasNext()) {
}
}
return baos.toByteArray();
}
while (keywordIter.hasNext()) {
if (compressed) {
} else {
}
}
}
while (keywordIter.hasNext()) {
}
}
}
}
return type;
}
int minX = sourceXOffset;
int minY = sourceYOffset;
int width = sourceWidth;
int height = sourceHeight;
// Adjust offsets and skips based on source subsampling factors
// Early exit if no data for this pass
return;
}
// Convert X offset and skip from pixels to samples
// Create row buffers
int[] samples = new int[numSamples];
bytesPerRow *= 2;
}
{
// reserve space for alpha samples
bytesPerRow *= 2;
// will be used to calculate alpha value for the pixel
}
if (sourceBands != null) {
}
samples);
samples);
}
// Reorder palette data if necessary
if (paletteOrder != null) {
for (int i = 0; i < numSamples; i++) {
}
}
int pos = 0;
int tmp = 0;
switch (bitDepth) {
case 1: case 2: case 4:
// Image can only have a single band
tmp = 0;
pos = 0;
}
}
// Left shift the last byte
}
break;
case 8:
if (numBands == 1) {
if (icm_gray_alpha != null) {
}
}
} else {
for (int b = 0; b < numBands; b++) {
}
}
}
break;
case 16:
for (int b = 0; b < numBands; b++) {
}
}
break;
}
// Perform filtering
bytesPerRow, bpp);
// Swap current and previous rows
pixelsDone += hpixels;
// If write has been aborted, just return;
// processWriteAborted will be called later
if (abortRequested()) {
return;
}
}
}
// Use sourceXOffset, etc.
try {
for (int i = 0; i < 7; i++) {
if (abortRequested()) {
break;
}
}
} else {
}
} finally {
}
}
}
// Check two int arrays for value equality, always returns false
// if either array is null
return false;
}
return false;
}
return false;
}
}
return true;
}
// hold the results of scaling an input value to the desired
// output bit depth
// If the existing tables are still valid, just return
if (bitDepth == scalingBitDepth &&
return;
}
// Compute new tables
this.sampleSize = sampleSize;
this.scalingBitDepth = bitDepth;
if (bitDepth <= 8) {
for (int b = 0; b < numBands; b++) {
for (int s = 0; s <= maxInSample; s++) {
scale[b][s] =
}
}
} else { // bitDepth == 16
// Divide scaling table into high and low bytes
for (int b = 0; b < numBands; b++) {
for (int s = 0; s <= maxInSample; s++) {
}
}
}
}
throw new IllegalStateException("output == null!");
}
throw new IllegalArgumentException("image == null!");
}
throw new UnsupportedOperationException("image has a Raster!");
}
// Set source region and subsampling to default values
this.sourceBands = null;
this.periodX = 1;
this.periodY = 1;
// Get source region and subsampling factors
if (sourceRegion != null) {
// Clip to actual image bounds
}
// Adjust for subsampling offsets
sourceXOffset += gridX;
sourceYOffset += gridY;
sourceWidth -= gridX;
sourceHeight -= gridY;
// Get subsampling factors
}
}
// Compute output dimensions
throw new IllegalArgumentException("Empty source region!");
}
// Compute total number of pixels for progress notification
this.pixelsDone = 0;
// Create metadata
null);
} else {
metadata = new PNGMetadata();
}
// Use Adam7 interlacing if set in write param
switch (param.getProgressiveMode()) {
case ImageWriteParam.MODE_DEFAULT:
break;
case ImageWriteParam.MODE_DISABLED:
break;
// MODE_COPY_FROM_METADATA should alreay be taken care of
// MODE_EXPLICIT is not allowed
}
}
// Initialize bitDepth and colorType
// Overwrite IHDR width and height values with values from image
// Initialize scaling tables for this image
try {
write_magic();
write_IHDR();
write_cHRM();
write_gAMA();
write_iCCP();
write_sBIT();
write_sRGB();
write_PLTE();
write_hIST();
write_tRNS();
write_bKGD();
write_pHYs();
write_sPLT();
write_tIME();
write_tEXt();
write_iTXt();
write_zTXt();
write_IDAT(im);
if (abortRequested()) {
} else {
// Finish up and inform the listeners we are done
writeIEND();
}
} catch (IOException e) {
throw new IIOException("I/O error writing PNG file!", e);
}
}
}