Jump to content

Feature Request: JPEG quality option to match original JPEG

Recommended Posts

I have read the discussion in the thread viewtopic.php?f=12&t=20431&p=100540&hilit=jpeg#p100540

and understand Rick Brewster's desire not to present an overly complicated quality options for saving JPEG images. However, I would like to suggest an option (a simple check box) to save an image using the same quality settings that were used in the JPEG file originally loaded into Paint.NET (assuming a JPEG was originally loaded). This would allow small edits to be made to a JPEG with minimal degradation without increasing the file size.

First, a little background. JPEG quality is actually determined by the Discrete Quantization Tables (DQTs) and optional subsampling factors for each color plane, where the RGB image in transformed into one intensity (Y) and two chrominance (Cr, Cb) planes before the operations involving the DQTs and subsampling are applied. Since each DQT is an 8 x 8 matrix, it is a rare person who can rattle off the exact DQTs that they want. Therefore, the Independent JPEG Group (IJG) came up with a simplified linear quality scale of 0-100 where each integer is mapped to a particular set of DQT tables and subsampling factors. This scheme is implemented by a number of free JPEG read/write utilities and is therefore very common. However, it does not necessarily give the best visual results; it is notable that no digicams nor any Photoshop JPEG image quality settings use this scheme. Thus, there is no JPEG quality setting on the 0-100 simplified scale that accurately reflects what was used to encode most images originally.

The upshot is that when a JPEG image originally created by a digicam, Photoshop, or various other programs is modified in Paint.NET, its quality will be degraded if it is saved at quality setting that results in a similar file size. One way around this problem, is to record the DQT and subsampling parameters from the JPEG when it is loaded and use the same exact DQT and subsampling values when resaving the image. A slight bit of numerical roundoff error is inevitable, but the damage is nearly minimized without excessive programming or undue complication of the user interface.

Alternatively, there is the optimal solution, but it requires quite a bit more programming. Understand that JPEG images are encoded in 8 x 8 pixel blocks (or 16 x 8, 8 x 16, 16 x 16 etc if subsampling is used). If a JPEG is resaved using the same DQT and subsampling values, the original discrete cosine transform (DCT) values can be imported from the original JPEG for the blocks which have not been altered, i.e. in which no pixel has been altered. Then the damage is both minimized and limited to the regions that are changed. Implementing this requires a detailed unpacking of the original JPEG, comparison of the original JPEG with the image to be saved, and more data manipulation at the DCT level. Though the result would be very nice, it is not simple (I have only seen one commercial Photoshop extension that claims to do it).

BTW, if you are truly curious about JPEG innards, you can grab a copy of JPEGsnoop at http://www.impulseadventure.com/photo/j ... ver=0.8.1a).

Link to comment
Share on other sites

What you're asking would basically require me to write a brand new JPEG codec from scratch, which would be a lot of work. As it is, I'm just using the built-in Windows GDI+ codec and it hardly takes any code on my part. Cool idea, but I'm not sure the benefit outweighs the cost, especially with respect to how much time I have in the first place. Maybe someone else can write up a plugin proof-of-concept, much like was done with the OptiPNG plugin.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html


Link to comment
Share on other sites

It is not as bad as writing your own codec. You can use the free Independent JPEG Group codec. It gives you access to the low level JPEG information. The latest version (6b), jpegsrc.v6b.tar.gz, can be downloaded at http://www.ijg.org/files/. Rather inconveniently, you need some sort of tool to unpack the Unix style gzipped TAR file, but 7zip (http://www.7-zip.org/) will do that for you without the hassle of installing all the Cygwin tools just to get gzip.exe and tar.exe.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...