PNG

Dies ist ein binäres Format in Big-Endian Anordnung. Folgende Datentypen kommen zur Anwendung:

char String mit 8-Bit Kodierung
uint8 vorzeichenlose 8-Bit Zahl
uint32vorzeichenlose 32-Bit Zahl

Die Datei beginnt mit der Signatur. Danach folgen die einzelnen Blocks direkt aufeinander.

Signatur

Details Signatur

Jede PNG Datei beginnt mit folgender Signatur:

<89 50 4E 47 0D 0A 1A 0A>

Auf die Signatur folgt direkt der erste Block.

Blockaufbau

Details Blockaufbau

Position Grösse Typ Wert
04 Byte uint32Blockgrösse
44 Byte char Blocktyp
8Blockgrösse* Blockdaten
Blockgrösse + 84 Byte uint32Prüfsumme

Die Prüfsumme ist eine normale CRC-32 Prüfsumme über Blocktyp und Blockdaten.

"IHDR" Block

Details "IHDR" Block

PositionGrösseTyp Wert
04 Byteuint32Blockgrösse
44 Bytechar Blocktyp
84 Byteuint32Bildbreite
124 Byteuint32Bildhöhe
161 Byteuint8 Bittiefe
171 Byteuint8 Farbmodell
181 Byteuint8 Kompression
191 Byteuint8 Prediktor
201 Byteuint8 Interlacing
214 Byteuint32Prüfsumme

Für das Farbmodell sind folgende Werte möglich:

WertModell
0Graustufen
2RGB
3RGB indexiert
4Graustufen mit Alphakanal
6RGB mit Alphakanal

Kompression ist immer 0 (Deflate).

Prediktor ist immer 0 (PNG Prediktor).

Interlacing kann die Werte 0 (kein Interlacing) und 1 (Adam7) haben.

"PLTE" Block

Details "PLTE" Block

Dieser Block kommt nur im indexierten Farbraum vor, ist dann aber zwingend notwendig.

Position Grösse Typ Wert
04 Byte uint32Blockgrösse
44 Byte char Blocktyp
8Blockgrösseuint8 Palette
Blockgrösse + 84 Byte uint32Prüfsumme

Die Palette hat einen Eintrag für jede verwendete Farbe, welcher wiederum aus drei uint8 für den Rot-, Grün- und Blauanteil der Farbe besteht.

"IDAT" Block

Details "IDAT" Block

Position Grösse Typ Wert
04 Byte uint32Blockgrösse
44 Byte char Blocktyp
8Blockgrösse* Bilddaten
Blockgrösse + 84 Byte uint32Prüfsumme

Falls mehrere IDAT Blöcke existieren, müssen die Bilddaten der einzelnen Blöcke in der Reihenfolge des Auftretens in der Datei zusammengesetzt werden.

"sRGB" Block

Details "sRGB" Block

PositionGrösseTyp Wert
04 Byteuint32Blockgrösse
44 Bytechar Blocktyp
81 Byteuint8 Umrechnungspriorität
94 Byteuint32Prüfsumme

Ist dieser Block enthalten, so sind die Bilddaten im sRGB Farbraum.

Für die Umrechnungspriorität sind folgende Werte möglich:

0/Perceptual
1/RelativeColorimetric
2/Saturation
3/AbsoluteColorimetric

"iCCP" Block

Details "iCCP" Block

PositionGrösseTyp Wert
04 Byteuint32Blockgrösse
44 Bytechar Blocktyp
8* char Profilname
*1 Byteuint8 0
*1 Byteuint8 Kompression
** * ICC-Profildaten
*4 Byteuint32Prüfsumme

Der Profilname ist in ISO Latin-1, und kann im Namen selbst kein 0-Byte enthalten.

Kompression ist immer 0 (Deflate).

"gAMA" Block

Details "gAMA" Block

PositionGrösseTyp Wert
04 Byteuint32Blockgrösse
44 Bytechar Blocktyp
84 Byteuint32Gammawert (invers)
124 Byteuint32Prüfsumme

Der inverse Gammawert ist auf einer Skala von 0 - 100'000.

Formel zur Umrechnung in den Wert für PDF:

gamma = 100000.0 / gamma

"cHRM" Block

Details "cHRM" Block

PositionGrösseTyp Wert
04 Byteuint32Blockgrösse
44 Bytechar Blocktyp
84 Byteuint32xw
124 Byteuint32yw
164 Byteuint32xr
204 Byteuint32yr
244 Byteuint32xg
284 Byteuint32yg
324 Byteuint32xb
364 Byteuint32yb
404 Byteuint32Prüfsumme

Die x und y Werte sind auf einer Skala von 0 - 100'000.

Formelsatz für die Umrechnung in PDF-Werte:

xw = xw / 100000.0
yw = yw / 100000.0
xr = xr / 100000.0
yr = yr / 100000.0
xg = xg / 100000.0
yg = yg / 100000.0
xb = xb / 100000.0
yb = yb / 100000.0

Xw = xw / yw
Yw = 1
Zw = (1 - xw - yw) / yw

zr = 1 - xr - yr
zg = 1 - xg - yg
zb = 1 - xb - yb
mxr = yg * zb - zg * yb
mxg = zr * yb - yr * zb
mxb = yr * zg - zr * yg
d = mxr * xr + mxg * xg + mxb * xb
Sr = (mxr * Xw + (yb * Zw - zb) * xg + (zg - yg * Zw) * xb) / d
Sg = (mxg * Xw + (yr * Zw - zr) * xb + (zb - yb * Zw) * xr) / d
Sb = (mxb * Xw + (yg * Zw - zg) * xr + (zr - yr * Zw) * xg) / d
Xr = xr * Sr
Yr = yr * Sr
Zr = zr * Sr
Xg = xg * Sg
Yg = yg * Sg
Zg = zg * Sg
Xb = xb * Sb
Yb = yb * Sb
Zb = zb * Sb

/WhitePoint [Xw Yw Zw]
/Matrix [Xr Yr Zr Xg Yg Zg Xb Yb Zb]

"IEND" Block

Details "IEND" Block

PositionGrösseTyp Wert
04 Byteuint32Blockgrösse
44 Bytechar Blocktyp
84 Byteuint32Prüfsumme

Dieser Block enthält keine Blockdaten. Er markiert lediglich das Dateiende.