Save JPG At 'Original' Quality

Ideas for improvements and requests for new features in XnView Classic

Moderators: XnTriq, helmut, xnview

GHammer
Posts: 2
Joined: Thu Oct 19, 2006 1:21 pm

Save JPG At 'Original' Quality

Post by GHammer »

I'd like to see the ability to save JPGs at their original quality.
Something like:

Default JPEG Quality [ ] 0-100
[] Save at original quality if possible.

Original quality being whatever the JPG is at, like 97% or 52%
My camera varies between 92% and 98% when I resize the files, I just like to match.

For other items, I like to have a 'default' value.
Hope this makes sense.
User avatar
Troken
Posts: 698
Joined: Thu Feb 09, 2006 10:18 am
Location: Sweden

Post by Troken »

Is it possible? Is there any way to see what quality the JPG was saved with? I didn't think any information of saving was stored in a JPG.
ckit
XnThusiast
Posts: 2577
Joined: Tue Feb 17, 2004 1:11 am
Location: QLD, Australia

Post by ckit »

Based on my understanding it's best to save them as 90%-100% and as another filename each time that way quality loss is minimal.
AMD Ryzen 3 3300X 3.8Ghz, 16Gb DDR4, RX6600XT with Dell U2520D at 2560x1440@60Hz scaling 125%
Windows 11 Pro x64 23H2, Listary Pro, PowerToys and Wintoys
GHammer
Posts: 2
Joined: Thu Oct 19, 2006 1:21 pm

Post by GHammer »

I have used a few other tools that have the option, so there is a way to tell. If I look at the EXIF for images from my camera there is info there that I believe shows the quality.

Yes, saving at that quality range is fine. For files that are being converted to JPG, captures, etc I agree. For files that you can know the quality, save them at the original quality.

And sure, I don't wish to overwrite the original files.
User avatar
xnview
Author of XnView
Posts: 44589
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Post by xnview »

Troken wrote:Is it possible? Is there any way to see what quality the JPG was saved with? I didn't think any information of saving was stored in a JPG.
No, this info is not stored in jpg; so we must try to compute it...
Pierre.
User avatar
XnTriq
Moderator & Librarian
Posts: 6375
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Post by XnTriq »

Troken wrote:Is it possible? Is there any way to see what quality the JPG was saved with?
  • photo.net
    • Jpeg Compression Introduction » Jpegdump
      A utility written by Allan Hessenflow (with modifications by Tom Lane) allows examination of actual Jpeg data. It has outputs that estimate the IJG quality settings for any given Jpeg. When used together with an IJG compression utility this allows almost exact recreation of a Jpeg. The only versions of this utility that I know of are source code and command line executables, so they are unlikely to be of direct use to the general public. It would be most useful for Jpeg writing software to list the prior quality level so you could rewrite (if necessary) at the same level.
  • Programmers Heaven
    • Dump JPEG marker information / Jpegdump.c
      Enclosed are C source code and a DOS executable for jpegdump, a JPEG file inspection program, which will print basic info about each file (image dimensions, quality setting, sampling ratios).
  • MediaChance
    • jpgQ – JPEG Quality Estimator
      What is the quality of JPEG already saved on disk? This small free software applet will estimate the quality of the JPG image. This is also the quality you should use if you load this image again in the photo editor (such Photobrush) and then re-save as JPG once again.
  • Pegasus Imaging
    • Compression / Recompression Optimization
      This feature uses advanced techniques to completely avoid generational loss caused by recompressing images. Unique technology minimizes JPEG artifacts by performing various image editing operations directly on compressed JPEG data without decompressing and recompressing files. This specific JPEG optimization does not uncompress then recompress to shrink JPEG files, as do all other so-called optimizer schemes. Recompress JPEG images with no additional loss than if you had started with the original image. Simply use the compression and editing features found in The JPEG Wizard and the compression utility found in the Online JPEG Wizard to see the results of Pegasus Imaging's research into this technology.
Once upon a time I had an ancient (stand-alone) version of Ulead SmartSaver on one of my older systems. If I remember it correctly, it was able to detect (or estimate) the original quality settings of a JPEG image:Can anybody confirm this :?:
User avatar
foxyshadis
Posts: 394
Joined: Sat Nov 18, 2006 8:57 am

