Lossless rotate question

Ask for help and post your question on how to use XnView Classic.

Moderators: XnTriq, xnview

drugo
Posts: 110
Joined: Wed Jun 02, 2010 6:23 am

Lossless rotate question

Post by drugo » Wed Sep 22, 2010 6:25 am

can i ask a question about Lossless rotate ?

does xnview store the rotate change in the exif only?

is this the meaning of Lossless rotate ?

thanks

User avatar
xnview
Author of XnView
Posts: 31738
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Lossless rotate question

Post by xnview » Wed Sep 22, 2010 7:49 am

In Options/Browser>Misc, you can choose if you want to change only the EXIF flag or make a lossless rotation
Pierre.

User avatar
Karl02
Posts: 134
Joined: Mon Sep 03, 2007 1:00 pm
Location: Germany

Re: Lossless rotate question

Post by Karl02 » Wed Sep 22, 2010 1:46 pm

The current options look like this (v1.97.8):

Code: Select all

[ ] Change EXIF orientation ONLY when possible (JPEG)
[ ] Use Lossless rotation when possible (JPEG)
This is unclear and misleading, because the change of the EXIF orientation tag is a special case of a lossless rotation and not independent. Therefore, the options should be displayed as follows:

Code: Select all

[ ] Use lossless rotation if possible (JPEG)
    [ ] Only change the EXIF orientation tag
If the lossless rotation is unchecked, the EXIF rotation option should be deactivated.
See also my post here from two and a half years ago: http://newsgroup.xnview.com/viewtopic.p ... 265#p58265
-- Karl

User avatar
xnview
Author of XnView
Posts: 31738
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Lossless rotate question

Post by xnview » Wed Sep 22, 2010 2:54 pm

No it's a different choice. You have lossless rotation (which change picture data), and EXIF orientation field
Pierre.

User avatar
Karl02
Posts: 134
Joined: Mon Sep 03, 2007 1:00 pm
Location: Germany

Re: Lossless rotate question

Post by Karl02 » Wed Sep 22, 2010 4:35 pm

The current display of the options is misleading. You cannot use them independently.
-- Karl

drugo
Posts: 110
Joined: Wed Jun 02, 2010 6:23 am

Re: Lossless rotate question

Post by drugo » Wed Sep 22, 2010 4:45 pm

xnview wrote:No it's a different choice. You have lossless rotation (which change picture data), and EXIF orientation field
but what 's the meaning of lossless ? is the meaning a little loss of image quality?

User avatar
JohnFredC
XnThusiast
Posts: 2010
Joined: Wed Mar 17, 2004 8:33 pm
Location: Sarasota Florida

Re: Lossless rotate question

Post by JohnFredC » Thu Sep 23, 2010 12:44 pm

Hi drugo...

Lossless rotation applies only to jpgs and other formats that use a "lossy" compression algorithm.

In order to reduce file size when saving the image to disk, the jpeg engine compresses the image data in a "lossy" manner... this means that the engine discards image information (either pixel position or color or both) in order to make the saved image file smaller. Conversely, when expanding the image out of the file to the display, the jpeg engine "estimates" the lost data and attempts to restore the image to as close to the original (in appearance) as it can. Naturally, since image data has been discarded, the original cannot never be completely restored.

The important thing to remember is that every time one loads a jpg and then saves it, more data is discarded. Eventually the loss of original image data becomes quite noticeable to the eye.

"Lossless rotation" attempts to avoid the loss of quality that happens when the file is saved (after the rotation has been applied). Lossless rotation takes into account mathematical characteristics of the jpeg compression to allow image rotation to occur "in place" (that is, without recompression) for images whose horizontal and vertical dimensions meet certain criteria.

So... use lossless rotation on jpgs.

I always recommend that one convert images from jpg to a lossless compression format (tiff, or png, or psd) before starting the editing/adjustment process. When the images have been rotated, corrected, or otherwise modified to the extent required, then (and only then) should the user convert them back to jpg for distribution as smaller files. (Lossless compression tends to make much large files than lossy compression does).

This topic has been discussed several times previously in the forum. It is actually more complicated than presented here, but you get the idea.
John

User avatar
Karl02
Posts: 134
Joined: Mon Sep 03, 2007 1:00 pm
Location: Germany

Re: Lossless rotate question

Post by Karl02 » Thu Sep 23, 2010 1:29 pm

Lossless means no loss of image quality. :o

There are two methods for lossless rotation of JPEG images:

