png_conform 0.1.1 → 0.1.3

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +82 -42
  3. data/Gemfile +2 -0
  4. data/README.adoc +3 -2
  5. data/benchmarks/README.adoc +570 -0
  6. data/benchmarks/config/default.yml +35 -0
  7. data/benchmarks/config/full.yml +32 -0
  8. data/benchmarks/config/quick.yml +32 -0
  9. data/benchmarks/direct_validation.rb +18 -0
  10. data/benchmarks/lib/benchmark_runner.rb +204 -0
  11. data/benchmarks/lib/metrics_collector.rb +193 -0
  12. data/benchmarks/lib/png_conform_runner.rb +68 -0
  13. data/benchmarks/lib/pngcheck_runner.rb +67 -0
  14. data/benchmarks/lib/report_generator.rb +301 -0
  15. data/benchmarks/lib/tool_runner.rb +104 -0
  16. data/benchmarks/profile_loading.rb +12 -0
  17. data/benchmarks/profile_validation.rb +18 -0
  18. data/benchmarks/results/.gitkeep +0 -0
  19. data/benchmarks/run_benchmark.rb +159 -0
  20. data/config/validation_profiles.yml +105 -0
  21. data/docs/CHUNK_TYPES.adoc +42 -0
  22. data/examples/README.md +282 -0
  23. data/lib/png_conform/analyzers/comparison_analyzer.rb +41 -7
  24. data/lib/png_conform/analyzers/metrics_analyzer.rb +6 -9
  25. data/lib/png_conform/analyzers/optimization_analyzer.rb +30 -24
  26. data/lib/png_conform/analyzers/resolution_analyzer.rb +31 -32
  27. data/lib/png_conform/cli.rb +12 -0
  28. data/lib/png_conform/commands/check_command.rb +118 -52
  29. data/lib/png_conform/configuration.rb +147 -0
  30. data/lib/png_conform/container.rb +113 -0
  31. data/lib/png_conform/models/decoded_chunk_data.rb +33 -0
  32. data/lib/png_conform/models/validation_result.rb +30 -4
  33. data/lib/png_conform/pipelines/pipeline_result.rb +39 -0
  34. data/lib/png_conform/pipelines/stages/analysis_stage.rb +35 -0
  35. data/lib/png_conform/pipelines/stages/base_stage.rb +23 -0
  36. data/lib/png_conform/pipelines/stages/chunk_validation_stage.rb +74 -0
  37. data/lib/png_conform/pipelines/stages/sequence_validation_stage.rb +77 -0
  38. data/lib/png_conform/pipelines/stages/signature_validation_stage.rb +41 -0
  39. data/lib/png_conform/pipelines/validation_pipeline.rb +90 -0
  40. data/lib/png_conform/readers/full_load_reader.rb +13 -4
  41. data/lib/png_conform/readers/streaming_reader.rb +27 -2
  42. data/lib/png_conform/reporters/color_reporter.rb +17 -14
  43. data/lib/png_conform/reporters/reporter_factory.rb +18 -11
  44. data/lib/png_conform/reporters/visual_elements.rb +22 -16
  45. data/lib/png_conform/services/analysis_manager.rb +120 -0
  46. data/lib/png_conform/services/chunk_processor.rb +195 -0
  47. data/lib/png_conform/services/file_signature.rb +226 -0
  48. data/lib/png_conform/services/file_strategy.rb +78 -0
  49. data/lib/png_conform/services/lru_cache.rb +170 -0
  50. data/lib/png_conform/services/parallel_validator.rb +118 -0
  51. data/lib/png_conform/services/profile_manager.rb +41 -12
  52. data/lib/png_conform/services/result_builder.rb +299 -0
  53. data/lib/png_conform/services/validation_cache.rb +210 -0
  54. data/lib/png_conform/services/validation_orchestrator.rb +188 -0
  55. data/lib/png_conform/services/validation_service.rb +82 -321
  56. data/lib/png_conform/services/validator_pool.rb +142 -0
  57. data/lib/png_conform/utils/colorizer.rb +149 -0
  58. data/lib/png_conform/validators/ancillary/idot_validator.rb +102 -0
  59. data/lib/png_conform/validators/chunk_registry.rb +143 -128
  60. data/lib/png_conform/validators/streaming_idat_validator.rb +123 -0
  61. data/lib/png_conform/version.rb +1 -1
  62. data/lib/png_conform.rb +7 -46
  63. data/png_conform.gemspec +1 -0
  64. metadata +55 -2
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../base_validator"
4
+
5
+ module PngConform
6
+ module Validators
7
+ # Streaming IDAT validator for memory-efficient validation
8
+ #
9
+ # This validator processes IDAT chunk data in streaming mode to avoid
10
+ # loading large decompressed image data into memory. Instead of
11
+ # fully decompressing, it validates the zlib stream incrementally.
12
+ #
13
+ class StreamingIdatValidator < BaseValidator
14
+ # Validate IDAT chunk
15
+ #
16
+ # Performs streaming validation of zlib-compressed image data
17
+ # without fully decompressing into memory.
18
+ #
19
+ # @return [void]
20
+ def validate
21
+ return add_error("Invalid IDAT sequence") unless check_idat_sequence
22
+ return add_error("Invalid IDAT order") unless check_idat_order
23
+
24
+ # Validate compression in streaming mode
25
+ validate_streaming_compression
26
+ end
27
+
28
+ private
29
+
30
+ # Check IDAT sequence requirements
31
+ #
32
+ # @return [Boolean] True if IDAT sequence is valid
33
+ def check_idat_sequence
34
+ # IDAT chunks must be consecutive
35
+ previous_chunk_type = @context.seen?("IDAT") ? "IDAT" : nil
36
+
37
+ if previous_chunk_type && previous_chunk_type != "IDAT"
38
+ add_warning("IDAT chunks must be consecutive")
39
+ return false
40
+ end
41
+
42
+ true
43
+ end
44
+
45
+ # Check IDAT order requirements
46
+ #
47
+ # IDAT must come after PLTE (if present) and before IEND
48
+ #
49
+ # @return [Boolean] True if IDAT is in correct position
50
+ def check_idat_order
51
+ # IDAT cannot be first (must have IHDR)
52
+ return false unless @context.seen?("IHDR")
53
+
54
+ # If PLTE exists, IDAT must come after it
55
+ if @context.seen?("PLTE")
56
+ @context.chunks_of_type("PLTE")
57
+ find_chunk_index("PLTE")
58
+ @context.chunks_of_type("IDAT").length
59
+
60
+ # For now, just check that PLTE was seen before any IDAT
61
+ # The actual ordering is validated in sequence validation
62
+ end
63
+
64
+ true
65
+ end
66
+
67
+ # Find the index of a chunk in the validation sequence
68
+ #
69
+ # @param chunk_type [String] Chunk type to find
70
+ # @return [Integer, nil] Index of chunk or nil
71
+ def find_chunk_index(_chunk_type)
72
+ # This would require tracking chunk order in context
73
+ # For now, return nil as this is handled by sequence validation
74
+ nil
75
+ end
76
+
77
+ # Validate compression using streaming zlib validation
78
+ #
79
+ # Instead of fully decompressing the image data (which can be huge),
80
+ # this validates that the compressed data is valid zlib format without
81
+ # loading the decompressed result.
82
+ #
83
+ # @return [void]
84
+ def validate_streaming_compression
85
+ require "zlib"
86
+
87
+ # Try to validate the zlib stream without full decompression
88
+ # We inflate just enough to verify validity
89
+ begin
90
+ inflater = Zlib::Inflate.new(Zlib::MAX_WBITS)
91
+
92
+ # Process data in chunks to avoid large memory allocation
93
+ chunk.data.each_slice(8192) do |slice|
94
+ # << is used to append data to the inflate stream
95
+ # This validates the data format without storing result
96
+ result = inflater << slice
97
+
98
+ # If we got decompressed data back, the stream is valid
99
+ # We don't need to store it, just validate
100
+ if result && !result.empty?
101
+ # Data is valid, we can discard it
102
+ # This means the compressed data is well-formed
103
+ end
104
+ rescue Zlib::DataError => e
105
+ return add_error("Invalid compressed data in IDAT: #{e.message}")
106
+ end
107
+
108
+ # Finish the stream to validate end of data
109
+ inflater.finish
110
+ inflater.close
111
+
112
+ add_info("Streaming compression validation successful")
113
+ rescue Zlib::StreamError => e
114
+ add_error("Invalid zlib stream in IDAT: #{e.message}")
115
+ rescue Zlib::BufError => e
116
+ add_error("Buffer error in IDAT compression: #{e.message}")
117
+ rescue StandardError => e
118
+ add_error("Compression validation error: #{e.message}")
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PngConform
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/png_conform.rb CHANGED
@@ -40,60 +40,21 @@ module PngConform
40
40
  require_relative "png_conform/models/validation_result"
