I've successfully used jpegtran to combine JPEGs of the same size (512x512) using the method described in this stackoverflow answer: https://stackoverflow.com/a/29615714/2364680
These are tiled JPEGs from the internet that make a 360 panorama when combined. As I said, the 512x512 images combined perfectly with jpegtran; however, I realized that some of the tiles that make up the panorama are 256x256 and need to be doubled in size when combined with the other tiles in order to form the panorama (in the 2D form of an equirectangular projection).
Simply put, I need to know if jpegtran can losslessly combine two JPEGs of different sizes -- for instance, if I can losslessly double the resolution of a 256x256 tile and then combine it with another 512x512 tile.
I know this can be done through reencoding, but I'm asking if it can be done totally losslessly. Thanks.
Not currently, no. We'd need the following:
Here's what I came up with given that jpegtran's
-crop
,-scale
and-drop
operations cannot be combined:However, the last command fails with: "Bogus virtual array access" which is the string for
JERR_BAD_VIRTUAL_ACCESS
error thrown by jpeg-9e/jmemmgr.c line 857.It fails because
end_row > ptr->rows_in_array
where rows_in_array is 32 macroblocks and end_row reaches 33 macroblocks - the first macroblock row not present inupscale.jpg
jpegtran is expecting a 512x512 pixel image to be 64x64 macroblocks using the destination image macroblock size, so halfway through
upscale.jpg
it runs out of source macroblocks and walks off the end of the image. If we patched libjpeg to use the correct macroblock size, we'd need some way to encode into the file that the size of macroblocks has changed, but I'm not sure how that would be done.