You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use decoded quantization tables for Jpeg encoding, store them in JpegMetadata #1705
Deducting quality twice as current code does not differ 2+ DQT markers
Proposal
Save decoded jpeg quantization tables to the jpeg metadata and use it as backup in the encoder:
// somewhere in the jpeg encoder// always prefer explicit qualityif(options.Quality!=null){returnGetStandardQuantizationTablesFromQuality(options.Quality);}if(metadata.UsesStandardQuantizationTables){returnGetStandardQuantizationTablesFromQuality(metadata.Quality);}returnmetadata.QuantizationTables;
changed the title [-]Jpeg default encoder (drastically) alters re-encoded image quality[/-][+]Use decoded quantization tables for Jpeg encoding, store them in JpegMetadata[/+]on Jul 17, 2021
Wouldn't more accurate evaluation negate the need to carry the tables?
You also need accurate quality evaluation in order to use the tables since you have to unscale these tables before copying to reuse in the encoder so that the user can re-encode them at a different quality.
Any quality-evaluation algorithm is just an approximation built around standard table from ITU specification (I didn't check JPEGsnoop implementation). Extacting quality from non-standard table and then rescaling non-standard matrix would introduce a lot of errors like in the example above.
Main idea of this proposal is to carry the tables if we don't want to alter 'quality' level. So we can potentially have 3 scenarios:
User provided 'quality' multiplier as encoder option - we must use it with standard table even if we had non-standard (this can have a discussion tbh)
Standard table - we only need to store the quality multiplier as scaling default matrix with it would result in the same result -> no space wasted for standard matrix case
Non-standard table - save table and estimate quality because we have it in the metadata (I would prefer to rename Quality to EstimatedQuality/ApproximateQuality marking Quality obsolete)
P.S.
Providing such API internally would bring the ability to alter tables on per-image/per-encoder basis but it's an another story.
Checked JPEGsnoop quality evaluation implementation - it's nice, really nice. I will port it and open a draft PR so we can discuss what to do with saving tables.
Activity
br3aker commentedon Jul 17, 2021
I'm already working on it, just need a confirmation on public API of
JpegMetadata.antonfirsov commentedon Jul 17, 2021
I like the proposal!
JimBobSquarePants commentedon Jul 17, 2021
We should probably have a look at how JPEGsnoop determines quality so ours are not so inaccurate.
br3aker commentedon Jul 17, 2021
@JimBobSquarePants better to do as a separate PR I guess so it won't be much of a clutter.
[-]Jpeg default encoder (drastically) alters re-encoded image quality[/-][+]Use decoded quantization tables for Jpeg encoding, store them in JpegMetadata[/+]JimBobSquarePants commentedon Jul 17, 2021
Wouldn't more accurate evaluation negate the need to carry the tables?
You also need accurate quality evaluation in order to use the tables since you have to unscale these tables before copying to reuse in the encoder so that the user can re-encode them at a different quality.
br3aker commentedon Jul 17, 2021
The main problem with 'quality' is that there's actually no 'quality' property of jpeg. Many professional cameras use custom tables:
https://www.impulseadventure.com/photo/jpeg-quantization.html
Any quality-evaluation algorithm is just an approximation built around standard table from ITU specification (I didn't check JPEGsnoop implementation). Extacting quality from non-standard table and then rescaling non-standard matrix would introduce a lot of errors like in the example above.
Main idea of this proposal is to carry the tables if we don't want to alter 'quality' level. So we can potentially have 3 scenarios:
QualitytoEstimatedQuality/ApproximateQualitymarkingQualityobsolete)P.S.
Providing such API internally would bring the ability to alter tables on per-image/per-encoder basis but it's an another story.
br3aker commentedon Jul 17, 2021
Checked JPEGsnoop quality evaluation implementation - it's nice, really nice. I will port it and open a draft PR so we can discuss what to do with saving tables.