feat!: lazy configuration for order-independent API#51
Open
lilith wants to merge 1 commit intoImageOptim:mainfrom
Open
feat!: lazy configuration for order-independent API#51lilith wants to merge 1 commit intoImageOptim:mainfrom
lilith wants to merge 1 commit intoImageOptim:mainfrom
Conversation
f17dc48 to e6af6ef Compare All setter methods now store to a pending configuration that is applied at start_compress() time in the correct order. This fixes configuration ordering bugs where set_scan_optimization_mode() and set_fastest_defaults() would reset other settings via internal jpeg_set_defaults() calls. New APIs: - mutate_components_last() - modify components via callback - mutate_cinfo_last() - access raw cinfo via callback - set_quality_force_8bit() - quality with 8-bit quantization control - write_scanlines_strided() - scanlines with custom stride Deprecated: components_mut(), cinfo_mut() (still functional) Validation in start_compress() returns io::Error for zero dims, oversized dims, and invalid sampling factors.
e6af6ef to ebca5b8 Compare This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PendingConfigapplied atstart_compress()time in the correct orderset_scan_optimization_mode()andset_fastest_defaults()silently reset other settings via internaljpeg_set_defaults()callsNew APIs
mutate_components_last()- modify components via a callback that runs after all other configmutate_cinfo_last()- access rawcinfovia a callback that runs after all other configset_force_8bit_quantization()- control 8-bit DQT clamping (applies to both quality and custom qtables)write_scanlines_strided()- write scanlines with custom stride for padded pixel datastart_compress()returnsio::Errorinstead of panicking for zero/oversized dimensions and invalid sampling factorsBreaking changes
components()andcinfo()now take&mut self(were&self) — they apply pending config before returning so callers always see current statecomponents_mut()→ deprecated, usemutate_components_last()cinfo_mut()→ deprecated, usemutate_cinfo_last()Both deprecated methods still work and emit deprecation warnings.
The Bug This Fixes
set_scan_optimization_mode(Auto)internally callsjpeg_simple_progression()which callsjpeg_set_defaults(), resetting quality, smoothing, subsampling, and more. Same forset_fastest_defaults().Test plan
cargo clippy --all-targets --all-features -- -D warningsclean