1. Reorganising the JPEG blocks (and resetting the EXIF orientation tag to the default value "1" if necessary).
Drawback: Works only then really lossless if the image size is an integer multiple of the JPEG block size (usually 8 pixels; with color subsampling 16 pixels). Otherwise up to 15 pixels at the right or lower image border are cropped.

2. Only changing the EXIF orientation tag (see e.g. here: http://sylvana.net/jpegcrop/exif_orientation.html)
Drawback: Older software (and maybe poor current software) does not respect the EXIF orientation tag.

It is not possible to use both at the same time, so there should not be two îndependent options.

Actually there is no reason for not using method 1 if it's possible without cropping. The question is what to do if this method is not possible: Either ask the user what to do, use method 2, perform a lossy rotation with recompressing the image, or use method 1 anyway and allow some cropping.

So the option could look like this:

Code: Select all

Method for lossless JPEG rotation:
X JPEG block reorganisation
  If this method will crop the image:
  X Ask user what to do
  O Only change the EXIF orientation tag
  O Perform a lossy rotation with recompressing the image
  O Allow cropping of up to 15 pixels at the right and lower border
O Only change the EXIF orientation tag
-- Karl

drugo
Posts: 110
Joined: Wed Jun 02, 2010 6:23 am

Re: Lossless rotate question

Post by drugo » Thu Sep 23, 2010 6:18 pm

JohnFredC wrote:Hi drugo...

Lossless rotation applies only to jpgs and other formats that use a "lossy" compression algorithm.

In order to reduce file size when saving the image to disk, the jpeg engine compresses the image data in a "lossy" manner... this means that the engine discards image information (either pixel position or color or both) in order to make the saved image file smaller. Conversely, when expanding the image out of the file to the display, the jpeg engine "estimates" the lost data and attempts to restore the image to as close to the original (in appearance) as it can. Naturally, since image data has been discarded, the original cannot never be completely restored.

The important thing to remember is that every time one loads a jpg and then saves it, more data is discarded. Eventually the loss of original image data becomes quite noticeable to the eye.

"Lossless rotation" attempts to avoid the loss of quality that happens when the file is saved (after the rotation has been applied). Lossless rotation takes into account mathematical characteristics of the jpeg compression to allow image rotation to occur "in place" (that is, without recompression) for images whose horizontal and vertical dimensions meet certain criteria.

So... use lossless rotation on jpgs.

I always recommend that one convert images from jpg to a lossless compression format (tiff, or png, or psd) before starting the editing/adjustment process. When the images have been rotated, corrected, or otherwise modified to the extent required, then (and only then) should the user convert them back to jpg for distribution as smaller files. (Lossless compression tends to make much large files than lossy compression does).

This topic has been discussed several times previously in the forum. It is actually more complicated than presented here, but you get the idea.
thank you so much

drugo
Posts: 110
Joined: Wed Jun 02, 2010 6:23 am

Re: Lossless rotate question

Post by drugo » Thu Sep 23, 2010 6:19 pm

Karl02 wrote:Lossless means no loss of image quality. :o

There are two methods for lossless rotation of JPEG images:

1. Reorganising the JPEG blocks (and resetting the EXIF orientation tag to the default value "1" if necessary).
Drawback: Works only then really lossless if the image size is an integer multiple of the JPEG block size (usually 8 pixels; with color subsampling 16 pixels). Otherwise up to 15 pixels at the right or lower image border are cropped.

2. Only changing the EXIF orientation tag (see e.g. here: http://sylvana.net/jpegcrop/exif_orientation.html)
Drawback: Older software (and maybe poor current software) does not respect the EXIF orientation tag.

It is not possible to use both at the same time, so there should not be two îndependent options.

Actually there is no reason for not using method 1 if it's possible without cropping. The question is what to do if this method is not possible: Either ask the user what to do, use method 2, perform a lossy rotation with recompressing the image, or use method 1 anyway and allow some cropping.

So the option could look like this:

Code: Select all

Method for lossless JPEG rotation:
X JPEG block reorganisation
  If this method will crop the image:
  X Ask user what to do
  O Only change the EXIF orientation tag
  O Perform a lossy rotation with recompressing the image
  O Allow cropping of up to 15 pixels at the right and lower border
O Only change the EXIF orientation tag
thanks a lot

drugo
Posts: 110
Joined: Wed Jun 02, 2010 6:23 am

Re: Lossless rotate question

Post by drugo » Mon Oct 21, 2013 5:22 pm

may i ask a question ?
but this feature in the screeshot is Lossless ?
Image

drugo
Posts: 110
Joined: Wed Jun 02, 2010 6:23 am

Re: Lossless rotate question

Post by drugo » Mon Oct 21, 2013 5:26 pm

JohnFredC wrote:Hi drugo...

Lossless rotation applies only to jpgs and other formats that use a "lossy" compression algorithm.
.
but the author of the program said
No it's a different choice. You have lossless rotation (which change picture data), and EXIF orientation field
do i miss something?

thanks

User avatar
Karl02
Posts: 134
Joined: Mon Sep 03, 2007 1:00 pm
Location: Germany

Re: Lossless rotate question

Post by Karl02 » Mon May 25, 2015 6:51 pm

No change in XnView v2.32 (2015-03-16). :(

The options are displayed under Browser > Misc. > Rotation as follows:

Code: Select all

[ ] Keep original date/time attributes
[ ] Change EXIF orientation ONLY when possible (JPEG)
[ ] Use Lossless rotation when possible (JPEG)
They refer to the saving of rotated JPEG images. So they would better fit under General > Read/Write > JPEG > Rotation as follows (default):

Code: Select all

Method for lossless JPEG rotation:
(*) Only change existing or add new EXIF orientation tag
( ) JPEG block transformation
      If not all JPEG blocks are transformable:
      ( ) Allow cropping of up to 15 pixels at the right and/or 
          lower border of the original image
      ( ) Keep all pixels of the original image
      ( ) Only change existing or add new EXIF orientation tag
      ( ) Perform a lossy rotation with recompressing the image
      (*) Ask user what to do
[X] Set EXIF orientation tag to "1" after JPEG block transformation  
[X] Create backup file
[ ] Keep original file modification date/time
These options should also be shown in the JPEG Lossless Transformations dialog window (directly or after clicking an "Options" button). See the following picture:
xnview_2.32_JPEG_Lossless_Transformations.png
xnview_2.32_JPEG_Lossless_Transformations.png (8.55 KiB) Viewed 2734 times
There should be an additional option:
[ ] Save current settings as defaults

Perhaps there could also be a preview window to see how the image will look after the transformation.

Here is a demo program for lossless JPEG rotate and crop: http://sylvana.net/jpegcrop/
Last edited by Karl02 on Tue Jun 23, 2015 2:36 pm, edited 1 time in total.
-- Karl

User avatar
Karl02
Posts: 134
Joined: Mon Sep 03, 2007 1:00 pm
Location: Germany

Re: Lossless rotate question

Post by Karl02 » Tue Jun 09, 2015 2:55 pm

I've created a new set of testimages for testing the lossless JPEG rotation.

Preview:
exif-orientation-testimages-v2_in_XnView_v2.32.png
Specifications:
- colored borders with a width of 22 pixels
- JPEG block size is 16 pixels for chrominance (color subsampling 4:2:0)
- width and height are different and not a multiple of the JPEG block size (239 x 255 for normal orientation)
- JPEG optimized and progressive
- embedded thumbnails
- 4 different EXIF dates with different seconds:
-- 01) 0x9003 DateTimeOriginal
-- 02) 0x9004 DateTimeDigitized (CreateDate in ExifTool)
-- 03) 0x0132 ModifyDate for main image
-- 04) 0x0132 ModifyDate for thumbnail image

