irfanview lossless jpg rotation

Discussion in 'Digital Photography' started by dohduhdah, Sep 24, 2006.

  1. dohduhdah

    dohduhdah Guest


    When I try to use irfanview to rotate jpg pics with lossless jpg
    operations, I notice that the filesize
    changes. When I do lossless rotations in ACDSee, I notice the filesize
    stays identical.
    Is there any way to rotate pics with irfanview that will yield an
    identical filesize for the rotated jpg?

    Greetings and thanks in advance for any feedback, Niek
    dohduhdah, Sep 24, 2006
    1. Advertisements

  2. dohduhdah

    Paul Lutus Guest

    By definition, rotated JPG files should not be the same size, except by pure
    chance. Because JPG is a lossy compression method, this should not be

    If a program emits a rotated JPG that is always the same size as the
    original, there is something wrong with the algorithm. The result should be
    larger or smaller, randomly, and only very rarely the exact same size.
    Paul Lutus, Sep 25, 2006
    1. Advertisements

  3. dohduhdah

    Don Wiss Guest

    Wrong. The thread is about lossless jpg rotation. The file is not
    decompressed and recompressed. It is rotated without changing the

    I just rotated a file 90 degrees losslessly in IrfanView. It went from
    636,930 bytes to 630,305 bytes. I rotated it back, going in 90 degree
    increments three times. Now it is 631,432, though it is the same
    orientation as it started.

    I just tried jpegcrop. It also rotates losslessly. I started with the
    orginal file again. To summarize:

    Original: 636,930 bytes
    180 flip: 636,982
    90 left: 635,768
    90 right: 635,726

    Don <> (e-mail link at home page bottom).
    Don Wiss, Sep 25, 2006
  4. dohduhdah

    sid derra Guest

    irfan might be able to shed some light on this...
    sid derra, Sep 25, 2006
  5. Is this a good program to use... i am just new to dig photography and i am
    jsut getting started on learning PhotoshopCS...

    tnx kk

    =>Kevin Kienlein - Entertainer/Inspirational Speaker
    =>Vernon, BC, Canada
    =>See my NEW WEBSITE
    =>Never give in, NEVER, NEVER, NEVER!
    =>Life is the Gig, THIS AIN'T NO REHEARSAL!
    =>Age 45/Tricuspid, Atresia, Atrial & Vent, Septal Defects.
    =>My Congenital Heart Defects
