png_conform 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +19 -0
  4. data/.rubocop_todo.yml +197 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/CONTRIBUTING.md +323 -0
  7. data/Gemfile +13 -0
  8. data/LICENSE +43 -0
  9. data/README.adoc +859 -0
  10. data/Rakefile +10 -0
  11. data/SECURITY.md +147 -0
  12. data/docs/ARCHITECTURE.adoc +681 -0
  13. data/docs/CHUNK_TYPES.adoc +450 -0
  14. data/docs/CLI_OPTIONS.adoc +913 -0
  15. data/docs/COMPATIBILITY.adoc +616 -0
  16. data/examples/README.adoc +398 -0
  17. data/examples/advanced_usage.rb +304 -0
  18. data/examples/basic_usage.rb +210 -0
  19. data/exe/png_conform +6 -0
  20. data/lib/png_conform/analyzers/comparison_analyzer.rb +230 -0
  21. data/lib/png_conform/analyzers/metrics_analyzer.rb +176 -0
  22. data/lib/png_conform/analyzers/optimization_analyzer.rb +190 -0
  23. data/lib/png_conform/analyzers/resolution_analyzer.rb +274 -0
  24. data/lib/png_conform/bindata/chunk_structure.rb +153 -0
  25. data/lib/png_conform/bindata/jng_file.rb +79 -0
  26. data/lib/png_conform/bindata/mng_file.rb +97 -0
  27. data/lib/png_conform/bindata/png_file.rb +162 -0
  28. data/lib/png_conform/cli.rb +116 -0
  29. data/lib/png_conform/commands/check_command.rb +323 -0
  30. data/lib/png_conform/commands/list_command.rb +67 -0
  31. data/lib/png_conform/models/chunk.rb +84 -0
  32. data/lib/png_conform/models/chunk_info.rb +71 -0
  33. data/lib/png_conform/models/compression_info.rb +49 -0
  34. data/lib/png_conform/models/decoded_chunk_data.rb +143 -0
  35. data/lib/png_conform/models/file_analysis.rb +181 -0
  36. data/lib/png_conform/models/file_info.rb +91 -0
  37. data/lib/png_conform/models/image_info.rb +52 -0
  38. data/lib/png_conform/models/validation_error.rb +89 -0
  39. data/lib/png_conform/models/validation_result.rb +137 -0
  40. data/lib/png_conform/readers/full_load_reader.rb +113 -0
  41. data/lib/png_conform/readers/streaming_reader.rb +180 -0
  42. data/lib/png_conform/reporters/base_reporter.rb +53 -0
  43. data/lib/png_conform/reporters/color_reporter.rb +65 -0
  44. data/lib/png_conform/reporters/json_reporter.rb +18 -0
  45. data/lib/png_conform/reporters/palette_reporter.rb +48 -0
  46. data/lib/png_conform/reporters/quiet_reporter.rb +18 -0
  47. data/lib/png_conform/reporters/reporter_factory.rb +108 -0
  48. data/lib/png_conform/reporters/summary_reporter.rb +65 -0
  49. data/lib/png_conform/reporters/text_reporter.rb +66 -0
  50. data/lib/png_conform/reporters/verbose_reporter.rb +87 -0
  51. data/lib/png_conform/reporters/very_verbose_reporter.rb +33 -0
  52. data/lib/png_conform/reporters/visual_elements.rb +66 -0
  53. data/lib/png_conform/reporters/yaml_reporter.rb +18 -0
  54. data/lib/png_conform/services/profile_manager.rb +242 -0
  55. data/lib/png_conform/services/validation_service.rb +457 -0
  56. data/lib/png_conform/services/zlib_validator.rb +270 -0
  57. data/lib/png_conform/validators/ancillary/bkgd_validator.rb +140 -0
  58. data/lib/png_conform/validators/ancillary/chrm_validator.rb +178 -0
  59. data/lib/png_conform/validators/ancillary/cicp_validator.rb +202 -0
  60. data/lib/png_conform/validators/ancillary/gama_validator.rb +105 -0
  61. data/lib/png_conform/validators/ancillary/hist_validator.rb +147 -0
  62. data/lib/png_conform/validators/ancillary/iccp_validator.rb +243 -0
  63. data/lib/png_conform/validators/ancillary/itxt_validator.rb +280 -0
  64. data/lib/png_conform/validators/ancillary/mdcv_validator.rb +201 -0
  65. data/lib/png_conform/validators/ancillary/offs_validator.rb +132 -0
  66. data/lib/png_conform/validators/ancillary/pcal_validator.rb +289 -0
  67. data/lib/png_conform/validators/ancillary/phys_validator.rb +107 -0
  68. data/lib/png_conform/validators/ancillary/sbit_validator.rb +176 -0
  69. data/lib/png_conform/validators/ancillary/scal_validator.rb +180 -0
  70. data/lib/png_conform/validators/ancillary/splt_validator.rb +223 -0
  71. data/lib/png_conform/validators/ancillary/srgb_validator.rb +117 -0
  72. data/lib/png_conform/validators/ancillary/ster_validator.rb +111 -0
  73. data/lib/png_conform/validators/ancillary/text_validator.rb +129 -0
  74. data/lib/png_conform/validators/ancillary/time_validator.rb +132 -0
  75. data/lib/png_conform/validators/ancillary/trns_validator.rb +154 -0
  76. data/lib/png_conform/validators/ancillary/ztxt_validator.rb +173 -0
  77. data/lib/png_conform/validators/apng/actl_validator.rb +81 -0
  78. data/lib/png_conform/validators/apng/fctl_validator.rb +155 -0
  79. data/lib/png_conform/validators/apng/fdat_validator.rb +117 -0
  80. data/lib/png_conform/validators/base_validator.rb +241 -0
  81. data/lib/png_conform/validators/chunk_registry.rb +219 -0
  82. data/lib/png_conform/validators/critical/idat_validator.rb +77 -0
  83. data/lib/png_conform/validators/critical/iend_validator.rb +68 -0
  84. data/lib/png_conform/validators/critical/ihdr_validator.rb +160 -0
  85. data/lib/png_conform/validators/critical/plte_validator.rb +120 -0
  86. data/lib/png_conform/validators/jng/jdat_validator.rb +66 -0
  87. data/lib/png_conform/validators/jng/jhdr_validator.rb +116 -0
  88. data/lib/png_conform/validators/jng/jsep_validator.rb +66 -0
  89. data/lib/png_conform/validators/mng/back_validator.rb +87 -0
  90. data/lib/png_conform/validators/mng/clip_validator.rb +65 -0
  91. data/lib/png_conform/validators/mng/clon_validator.rb +45 -0
  92. data/lib/png_conform/validators/mng/defi_validator.rb +104 -0
  93. data/lib/png_conform/validators/mng/dhdr_validator.rb +104 -0
  94. data/lib/png_conform/validators/mng/disc_validator.rb +44 -0
  95. data/lib/png_conform/validators/mng/endl_validator.rb +65 -0
  96. data/lib/png_conform/validators/mng/fram_validator.rb +91 -0
  97. data/lib/png_conform/validators/mng/loop_validator.rb +75 -0
  98. data/lib/png_conform/validators/mng/mend_validator.rb +31 -0
  99. data/lib/png_conform/validators/mng/mhdr_validator.rb +69 -0
  100. data/lib/png_conform/validators/mng/move_validator.rb +61 -0
  101. data/lib/png_conform/validators/mng/save_validator.rb +39 -0
  102. data/lib/png_conform/validators/mng/seek_validator.rb +42 -0
  103. data/lib/png_conform/validators/mng/show_validator.rb +52 -0
  104. data/lib/png_conform/validators/mng/term_validator.rb +84 -0
  105. data/lib/png_conform/version.rb +5 -0
  106. data/lib/png_conform.rb +101 -0
  107. data/png_conform.gemspec +43 -0
  108. metadata +201 -0
