feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,103 @@
/*
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package com.sun.imageio.plugins.png;
import java.io.IOException;
import java.util.Locale;
import java.util.Iterator;
import javax.imageio.ImageReader;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.stream.ImageInputStream;
public class PNGImageReaderSpi extends ImageReaderSpi {
private static final String vendorName = "Oracle Corporation";
private static final String version = "1.0";
private static final String[] names = { "png", "PNG" };
private static final String[] suffixes = { "png" };
private static final String[] MIMETypes = { "image/png", "image/x-png" };
private static final String readerClassName =
"com.sun.imageio.plugins.png.PNGImageReader";
private static final String[] writerSpiNames = {
"com.sun.imageio.plugins.png.PNGImageWriterSpi"
};
public PNGImageReaderSpi() {
super(vendorName,
version,
names,
suffixes,
MIMETypes,
readerClassName,
new Class[] { ImageInputStream.class },
writerSpiNames,
false,
null, null,
null, null,
true,
PNGMetadata.nativeMetadataFormatName,
"com.sun.imageio.plugins.png.PNGMetadataFormat",
null, null
);
}
public String getDescription(Locale locale) {
return "Standard PNG image reader";
}
public boolean canDecodeInput(Object input) throws IOException {
if (!(input instanceof ImageInputStream)) {
return false;
}
ImageInputStream stream = (ImageInputStream)input;
byte[] b = new byte[8];
stream.mark();
stream.readFully(b);
stream.reset();
return (b[0] == (byte)137 &&
b[1] == (byte)80 &&
b[2] == (byte)78 &&
b[3] == (byte)71 &&
b[4] == (byte)13 &&
b[5] == (byte)10 &&
b[6] == (byte)26 &&
b[7] == (byte)10);
}
public ImageReader createReaderInstance(Object extension) {
return new PNGImageReader(this);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,126 @@
/*
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package com.sun.imageio.plugins.png;
import java.awt.image.ColorModel;
import java.awt.image.IndexColorModel;
import java.awt.image.SampleModel;
import java.util.Locale;
import javax.imageio.ImageWriter;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageOutputStream;
public class PNGImageWriterSpi extends ImageWriterSpi {
private static final String vendorName = "Oracle Corporation";
private static final String version = "1.0";
private static final String[] names = { "png", "PNG" };
private static final String[] suffixes = { "png" };
private static final String[] MIMETypes = { "image/png", "image/x-png" };
private static final String writerClassName =
"com.sun.imageio.plugins.png.PNGImageWriter";
private static final String[] readerSpiNames = {
"com.sun.imageio.plugins.png.PNGImageReaderSpi"
};
public PNGImageWriterSpi() {
super(vendorName,
version,
names,
suffixes,
MIMETypes,
writerClassName,
new Class[] { ImageOutputStream.class },
readerSpiNames,
false,
null, null,
null, null,
true,
PNGMetadata.nativeMetadataFormatName,
"com.sun.imageio.plugins.png.PNGMetadataFormat",
null, null
);
}
public boolean canEncodeImage(ImageTypeSpecifier type) {
SampleModel sampleModel = type.getSampleModel();
ColorModel colorModel = type.getColorModel();
// Find the maximum bit depth across all channels
int[] sampleSize = sampleModel.getSampleSize();
int bitDepth = sampleSize[0];
for (int i = 1; i < sampleSize.length; i++) {
if (sampleSize[i] > bitDepth) {
bitDepth = sampleSize[i];
}
}
// Ensure bitDepth is between 1 and 16
if (bitDepth < 1 || bitDepth > 16) {
return false;
}
// Check number of bands, alpha
int numBands = sampleModel.getNumBands();
if (numBands < 1 || numBands > 4) {
return false;
}
boolean hasAlpha = colorModel.hasAlpha();
// Fix 4464413: PNGTransparency reg-test was failing
// because for IndexColorModels that have alpha,
// numBands == 1 && hasAlpha == true, thus causing
// the check below to fail and return false.
if (colorModel instanceof IndexColorModel) {
return true;
}
if ((numBands == 1 || numBands == 3) && hasAlpha) {
return false;
}
if ((numBands == 2 || numBands == 4) && !hasAlpha) {
return false;
}
return true;
}
public String getDescription(Locale locale) {
return "Standard PNG image writer";
}
public ImageWriter createWriterInstance(Object extension) {
return new PNGImageWriter(this);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,500 @@
/*
* Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package com.sun.imageio.plugins.png;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListResourceBundle;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.metadata.IIOMetadataFormat;
import javax.imageio.metadata.IIOMetadataFormatImpl;
public class PNGMetadataFormat extends IIOMetadataFormatImpl {
private static IIOMetadataFormat instance = null;
private static String VALUE_0 = "0";
private static String VALUE_1 = "1";
private static String VALUE_12 = "12";
private static String VALUE_23 = "23";
private static String VALUE_31 = "31";
private static String VALUE_59 = "59";
private static String VALUE_60 = "60";
private static String VALUE_255 = "255";
private static String VALUE_MAX_16 = "65535"; // 2^16 - 1
private static String VALUE_MAX_32 = "2147483647"; // 2^32 - 1
private PNGMetadataFormat() {
super(PNGMetadata.nativeMetadataFormatName,
CHILD_POLICY_SOME);
// root -> IHDR
addElement("IHDR", PNGMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("IHDR", "width",
DATATYPE_INTEGER, true, null,
VALUE_1, VALUE_MAX_32, true, true);
addAttribute("IHDR", "height",
DATATYPE_INTEGER, true, null,
VALUE_1, VALUE_MAX_32, true, true);
addAttribute("IHDR", "bitDepth",
DATATYPE_INTEGER, true, null,
Arrays.asList(PNGMetadata.IHDR_bitDepths));
String[] colorTypes = {
"Grayscale", "RGB", "Palette", "GrayAlpha", "RGBAlpha"
};
addAttribute("IHDR", "colorType",
DATATYPE_STRING, true, null,
Arrays.asList(colorTypes));
addAttribute("IHDR", "compressionMethod",
DATATYPE_STRING, true, null,
Arrays.asList(PNGMetadata.IHDR_compressionMethodNames));
addAttribute("IHDR", "filterMethod",
DATATYPE_STRING, true, null,
Arrays.asList(PNGMetadata.IHDR_filterMethodNames));
addAttribute("IHDR", "interlaceMethod",
DATATYPE_STRING, true, null,
Arrays.asList(PNGMetadata.IHDR_interlaceMethodNames));
// root -> PLTE
addElement("PLTE", PNGMetadata.nativeMetadataFormatName,
1, 256);
// root -> PLTE -> PLTEEntry
addElement("PLTEEntry", "PLTE",
CHILD_POLICY_EMPTY);
addAttribute("PLTEEntry", "index",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("PLTEEntry", "red",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("PLTEEntry", "green",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("PLTEEntry", "blue",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
// root -> bKGD
addElement("bKGD", PNGMetadata.nativeMetadataFormatName,
CHILD_POLICY_CHOICE);
// root -> bKGD -> bKGD_Grayscale
addElement("bKGD_Grayscale", "bKGD",
CHILD_POLICY_EMPTY);
addAttribute("bKGD_Grayscale", "gray",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
// root -> bKGD -> bKGD_RGB
addElement("bKGD_RGB", "bKGD",
CHILD_POLICY_EMPTY);
addAttribute("bKGD_RGB", "red",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("bKGD_RGB", "green",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("bKGD_RGB", "blue",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
// root -> bKGD -> bKGD_Palette
addElement("bKGD_Palette", "bKGD",
CHILD_POLICY_EMPTY);
addAttribute("bKGD_Palette", "index",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
// root -> cHRM
addElement("cHRM", PNGMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("cHRM", "whitePointX",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("cHRM", "whitePointY",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("cHRM", "redX",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("cHRM", "redY",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("cHRM", "greenX",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("cHRM", "greenY",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("cHRM", "blueX",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("cHRM", "blueY",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
// root -> gAMA
addElement("gAMA", PNGMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("gAMA", "value",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_32, true, true);
// root -> hIST
addElement("hIST", PNGMetadata.nativeMetadataFormatName,
1, 256);
// root -> hISTEntry
addElement("hISTEntry", "hIST",
CHILD_POLICY_EMPTY);
addAttribute("hISTEntry", "index",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("hISTEntry", "value",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
// root -> iCCP
addElement("iCCP", PNGMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("iCCP", "profileName",
DATATYPE_STRING, true, null);
addAttribute("iCCP", "compressionMethod",
DATATYPE_STRING, true, null,
Arrays.asList(PNGMetadata.iCCP_compressionMethodNames));
addObjectValue("iCCP", byte.class, 0, Integer.MAX_VALUE);
// root -> iTXt
addElement("iTXt", PNGMetadata.nativeMetadataFormatName,
1, Integer.MAX_VALUE);
// root -> iTXt -> iTXtEntry
addElement("iTXtEntry", "iTXt",
CHILD_POLICY_EMPTY);
addAttribute("iTXtEntry", "keyword",
DATATYPE_STRING, true, null);
addBooleanAttribute("iTXtEntry", "compressionFlag",
false, false);
addAttribute("iTXtEntry", "compressionMethod",
DATATYPE_STRING, true, null);
addAttribute("iTXtEntry", "languageTag",
DATATYPE_STRING, true, null);
addAttribute("iTXtEntry", "translatedKeyword",
DATATYPE_STRING, true, null);
addAttribute("iTXtEntry", "text",
DATATYPE_STRING, true, null);
// root -> pHYS
addElement("pHYS", PNGMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("pHYS", "pixelsPerUnitXAxis",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_32, true, true);
addAttribute("pHYS", "pixelsPerUnitYAxis",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_32, true, true);
addAttribute("pHYS", "unitSpecifier",
DATATYPE_STRING, true, null,
Arrays.asList(PNGMetadata.unitSpecifierNames));
// root -> sBIT
addElement("sBIT", PNGMetadata.nativeMetadataFormatName,
CHILD_POLICY_CHOICE);
// root -> sBIT -> sBIT_Grayscale
addElement("sBIT_Grayscale", "sBIT",
CHILD_POLICY_EMPTY);
addAttribute("sBIT_Grayscale", "gray",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
// root -> sBIT -> sBIT_GrayAlpha
addElement("sBIT_GrayAlpha", "sBIT",
CHILD_POLICY_EMPTY);
addAttribute("sBIT_GrayAlpha", "gray",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sBIT_GrayAlpha", "alpha",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
// root -> sBIT -> sBIT_RGB
addElement("sBIT_RGB", "sBIT",
CHILD_POLICY_EMPTY);
addAttribute("sBIT_RGB", "red",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sBIT_RGB", "green",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sBIT_RGB", "blue",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
// root -> sBIT -> sBIT_RGBAlpha
addElement("sBIT_RGBAlpha", "sBIT",
CHILD_POLICY_EMPTY);
addAttribute("sBIT_RGBAlpha", "red",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sBIT_RGBAlpha", "green",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sBIT_RGBAlpha", "blue",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sBIT_RGBAlpha", "alpha",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
// root -> sBIT -> sBIT_Palette
addElement("sBIT_Palette", "sBIT",
CHILD_POLICY_EMPTY);
addAttribute("sBIT_Palette", "red",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sBIT_Palette", "green",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sBIT_Palette", "blue",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
// root -> sPLT
addElement("sPLT", PNGMetadata.nativeMetadataFormatName,
1, 256);
// root -> sPLT -> sPLTEntry
addElement("sPLTEntry", "sPLT",
CHILD_POLICY_EMPTY);
addAttribute("sPLTEntry", "index",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sPLTEntry", "red",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sPLTEntry", "green",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sPLTEntry", "blue",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("sPLTEntry", "alpha",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
// root -> sRGB
addElement("sRGB", PNGMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("sRGB", "renderingIntent",
DATATYPE_STRING, true, null,
Arrays.asList(PNGMetadata.renderingIntentNames));
// root -> tEXt
addElement("tEXt", PNGMetadata.nativeMetadataFormatName,
1, Integer.MAX_VALUE);
// root -> tEXt -> tEXtEntry
addElement("tEXtEntry", "tEXt",
CHILD_POLICY_EMPTY);
addAttribute("tEXtEntry", "keyword",
DATATYPE_STRING, true, null);
addAttribute("tEXtEntry", "value",
DATATYPE_STRING, true, null);
// root -> tIME
addElement("tIME", PNGMetadata.nativeMetadataFormatName,
CHILD_POLICY_EMPTY);
addAttribute("tIME", "year",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("tIME", "month",
DATATYPE_INTEGER, true, null,
VALUE_1, VALUE_12, true, true);
addAttribute("tIME", "day",
DATATYPE_INTEGER, true, null,
VALUE_1, VALUE_31, true, true);
addAttribute("tIME", "hour",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_23, true, true);
addAttribute("tIME", "minute",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_59, true, true);
addAttribute("tIME", "second",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_60, true, true);
// root -> tRNS
addElement("tRNS", PNGMetadata.nativeMetadataFormatName,
CHILD_POLICY_CHOICE);
// root -> tRNS -> tRNS_Grayscale
addElement("tRNS_Grayscale", "tRNS",
CHILD_POLICY_EMPTY);
addAttribute("tRNS_Grayscale", "gray",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
// root -> tRNS -> tRNS_RGB
addElement("tRNS_RGB", "tRNS",
CHILD_POLICY_EMPTY);
addAttribute("tRNS_RGB", "red",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("tRNS_RGB", "green",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
addAttribute("tRNS_RGB", "blue",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_MAX_16, true, true);
// root -> tRNS -> tRNS_Palette
addElement("tRNS_Palette", "tRNS",
CHILD_POLICY_EMPTY);
addAttribute("tRNS_Palette", "index",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
addAttribute("tRNS_Palette", "alpha",
DATATYPE_INTEGER, true, null,
VALUE_0, VALUE_255, true, true);
// root -> zTXt
addElement("zTXt", PNGMetadata.nativeMetadataFormatName,
1, Integer.MAX_VALUE);
// root -> zTXt -> zTXtEntry
addElement("zTXtEntry", "zTXt",
CHILD_POLICY_EMPTY);
addAttribute("zTXtEntry", "keyword",
DATATYPE_STRING, true, null);
addAttribute("zTXtEntry", "compressionMethod",
DATATYPE_STRING, true, null,
Arrays.asList(PNGMetadata.zTXt_compressionMethodNames));
addAttribute("zTXtEntry", "text",
DATATYPE_STRING, true, null);
// root -> UnknownChunks
addElement("UnknownChunks", PNGMetadata.nativeMetadataFormatName,
1, Integer.MAX_VALUE);
// root -> UnknownChunks -> UnknownChunk
addElement("UnknownChunk", "UnknownChunks",
CHILD_POLICY_EMPTY);
addAttribute("UnknownChunk", "type",
DATATYPE_STRING, true, null);
addObjectValue("UnknownChunk", byte.class, 0, Integer.MAX_VALUE);
}
public boolean canNodeAppear(String elementName,
ImageTypeSpecifier imageType) {
return true;
}
public static synchronized IIOMetadataFormat getInstance() {
if (instance == null) {
instance = new PNGMetadataFormat();
}
return instance;
}
}

View File

@@ -0,0 +1,219 @@
/*
* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package com.sun.imageio.plugins.png;
import java.util.ListResourceBundle;
public class PNGMetadataFormatResources extends ListResourceBundle {
public PNGMetadataFormatResources() {}
protected Object[][] getContents() {
return new Object[][] {
// Node name, followed by description
{ "IHDR", "The IHDR chunk, containing the header" },
{ "PLTE", "The PLTE chunk, containing the palette" },
{ "PLTEEntry", "A palette entry" },
{ "bKGD", "The bKGD chunk, containing the background color" },
{ "bKGD_RGB", "An RGB background color, for RGB and RGBAlpha images" },
{ "bKGD_Grayscale",
"A grayscale background color, for Gray and GrayAlpha images" },
{ "bKGD_Palette", "A background palette index" },
{ "cHRM", "The cHRM chunk, containing color calibration" },
{ "gAMA", "The gAMA chunk, containing the image gamma" },
{ "hIST", "The hIST chunk, containing histogram information " },
{ "hISTEntry", "A histogram entry" },
{ "iCCP", "The iCCP chunk, containing an ICC color profile" },
{ "iTXt", "The iTXt chunk, containing internationalized text" },
{ "iTXtEntry", "A localized text entry" },
{ "pHYS",
"The pHYS chunk, containing the pixel size and aspect ratio" },
{ "sBIT", "The sBIT chunk, containing significant bit information" },
{ "sBIT_Grayscale", "Significant bit information for gray samples" },
{ "sBIT_GrayAlpha",
"Significant bit information for gray and alpha samples" },
{ "sBIT_RGB", "Significant bit information for RGB samples" },
{ "sBIT_RGBAlpha", "Significant bit information for RGBA samples" },
{ "sBIT_Palette",
"Significant bit information for RGB palette entries" },
{ "sPLT", "The sPLT chunk, containing a suggested palette" },
{ "sPLTEntry", "A suggested palette entry" },
{ "sRGB", "The sRGB chunk, containing rendering intent information" },
{ "tEXt", "The tEXt chunk, containing text" },
{ "tEXtEntry", "A text entry" },
{ "tIME", "The tIME chunk, containing the image modification time" },
{ "tRNS", "The tRNS chunk, containing transparency information" },
{ "tRNS_Grayscale",
"A grayscale value that should be considered transparent" },
{ "tRNS_RGB",
"An RGB value that should be considered transparent" },
{ "tRNS_Palette",
"A palette index that should be considered transparent" },
{ "zTXt", "The zTXt chunk, containing compressed text" },
{ "zTXtEntry", "A compressed text entry" },
{ "UnknownChunks", "A set of unknown chunks" },
{ "UnknownChunk", "Unknown chunk data stored as a byte array" },
// Node name + "/" + AttributeName, followed by description
{ "IHDR/width", "The width of the image in pixels" },
{ "IHDR/height", "The height of the image in pixels" },
{ "IHDR/bitDepth", "The bit depth of the image samples" },
{ "IHDR/colorType", "The color type of the image" },
{ "IHDR/compressionMethod",
"The compression used for image data, always \"deflate\"" },
{ "IHDR/filterMethod",
"The filtering method used for compression, always \"adaptive\"" },
{ "IHDR/interlaceMethod",
"The interlacing method, \"none\" or \"adam7\"" },
{ "PLTEEntry/index", "The index of a palette entry" },
{ "PLTEEntry/red", "The red value of a palette entry" },
{ "PLTEEntry/green", "The green value of a palette entry" },
{ "PLTEEntry/blue", "The blue value of a palette entry" },
{ "bKGD_Grayscale/gray", "A gray value to be used as a background" },
{ "bKGD_RGB/red", "A red value to be used as a background" },
{ "bKGD_RGB/green", "A green value to be used as a background" },
{ "bKGD_RGB/blue", "A blue value to be used as a background" },
{ "bKGD_Palette/index", "A palette index to be used as a background" },
{ "cHRM/whitePointX",
"The CIE x coordinate of the white point, multiplied by 1e5" },
{ "cHRM/whitePointY",
"The CIE y coordinate of the white point, multiplied by 1e5" },
{ "cHRM/redX",
"The CIE x coordinate of the red primary, multiplied by 1e5" },
{ "cHRM/redY",
"The CIE y coordinate of the red primary, multiplied by 1e5" },
{ "cHRM/greenX",
"The CIE x coordinate of the green primary, multiplied by 1e5" },
{ "cHRM/greenY",
"The CIE y coordinate of the green primary, multiplied by 1e5" },
{ "cHRM/blueX",
"The CIE x coordinate of the blue primary, multiplied by 1e5" },
{ "cHRM/blueY",
"The CIE y coordinate of the blue primary, multiplied by 1e5" },
{ "gAMA/value",
"The image gamma, multiplied by 1e5" },
{ "hISTEntry/index", "The palette index of this histogram entry" },
{ "hISTEntry/value", "The frequency of this histogram entry" },
{ "iCCP/profileName", "The name of this ICC profile" },
{ "iCCP/compressionMethod",
"The compression method used to store this ICC profile" },
{ "iTXtEntry/keyword", "The keyword" },
{ "iTXtEntry/compressionMethod",
"The compression method used to store this iTXt entry" },
{ "iTXtEntry/languageTag",
"The ISO tag describing the language this iTXt entry" },
{ "iTXtEntry/translatedKeyword",
"The translated keyword for iTXt entry" },
{ "iTXtEntry/text",
"The localized text" },
{ "pHYS/pixelsPerUnitXAxis",
"The number of horizontal pixels per unit, multiplied by 1e5" },
{ "pHYS/pixelsPerUnitYAxis",
"The number of vertical pixels per unit, multiplied by 1e5" },
{ "pHYS/unitSpecifier",
"The unit specifier for this chunk (i.e., meters)" },
{ "sBIT_Grayscale/gray",
"The number of significant bits of the gray samples" },
{ "sBIT_GrayAlpha/gray",
"The number of significant bits of the gray samples" },
{ "sBIT_GrayAlpha/alpha",
"The number of significant bits of the alpha samples" },
{ "sBIT_RGB/red",
"The number of significant bits of the red samples" },
{ "sBIT_RGB/green",
"The number of significant bits of the green samples" },
{ "sBIT_RGB/blue",
"The number of significant bits of the blue samples" },
{ "sBIT_RGBAlpha/red",
"The number of significant bits of the red samples" },
{ "sBIT_RGBAlpha/green",
"The number of significant bits of the green samples" },
{ "sBIT_RGBAlpha/blue",
"The number of significant bits of the blue samples" },
{ "sBIT_RGBAlpha/alpha",
"The number of significant bits of the alpha samples" },
{ "sBIT_Palette/red",
"The number of significant bits of the red palette entries" },
{ "sBIT_Palette/green",
"The number of significant bits of the green palette entries" },
{ "sBIT_Palette/blue",
"The number of significant bits of the blue palette entries" },
{ "sPLTEntry/index", "The index of a suggested palette entry" },
{ "sPLTEntry/red", "The red value of a suggested palette entry" },
{ "sPLTEntry/green", "The green value of a suggested palette entry" },
{ "sPLTEntry/blue", "The blue value of a suggested palette entry" },
{ "sPLTEntry/alpha", "The blue value of a suggested palette entry" },
{ "sRGB/renderingIntent", "The rendering intent" },
{ "tEXtEntry/keyword", "The keyword" },
{ "tEXtEntry/value", "The text" },
{ "tIME/year", "The year when the image was last modified" },
{ "tIME/month",
"The month when the image was last modified, 1 = January" },
{ "tIME/day",
"The day of the month when the image was last modified" },
{ "tIME/hour",
"The hour when the image was last modified" },
{ "tIME/minute",
"The minute when the image was last modified" },
{ "tIME/second",
"The second when the image was last modified, 60 = leap second" },
{ "tRNS_Grayscale/gray",
"The gray value to be considered transparent" },
{ "tRNS_RGB/red",
"The red value to be considered transparent" },
{ "tRNS_RGB/green",
"The green value to be considered transparent" },
{ "tRNS_RGB/blue",
"The blure value to be considered transparent" },
{ "tRNS_Palette/index",
"A palette index to be considered transparent" },
{ "tRNS_Palette/alpha",
"The transparency associated with the palette entry" },
{ "zTXtEntry/keyword", "The keyword" },
{ "zTXtEntry/compressionMethod", "The compression method" },
{ "zTXtEntry/text", "The compressed text" },
{ "UnknownChunk/type", "The 4-character type of the unknown chunk" }
};
}
}

View File

@@ -0,0 +1,192 @@
/*
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package com.sun.imageio.plugins.png;
public class RowFilter {
private static final int abs(int x) {
return (x < 0) ? -x : x;
}
// Returns the sum of absolute differences
protected static int subFilter(byte[] currRow,
byte[] subFilteredRow,
int bytesPerPixel,
int bytesPerRow) {
int badness = 0;
for (int i = bytesPerPixel; i < bytesPerRow + bytesPerPixel; i++) {
int curr = currRow[i] & 0xff;
int left = currRow[i - bytesPerPixel] & 0xff;
int difference = curr - left;
subFilteredRow[i] = (byte)difference;
badness += abs(difference);
}
return badness;
}
// Returns the sum of absolute differences
protected static int upFilter(byte[] currRow,
byte[] prevRow,
byte[] upFilteredRow,
int bytesPerPixel,
int bytesPerRow) {
int badness = 0;
for (int i = bytesPerPixel; i < bytesPerRow + bytesPerPixel; i++) {
int curr = currRow[i] & 0xff;
int up = prevRow[i] & 0xff;
int difference = curr - up;
upFilteredRow[i] = (byte)difference;
badness += abs(difference);
}
return badness;
}
protected final int paethPredictor(int a, int b, int c) {
int p = a + b - c;
int pa = abs(p - a);
int pb = abs(p - b);
int pc = abs(p - c);
if ((pa <= pb) && (pa <= pc)) {
return a;
} else if (pb <= pc) {
return b;
} else {
return c;
}
}
public int filterRow(int colorType,
byte[] currRow,
byte[] prevRow,
byte[][] scratchRows,
int bytesPerRow,
int bytesPerPixel) {
// Use type 0 for palette images
if (colorType != PNGImageReader.PNG_COLOR_PALETTE) {
System.arraycopy(currRow, bytesPerPixel,
scratchRows[0], bytesPerPixel,
bytesPerRow);
return 0;
}
int[] filterBadness = new int[5];
for (int i = 0; i < 5; i++) {
filterBadness[i] = Integer.MAX_VALUE;
}
{
int badness = 0;
for (int i = bytesPerPixel; i < bytesPerRow + bytesPerPixel; i++) {
int curr = currRow[i] & 0xff;
badness += curr;
}
filterBadness[0] = badness;
}
{
byte[] subFilteredRow = scratchRows[1];
int badness = subFilter(currRow,
subFilteredRow,
bytesPerPixel,
bytesPerRow);
filterBadness[1] = badness;
}
{
byte[] upFilteredRow = scratchRows[2];
int badness = upFilter(currRow,
prevRow,
upFilteredRow,
bytesPerPixel,
bytesPerRow);
filterBadness[2] = badness;
}
{
byte[] averageFilteredRow = scratchRows[3];
int badness = 0;
for (int i = bytesPerPixel; i < bytesPerRow + bytesPerPixel; i++) {
int curr = currRow[i] & 0xff;
int left = currRow[i - bytesPerPixel] & 0xff;
int up = prevRow[i] & 0xff;
int difference = curr - (left + up)/2;;
averageFilteredRow[i] = (byte)difference;
badness += abs(difference);
}
filterBadness[3] = badness;
}
{
byte[] paethFilteredRow = scratchRows[4];
int badness = 0;
for (int i = bytesPerPixel; i < bytesPerRow + bytesPerPixel; i++) {
int curr = currRow[i] & 0xff;
int left = currRow[i - bytesPerPixel] & 0xff;
int up = prevRow[i] & 0xff;
int upleft = prevRow[i - bytesPerPixel] & 0xff;
int predictor = paethPredictor(left, up, upleft);
int difference = curr - predictor;
paethFilteredRow[i] = (byte)difference;
badness += abs(difference);
}
filterBadness[4] = badness;
}
int minBadness = filterBadness[0];
int filterType = 0;
for (int i = 1; i < 5; i++) {
if (filterBadness[i] < minBadness) {
minBadness = filterBadness[i];
filterType = i;
}
}
if (filterType == 0) {
System.arraycopy(currRow, bytesPerPixel,
scratchRows[0], bytesPerPixel,
bytesPerRow);
}
return filterType;
}
}