Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Digital Photography (http://www.velocityreviews.com/forums/f37-digital-photography.html)
-   -   lossless rotate of 4mp image- impossible? (http://www.velocityreviews.com/forums/t242072-lossless-rotate-of-4mp-image-impossible.html)

 B Young 08-26-2003 05:07 AM

lossless rotate of 4mp image- impossible?

The popular jpegtran library from the IJG is in use by many major
commerical applications. The general info that circulates says that a
JPEG can be losslessly rotated if both dimensions are divisible by 16.
No problem until the 4 megapixel cams came out. Mine produces
2274x1704. 1704 is NOT divisible by 16.

What does this imply? Lossless rotation is lost for 4mp images? Or,
are these apps shaving a few pixels (8, to be exact) off the width to
make it happen?

Thanks,
Brian

 Guido Vollbeding 08-26-2003 10:27 AM

Re: lossless rotate of 4mp image- impossible?

"Paul D. Sullivan" wrote:
>
> Doesn't Irfanview do that?

There are some more:

http://jpegclub.org/losslessapps.html

Regards
Guido

 B Young 08-26-2003 01:57 PM

Re: lossless rotate of 4mp image- impossible?

Excellent information! Thanks. I had originally coded around the
jpegtran library with the same "extra safe" restriction as Microsoft-
16x16. Now I think the safest thing for a person to do would be to
grab the subsampling of the image and make a determination if a
lossless rotation is possible or not instead of trying to use
primative calculations.

One issue, for example: If you rotate a 2274x1704 90 degrees, your
dimensions are obviously flipped. Simple logic that just checks if
the height is divisible by 8 will fail, prohibiting a user from
rotating the image again. In reality the image *can* be rotated
again, without loss.

Also, there is the issue of what jpegtran might do if you passed it an
image that wasn't in a 2x1 configuration. I haven't tested enough to

Thanks again
Brian

Guido Vollbeding <guido@jpegclub.org> wrote in message news:<3F4B122A.196ED143@jpegclub.org>...
> The condition for complete lossless rotation is that the dimension
> must be divisible by the *MCU* size (MCU = Minimal Coded Unit)!
> The MCU size is determined by the subsampling parameters of the
> JPEG image. Almost all digital cameras today use a subsampling
> configuration of 2x1 (horizontal only subsampling), giving an
> MCU size of 2x1 DCT blocks, or 16x8 pixels.

 Guido Vollbeding 08-26-2003 05:27 PM

Re: lossless rotate of 4mp image- impossible?

B Young wrote:
>
> Excellent information! Thanks.

Well, I should know it since I wrote the original lossless rotation code :).

> I had originally coded around the
> jpegtran library with the same "extra safe" restriction as Microsoft-
> 16x16. Now I think the safest thing for a person to do would be to
> grab the subsampling of the image and make a determination if a
> lossless rotation is possible or not instead of trying to use
> primative calculations.

I have a patch for jpegtran in the pipeline which provides exactly that.
It adds a "-perfect" option to the program which uses following new

/* jtransform_perfect_transform
*
* Determine whether lossless transformation is perfectly
* possible for a specified image and transformation.
*
* Inputs:
* image_width, image_height: source image dimensions.
* MCU_width, MCU_height: pixel dimensions of MCU.
* transform: transformation identifier.
* Parameter sources from initialized jpeg_struct
* image_width = cinfo.image_width
* image_height = cinfo.image_height
* MCU_width = cinfo.max_h_samp_factor * DCTSIZE
* MCU_height = cinfo.max_v_samp_factor * DCTSIZE
* Result:
* TRUE = perfect transformation possible
* FALSE = perfect transformation not possible
* (may use custom action then)
*/

GLOBAL(boolean)
jtransform_perfect_transform(JDIMENSION image_width, JDIMENSION image_height,
int MCU_width, int MCU_height,
JXFORM_CODE transform)
{
boolean result = TRUE; /* initialize TRUE */

switch (transform) {
case JXFORM_FLIP_H:
case JXFORM_ROT_270:
if (image_width % (JDIMENSION) MCU_width)
result = FALSE;
break;
case JXFORM_FLIP_V:
case JXFORM_ROT_90:
if (image_height % (JDIMENSION) MCU_height)
result = FALSE;
break;
case JXFORM_TRANSVERSE:
case JXFORM_ROT_180:
if (image_width % (JDIMENSION) MCU_width)
result = FALSE;
if (image_height % (JDIMENSION) MCU_height)
result = FALSE;
break;
}

return result;
}

> One issue, for example: If you rotate a 2274x1704 90 degrees, your
> dimensions are obviously flipped. Simple logic that just checks if
> the height is divisible by 8 will fail, prohibiting a user from
> rotating the image again. In reality the image *can* be rotated
> again, without loss.

The sampling setting then also flips, so all is well.
The above code handles all cases properly.

> Also, there is the issue of what jpegtran might do if you passed it an
> image that wasn't in a 2x1 configuration. I haven't tested enough to
> know the answer to that.

jpegtran works with *any* subsampling configuration. This feature was
the main challenge while writing the core transformation functions.

Regards
Guido

 Guido Vollbeding 08-26-2003 07:08 PM

Re: lossless rotate of 4mp image- impossible?

Mick Ruthven wrote:
>
> I'm confused by the following two statements. 2274 is not divisible by 16,
> so how can a 2274x1704 be losslessly rotated? I have a feeling I'm missing
> something.

Oops, a typo in the original post which propagated.
The 4MP image size is 2272x1704.

Regards
Guido

 Mick Ruthven 08-26-2003 07:14 PM

Re: lossless rotate of 4mp image- impossible?

Thanks. And I have a 4mp G2 and should have remembered 2272...

"Guido Vollbeding" <guido@jpegclub.org> wrote in message
news:3F4BB010.19AAFB1C@jpegclub.org...
> Mick Ruthven wrote:
> >
> > I'm confused by the following two statements. 2274 is not divisible by

16,
> > so how can a 2274x1704 be losslessly rotated? I have a feeling I'm

missing
> > something.

>
> Oops, a typo in the original post which propagated.
> The 4MP image size is 2272x1704.
>
> Regards
> Guido

 Robert Carter 08-27-2003 02:38 AM

Re: lossless rotate of 4mp image- impossible?

You have got me. Why not just save the original as a tif or psd and then rotate it or am I missing something here?

Guido Vollbeding <guido@jpegclub.org> wrote in message news:3F4B3600.924DD8C2@jpegclub.org...
"Paul D. Sullivan" wrote:
>
> Doesn't Irfanview do that?

There are some more:

http://jpegclub.org/losslessapps.html

Regards
Guido

 gsum 08-27-2003 06:50 AM

Re: lossless rotate of 4mp image- impossible?

I'm also confused. Rotation by 90 degrees or a
multiple of 90 simply results in a rearrangement
of data in the jpg (or tif etc.) file. There is no division
by 16 as the data itself is not altered. That is why
90 degree rotation is lossless and is much faster than
arbitrary rotation.

Graham

"Robert Carter" <retrack@idx.com.au> wrote in message news:3f4c1a6b@news1...
> You have got me. Why not just save the original as a tif or psd and then

rotate it or am I missing something here?
>
> Guido Vollbeding <guido@jpegclub.org> wrote in message

news:3F4B3600.924DD8C2@jpegclub.org...
> "Paul D. Sullivan" wrote:
> >
> > Doesn't Irfanview do that?

>
> There are some more:
>
> http://jpegclub.org/losslessapps.html
>
> Regards
> Guido
>
>

 Ed Ruf 08-27-2003 11:24 AM

Re: lossless rotate of 4mp image- impossible?

On Wed, 27 Aug 2003 12:38:28 +1000, in rec.photo.digital "Robert
Carter" <retrack@idx.com.au> wrote:

>You have got me. Why not just save the original as a tif or psd and then rotate it or am I missing something here?

The size of the file is much larger this way. Lossless rotation
provides a means of rotating the image and keeping it in jpg format
without the loss of any information contained in the original jpg in
the first place.
__________________________________________________ ______
Ed Ruf Lifetime AMA# 344007 (EGRuf@cox.net)
http://members.cox.net/egruf
See images taken with my CP-990 and 5700 at
http://members.cox.net/egruf-digicam

Re: lossless rotate of 4mp image- impossible?

I pondered over the same problem until a friend (mathematician, not
photographer) offered a solution:
first, resize your jpg picture to as large a format as your computer will
allow. save as bmp or tiff, rotate and do all your digital processing on
this huge file; what with modern pentium4s and fast ram, this is not nearly
as daunting as it sounds.
only when you're done and have the final picture, resize and reconvert to
I followed this advice although it made me work with a 220Mb file, and was
amazed at the results.
question remains: can you afford the time and computing power involved?

--
pary@netvision.net.il

All times are GMT. The time now is 03:34 AM.