41
41
  require_relative "png_conform/models/file_analysis"
42
42
 
43
- # Load validators (Phase 4 & 5 - implemented)
43
+ # Load base validator and registry (Phase 4 optimization: lazy validator loading)
44
+ # All validators are loaded on-demand by chunk_registry
44
45
  require_relative "png_conform/validators/base_validator"
45
-
46
- # Critical validators
47
- require_relative "png_conform/validators/critical/ihdr_validator"
48
- require_relative "png_conform/validators/critical/plte_validator"
49
- require_relative "png_conform/validators/critical/idat_validator"
50
- require_relative "png_conform/validators/critical/iend_validator"
51
-
52
- # Ancillary validators
53
- require_relative "png_conform/validators/ancillary/gama_validator"
54
- require_relative "png_conform/validators/ancillary/trns_validator"
55
- require_relative "png_conform/validators/ancillary/chrm_validator"
56
- require_relative "png_conform/validators/ancillary/srgb_validator"
57
- require_relative "png_conform/validators/ancillary/iccp_validator"
58
- require_relative "png_conform/validators/ancillary/text_validator"
59
- require_relative "png_conform/validators/ancillary/ztxt_validator"
60
- require_relative "png_conform/validators/ancillary/itxt_validator"
61
- require_relative "png_conform/validators/ancillary/bkgd_validator"
62
- require_relative "png_conform/validators/ancillary/phys_validator"
63
- require_relative "png_conform/validators/ancillary/sbit_validator"
64
- require_relative "png_conform/validators/ancillary/splt_validator"
65
- require_relative "png_conform/validators/ancillary/hist_validator"
66
- require_relative "png_conform/validators/ancillary/time_validator"
67
- require_relative "png_conform/validators/ancillary/offs_validator"
68
- require_relative "png_conform/validators/ancillary/pcal_validator"
69
- require_relative "png_conform/validators/ancillary/scal_validator"
70
- require_relative "png_conform/validators/ancillary/ster_validator"
71
- require_relative "png_conform/validators/ancillary/cicp_validator"
72
- require_relative "png_conform/validators/ancillary/mdcv_validator"
46
+ require_relative "png_conform/validators/chunk_registry"
73
47
 
