New (08-Feb-2005):
An article about the jpegtran lossless transformation functions has been published in the German c't magazine 4/2005 (released 07-Feb-2005), title "Fotoschoner", page 188 ff. The article derives and describes the lossless transformation functions in a clear and understandable form.
My draft of the article (in German) is available here:
Verlustfreie_JPEG_Drehung.doc or Verlustfreie_JPEG_Drehung.pdf .
Note that the draft is quite different from the published version, but the essence is the same.
An Exif Patch has been added to the lossless
transformation code to avoid some application problems.
It is part of the release-candidate croppatch to jpegtran (see below).
A new "-perfect" switch has recently been added to the lossless transformation support in jpegtran:
-perfect Fail if there is non-transformable edge blocks
Fails with an error if the transformation is not perfect.
For example you may want to do
jpegtran -rot 90 -perfect foo.jpg || djpeg foo.jpg | pnmflip -r90 | cjpeg
to do a perfect rotation if available or an approximated one if not.
/* 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
* (after reading source header):
* 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;
}
The new switch and function are part of the release-candidate croppatch to jpegtran
(see below).
-crop WxH+X+Y Crop to a rectangular subarea
Windows binary compilation: jpegtran.exe
or packed jpegtran.zip.| J | P | E | G |
| j | o | i | n |
-crop WxH+X+Y Crop to a rectangular subarea
-drop +X+Y filename Drop another image
Windows binary compilation: jpegtran.exe
or packed jpegtran.zip.