IVR is a high-speed, lossless image compression format that represents images as a sequence of optimized, same-color rectangles. It occupies a unique niche between traditional raster formats (like PNG) and vector-like structured data.
- High-Speed Decoding: Reaches up to 350+ MP/s, making it ideal for real-time applications.
- Superior Compression: Outperforms PNG by 10–60% on structured, flat-colored, or UI-heavy images.
- Native Scalability: Can decode at arbitrary scales (e.g., 2x, 4x) by simply multiplying rectangle dimensions, avoiding heavy pixel-interpolation overhead.
- UI & Web Graphics: Buttons, icons, and wireframes.
- Document Archiving: Scanned text, forms, and diagrams.
- Runtime Caching: Fast intermediate storage for engine textures or screenshots.
Unlike PNG which scans line-by-line, IVR identifies the largest possible same-color rectangle starting from the top-left unprocessed pixel. It compares horizontal-first vs. vertical-first growth and selects the one with the maximum area.
- Header: Magic bytes (
IVR1), Width, Height. - Payload (Zstd compressed):
- Palette: Adaptive size with delta-encoding for RGB values.
- Rectangle List: -
Width: Exp-Golomb encoded.Height: Exp-Golomb encoded.Color Index: Fixed-bit length based on palette size.
(Benchmark)
Image: 2559 x 1391 (VSCODE)
-
BMP: 10.1 MB
-
PNG: 268 KB
-
IVR: 92.9 KB (Down to approx. 33% of PNG size)
-
Encode Time: 0.0105s
-
Zstd Time: 0.0283s
-
Decode Time: 0.0144s
Log: === File Info === Input Size : 274440 bytes
=== Any -> IVR === Resolution : 2559 x 1391 (Raw) Scale : x1 , y1 Output Res : 2559 x 1391
Palette : 4082 colors Rectangles : 72837 Raw Data : 152524 bytes Zstd Data : 92973 bytes Ratio : 33.88 % of original Zstd Level : 19
Make Pal : 0.0075 s Encode : 0.0105 s Zip : 0.0283 s Decode : 0.0144 s TOTAL : 0.0715 s
Since IVR can represent massive images with tiny file sizes (similar to a "zip bomb"), implementations include safety guards for:
- Max output dimensions/pixel count.
- Recursion/Allocation limits.
IVR (Infinitely Variable Rectangle) は、画像を「最適化された同色長方形の集合」として表現する、超高速・可逆圧縮画像フォーマットです。PNGのような従来のラスタ形式と、構造化データの利点を併せ持っています。
- 爆速デコード: 最大 350 MP/s 以上の処理速度を誇り、4K画像も一瞬で展開可能です。
- 高い圧縮効率: UIグラフィックスやフラットイラストにおいて、PNG比で 10%〜60% のサイズ削減を実現します。
- ネイティブ・スケーリング: 矩形データとして記録されているため、デコード時に座標を倍数化するだけで、計算負荷を抑えたまま巨大な解像度へ拡大展開(Scale)が可能です。
- UI・ウェブグラフィックス: ボタン、アイコン、ワイヤーフレームなど。
- 文書・図面アーカイブ: スキャンされた書類、FAX、回路図。
- ランタイムキャッシュ: ゲームエンジン内での一時的なテクスチャ保存やスクショ。
IVRは左上の未処理ピクセルを起点に、**「最も面積が大きくなる同色の長方形」**を探索します。
- 「横方向に伸ばしてから縦に広げる」
- 「縦方向に伸ばしてから横に広げる」 この2パターンを比較し、より効率的な方を採用することで、PNGの走査線方式(Filter)よりも構造的に冗長性を排除します。
Zstdによる強力なエントロピー圧縮の前に、データを以下の構造に最適化します。
- パレット: RGBの差分(Delta)をとることで連続性を向上。
- 矩形リスト: -
幅 / 高さ: 指数ゴロム符号(Exp-Golomb)による可変長符号化。色インデックス: パレット数に応じた最小ビット割り当て。
Image: 2559 x 1391 (VSCODE)
-
BMP: 10.1 MB
-
PNG: 268 KB
-
IVR: 92.9 KB (PNG比 約33%)
-
Encode Time: 0.0105s
-
Zstd Time: 0.0283s
-
Decode Time: 0.0144s
Log: === File Info === Input Size : 274440 bytes
=== Any -> IVR === Resolution : 2559 x 1391 (Raw) Scale : x1 , y1 Output Res : 2559 x 1391
Palette : 4082 colors Rectangles : 72837 Raw Data : 152524 bytes Zstd Data : 92973 bytes Ratio : 33.88 % of original Zstd Level : 19
Make Pal : 0.0075 s Encode : 0.0105 s Zip : 0.0283 s Decode : 0.0144 s TOTAL : 0.0715 s
IVRは「小さなファイルから巨大な画素」を生成できるため、信頼できないファイルを扱う際は以下の制限を設けています。
- 最大出力画素数および拡大率の制限
- メモリ確保前のオーバーフロー・チェック
MIT License