mosaic jpegs w/ size a multiple of tile size w/o recompres

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

mosaic jpegs w/ size a multiple of tile size w/o recompres

Post by NicolasRobidoux »

Suppose that you have a collection of jpeg thumbails with fixed width and height, both of them an exact multiple of the tile size (8 if using -sampling-factor 1x1 and 16 if using -sampling-factor 2x2).

For example, a collection of 40x40 JPEG thumbnails done using -sampling-factor 1x1 (and somewhat low quality).

Is there an easy way to assemble them into a mosaic jpeg strip (vertical or horizontal) without decompression/recompression artifacts?

My understanding is that generically the individual thumbnails will be decompressed, assembled into a mosaic, and then recompressed, and this will introduce artifacts, even if the JPEG parameters are the same across the board.

What I want to do is exploit the fact that JPEG compression is done one tile at a time, so the result, in principle, should be the same if I assemble the mosaic "directly." I'm guessing it's not (but have not checked yet).

(I actually am assuming that the usual ways of assembling the mosaic would be lossy. Is IM smart enough to assemble losslessly without special handling in my special case? Of course, if you have dimensions VS JPEG tile mismatch, doing this losslessly is basically impossible within the JPEG framework.)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mosaic jpegs w/ size a multiple of tile size w/o recompr

Post by fmw42 »

As far as I know, IM will decompress and recompress. So you probably need to look for some other custom non-IM solution.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: mosaic jpegs w/ size a multiple of tile size w/o recompr

Post by anthony »

I would look at the source code of jpegtrans. Others have already figured out extracting and rearraging the JPEG tile cells. appropriately. I think they have also crop and insert type functions too.
If so you may be able just create a new large JPEG and insert the data into it ;-)
That is essentially how IM does append internally!

However be aware that while JPEG saves image data as YCrCb colorspace you may have to be sure all the other attributes are the same in between the two JPEG images.

Please let us know how you go, and if you publish a 'JPEG append' type program.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: mosaic jpegs w/ size a multiple of tile size w/o recompr

Post by NicolasRobidoux »

anthony wrote:I would look at the source code of jpegtrans. Others have already figured out extracting and rearraging the JPEG tile cells. appropriately. I think they have also crop and insert type functions too.
If so you may be able just create a new large JPEG and insert the data into it ;-)
...
Thank you Anthony (and Fred).

Without knowing the details, I figured that it would be likely that one have to do it like you describe.

Because the person I'm helping has the "pre-thumbnail/pre-resize" jpeg original images, it may just be simpler to preassemble "internally" in hdri mode and produce the jpeg mosaic strip at the very end (instead of storing the individual thumbnails to be mosaiced).

But if it's not practical for him to do what I just described, I'll let you know what we come up with.

Things are simpler for us than the more general situation you describe: We control how all the thumbnails are produced, they are all done exactly the same way (save for image content, of course), and we -strip after converting to sRGB.

FYI, we are constructing JPEG sprites, which I am not sure anybody has done before?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mosaic jpegs w/ size a multiple of tile size w/o recompr

Post by fmw42 »

perhaps save all the thumbnails as (lossless) png or tiff, then montage them or append them and save the result as jpg
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: mosaic jpegs w/ size a multiple of tile size w/o recompr

Post by NicolasRobidoux »

fmw42 wrote:perhaps save all the thumbnails as (lossless) png or tiff, then montage them or append them and save the result as jpg
I thought of this too.

It appears that we all agree on what to try.

Thank you Fred.
Post Reply