74
48
  # Load services (Phase 9 - implemented)
75
- require_relative "png_conform/validators/chunk_registry"
76
49
  require_relative "png_conform/services/validation_service"
77
50
  require_relative "png_conform/services/profile_manager"
78
51
 
79
52
  # Load analyzers (Phase 13 - Quick Win features)
80
- require_relative "png_conform/analyzers/optimization_analyzer"
81
- require_relative "png_conform/analyzers/metrics_analyzer"
82
- require_relative "png_conform/analyzers/resolution_analyzer"
83
- require_relative "png_conform/analyzers/comparison_analyzer"
53
+ # Analyzers are lazy-loaded on-demand in validation_service.rb (Phase 3 optimization)
54
+ # No upfront loading needed here
84
55
 
85
- # Load reporters (Phase 10 & 7 - implemented)
86
- require_relative "png_conform/reporters/visual_elements"
87
- require_relative "png_conform/reporters/base_reporter"
88
- require_relative "png_conform/reporters/summary_reporter"
89
- require_relative "png_conform/reporters/verbose_reporter"
90
- require_relative "png_conform/reporters/very_verbose_reporter"
91
- require_relative "png_conform/reporters/quiet_reporter"
92
- require_relative "png_conform/reporters/palette_reporter"
93
- require_relative "png_conform/reporters/text_reporter"
94
- require_relative "png_conform/reporters/color_reporter"
95
- require_relative "png_conform/reporters/yaml_reporter"
96
- require_relative "png_conform/reporters/json_reporter"
56
+ # Load reporter factory only (Phase 2 optimization: lazy reporter loading)
57
+ # Individual reporters are loaded on-demand by the factory
97
58
  require_relative "png_conform/reporters/reporter_factory"
98
59
 
99
60
  # Load CLI (Phase 11 - implemented)
data/png_conform.gemspec CHANGED
@@ -39,5 +39,6 @@ Gem::Specification.new do |spec|
39
39
 
40
40
  spec.add_dependency "bindata", "~> 2.5"
41
41
  spec.add_dependency "lutaml-model", "~> 0.7"
42
+ spec.add_dependency "paint", "~> 2.3"
42
43
  spec.add_dependency "thor", "~> 1.4"
43
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: png_conform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-11-17 00:00:00.000000000 Z
11
+ date: 2026-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: paint
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: thor
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -76,11 +90,28 @@ files:
76
90
  - README.adoc
77
91
  - Rakefile
78
92
  - SECURITY.md
