Page 1 of 1

Merging JPEGS without recompression

Posted: Wed Apr 26, 2017 2:48 pm
by Squarefox
Hi all,

I am currently searching for a possibility to merge several jpegs into one jpeg.
For example: merging four 512x512 jpegs into one 1024x1024 jpeg.
I want to do this in code, since many images are affected.
The merging should be done losslessly, without decompression & compressing again.
I already searched in the internet, this should be possible, since jpeg is block-based.
Sadly I didn't found any code example about this.

Has anyone of you has some idea, where to get such an example?

Kind regards,
Squarefox

Re: Merging JPEGS without recompression

Posted: Wed Apr 26, 2017 5:59 pm
by devsh
use pngs

Re: Merging JPEGS without recompression

Posted: Wed Apr 26, 2017 8:38 pm
by Cube_
jpeg implies lossy compression, it's not a good format to use.
use png or tiff or any other more suitable format (ideally something using DXT compression)

Re: Merging JPEGS without recompression

Posted: Thu Apr 27, 2017 7:56 am
by AReichl
I have done jpeg saving without loss.
I used the FreeImage library and upon saving the parameter JPEG_SUBSAMPLING_444.
Probably this does not help you; i only mention it, because i was surprised myself that
is is possible with jpeg.

Re: Merging JPEGS without recompression

Posted: Thu Apr 27, 2017 12:28 pm
by MartinVee
Just my two cents ... JPEG-LS and JPEG-2000 formats support lossless compression. Like AReichl mentioned, FreeImage library can save in those formats.

Re: Merging JPEGS without recompression

Posted: Sat Apr 29, 2017 10:43 am
by Mel
The JPEG specification enforces that there should be a loss-less method for image compression, so JPEG is fine as long as you use the lossless setting. That aside, take a good look to the IImage objects, so you can learn how to copy data between software images, prior to converting them into hardware textures, or saving them to disk :)

Re: Merging JPEGS without recompression

Posted: Sat Apr 29, 2017 10:45 am
by Cube_
lossless jpegs are typically larger than an equivalent png, and you can't have alpha.

Re: Merging JPEGS without recompression

Posted: Sat Apr 29, 2017 2:21 pm
by CuteAlien
I think I get the idea. Jpg compression works with those 8x8 blocks so you should be able to merge compressed images without having to do any kind of de-compression/compression. But reading up on it a little - I think that's only for the compression part - the Huffman coding part seems to use all blocks. So I suspect you would have to that decoding/encoding part at least. And also adapt the meta-data (thought that's the more trivial part).
I haven't heard yet of a tool doing that. It would likely only work if both images used the exact same compression. I guess your best chance is to study libjpeg and see if it offers the functions you would need for this.