Author Topic: Transcoding of JPEGs during "Save as"  (Read 3534 times)

Offline rjp

  • Member
  • **
  • Posts: 93
    • View Profile
Transcoding of JPEGs during "Save as"
« on: April 09, 2009, 03:05:28 PM »
When RAW Apple's rendering is disabled my understanding is that the "Save As JPEG" option will decode the embedded JPEG preview in a RAW file and then re-encode it at the quality level set by the slider.

It appears this can actually lead to an increase in file size in cases where the original JPEG is a basic quality preview and the PM quality slider is in the middle or upper end. Since the quality can never be increased in this conversion the new larger size is a waste of bits and misleading because it's file size may lead people to think it is a high quality image.

Is there a way to avoid this; that is, to make sure the new JPEG never exceeds the size of the original.

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24764
    • View Profile
    • Camera Bits, Inc.
Re: Transcoding of JPEGs during "Save as"
« Reply #1 on: April 09, 2009, 03:21:49 PM »
When RAW Apple's rendering is disabled my understanding is that the "Save As JPEG" option will decode the embedded JPEG preview in a RAW file and then re-encode it at the quality level set by the slider.

It appears this can actually lead to an increase in file size in cases where the original JPEG is a basic quality preview and the PM quality slider is in the middle or upper end. Since the quality can never be increased in this conversion the new larger size is a waste of bits and misleading because it's file size may lead people to think it is a high quality image.

Is there a way to avoid this; that is, to make sure the new JPEG never exceeds the size of the original.

Sure.  You can instead use the Extract JPEG previews from RAW photos command on the Tools menu.  You will be getting the exact JPEG data (not re-encoded at all.)

-Kirk

Offline rjp

  • Member
  • **
  • Posts: 93
    • View Profile
Re: Transcoding of JPEGs during "Save as"
« Reply #2 on: April 09, 2009, 03:47:30 PM »
When RAW Apple's rendering is disabled my understanding is that the "Save As JPEG" option will decode the embedded JPEG preview in a RAW file and then re-encode it at the quality level set by the slider.

It appears this can actually lead to an increase in file size in cases where the original JPEG is a basic quality preview and the PM quality slider is in the middle or upper end. Since the quality can never be increased in this conversion the new larger size is a waste of bits and misleading because it's file size may lead people to think it is a high quality image.

Is there a way to avoid this; that is, to make sure the new JPEG never exceeds the size of the original.

Sure.  You can instead use the Extract JPEG previews from RAW photos command on the Tools menu.  You will be getting the exact JPEG data (not re-encoded at all.)

-Kirk


The Extract JPEG is a great feature, but my question is specifically about the "Save As JPEG" feature.

Here is an example of why I am interested in this.

Suppose you have a contact sheet full of NEF images, some of which you've edited in NX and some of which you have not. For a D40, Images that have been edited have roughly 4MG JPEGS in them and images that have not been edited have 600KB JPEGS in them. I'd like to be able to save all the JPEGS at about a 2 MB size, but I don't want to end up inflating the size of the little 600KB images. They should stay as they are. Sure I could select these separately and extract, but it would be nice to be able to apply a single operation to the whole sheet.

Does the JPEG encoding algorithm you use allow for a target size or max size? or is quality the only parameter you have to play with.



Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24764
    • View Profile
    • Camera Bits, Inc.
Re: Transcoding of JPEGs during "Save as"
« Reply #3 on: April 09, 2009, 03:53:03 PM »
When RAW Apple's rendering is disabled my understanding is that the "Save As JPEG" option will decode the embedded JPEG preview in a RAW file and then re-encode it at the quality level set by the slider.

It appears this can actually lead to an increase in file size in cases where the original JPEG is a basic quality preview and the PM quality slider is in the middle or upper end. Since the quality can never be increased in this conversion the new larger size is a waste of bits and misleading because it's file size may lead people to think it is a high quality image.

Is there a way to avoid this; that is, to make sure the new JPEG never exceeds the size of the original.

Sure.  You can instead use the Extract JPEG previews from RAW photos command on the Tools menu.  You will be getting the exact JPEG data (not re-encoded at all.)

-Kirk


The Extract JPEG is a great feature, but my question is specifically about the "Save As JPEG" feature.

Here is an example of why I am interested in this.

Suppose you have a contact sheet full of NEF images, some of which you've edited in NX and some of which you have not. For a D40, Images that have been edited have roughly 4MG JPEGS in them and images that have not been edited have 600KB JPEGS in them. I'd like to be able to save all the JPEGS at about a 2 MB size, but I don't want to end up inflating the size of the little 600KB images. They should stay as they are. Sure I could select these separately and extract, but it would be nice to be able to apply a single operation to the whole sheet.

Does the JPEG encoding algorithm you use allow for a target size or max size? or is quality the only parameter you have to play with.

No, there is only quality.

Let me explain how the process works internally.  First the image is decoded to a bitmap in memory.  At this point it is taking just as much space in memory for a very low quality JPEG as it would for a high quality JPEG.  Once decoded, quality doesn't matter to the size in memory as it is no longer compressed.  Then various operations are performed (Convert to sRGB, rotation, scaling, cropping, sharpening, etc.)  Finally the image in memory is encoded as a JPEG with the quality setting you chose.

The save code has no knowledge of the original JPEG size, or for that matter whether the image being saved was a JPEG at all.  It could have been a PSD, TIFF, PNG, etc. and not a JPEG at all.

