   Ascertaining JPEG quality (with libjpeg)
  I'm wondering whether or not there is a way to figure out the quality setting with which a JPEG was encoded, such that the same setting can be used when writing images produced from it. Looking through the libjpeg headers it doesn't seem immediately obvious, if possible at all. Thanks, ~SPH   
  Not sure what you're trying to do... want to mention: JPEG is a lossy compression standard.  If you recompress a jpg with the same compression level as before, it's like compound interest - the compression artifacts get worse...-michael g.;  The closest you could come is reusing the quantization table from the original JPEG - the "quality" setting you see in some JPEG encoders is not a magic standard value, it's a program specific alias for whatever settings and optimizations it has available. Photoshop presents the user with a value from 1 to 100 for quality, another encoder might have "high, medium and low". These do not correspond to any standard. Instead these can be used to affect a varity of settings - thresholds (which can be simple pixel to pixel or complex area tracking) for adding corrections, preprocessing, and as mentioned the quantization table. There is a "reference" quantization table, but encoders are free to develop their own sets of tables: one table may represent "high" quality compression, while another might represent "low" quality.Of course Thr33d already covered the main point - even if you tried to "copy" the quality setting (which you can't, unless you think you can precisely emulate every major JPEG encoder on the market, then determine the encoder and settings used from the file to use it the same way it was before) you won't get the same image. Using "same" type of lossy compression on an already lossy compressed file will just make it more lossy. Go ahead, save an image as a JPEG (say Photoshop quality "60"). Now load the JPEG as a new file, and compress it again with the same setting. You'll notice more noise then before. Repeat the compression a third time - the noise is really getting noticable. Repeat as needed until the image is nothing but a big smudge.   ;  Wanted to also quickly mention - I toyed around with the idea of making a Jpeg editor which would allow you to directly edit the different values used for the quantilization tables, thus allowing you to make changes (even stuff such as chroma changes) and not have to re-quantalize the image - thus making sure you had the same quality as before.One would also be able to make changes to individual levels of information in the image - if a section didn't have detail in it, you couldn't really *add* detail, but you could always change or remove details!(Hmm... should do that, when I have time to code again)This is, of course, based off of the assumption that my understanding of Jpeg compression is correct: (someone correct me if I'm wrong)Jpeg data could be effectively viewed as quadtree-like layers of the wavelet data (not a filled quadtree, of course, but a quadtree or multiple layered grid structure)-Michael g.   