- 可逆圧縮の画像データを保存するタグ
- 例えば細かい模様等は JPEG だとぼやけてダメ
- zlib 圧縮するが PNG とも違う独自フォーマット
(20) DefineBitsLossless
- フォーマットによってパレット形式とビットマップ形式がある。どちらも独自形式
- 共通部分
+--------------------------------------------------------------------+---
| tag | length | length | image_id | format | width | height | ...
| 6 | 0x3f | | | | | |
+--------------------------------------------------------------------+---
<-- 2 bytes --><- 4 bytes -><-2 bytes-><-1 byte-><-2 bytes-><-2 bytes->
<------------------ length ---(最後まで)
- format 3 (GIF のようなパレット形式)
----------------------------------------------+
共通 |colormap_count| (colormap & indices) |
部分 | | zlib compressed |
----------------------------------------------+
<-- 2 bytes -><-- contents 残り全部 -->
RGBの順で並ぶ↓ ↑ zlib compress ↑
------------------------------------------------+
| colormap | indices |
------------------------------------------------+
<-- colormap --><-((width + 3) & -4) * height->
count * 3
- format 4 (実物にお目にかかった事がないけど)
----------------------------------------------+
共通 |colormap_count| (colormap & indices) |
部分 | | zlib compressed |
----------------------------------------------+
<-- 2 bytes -><-- contents 残り全部 -->
↑ zlib compress ↑
------------------------------------------------+
| colormap | indices |
------------------------------------------------+
<-- colormap --><-((width + 3) & -4) * height->
count * 2
- colormap を 0RRRRRGGGGGBBBBB の 16bit (BigEndian)で表現する
(36) DefineBitsLossless2
- DefineBitsLossless2 に透明度がついたもの。
- 共通部分 (DefineBitsLossless と同じ)
+--------------------------------------------------------------------+---
| tag | length | length | image_id | format | width | height | ...
| 6 | 0x3f | | | | | |
+--------------------------------------------------------------------+---
<-- 2 bytes --><- 4 bytes -><-2 bytes-><-1 byte-><-2 bytes-><-2 bytes->
<------------------ length ---(最後まで)
- format 3 (GIF のようなパレット形式)
----------------------------------------------+
共通 |colormap_count| (colormap & indices) |
部分 | | zlib compressed |
----------------------------------------------+
<-- 2 bytes -><-- contents 残り全部 -->
ARGBの順で並ぶ↓ ↑ zlib compress ↑
------------------------------------------------+
| colormap | indices |
------------------------------------------------+
<-- colormap --><-((width + 3) & -4) * height->
count * 4
備考
((width + 3) & -4) * height
- って何じゃらほい。という感じだけど、witdh を4の倍数で合わせるという意味
- ほら、-4 って 2 の補数だと二進数で 1111(略)00 じゃないですか。
witdh = 1 の場合 => ((1 + 3) & -4) = 4 & 1111(略)00 = 4
witdh = 2 の場合 => ((2 + 3) & -4) = 5 & 1111(略)00 = 4
witdh = 3 の場合 => ((3 + 3) & -4) = 6 & 1111(略)00 = 4
witdh = 4 の場合 => ((4 + 3) & -4) = 7 & 1111(略)00 = 4
witdh = 5 の場合 => ((5 + 3) & -4) = 8 & 1111(略)00 = 8
- 4の倍数に繰り上げてる。Windows BMP もピクセルデータはこんな並びだし、まぁ普通?
- % 4 とか mod 4 とか書けばいいんだけど、alexref にリスペクトして、あえて、そのままに。(実際、処理速そうだし)