I hope this explains things a bit better.

-Kirk

Offline rjp

  • Member
  • **
  • Posts: 93
    • View Profile
Re: Transcoding of JPEGs during "Save as"
« Reply #4 on: April 09, 2009, 03:59:35 PM »
When RAW Apple's rendering is disabled my understanding is that the "Save As JPEG" option will decode the embedded JPEG preview in a RAW file and then re-encode it at the quality level set by the slider.

It appears this can actually lead to an increase in file size in cases where the original JPEG is a basic quality preview and the PM quality slider is in the middle or upper end. Since the quality can never be increased in this conversion the new larger size is a waste of bits and misleading because it's file size may lead people to think it is a high quality image.

Is there a way to avoid this; that is, to make sure the new JPEG never exceeds the size of the original.

Sure.  You can instead use the Extract JPEG previews from RAW photos command on the Tools menu.  You will be getting the exact JPEG data (not re-encoded at all.)

-Kirk


The Extract JPEG is a great feature, but my question is specifically about the "Save As JPEG" feature.

Here is an example of why I am interested in this.

Suppose you have a contact sheet full of NEF images, some of which you've edited in NX and some of which you have not. For a D40, Images that have been edited have roughly 4MG JPEGS in them and images that have not been edited have 600KB JPEGS in them. I'd like to be able to save all the JPEGS at about a 2 MB size, but I don't want to end up inflating the size of the little 600KB images. They should stay as they are. Sure I could select these separately and extract, but it would be nice to be able to apply a single operation to the whole sheet.

Does the JPEG encoding algorithm you use allow for a target size or max size? or is quality the only parameter you have to play with.

No, there is only quality.

Let me explain how the process works internally.  First the image is decoded to a bitmap in memory.  At this point it is taking just as much space in memory for a very low quality JPEG as it would for a high quality JPEG.  Once decoded, quality doesn't matter to the size in memory as it is no longer compressed.  Then various operations are performed (Convert to sRGB, rotation, scaling, cropping, sharpening, etc.)  Finally the image in memory is encoded as a JPEG with the quality setting you chose.

The save code has no knowledge of the original JPEG size, or for that matter whether the image being saved was a JPEG at all.  It could have been a PSD, TIFF, PNG, etc. and not a JPEG at all.

I hope this explains things a bit better.

-Kirk


Thanks Kirk, that is really clear. It would be nice if the JPEG encode algorithm allowed for the setting of a target encoded size rather than just "quality", but I guess you have to work with what's available unless you write your own. I can see where specifying "quality", which probably translates into quantizer step size, would be faster than specifying a target size.


Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24764
    • View Profile
    • Camera Bits, Inc.
Re: Transcoding of JPEGs during "Save as"
« Reply #5 on: April 09, 2009, 04:12:58 PM »
When RAW Apple's rendering is disabled my understanding is that the "Save As JPEG" option will decode the embedded JPEG preview in a RAW file and then re-encode it at the quality level set by the slider.

It appears this can actually lead to an increase in file size in cases where the original JPEG is a basic quality preview and the PM quality slider is in the middle or upper end. Since the quality can never be increased in this conversion the new larger size is a waste of bits and misleading because it's file size may lead people to think it is a high quality image.

Is there a way to avoid this; that is, to make sure the new JPEG never exceeds the size of the original.

Sure.  You can instead use the Extract JPEG previews from RAW photos command on the Tools menu.  You will be getting the exact JPEG data (not re-encoded at all.)

-Kirk


The Extract JPEG is a great feature, but my question is specifically about the "Save As JPEG" feature.

Here is an example of why I am interested in this.

Suppose you have a contact sheet full of NEF images, some of which you've edited in NX and some of which you have not. For a D40, Images that have been edited have roughly 4MG JPEGS in them and images that have not been edited have 600KB JPEGS in them. I'd like to be able to save all the JPEGS at about a 2 MB size, but I don't want to end up inflating the size of the little 600KB images. They should stay as they are. Sure I could select these separately and extract, but it would be nice to be able to apply a single operation to the whole sheet.

Does the JPEG encoding algorithm you use allow for a target size or max size? or is quality the only parameter you have to play with.

No, there is only quality.

Let me explain how the process works internally.  First the image is decoded to a bitmap in memory.  At this point it is taking just as much space in memory for a very low quality JPEG as it would for a high quality JPEG.  Once decoded, quality doesn't matter to the size in memory as it is no longer compressed.  Then various operations are performed (Convert to sRGB, rotation, scaling, cropping, sharpening, etc.)  Finally the image in memory is encoded as a JPEG with the quality setting you chose.

The save code has no knowledge of the original JPEG size, or for that matter whether the image being saved was a JPEG at all.  It could have been a PSD, TIFF, PNG, etc. and not a JPEG at all.

I hope this explains things a bit better.

-Kirk


Thanks Kirk, that is really clear. It would be nice if the JPEG encode algorithm allowed for the setting of a target encoded size rather than just "quality", but I guess you have to work with what's available unless you write your own. I can see where specifying "quality", which probably translates into quantizer step size, would be faster than specifying a target size.

Yes, the only way to do it with libJPEG is to use a 'binary search' type of algorithm, adjusting the JPEG quality until the size fits the required parameters.  It is unfortunately fairly compute intensive.

-Kirk