Post by foxyshadis »

Hellllllla late, but I thought you guys (esp XnTriq) might be interested in this, since I wrote a jpeg parser a while back and have the information at hand.

IJG has a rather interesting way of computing the quality level, which is adding up parts of the quant table. Since almost no tool will use custom quant tables, sadly, let alone multiple tables in a single image, it works pretty well, and it's an easy way to map quality levels between apps.

Adobe's 0-12 scale mapped to Imagemagick's 0-100 scale:
78,81,86,89,90,91,92,91,92,93,95,97,99
(Between 5 and 6, chroma sampling goes from 2x2 to 1x1, thus the backtracking.)

The code ImageMagick uses to estimage the q level is in ImageMagick-6.3.0/coders/jpeg.c starting at line 835. All of this is very fast, almost instantaneous, unlike jpgQ. JpegSnoop is better.

Frankly, I'm no fan of IJG's and IM's linear quant scaling, since the best are crowded at the top and it's useless below 60, but it has its uses.

For optimization, a simple "jpegtran -o -progressive <old> <new>" will do it, by stripping out exif, thumbnails, and any other extra information. You can custom compile an arithmetic version for 10% higher compression, but thanks to an old ibm patent nothing really supports those. I once had the software for that, but can't seem to find it now. (Once I figure out how to write xnview plugins, I might offer such a batch optimizer, if it isn't in xnview by then.)

Aaaanyway, the flip side is that not only does xnview have to use the same quant tables (which is very easy and doesn't need any of the above digression), it would also have to decide which blocks have been modified and recompress those, while storing the unmodified ones back to the new file unrecoded. This is because not only is there recompress error, but also a yuv->rgb->yuv conversion, which will trash lowlight areas nicely.

The best way I've seen to accomplish this is to keep a bitmap of "dirty" pixels, or just compare the final to the original, when saving, recompressing only those blocks that have changed pixels. Fortunately, jpeg is very amenable to this and doesn't really have inter-block dependencies.

I think it'd be neat to have in xnview, since it's a rare enough feature that it's still worth touting, especially for little edits like applying logos and datestamps. But its absense doesn't bother me much.
prof_unto
Posts: 3
Joined: Sat Nov 25, 2006 4:43 pm

Post by prof_unto »

Addition to XnTriq
Xat Image Optimizer able to read/guess(?) JPEG quality :wink:
Janis
Posts: 11
Joined: Thu Jun 18, 2009 5:36 pm

Re: Save JPG At 'Original' Quality

Post by Janis »

Hi!

I know that this feature already exists in XnView. However, I'm not sure why one would like to save an image in its original "quality". What benefit does that give?

As I understand it, resaving a JPG image will result in quality loss every time you do it, so even with 100% "quality" you won't get the same quality — quality as a person who's looking at the image sees it — as in the original image.

So you are left to choose a "quality" based on what image size vs quality you'd like to get. The original "quality" in this context seems to me like some random parameter (named "quality" — that's why I put it in quotes) in the JPEG compression algorithm. A relative quality maybe.
obelisk
Posts: 467
Joined: Fri Jan 09, 2009 9:54 am

Re: Save JPG At 'Original' Quality

Post by obelisk »

I agree. Interesting, but time can be better spent on other bug/features
User avatar
Drahken
Posts: 884
Joined: Sun Apr 10, 2005 4:29 pm

Re: Save JPG At 'Original' Quality

Post by Drahken »

1) Saving at the truly original quality would result in a higher quality file (not higher quality than the original of course, but higher quality than any other option). Saving a jpg at a quality different than the original will force it to be re-encoded, thus dramactically reducing it's quality. This even applies if you save the image at a higher quality setting than the original (it's counterintuitive, but using a higher quality setting will actually produce an image of lower quality than the original, just like using a lower setting would). If you can save it again with the exact same settings as originally used, then any impact on quality will be minimal.


...However, there is no accurate way to determine exactly what settings were originally used, so the above point is rendered moot.


