
Lossless flip/rotate
Moderators: XnTriq, helmut, xnview
-
- Posts: 39
- Joined: Mon May 21, 2007 10:29 pm
Lossless flip/rotate
Hi everyone, I apologise if these questions have been asked already but I couldn't find anything using search. I installed XnView MP yesterday and I was absolutely loving it until I ran into lossless transformation. So I'm wondering: Why can lossless transformation be turned off for rotate but not for flip? Why do lossless rotate and flip change the size of an image (eg: 1000x1000 becomes 992x1000)? Why is only the width affected? Not a lossless question, and I haven't tried all image filetypes, but why doesn't flip work for png or webp files? Thanks in advance for any help given 

-
- Moderator & Librarian
- Posts: 6183
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Lossless flip/rotate
Hi kiwichick (-:
Available commands in Tools → Settings… → Interface → ToolBar:
Could you please upload a sample?
You mean Tools → JPEG lossless transformations → Flip horizontal | Flip vertical?
Available commands in Tools → Settings… → Interface → ToolBar:
- Browse mode
- cmd_lhflip = Flip horizontal (JPEG lossless transformation)
- cmd_lvflip = Flip vertical (JPEG lossless transformation)
- View mode
- cmd_FlipM = Mirror [menu]
- cmd_FlipH = Horizontal
- cmd_FlipV = Vertical
- cmd_lhflip = Flip horizontal (JPEG lossless transformation)
- cmd_lvflip = Flip vertical (JPEG lossless transformation)
-
- Posts: 39
- Joined: Mon May 21, 2007 10:29 pm
Re: Lossless flip/rotate
Thanks for your reply, XnTriq.
* I was going to try adding custom buttons in Browse using the cmd_FlipH/cmd_FlipV commands but is that possible? When I add -- COMMAND -- and click Set command, all I get is a browse dialog to select a file. I can't see how to enter a command.
* Here you can see the difference before and after rotate. The same thing happens for flip.
* No, I don't because that option is greyed out for non-jpg files.
* In Browse, I have added the Flip horizontal and Flip vertical buttons to the toolbar but they don't appear to work for anything other than jpg files. I've tried png, webp, bmp, and ico. Here you can see for this png file the flip buttons are "active" but they don't work. (The rotate buttons do.) * In View, I didn't realise there were two different sets of flip buttons (as you indicated above, one for Browse and one for View) but both are available in the Interface / ToolBar / View mode options (is that a bug?). Here you can see both horizontal buttons. Initially, I had just added the same buttons as for Browse but they didn't work. I've now changed those to the other ones (Horizontal and Vertical) and they work.
* I was going to try adding custom buttons in Browse using the cmd_FlipH/cmd_FlipV commands but is that possible? When I add -- COMMAND -- and click Set command, all I get is a browse dialog to select a file. I can't see how to enter a command.
You do not have the required permissions to view the files attached to this post.
Last edited by kiwichick on Fri Oct 15, 2021 5:37 am, edited 1 time in total.
-
- Moderator & Librarian
- Posts: 6183
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Lossless flip/rotate
Is it possible to attach colorful-floral-pattern-seamless-background-vector-1815061.jpg (1000×1000 pixels) so I can do some tests?
You're right. I've since edited my previous post accordingly.
As you probably know, JPEG compression is lossy, and each time a JPEG image is re-saved, it is re-encoded. This process introduces further quality degradation known as “generation loss”. However…kiwichick wrote: ↑Thu Oct 07, 2021 10:22 pm* In Browse, I have added the Flip horizontal and Flip vertical buttons to the toolbar but they don't appear to work for anything other than jpg files. I've tried png, webp, bmp, and ico. Here you can see for this png file the flip buttons are "active" but they don't work. (The rotate buttons do.)
https://en.wikipedia.org/wiki/JPEG#Lossless_editing wrote:A number of alterations to a JPEG image can be performed losslessly (that is, without recompression and the associated quality loss) as long as the image size is a multiple of 1 MCU block (Minimum Coded Unit)
XnView MP's commands for “JPEG lossless transformations”:https://www.impulseadventure.com/photo/jpeg-minimum-coded-unit.html wrote:Every JPEG image is actually stored as a series of compressed image tiles that are usually only 8x8 pixels in size. The proper name for one of these tiles is the MCU or Minimum Coded Unit. When one refers to image blocking artifacts, they are really talking about visual discontinuities observed between one or more of these tiles. You can see the edges or boundaries of these tiles in JPEG images that have been compressed at a very low quality.
[…]
The Minimum Coded Unit size for JPEG images is usually 8x8, 16x8 or 16x16 pixels in size. The variations here (more specifically 16x8 and 16x16) are due to an optimization called chroma subsampling.
- cmd_lhflip = Flip horizontal
- cmd_lvflip = Flip horizontal
- cmd_lrotate90 = Rotate clockwise
- cmd_lrotate180 = Rotate 180°
- cmd_lrotate270 = Rotate counter clockwise
- cmd_lrotateExif = Rotate based on EXIF orientation field
- cmd_lresetExif = Reset EXIF orientation field
Activating Use lossless rotation (if possible) in Tools → Settings… → Browser → Misc. → Rotation should make the following commands lossless when used on JPEGs:
- Browse mode
- cmd_rotate180 = Rotate 180°
- View mode
- cmd_FlipH = Horizontal
- cmd_FlipV = Vertical
Related settings:
- Tools → Settings… → Browser → Misc. → Rotation
- Change EXIF orientation ONLY (if possible)
- Tools → Settings… → General → File operations
- Make backup for lossless flip/rotation
- Make backup for lossless crop
- Make backup for all other lossless operations
- Keep original date/time → Lossless transformations
-
- Posts: 39
- Joined: Mon May 21, 2007 10:29 pm
Re: Lossless flip/rotate
Thanks again, sorry for the delay in replying.
And could you please answer my question about if it's possible to use custom buttons with XnView commands? And if it is, how do I do that?
I've attached that image but I don't see how it will help. I've tried several images and the change in size has happened for every one of them. And I've just noticed the size change is from cropping the file not shrinking the file.Is it possible to attach colorful-floral-pattern-seamless-background-vector-1815061.jpg (1000×1000 pixels) so I can do some tests?
Yes, I understand JPEG compression is lossy. I've had to turn off "use lossless rotation (if possible)" to stop the size change happening. But it doesn't help the size change which still happens for flip. Why can't we turn off lossless flip?As you probably know, JPEG compression is lossy
I realise it's not a bug that they don't work on other image formats but why are the buttons active for other image formats? And that wasn't what I was referrring to when I asked if it was a bug. I was referrring to the fact that Flip Vertical/Flip Horizontal and Vertical/Horizontal were all available in View options. You've confirmed it's not a bug but it does have me asking why, then, aren't the Vertical/Horizontal buttons available in Browse options? How do I get Vertical/Horizontal flip for non-jpg files in Browse?So It's not a bug that they don't work on other image formats.
And could you please answer my question about if it's possible to use custom buttons with XnView commands? And if it is, how do I do that?
You do not have the required permissions to view the files attached to this post.
-
- Moderator & Librarian
- Posts: 6183
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Lossless flip/rotate
These questions have to be answered by Pierre, who is the (sole) developer of XnView. (I'm just a user.)kiwichick wrote: ↑Mon Oct 11, 2021 8:47 pmI realise it's not a bug that they don't work on other image formats but why are the buttons active for other image formats? And that wasn't what I was referrring to when I asked if it was a bug. I was referrring to the fact that Flip Vertical/Flip Horizontal and Vertical/Horizontal were all available in View options. You've confirmed it's not a bug but it does have me asking why, then, aren't the Vertical/Horizontal buttons available in Browse options? How do I get Vertical/Horizontal flip for non-jpg files in Browse?
Do these instructions work for you?
XnTriq wrote: ↑Tue Oct 14, 2014 2:45 am
- Click somewhere on the toolbar with the right mouse button and select Customize toolbar... in the context menu.
- Select a mode (Browse mode or View mode).
- Select -- COMMAND -- in the list on the left and add it to the list on the right by clicking on the ► button.
- Click on Set command... to specify an EXE/BAT file or an XBS script.
- Click on Set label... to define a tooltip.
- Click on the blank button to select an icon.
Mrakobes666 wrote: ↑Tue Aug 18, 2020 8:48 amyou can set an internal command, for example
cmd_googleMap
Chroma sub-sampling of seamless-colorful-floral-pattern-seamless-background-vector-1815061.jpg is 2x2,1x1,1x1, which means that the MCU size is 16×16 pixels. Because its dimensions (1000×1000 pixels) are not a multiple of 16, partial MCUs (i.e. non-transformable edge blocks) are discarded/trimmed/dropped by XnView when a lossless flip/mirror or rotate operation/transformation is executed (62×16=992):
- cmd_lhflip → 992×1000 pixels
- cmd_lvflip → 1000×992 pixels
https://www.jpegclub.org/jpegcrop/index.html wrote:Transform Trim Edges
Drop non-transformable edge blocks.
Here is what the IJG v9 usage.txt file says about this switch:
The transpose transformation has no restrictions regarding image dimensions. The other transformations operate rather oddly if the image dimensions are not a multiple of the iMCU size (usually 8 or 16 pixels), because they can only transform complete blocks of DCT coefficient data in the desired way.
jpegtran's default behavior when transforming an odd-size image is designed to preserve exact reversibility and mathematical consistency of the transformation set. As stated, transpose is able to flip the entire image area. Horizontal mirroring leaves any partial iMCU column at the right edge untouched, but is able to flip all rows of the image. Similarly, vertical mirroring leaves any partial iMCU row at the bottom edge untouched, but is able to flip all columns. The other transforms can be built up as sequences of transpose and flip operations; for consistency, their actions on edge pixels are defined to be the same as the end result of the corresponding transpose-and-flip sequence.
For practical use, you may prefer to discard any untransformable edge pixels rather than having a strange-looking strip along the right and/or bottom edges of a transformed image. To do this, add the -trim switch.
Obviously, a transformation with -trim is not reversible, so strictly speaking jpegtran with this switch is not lossless. Also, the expected mathematical equivalences between the transformations no longer hold. For example, "-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by "-rot 180 -trim" trims both edges.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 39
- Joined: Mon May 21, 2007 10:29 pm
Re: Lossless flip/rotate
Yes they do but as they say, and as I've already pointed out, I only get to select an EXE/BAT file or XBS script. How do I add an XnView command (eg: cmd_FlipH)?
The popup says it must be a multiple of 8, which 1000x1000 is. Thanks for the time you've taken to try and explain it all to me but I am now completely confused. I've never come across this with other image viewer I've used. They flip and rotate without any size change. I guess I'll just have to make sure I don't do any flipping or rotating if I'm going to continue using XnView. Your help is much appreciated.
But how? As I've already said I only get the option to select a file.
-
- Moderator & Librarian
- Posts: 6183
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Lossless flip/rotate
Causing confusion is the opposite of what I intended to achieve. Unfortunately, JPEG compression is a very complex subject

I've yet to see an ideal solution.
https://www.raymond.cc/blog/rotating-photos-or-pictures-in-windows-photo-viewer-causes-quality-loss/ wrote:If you’ve been a user of Windows XP, you might have encountered a scary warning informing you that “Because of the dimensions of this picture, rotating it might permanently reduce its quality. Rotating a picture automatically saves it using the original name”.
Basically it is telling you that rotating the picture will reduce the quality and overwrites the original file without creating a backup copy. Fortunately this warning message will not appear on all images except for some with certain dimensions. Rotating a JPG image without any quality loss is called lossless rotation and this feature is actually already supported since Windows XP, although there are many claims stating otherwise just because of the file size difference.
If you rotate an image with a dimension that can be perfectly divided by 8, then every pixel on the image will be preserved. However, rotating an image that is not an exact multiple of 8 will cause quality loss and this is when the Windows Fax and Picture Viewer will show the warning.
The correct popup message would be: “width and height must me a multiple of the MCU size”. The MCU size depends on the JPEG's chroma sub-sampling factor (Tools → Settings… → Formats → Write → JPEG):
- 8×8 pixels = 1x1,1x1,1x1 (best quality) = 4:4:4 = full horizontal resolution, full vertical resolution = no sub-sampling
- 16×8 pixels = 2x1,1x1,1x1 = 4:2:2 = ½ horizontal resolution, full vertical resolution
- 16×16 pixels = 2x2,1x1,1x1 (default) = 4:2:0 = ½ horizontal resolution, ½ vertical resolution
As far as I can tell, there's no way to add buttons for cmd_FlipH and/or cmd_FlipV to the toolbar of browse mode. I even tried to add these commands by creating a toolbar preset (foo.bar) with a text editor…
Code: Select all
[Browser]
cmd_flipM
cmd_flipH
cmd_flipV
cmd_lhflip
cmd_lvflip
[View]
cmd_flipM
cmd_flipH
cmd_flipV
cmd_lhflip
cmd_lvflip
Have you considered making a request in the “Suggestions” sub-forum?
If you turn off Use lossless rotation (if possible) in Tools → Settings… → Browser → Misc. → Rotation, images of any format – including “odd-sized” JPEGs – can be rotated mirrored with cmd_FlipH and cmd_FlipV in view mode without being trimmed.
-
- Posts: 39
- Joined: Mon May 21, 2007 10:29 pm
Re: Lossless flip/rotate
Thanks yet again, XnTriq
It's purely down to my lack of lossless knowledge.

Thanks, I realise that"Causing confusion is the opposite of what I intended to achieve."

I'm definitely going to do that. I just don't understand why it's not possible to use XnView commands for custom buttons. XnViewMP is supposed to be an improvement on XnView Classic so why would this awesome feature be removed?"Have you considered making a request in the “Suggestions” sub-forum?"
Yes I've previously mentioned I had done that. But it's disappointing that it's only for rotation and can't be turned off for flip as well."If you turn off Use lossless rotation"
Sorry, confusion again. Rotate using Flip commands???"rotated with cmd_FlipH and cmd_FlipV"

-
- Moderator & Librarian
- Posts: 6183
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Lossless flip/rotate
My bad! Corrected!
Thank you! We'll see what Pierre says.kiwichick wrote: ↑Thu Oct 14, 2021 11:36 pmI'm definitely going to do that.XnTriq wrote: ↑Wed Oct 13, 2021 2:00 amHave you considered making a request in the “Suggestions” sub-forum?
I'm sure Pierre will consider adding an option if you post another suggestion. Just remember: One request per topic helps him keep track.
- What's different in XnView MP [Full List]
- List of missing features (compared to XnView Classic)
- XnView Classic vs XnView MP
From “Custom Themes” (XnView Classic) for reference:
- Commands available in browse mode
- cmd_rotate90
- cmd_rotate180
- cmd_rotate270
- cmd_losslessM
- cmd_lrotate90
- cmd_lrotate180
- cmd_lrotate270
- cmd_lhflip
- cmd_lvflip
- cmd_lrotateExif
- cmd_lresetExif
- Commands missing in browse mode
- cmd_flipM
- cmd_flipH
- cmd_flipV