djpeg -crop: Exit gracefully with non-PPM formats
... and document that only PPM/PGM output images are supported with the -crop option for the moment. I investigated the possibility of supporting -crop with -bmp, but even after resetting the buffer dimensions, I still kept getting virtual array access errors. It seems that doing this the "right way" would require creating a re-initialization function for each image format's destination manager. I'm disinclined to do that right now, given that this feature was Google's baby (developed as a prerequisite for including libjpeg-turbo in Android), and the -crop option in djpeg is intended only as an example of how to use the partial image decompression API. Real-world applications would need to handle this in their own destination managers. It would probably be possible to make this work with Targa by employing a similar hack to the one we used with PPM, but Targa isn't popular enough to bother. Fixes #185
This commit is contained in:
@@ -10,6 +10,10 @@ image planes and allocates memory for the image planes.
|
|||||||
2. Fixed an issue whereby the Java version of TJUnitTest would fail when
|
2. Fixed an issue whereby the Java version of TJUnitTest would fail when
|
||||||
testing BufferedImage encoding/decoding on big endian systems.
|
testing BufferedImage encoding/decoding on big endian systems.
|
||||||
|
|
||||||
|
3. djpeg will now exit gracefully if an output image format other than PPM/PGM
|
||||||
|
is selected along with the `-crop` option. That option does not currently work
|
||||||
|
with other output image formats.
|
||||||
|
|
||||||
|
|
||||||
1.5.2
|
1.5.2
|
||||||
=====
|
=====
|
||||||
|
|||||||
5
djpeg.1
5
djpeg.1
@@ -1,4 +1,4 @@
|
|||||||
.TH DJPEG 1 "18 March 2017"
|
.TH DJPEG 1 "8 November 2017"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
djpeg \- decompress a JPEG file to an image file
|
djpeg \- decompress a JPEG file to an image file
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
@@ -204,7 +204,8 @@ Decompress only a rectangular subregion of the image, starting at point X,Y
|
|||||||
with width W and height H. If necessary, X will be shifted left to the nearest
|
with width W and height H. If necessary, X will be shifted left to the nearest
|
||||||
iMCU boundary, and the width will be increased accordingly. Note that if
|
iMCU boundary, and the width will be increased accordingly. Note that if
|
||||||
decompression scaling is being used, then X, Y, W, and H are relative to the
|
decompression scaling is being used, then X, Y, W, and H are relative to the
|
||||||
scaled image dimensions.
|
scaled image dimensions. Currently this option only works with the
|
||||||
|
PBMPLUS (PPM/PGM) output format.
|
||||||
.TP
|
.TP
|
||||||
.B \-verbose
|
.B \-verbose
|
||||||
Enable debug printout. More
|
Enable debug printout. More
|
||||||
|
|||||||
5
djpeg.c
5
djpeg.c
@@ -5,7 +5,7 @@
|
|||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
* Modified 2013 by Guido Vollbeding.
|
* Modified 2013 by Guido Vollbeding.
|
||||||
* libjpeg-turbo Modifications:
|
* libjpeg-turbo Modifications:
|
||||||
* Copyright (C) 2010-2011, 2013-2016, D. R. Commander.
|
* Copyright (C) 2010-2011, 2013-2017, D. R. Commander.
|
||||||
* Copyright (C) 2015, Google, Inc.
|
* Copyright (C) 2015, Google, Inc.
|
||||||
* For conditions of distribution and use, see the accompanying README.ijg
|
* For conditions of distribution and use, see the accompanying README.ijg
|
||||||
* file.
|
* file.
|
||||||
@@ -173,6 +173,7 @@ usage (void)
|
|||||||
|
|
||||||
fprintf(stderr, " -skip Y0,Y1 Decompress all rows except those between Y0 and Y1 (inclusive)\n");
|
fprintf(stderr, " -skip Y0,Y1 Decompress all rows except those between Y0 and Y1 (inclusive)\n");
|
||||||
fprintf(stderr, " -crop WxH+X+Y Decompress only a rectangular subregion of the image\n");
|
fprintf(stderr, " -crop WxH+X+Y Decompress only a rectangular subregion of the image\n");
|
||||||
|
fprintf(stderr, " [requires PBMPLUS (PPM/PGM) output format]\n");
|
||||||
fprintf(stderr, " -verbose or -debug Emit debug output\n");
|
fprintf(stderr, " -verbose or -debug Emit debug output\n");
|
||||||
fprintf(stderr, " -version Print version information and exit\n");
|
fprintf(stderr, " -version Print version information and exit\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@@ -713,6 +714,8 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
jpeg_crop_scanline(&cinfo, &crop_x, &crop_width);
|
jpeg_crop_scanline(&cinfo, &crop_x, &crop_width);
|
||||||
|
if (requested_fmt != FMT_PPM)
|
||||||
|
ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
|
||||||
((ppm_dest_ptr) dest_mgr)->buffer_width = cinfo.output_width *
|
((ppm_dest_ptr) dest_mgr)->buffer_width = cinfo.output_width *
|
||||||
cinfo.out_color_components *
|
cinfo.out_color_components *
|
||||||
sizeof(JSAMPLE);
|
sizeof(JSAMPLE);
|
||||||
|
|||||||
Reference in New Issue
Block a user