2) Saving at estimated original quality allows you to use a minimum ammount of space for the image, yet still retain as much quality as possible. Without it you would have to just take a guess at the quality & wind up either consuming more disc space than you need to, or reducing the image's quality more than you need to.
Oh the feuhrer, oh the feuhrer, oh the feuhrer's nipples bonk!
User avatar
XnTriq
Moderator & Librarian
Posts: 6375
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Save JPG At 'Original' Quality

Post by XnTriq »

Sample: test.jpeg
  • Image Image
    Cerious ThumbsPlus & Ulead SmartSaver
  • Image Image
    XAT Image Optimizer & MediaChance JpgQ Estimator
  • Code: Select all

    *** Marker: DQT (xFFDB) ***
      Define a Quantization Table.
      OFFSET: 0x00002895
      Table length = 132
      ----
      Precision=8 bits
      Destination ID=0 (Luminance)
        DQT, Row #0:  20  17  26  41  51  39  34  17 
        DQT, Row #1:  17  18  24  39  28  23  12  12 
        DQT, Row #2:  26  24  32  28  23  12  12  12 
        DQT, Row #3:  41  39  28  23  12  12  12  12 
        DQT, Row #4:  51  28  23  12  12  12  12  12 
        DQT, Row #5:  39  23  12  12  12  12  12  12 
        DQT, Row #6:  34  12  12  12  12  12  12  12 
        DQT, Row #7:  17  12  12  12  12  12  12  12 
        Approx quality factor = 62.50 (scaling=75.01 variance=6735.90)
      ----
      Precision=8 bits
      Destination ID=1 (Chrominance)
        DQT, Row #0:  21  26  33  34  20  20  17  17 
        DQT, Row #1:  26  29  24  14  14  12  12  12 
        DQT, Row #2:  33  24  14  14  12  12  12  12 
        DQT, Row #3:  34  14  14  12  12  12  12  12 
        DQT, Row #4:  20  14  12  12  12  12  12  12 
        DQT, Row #5:  20  12  12  12  12  12  12  12 
        DQT, Row #6:  17  12  12  12  12  12  12  12 
        DQT, Row #7:  17  12  12  12  12  12  12  12 
        Approx quality factor = 85.15 (scaling=29.70 variance=1496.54)
    JPEGsnoop
  • Code: Select all

    X:\TEST~1.JPE:
      Approximate quality factor for qtable 0: 62 (scale 75.01, var 6735.90)
      Approximate quality factor for qtable 1: 85 (scale 29.70, var 1496.54)
      width 636, height 477  components 3
        id 1 horizontal sampling 2, vertical sampling 2, quantization table 0
        id 2 horizontal sampling 1, vertical sampling 1, quantization table 1
        id 3 horizontal sampling 1, vertical sampling 1, quantization table 1
    jpegdump
User avatar
CreativeWorld
Posts: 141
Joined: Fri Dec 30, 2011 7:08 pm

Re: Save JPG At 'Original' Quality

Post by CreativeWorld »

Could you add JPEG quality estimation to the classic version too? :|
User avatar
oops66
XnThusiast
Posts: 2005
Joined: Tue Jul 17, 2007 1:17 am
Location: France

Re: Save JPG At 'Original' Quality

Post by oops66 »

Hello,
FI: ... You can check the quality estimation with imagemagick too.

http://www.imagemagick.org/script/identify.php

Code: Select all

identify -verbose a.jpg | grep Quality
  Quality: 85
http://newsgroup.xnview.com/viewtopic.p ... 14#p111414
XnViewMP Linux X64 - Debian - X64
User avatar
Drahken
Posts: 884
Joined: Sun Apr 10, 2005 4:29 pm

Re: Save JPG At 'Original' Quality

Post by Drahken »

CreativeWorld wrote:Could you add JPEG quality estimation to the classic version too? :|
This already exists, it's in the dialog for the jpg settings (though not on the export dialog). You'll see a bunch of checkboxes for keeping various metadata, at the bottom of those is one for using estimated original quality.
Oh the feuhrer, oh the feuhrer, oh the feuhrer's nipples bonk!