@@ -0,0 +1,450 @@
1
+ = PNG Chunk Types Reference
2
+
3
+ == Purpose
4
+
5
+ Complete reference of all PNG, MNG, JNG, and APNG chunk types validated by PngConform.
6
+
7
+ == PNG Critical Chunks
8
+
9
+ === IHDR (Image Header)
10
+
11
+ **Purpose**: Defines fundamental image properties
12
+ **Required**: Yes (must be first chunk)
13
+ **Size**: 13 bytes
14
+
15
+ **Contents**:
16
+
17
+ * Width (4 bytes)
18
+ * Height (4 bytes)
19
+ * Bit depth (1 byte)
20
+ * Color type (1 byte)
21
+ * Compression method (1 byte)
22
+ * Filter method (1 byte)
23
+ * Interlace method (1 byte)
24
+
25
+ **Validation**:
26
+
27
+ * Width and height must be non-zero
28
+ * Bit depth must be valid for color type
29
+ * Color type must be 0, 2, 3, 4, or 6
30
+ * Compression method must be 0 (deflate)
31
+ * Filter method must be 0 (adaptive)
32
+ * Interlace method must be 0 (none) or 1 (Adam7)
33
+
34
+ === PLTE (Palette)
35
+
36
+ **Purpose**: Defines color palette for indexed-color images
37
+ **Required**: Yes for color type 3, optional for types 2 and 6
38
+ **Size**: Variable (multiple of 3)
39
+
40
+ **Contents**:
41
+
42
+ * RGB triplets (3 bytes each)
43
+
44
+ **Validation**:
45
+
46
+ * Length must be divisible by 3
47
+ * Maximum 256 entries (2^8)
48
+ * Must appear before IDAT
49
+ * Required for indexed-color images
50
+ * Must not appear for grayscale
51
+
52
+ === IDAT (Image Data)
53
+
54
+ **Purpose**: Contains compressed image pixel data
55
+ **Required**: Yes (at least one)
56
+ **Size**: Variable
57
+
58
+ **Contents**:
59
+
60
+ * zlib-compressed image data
61
+
62
+ **Validation**:
63
+
64
+ * Must be consecutive (no other chunks between)
65
+ * zlib data must be valid
66
+ * Decompressed size must match expected
67
+ * Filter bytes must be 0-4
68
+
69
+ === IEND (Image End)
70
+
71
+ **Purpose**: Marks end of PNG datastream
72
+ **Required**: Yes (must be last chunk)
73
+ **Size**: 0 bytes
74
+
75
+ **Validation**:
76
+
77
+ * Must be last chunk in file
78
+ * Data length must be exactly 0
79
+ * Must appear exactly once
80
+
81
+ == PNG Ancillary Chunks
82
+
83
+ === Color Space Chunks
84
+
85
+ ==== gAMA (Gamma)
86
+
87
+ **Purpose**: Specifies gamma correction value
88
+ **Size**: 4 bytes
89
+ **Value**: Gamma * 100000 (e.g., 45455 = 0.45455 gamma)
90
+
91
+ ==== cHRM (Chromaticity)
92
+
93
+ **Purpose**: Defines color space primaries and white point
94
+ **Size**: 32 bytes
95
+ **Values**: 8 x/y pairs for red, green, blue, white point
96
+
97
+ ==== sRGB (Standard RGB)
98
+
99
+ **Purpose**: Indicates standard RGB color space
100
+ **Size**: 1 byte
101
+ **Values**: Rendering intent (0-3)
102
+
103
+ ==== iCCP (ICC Profile)
104
+
105
+ **Purpose**: Embeds ICC color profile
106
+ **Size**: Variable
107
+ **Contents**: Profile name + compressed ICC profile data
108
+
109
+ ==== cICP (Coding-Independent Code Points)
110
+
111
+ **Purpose**: Color space for HDR and wide color gamut (PNG 3rd edition)
112
+ **Size**: 4 bytes
113
+ **Values**: Color primaries, transfer function, matrix coefficients, range
114
+
115
+ ==== mDCv (Mastering Display Color Volume)
116
+
117
+ **Purpose**: HDR display metadata (PNG 3rd edition)
118
+ **Size**: 24 bytes
119
+ **Values**: Display primaries, white point, luminance
120
+
121
+ === Transparency Chunks
122
+
123
+ ==== tRNS (Transparency)
124
+
125
+ **Purpose**: Defines transparency information
126
+ **Size**: Variable (depends on color type)
127
+
128
+ **For grayscale**: 2 bytes (gray value)
129
+ **For RGB**: 6 bytes (R, G, B values)
130
+ **For palette**: 1-256 bytes (alpha for each palette entry)
131
+
132
+ ==== bKGD (Background Color)
133
+
134
+ **Purpose**: Suggests background color
135
+ **Size**: Variable (depends on color type)
136
+
137
+ **For grayscale**: 2 bytes
138
+ **For RGB**: 6 bytes
139
+ **For palette**: 1 byte (palette index)
140
+
141
+ === Text Chunks
142
+
143
+ ==== tEXt (Textual Data)
144
+
145
+ **Purpose**: Stores Latin-1 text metadata
146
+ **Size**: Variable
147
+ **Contents**: Keyword (1-79 bytes) + null + text
148
+
149
+ **Common Keywords**:
150
+
151
+ * Title
152
+ * Author
153
+ * Description
154
+ * Copyright
155
+ * Creation Time
156
+ * Software
157
+
158
+ ==== zTXt (Compressed Text)
159
+
160
+ **Purpose**: Stores compressed Latin-1 text
161
+ **Size**: Variable
162
+ **Contents**: Keyword + null + compression method + compressed text
163
+
164
+ ==== iTXt (International Text)
165
+
166
+ **Purpose**: Stores UTF-8 text with language tag
167
+ **Size**: Variable
168
+ **Contents**: Keyword + compression + language tag + translated keyword + text
169
+
170
+ === Physical Dimension Chunks
171
+
172
+ ==== pHYs (Physical Pixel Dimensions)
173
+
174
+ **Purpose**: Specifies intended pixel size
175
+ **Size**: 9 bytes
176
+
177
+ **Contents**:
178
+
179
+ * Pixels per unit X (4 bytes)
180
+ * Pixels per unit Y (4 bytes)
181
+ * Unit specifier (1 byte): 0=unknown, 1=meter
182
+
183
+ **Usage**: Calculate DPI for print resolution
184
+
185
+ ==== sCAL (Physical Scale)
186
+
187
+ **Purpose**: Specifies physical dimensions
188
+ **Size**: Variable
189
+
190
+ **Contents**:
191
+
192
+ * Unit specifier (1 byte): 1=meter, 2=radian
193
+ * Pixel width (ASCII)
194
+ * Pixel height (ASCII)
195
+
196
+ === Metadata Chunks
197
+
198
+ ==== tIME (Last Modification Time)
199
+
200
+ **Purpose**: Stores last modification timestamp
201
+ **Size**: 7 bytes
202
+
203
+ **Contents**:
204
+
205
+ * Year (2 bytes)
206
+ * Month (1 byte, 1-12)
207
+ * Day (1 byte, 1-31)
208
+ * Hour (1 byte, 0-23)
209
+ * Minute (1 byte, 0-59)
210
+ * Second (1 byte, 0-60)
211
+
212
+ ==== hIST (Histogram)
213
+
214
+ **Purpose**: Approximate usage frequency of palette colors
215
+ **Size**: Variable (2 bytes per palette entry)
216
+
217
+ ==== sPLT (Suggested Palette)
218
+
219
+ **Purpose**: Suggests reduced palette for displays
220
+ **Size**: Variable
221
+
222
+ ==== sBIT (Significant Bits)
223
+
224
+ **Purpose**: Original number of significant bits
225
+ **Size**: Variable (depends on color type)
226
+
227
+ ==== oFFs (Image Offset)
228
+
229
+ **Purpose**: Image position offset
230
+ **Size**: 9 bytes
231
+
232
+ ==== pCAL (Pixel Calibration)
233
+
234
+ **Purpose**: Calibration for scientific/medical imaging
235
+ **Size**: Variable
236
+
237
+ ==== sTER (Stereo Image)
238
+
239
+ **Purpose**: Indicates stereo image layout
240
+ **Size**: 1 byte
241
+ **Values**: 0=cross-fuse, 1=diverging-fuse
242
+
243
+ == APNG (Animated PNG) Chunks
244
+
245
+ === acTL (Animation Control)
246
+
247
+ **Purpose**: Defines animation parameters
248
+ **Size**: 8 bytes
249
+ **Required**: First for animated PNGs
250
+
251
+ **Contents**:
252
+
253
+ * Number of frames (4 bytes)
254
+ * Number of plays (4 bytes, 0=infinite)
255
+
256
+ === fcTL (Frame Control)
257
+
258
+ **Purpose**: Controls individual frame rendering
259
+ **Size**: 26 bytes
260
+ **Required**: Before each frame
261
+
262
+ **Contents**:
263
+
264
+ * Sequence number (4 bytes)
265
+ * Frame width/height (4+4 bytes)
266
+ * X/Y offset (4+4 bytes)
267
+ * Delay numerator/denominator (2+2 bytes)
268
+ * Dispose operation (1 byte)
269
+ * Blend operation (1 byte)
270
+
271
+ === fdAT (Frame Data)
272
+
273
+ **Purpose**: Contains frame image data
274
+ **Size**: Variable
275
+ **Contents**: Sequence number + image data
276
+
277
+ == MNG (Multiple-Image Network Graphics) Chunks
278
+
279
+ === MHDR (MNG Header)
280
+
281
+ **Purpose**: MNG file header
282
+ **Required**: Yes (must be first)
283
+ **Size**: 28 bytes
284
+
285
+ === MEND (MNG End)
286
+
287
+ **Purpose**: Marks end of MNG file
288
+ **Required**: Yes (must be last)
289
+ **Size**: 0 bytes
290
+
291
+ === DHDR (Delta PNG Header)
292
+
293
+ **Purpose**: Defines delta-PNG header
294
+ **Size**: 4 or 20 bytes
295
+
296
+ === FRAM (Frame Parameters)
297
+
298
+ **Purpose**: Controls frame rendering parameters
299
+ **Size**: Variable
300
+
301
+ === Animation Control Chunks
302
+
303
+ ==== LOOP (Loop Control)
304
+
305
+ **Purpose**: Defines animation loop
306
+ **Size**: 5 or 6 bytes
307
+
308
+ ==== ENDL (End Loop)
309
+
310
+ **Purpose**: Marks end of loop
311
+ **Size**: 1 byte
312
+
313
+ ==== TERM (Termination Action)
314
+
315
+ **Purpose**: Specifies termination behavior
316
+ **Size**: 1 or 10 bytes
317
+
318
+ === Object Management Chunks
319
+
320
+ ==== DEFI (Object Definition)
321
+
322
+ **Purpose**: Defines object parameters
323
+ **Size**: 2, 3, 4, 12, or 28 bytes
324
+
325
+ ==== MOVE (Move Object)
326
+
327
+ **Purpose**: Repositions object
328
+ **Size**: 13 bytes
329
+
330
+ ==== CLIP (Clip Object)
331
+
332
+ **Purpose**: Sets clipping boundaries
333
+ **Size**: 21 bytes
334
+
335
+ ==== SHOW (Show Object)
336
+
337
+ **Purpose**: Displays object
338
+ **Size**: 0 or 2 bytes
339
+
340
+ ==== CLON (Clone Object)
341
+
342
+ **Purpose**: Clones existing object
343
+ **Size**: Variable
344
+
345
+ ==== DISC (Discard Objects)
346
+
347
+ **Purpose**: Discards objects from buffer
348
+ **Size**: Variable
349
+
350
+ === State Management Chunks
351
+
352
+ ==== SAVE (Save State)
353
+
354
+ **Purpose**: Saves current state
355
+ **Size**: 0 bytes
356
+
357
+ ==== SEEK (Seek to State)
358
+
359
+ **Purpose**: Restores saved state
360
+ **Size**: 0 bytes
361
+
362
+ === Background Chunk
363
+
364
+ ==== BACK (Background)
365
+
366
+ **Purpose**: Sets background color
367
+ **Size**: 6 or 10 bytes
368
+
369
+ == JNG (JPEG Network Graphics) Chunks
370
+
371
+ === JHDR (JNG Header)
372
+
373
+ **Purpose**: JNG file header
374
+ **Required**: Yes (must be first)
375
+ **Size**: 16 bytes
376
+
377
+ **Contents**:
378
+
379
+ * Width/height (4+4 bytes)
380
+ * Color type, bit depth (1+1 byte)
381
+ * Compression method (1 byte)
382
+ * Interlace method (1 byte)
383
+ * Alpha sample depth, compression (1+1 byte)
384
+ * Alpha filter, interlace (1+1 byte)
385
+
386
+ === JDAT (JPEG Data)
387
+
388
+ **Purpose**: Contains JPEG image data
389
+ **Required**: Yes
390
+ **Size**: Variable
391
+
392
+ === JSEP (8/12-bit Separator)
393
+
394
+ **Purpose**: Separates 8-bit and 12-bit JPEG data
395
+ **Size**: 0 bytes
396
+
397
+ == Chunk Validation Rules
398
+
399
+ === General Rules
400
+
401
+ All chunks must:
402
+
403
+ * Have valid CRC-32 checksum
404
+ * Follow PNG chunk structure (length + type + data + CRC)
405
+ * Respect chunk ordering constraints
406
+ * Meet size requirements
407
+
408
+ === Critical vs Ancillary
409
+
410
+ **Critical chunks** (uppercase first letter):
411
+
412
+ * Must be recognized by decoder
413
+ * File is invalid if unknown critical chunk present
414
+ * Examples: IHDR, PLTE, IDAT, IEND
415
+
416
+ **Ancillary chunks** (lowercase first letter):
417
+
418
+ * Can be safely ignored if unknown
419
+ * File remains valid if unknown ancillary chunk present
420
+ * Examples: gAMA, tEXt, tIME
421
+
422
+ === Private vs Public
423
+
424
+ **Public chunks** (uppercase second letter):
425
+
426
+ * Defined in PNG specification or registered
427
+ * Examples: IHDR, gAMA, tEXt
428
+
429
+ **Private chunks** (lowercase second letter):
430
+
431
+ * Application-specific
432
+ * Not defined in standard
433
+
434
+ === Safe to Copy
435
+
436
+ **Safe-to-copy chunks** (lowercase fourth letter):
437
+
438
+ * Can be copied when PNG is modified
439
+ * Examples: tEXt, tIME
440
+
441
+ **Unsafe-to-copy chunks** (uppercase fourth letter):
442
+
443
+ * May become invalid if image data modified
444
+ * Examples: hIST (depends on palette)
445
+
446
+ == See Also
447
+
448
+ * link:../README.adoc[PngConform Documentation]
449
+ * link:COMPATIBILITY.adoc[Tool Compatibility]
450
+ * link:CLI_OPTIONS.adoc[CLI Options Reference]