93
+ - benchmarks/README.adoc
94
+ - benchmarks/config/default.yml
95
+ - benchmarks/config/full.yml
96
+ - benchmarks/config/quick.yml
97
+ - benchmarks/direct_validation.rb
98
+ - benchmarks/lib/benchmark_runner.rb
99
+ - benchmarks/lib/metrics_collector.rb
100
+ - benchmarks/lib/png_conform_runner.rb
101
+ - benchmarks/lib/pngcheck_runner.rb
102
+ - benchmarks/lib/report_generator.rb
103
+ - benchmarks/lib/tool_runner.rb
104
+ - benchmarks/profile_loading.rb
105
+ - benchmarks/profile_validation.rb
106
+ - benchmarks/results/.gitkeep
107
+ - benchmarks/run_benchmark.rb
108
+ - config/validation_profiles.yml
79
109
  - docs/ARCHITECTURE.adoc
80
110
  - docs/CHUNK_TYPES.adoc
81
111
  - docs/CLI_OPTIONS.adoc
82
112
  - docs/COMPATIBILITY.adoc
83
113
  - examples/README.adoc
114
+ - examples/README.md
84
115
  - examples/advanced_usage.rb
85
116
  - examples/basic_usage.rb
86
117
  - exe/png_conform
@@ -96,6 +127,8 @@ files:
96
127
  - lib/png_conform/cli.rb
97
128
  - lib/png_conform/commands/check_command.rb
98
129
  - lib/png_conform/commands/list_command.rb
130
+ - lib/png_conform/configuration.rb
131
+ - lib/png_conform/container.rb
99
132
  - lib/png_conform/models/chunk.rb
100
133
  - lib/png_conform/models/chunk_info.rb
101
134
  - lib/png_conform/models/compression_info.rb
@@ -105,6 +138,13 @@ files:
105
138
  - lib/png_conform/models/image_info.rb
106
139
  - lib/png_conform/models/validation_error.rb
107
140
  - lib/png_conform/models/validation_result.rb
141
+ - lib/png_conform/pipelines/pipeline_result.rb
142
+ - lib/png_conform/pipelines/stages/analysis_stage.rb
143
+ - lib/png_conform/pipelines/stages/base_stage.rb
144
+ - lib/png_conform/pipelines/stages/chunk_validation_stage.rb
145
+ - lib/png_conform/pipelines/stages/sequence_validation_stage.rb
146
+ - lib/png_conform/pipelines/stages/signature_validation_stage.rb
147
+ - lib/png_conform/pipelines/validation_pipeline.rb
108
148
  - lib/png_conform/readers/full_load_reader.rb
109
149
  - lib/png_conform/readers/streaming_reader.rb
110
150
  - lib/png_conform/reporters/base_reporter.rb
@@ -119,15 +159,27 @@ files:
119
159
  - lib/png_conform/reporters/very_verbose_reporter.rb
120
160
  - lib/png_conform/reporters/visual_elements.rb
121
161
  - lib/png_conform/reporters/yaml_reporter.rb
162
+ - lib/png_conform/services/analysis_manager.rb
163
+ - lib/png_conform/services/chunk_processor.rb
164
+ - lib/png_conform/services/file_signature.rb
165
+ - lib/png_conform/services/file_strategy.rb
166
+ - lib/png_conform/services/lru_cache.rb
167
+ - lib/png_conform/services/parallel_validator.rb
122
168
  - lib/png_conform/services/profile_manager.rb
169
+ - lib/png_conform/services/result_builder.rb
170
+ - lib/png_conform/services/validation_cache.rb
171
+ - lib/png_conform/services/validation_orchestrator.rb
123
172
  - lib/png_conform/services/validation_service.rb
173
+ - lib/png_conform/services/validator_pool.rb
124
174
  - lib/png_conform/services/zlib_validator.rb
175
+ - lib/png_conform/utils/colorizer.rb
125
176
  - lib/png_conform/validators/ancillary/bkgd_validator.rb
126
177
  - lib/png_conform/validators/ancillary/chrm_validator.rb
127
178
  - lib/png_conform/validators/ancillary/cicp_validator.rb
128
179
  - lib/png_conform/validators/ancillary/gama_validator.rb
129
180
  - lib/png_conform/validators/ancillary/hist_validator.rb
130
181
  - lib/png_conform/validators/ancillary/iccp_validator.rb
182
+ - lib/png_conform/validators/ancillary/idot_validator.rb
131
183
  - lib/png_conform/validators/ancillary/itxt_validator.rb
132
184
  - lib/png_conform/validators/ancillary/mdcv_validator.rb
133
185
  - lib/png_conform/validators/ancillary/offs_validator.rb
@@ -170,6 +222,7 @@ files:
170
222
  - lib/png_conform/validators/mng/seek_validator.rb
171
223
  - lib/png_conform/validators/mng/show_validator.rb
172
224
  - lib/png_conform/validators/mng/term_validator.rb
225
+ - lib/png_conform/validators/streaming_idat_validator.rb
173
226
  - lib/png_conform/version.rb
174
227
  - png_conform.gemspec
175
228
  homepage: https://github.com/claricle/png_conform