, Sep 25, 2006
  6. dohduhdah

    Ron Hunter Guest

    It is a great program for quick and easy display and minor editing of
    pictures. A free program that does everything this one does is a thing
    of beauty, and well worth the download. Compared with Photoshop CS, the
    editing ability is trivial, but you can load Irfanview, display a dozen
    pictures, edit and save one while Photoshop CS is still loading, at
    least on most computers.
    Ron Hunter, Sep 25, 2006
  7. dohduhdah

    Martin Brown Guest

    Tends to suggest ACDSee does it with a flag then. Lossless rotation of
    a JPEG should normally change the filesize very slightly. +- 0.1% or so
    would be typical.
    It is losslessly decompressed into the JPEG coefficient space,
    transposed to change the real space orientation of the image and then
    losslessly recompressed. At no point in this process do the lossy steps
    of cosine tranform or quantisation occur. It is truly lossless.

    The reordering of the coefficients means that it is most unlikely that
    a losslessly rotated image will have exactly the same size as the

    However due to quirks in some decoders handling of 2x1 vs 1x2 chroma
    subsampling it is possible that lossless rotate JPEG image +90 subtract
    rotate BMP image +90 is not identically zero. This does not mean that
    the JPEG rotation failed. If you losslessly rotate the JPEG back to its
    original state the decoding will be identical.
    Reordering the sequence of coefficients in a block changes their
    compressibilty slightly. However the size difference in all but the
    most pathological of test cases is miniscule.

    Martin Brown
    Martin Brown, Sep 25, 2006
  8. dohduhdah

    John Bean Guest

    Was the EXIF (and other metadata) intact after the rotation?
    John Bean, Sep 25, 2006
  9. When I try to use irfanview to rotate jpg pics with lossless jpg
    Why worry that the file size has changed? If you just want an explanation,
    how about this one...

    A jpeg file contains a lot more than just the jpeg image data. There is a
    whole load of header stuff (eg. EXIF headers) and the spec is such that it
    gives application software a huge amount of leeway in how it lays it out.
    There are even opportunities for software to add history information (eg.
    the fact that it _was_ rotated).

    Just to take a specific example, I discovered that the firmware in my first
    camera layed out the header information in a very inefficient manner. It
    looks like the main reason was to ensure that specific items always ended up
    at fixed offsets within the file. I guess the firmware writers used this
    "bodge" to reduce the size, or increase the speed, of the firmware
    algorithms in the camera. I discovered that simply opening the photo in my
    own photo application and rewriting it _without_ resampling the image (ie. a
    lossless rewrite) saved me hundreds of bytes on every image.

    I would expect the actual compressed image data for a lossless rotation
    would probably be identical in size to the original (I'm not sure if there
    could be a small difference if the width and/or height was not a multiple of
    8 pixels but the difference, if any, would be trivial). However the
    lossless rotation program has two options. It could take the original file
    and "patch" the new image data over the original - making no change to the
    headers other than to change the image dimensions. Just as legitimately,
    though, it could read in and process all the header information and write a
    new jpeg, using its own personal preferences as to how to lay out the header
    information, and produce a file of a different size.

    The point is that it really doesn't matter. Provided your application does
    what it says on the tin and does a true lossless rotation, and assuming that
    the application isn't so dumb as to lose header fields, who cares if the
    file size is a few bytes different from what you started with? Has the
    quality of the picture deteriorated? Have any header fields been lost? Are
    the files now so huge that they fill your disk when they didn't before?

    Provided you can record a "no" against all of those, I would just stop
    worrying about it but if you cannot do that, just send me a before and after
    image and I'll run it through my application's image analyser and tell you
    where the extra data went or came from.

    Keith Sheppard, Sep 25, 2006
  10. dohduhdah

    Bruce Uttley Guest

    One of the lossless transformation options in irfanview is
    "None (can be used for optimizing and cleaning)". All lossless
    rotations in irfanview 'optimize' and 'clean' the resulting file.
    The resulting image is not degraded in any way.
    Bruce Uttley, Sep 25, 2006
  11. dohduhdah

    Paul Lutus Guest

    The thread is based on a misconception. There is no such thing as lossless
    JPEG rotation.
    That isn't possible. JPEG doesn't work this way. In order for a JPEG file to
    be rotated, it must first be decompressed into an RGB form, rotated, then
    No, you did not.
    I originally said there was a random relationship between starting and
    ending file sizes. So, Q.E.D.
    JPEG is a lossy compresion method. Please stop referring to it as
    "lossless". Each decompression/recompression cycle can and normally does
    degrade the original image content.
    As expected. These numbers tell us nothing about the state of the image
    itself, all they do is show that the numbers vary randomly.
    Paul Lutus, Sep 25, 2006
  12. dohduhdah

    Bill Tuthill Guest

    You do not understand JPEG encoding. Lossless rotation is possible
    in 90 degree increments because the DCT-encoded 8x8 blocks are turned
    on their side, but their quantization tables remain the same.

    What really destroys JPEG quality is when the 8x8 blocks are recoded,
    especially at different Q-values or with altered chroma subsampling.
    As the JPEG FAQ says, increasing lossiness is worse at high Q values
    but (counterintuitively) not so bad at low Q values.

    That can probably be explained by size-reduction of header information,
    or possibly more efficient encoding. Also, quantization tables might
    occupy more or less space depending on landscape/portrait orientation.
    The loss has already occurred, but rotation incurs no additional loss,
    so perhaps it should be called loss-constant rotation.
    Bill Tuthill, Sep 25, 2006
  13. dohduhdah

    Don Wiss Guest

    Yes. When losslessly rotating in either IrfanView or jpegcrop the EXIF
    remains intact. Also when cropping losslessly in jpegcrop (only on 8 bit
    increments) it also remains intact.

    Both also preserve the orginal time stamp.

    Don <> (e-mail link at home page bottom).
    Don Wiss, Sep 26, 2006
  14. dohduhdah

    Don Wiss Guest

    Now I see. The check box for Optimize is checked. If I uncheck it the size
    changes slightly, and the new sizes match what I posted for jpegcrop above.
    So jpegcrop doesn't optimize. This is fine, as I use IrfanView to rotate.
    And as you point out, I could use IrfanView to slightly reduce all of my

    Don <> (e-mail link at home page bottom).
    Don Wiss, Sep 26, 2006
  15. dohduhdah

    Ed Ruf Guest

    Why would one care to bother doing this? It would appear that for all
    but very specialized cases the file difference is in the noise of
    slack space..
    Ed Ruf Lifetime AMA# 344007 ()
    Ed Ruf, Sep 26, 2006
  16. Sure there is. More precisely, it is possible to rotate a JPEG image
    *without further loss* compared to the original JPEG. The JPEG is lossy
    compared to the original before compression, but the rotation does not
    change any of the image content, so the rotation is lossless.
    No, that's not true. It is possible to decompress the Huffman encoding,
    rotate the DCT coefficients in frequency space, and redo the Huffman
    encoding. All of these steps are lossless. The image is never
    decompressed fully to RGB form (an IDCT is never performed), nor is a
    DCT followed by coefficient quantization done.

    Not only is it theoretically possible, there are a number of real tools
    that do it routinely - including irfanview.

    (This only works because of a nice mathematical property of the DCT:
    when the image is rotated, the DCT rotates by the same amount in the
    same direction).

    The header information might have changed. Also, JPEG encoders can do
    the Huffman encoding using one pass (with a generic table) or two passes
    (with an optimized frequency table). The latter gives better
    compression than the former, but both are lossless. Any one application
    can use 1-pass, 2-pass, or give you a choice.
    The original compression step is lossless. But rotation can be done
    without further loss, as many times as you want.

    Dave Martindale, Sep 28, 2006
  17. dohduhdah

    Bill Tuthill Guest

    Well, if a person has a website with that allows 10 gigabits per month
    bandwidth, most of that being JPEG files, reducing all the image files
    by 10% would allow 10% more traffic without overage charge.
    Bill Tuthill, Sep 28, 2006
  18. dohduhdah

    Don Wiss Guest

    10 gigaBITs won't get you very far for anything. I'll assume you meant
    bytes. But if your pictures are popular, 10 GB won't get you very far
    either. Fortunately for $92.40/year I get 250 GB a month bandwidth. I
    usually run 45-55 GB, with a 94 GB month when the NY Times did an article
    on Brooklyn stores.

    I see it jumped up to 2.9 GB on Tuesday. Some forum or blog must be
    discussing Brooklyn stores.

    Don <> (e-mail link at page bottoms).
    Don Wiss, Sep 28, 2006
  19. SNIP of good info for brevity
    I believe you intended to say lossy.
    Small addition, in 90 degree multiples.
    Bart van der Wolf, Sep 28, 2006
  20. Yes indeed. I finished that posting in a hurry.
    Right. You can do vertical and horizontal mirroring too.

    Dave Martindale, Sep 28, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.