PNG ネイティブ形式は、実際のイメージデータを含む IDAT チャンクを除き、PNG ファイルの内容全体をチャンクごとにエンコードします。PNG 1.2 の仕様で定義されていないチャンクは UnknownChunks
要素に格納されます。PNG 仕様に記載されている PNG リーダー、ライター、およびエディタの規則 (たとえば、コピーが安全でないチャンクに関する規則) の実装は、アプリケーションソフトウェアが担当します。仕様という点では、Image I/O ライブラリ自体は PNG リーダー、ライター、またはエディタではありません。どちらかといえば、PNG リーダー、ライター、またはエディタの構築に使用できるツールです。
イメージの実際の幅、高さ、ビット深度、およびカラータイプは 1 つの例外を除き、メタデータ経由でライターに渡されるあらゆる値をオーバーライドします。イメージに IndexColorModel
がある場合、カラーテーブルエントリがチェックされ、均一なグレースケールの階調を作成するかどうかが判定されます。その場合、イメージはパレットカラーではなくグレースケールを使用して通常どおりエンコードされます。ただし、メタデータに設定されているカラータイプが「Palette」の場合、パレットカラーが使用されます。
イメージをエンコードするときにメタデータが指定されていない場合は、エンコードされるイメージからヘッダーが初期化され、オプションのチャンクは含められません。
標準のチャンクのセマンティクスは、PNG 仕様に記載されています。各カラータイプに存在可能なチャンクの種類については、いくつかの制限があります。特に次の点が重要です。
PLTE
チャンクは Gray
または GrayAlpha
イメージには存在することができません
hIST
および tRNS
チャンクは前に PLTE
チャンクを必要とします
tRNS
チャンクは GrayAlpha
および RGBA
イメージには存在することができません
bKGD
、sBIT
、および tRNS
チャンクの子ノードは、イメージのカラータイプと一致する必要があります。
PNG ファイルでは、一部のチャンク、特にテキスト関連のチャンクが意味のあるかたちで複数回現れる場合があります。メタデータ形式を簡略化するため、これらのチャンクの複数のインスタンスは、ゼロ以上の子 (たとえば、tEXtEntry
ノード) を持つことができる 1 つの親ノード (たとえば、tEXt
ノード) に統合されます。子が存在しない場合は、チャンクは書き込まれません。同様に、未知のチャンクは単一の UnknownChunks
ノードの子として格納されます。
チャンクを書き込むときの順序付けを制御したり、ファイル内の読み込まれるチャンクの順序を設定したりすることはできません。
<!DOCTYPE "javax_imageio_png_1.0" [ <!ELEMENT "javax_imageio_png_1.0" (IHDR?, PLTE?, bKGD?, cHRM?, gAMA?, hIST?, iCCP?, iTXt?, pHYS?, sBIT?, sPLT?, sRGB?, tEXt?, tIME?, tRNS?, zTXt?, UnknownChunks?)> <!ELEMENT "IHDR" EMPTY> <!-- The IHDR chunk, containing the header --> <!ATTLIST "IHDR" "width" #CDATA #REQUIRED> <!-- The width of the image in pixels --> <!-- Data type: Integer --> <!-- Min value: 1 (inclusive) --> <!-- Max value: 2147483647 (inclusive) --> <!ATTLIST "IHDR" "height" #CDATA #REQUIRED> <!-- The height of the image in pixels --> <!-- Data type: Integer --> <!-- Min value: 1 (inclusive) --> <!-- Max value: 2147483647 (inclusive) --> <!ATTLIST "IHDR" "bitDepth" ("1" | "2" | "4" | "8" | "16") #REQUIRED> <!-- The bit depth of the image samples --> <!ATTLIST "IHDR" "colorType" ("Grayscale" | "RGB" | "Palette" | "GrayAlpha" | "RGBAlpha") #REQUIRED> <!-- The color type of the image --> <!ATTLIST "IHDR" "compressionMethod" ("deflate") #REQUIRED> <!-- The compression used for image data, always "deflate" --> <!ATTLIST "IHDR" "filterMethod" ("adaptive") #REQUIRED> <!-- The filtering method used for compression, always "adaptive" --> <!ATTLIST "IHDR" "interlaceMethod" ("none" | "adam7") #REQUIRED> <!-- The interlacing method, "none" or "adam7" --> <!ELEMENT "PLTE" (PLTEEntry)*> <!-- The PLTE chunk, containing the palette --> <!-- Min children: 1 --> <!-- Max children: 256 --> <!ELEMENT "PLTEEntry" EMPTY> <!-- A palette entry --> <!ATTLIST "PLTEEntry" "index" #CDATA #REQUIRED> <!-- The index of a palette entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "PLTEEntry" "red" #CDATA #REQUIRED> <!-- The red value of a palette entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "PLTEEntry" "green" #CDATA #REQUIRED> <!-- The green value of a palette entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "PLTEEntry" "blue" #CDATA #REQUIRED> <!-- The blue value of a palette entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ELEMENT "bKGD" (bKGD_Grayscale | bKGD_RGB | bKGD_Palette)> <!-- The bKGD chunk, containing the background color --> <!ELEMENT "bKGD_Grayscale" EMPTY> <!-- A grayscale background color, for Gray and GrayAlpha images --> <!ATTLIST "bKGD_Grayscale" "gray" #CDATA #REQUIRED> <!-- A gray value to be used as a background --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ELEMENT "bKGD_RGB" EMPTY> <!-- An RGB background color, for RGB and RGBAlpha images --> <!ATTLIST "bKGD_RGB" "red" #CDATA #REQUIRED> <!-- A red value to be used as a background --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "bKGD_RGB" "green" #CDATA #REQUIRED> <!-- A green value to be used as a background --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "bKGD_RGB" "blue" #CDATA #REQUIRED> <!-- A blue value to be used as a background --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ELEMENT "bKGD_Palette" EMPTY> <!-- A background palette index --> <!ATTLIST "bKGD_Palette" "index" #CDATA #REQUIRED> <!-- A palette index to be used as a background --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ELEMENT "cHRM" EMPTY> <!-- The cHRM chunk, containing color calibration --> <!ATTLIST "cHRM" "whitePointX" #CDATA #REQUIRED> <!-- The CIE x coordinate of the white point, multiplied by 1e5 --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "cHRM" "whitePointY" #CDATA #REQUIRED> <!-- The CIE y coordinate of the white point, multiplied by 1e5 --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "cHRM" "redX" #CDATA #REQUIRED> <!-- The CIE x coordinate of the red primary, multiplied by 1e5 --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "cHRM" "redY" #CDATA #REQUIRED> <!-- The CIE y coordinate of the red primary, multiplied by 1e5 --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "cHRM" "greenX" #CDATA #REQUIRED> <!-- The CIE x coordinate of the green primary, multiplied by 1e5 --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "cHRM" "greenY" #CDATA #REQUIRED> <!-- The CIE y coordinate of the green primary, multiplied by 1e5 --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "cHRM" "blueX" #CDATA #REQUIRED> <!-- The CIE x coordinate of the blue primary, multiplied by 1e5 --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "cHRM" "blueY" #CDATA #REQUIRED> <!-- The CIE y coordinate of the blue primary, multiplied by 1e5 --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ELEMENT "gAMA" EMPTY> <!-- The gAMA chunk, containing the image gamma --> <!ATTLIST "gAMA" "value" #CDATA #REQUIRED> <!-- The image gamma, multiplied by 1e5 --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 2147483647 (inclusive) --> <!ELEMENT "hIST" (hISTEntry)*> <!-- The hIST chunk, containing histogram information --> <!-- Min children: 1 --> <!-- Max children: 256 --> <!ELEMENT "hISTEntry" EMPTY> <!-- A histogram entry --> <!ATTLIST "hISTEntry" "index" #CDATA #REQUIRED> <!-- The palette index of this histogram entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "hISTEntry" "value" #CDATA #REQUIRED> <!-- The frequency of this histogram entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ELEMENT "iCCP" EMPTY> <!-- The iCCP chunk, containing an ICC color profile --> <!-- User object: array of byte --> <!-- Min length: 0 --> <!-- Max length: 2147483647 --> <!ATTLIST "iCCP" "profileName" #CDATA #REQUIRED> <!-- The name of this ICC profile --> <!-- Data type: String --> <!ATTLIST "iCCP" "compressionMethod" ("deflate") #REQUIRED> <!-- The compression method used to store this ICC profile --> <!ELEMENT "iTXt" (iTXtEntry)*> <!-- The iTXt chunk, containing internationalized text --> <!-- Min children: 1 --> <!-- Max children: 2147483647 --> <!ELEMENT "iTXtEntry" EMPTY> <!-- A localized text entry --> <!ATTLIST "iTXtEntry" "keyword" #CDATA #REQUIRED> <!-- The keyword --> <!-- Data type: String --> <!ATTLIST "iTXtEntry" "compressionFlag" ("TRUE" | "FALSE") #REQUIRED> <!ATTLIST "iTXtEntry" "compressionMethod" #CDATA #REQUIRED> <!-- The compression method used to store this iTXt entry --> <!-- Data type: String --> <!ATTLIST "iTXtEntry" "languageTag" #CDATA #REQUIRED> <!-- The ISO tag describing the language this iTXt entry --> <!-- Data type: String --> <!ATTLIST "iTXtEntry" "translatedKeyword" #CDATA #REQUIRED> <!-- The translated keyword for iTXt entry --> <!-- Data type: String --> <!ATTLIST "iTXtEntry" "text" #CDATA #REQUIRED> <!-- The localized text --> <!-- Data type: String --> <!ELEMENT "pHYS" EMPTY> <!-- The pHYS chunk, containing the pixel size and aspect ratio --> <!ATTLIST "pHYS" "pixelsPerUnitXAxis" #CDATA #REQUIRED> <!-- The number of horizontal pixels per unit, multiplied by 1e5 --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 2147483647 (inclusive) --> <!ATTLIST "pHYS" "pixelsPerUnitYAxis" #CDATA #REQUIRED> <!-- The number of vertical pixels per unit, multiplied by 1e5 --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 2147483647 (inclusive) --> <!ATTLIST "pHYS" "unitSpecifier" ("unknown" | "meter") #REQUIRED> <!-- The unit specifier for this chunk (i.e., meters) --> <!ELEMENT "sBIT" (sBIT_Grayscale | sBIT_GrayAlpha | sBIT_RGB | sBIT_RGBAlpha | sBIT_Palette)> <!-- The sBIT chunk, containing significant bit information --> <!ELEMENT "sBIT_Grayscale" EMPTY> <!-- Significant bit information for gray samples --> <!ATTLIST "sBIT_Grayscale" "gray" #CDATA #REQUIRED> <!-- The number of significant bits of the gray samples --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ELEMENT "sBIT_GrayAlpha" EMPTY> <!-- Significant bit information for gray and alpha samples --> <!ATTLIST "sBIT_GrayAlpha" "gray" #CDATA #REQUIRED> <!-- The number of significant bits of the gray samples --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sBIT_GrayAlpha" "alpha" #CDATA #REQUIRED> <!-- The number of significant bits of the alpha samples --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ELEMENT "sBIT_RGB" EMPTY> <!-- Significant bit information for RGB samples --> <!ATTLIST "sBIT_RGB" "red" #CDATA #REQUIRED> <!-- The number of significant bits of the red samples --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sBIT_RGB" "green" #CDATA #REQUIRED> <!-- The number of significant bits of the green samples --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sBIT_RGB" "blue" #CDATA #REQUIRED> <!-- The number of significant bits of the blue samples --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ELEMENT "sBIT_RGBAlpha" EMPTY> <!-- Significant bit information for RGBA samples --> <!ATTLIST "sBIT_RGBAlpha" "red" #CDATA #REQUIRED> <!-- The number of significant bits of the red samples --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sBIT_RGBAlpha" "green" #CDATA #REQUIRED> <!-- The number of significant bits of the green samples --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sBIT_RGBAlpha" "blue" #CDATA #REQUIRED> <!-- The number of significant bits of the blue samples --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sBIT_RGBAlpha" "alpha" #CDATA #REQUIRED> <!-- The number of significant bits of the alpha samples --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ELEMENT "sBIT_Palette" EMPTY> <!-- Significant bit information for RGB palette entries --> <!ATTLIST "sBIT_Palette" "red" #CDATA #REQUIRED> <!-- The number of significant bits of the red palette entries --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sBIT_Palette" "green" #CDATA #REQUIRED> <!-- The number of significant bits of the green palette entries --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sBIT_Palette" "blue" #CDATA #REQUIRED> <!-- The number of significant bits of the blue palette entries --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ELEMENT "sPLT" (sPLTEntry)*> <!-- The sPLT chunk, containing a suggested palette --> <!-- Min children: 1 --> <!-- Max children: 256 --> <!ELEMENT "sPLTEntry" EMPTY> <!-- A suggested palette entry --> <!ATTLIST "sPLTEntry" "index" #CDATA #REQUIRED> <!-- The index of a suggested palette entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sPLTEntry" "red" #CDATA #REQUIRED> <!-- The red value of a suggested palette entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sPLTEntry" "green" #CDATA #REQUIRED> <!-- The green value of a suggested palette entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sPLTEntry" "blue" #CDATA #REQUIRED> <!-- The blue value of a suggested palette entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "sPLTEntry" "alpha" #CDATA #REQUIRED> <!-- The blue value of a suggested palette entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ELEMENT "sRGB" EMPTY> <!-- The sRGB chunk, containing rendering intent information --> <!ATTLIST "sRGB" "renderingIntent" ("Perceptual" | "Relative colorimetric" | "Saturation" | "Absolute colorimetric") #REQUIRED> <!-- The rendering intent --> <!ELEMENT "tEXt" (tEXtEntry)*> <!-- The tEXt chunk, containing text --> <!-- Min children: 1 --> <!-- Max children: 2147483647 --> <!ELEMENT "tEXtEntry" EMPTY> <!-- A text entry --> <!ATTLIST "tEXtEntry" "keyword" #CDATA #REQUIRED> <!-- The keyword --> <!-- Data type: String --> <!ATTLIST "tEXtEntry" "value" #CDATA #REQUIRED> <!-- The text --> <!-- Data type: String --> <!ELEMENT "tIME" EMPTY> <!-- The tIME chunk, containing the image modification time --> <!ATTLIST "tIME" "year" #CDATA #REQUIRED> <!-- The year when the image was last modified --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "tIME" "month" #CDATA #REQUIRED> <!-- The month when the image was last modified, 1 = January --> <!-- Data type: Integer --> <!-- Min value: 1 (inclusive) --> <!-- Max value: 12 (inclusive) --> <!ATTLIST "tIME" "day" #CDATA #REQUIRED> <!-- The day of the month when the image was last modified --> <!-- Data type: Integer --> <!-- Min value: 1 (inclusive) --> <!-- Max value: 31 (inclusive) --> <!ATTLIST "tIME" "hour" #CDATA #REQUIRED> <!-- The hour when the image was last modified --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 23 (inclusive) --> <!ATTLIST "tIME" "minute" #CDATA #REQUIRED> <!-- The minute when the image was last modified --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 59 (inclusive) --> <!ATTLIST "tIME" "second" #CDATA #REQUIRED> <!-- The second when the image was last modified, 60 = leap second --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 60 (inclusive) --> <!ELEMENT "tRNS" (tRNS_Grayscale | tRNS_RGB | tRNS_Palette)> <!-- The tRNS chunk, containing transparency information --> <!ELEMENT "tRNS_Grayscale" EMPTY> <!-- A grayscale value that should be considered transparent --> <!ATTLIST "tRNS_Grayscale" "gray" #CDATA #REQUIRED> <!-- The gray value to be considered transparent --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ELEMENT "tRNS_RGB" EMPTY> <!-- An RGB value that should be considered transparent --> <!ATTLIST "tRNS_RGB" "red" #CDATA #REQUIRED> <!-- The red value to be considered transparent --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "tRNS_RGB" "green" #CDATA #REQUIRED> <!-- The green value to be considered transparent --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ATTLIST "tRNS_RGB" "blue" #CDATA #REQUIRED> <!-- The blure value to be considered transparent --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 65535 (inclusive) --> <!ELEMENT "tRNS_Palette" EMPTY> <!-- A palette index that should be considered transparent --> <!ATTLIST "tRNS_Palette" "index" #CDATA #REQUIRED> <!-- A palette index to be considered transparent --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ATTLIST "tRNS_Palette" "alpha" #CDATA #REQUIRED> <!-- The transparency associated with the palette entry --> <!-- Data type: Integer --> <!-- Min value: 0 (inclusive) --> <!-- Max value: 255 (inclusive) --> <!ELEMENT "zTXt" (zTXtEntry)*> <!-- The zTXt chunk, containing compressed text --> <!-- Min children: 1 --> <!-- Max children: 2147483647 --> <!ELEMENT "zTXtEntry" EMPTY> <!-- A compressed text entry --> <!-- User object: array of byte --> <!-- Min length: 0 --> <!-- Max length: 2147483647 --> <!ATTLIST "zTXtEntry" "keyword" #CDATA #REQUIRED> <!-- The keyword --> <!-- Data type: String --> <!ATTLIST "zTXtEntry" "compressionMethod" ("deflate") #REQUIRED> <!-- The compressed text --> <!ELEMENT "UnknownChunks" (UnknownChunk)*> <!-- A set of unknown chunks --> <!-- Min children: 1 --> <!-- Max children: 2147483647 --> <!ELEMENT "UnknownChunk" EMPTY> <!-- Unknown chunk data stored as a byte array --> <!-- User object: array of byte --> <!-- Min length: 0 --> <!-- Max length: 2147483647 --> <!ATTLIST "UnknownChunk" "type" #CDATA #REQUIRED> <!-- The 4-character type of the unknown chunk --> <!-- Data type: String --> ]>