Download:
exif-orientation-testimages-v2.rar
(49.57 KiB) Downloaded 115 times
Test in jpegcrop:
jpegcrop_v2013-12_rotate.png
-- Karl

User avatar
Karl02
Posts: 134
Joined: Mon Sep 03, 2007 1:00 pm
Location: Germany

Re: Lossless rotate question

Post by Karl02 » Tue Jan 05, 2016 11:41 pm

Perhaps it would be easier to avoid separate lossy and lossless JPEG transformation functions and use general JPEG transformation functions that work according to the options.

The options for the saving of transformed JPEG images should be in "General > Read/Write > JPEG > Transformation" and look as follows (default):

Code: Select all

Method for JPEG transformations (rotate/flip):
(*) Only change existing or add new EXIF orientation tag
( ) JPEG block transformation
      If not all JPEG blocks are transformable:
      ( ) Allow cropping of up to 15 pixels at the right and/or 
          lower border of the original image
      ( ) Keep all pixels of the original image
      ( ) Only change existing or add new EXIF orientation tag
      ( ) Perform a lossy rotation with recompressing the image
      (*) Ask user what to do
[X] Set EXIF orientation tag to "1" after JPEG block transformation  
[X] Create backup file
[ ] Keep original file modification date/time
-- Karl

Post Reply