Merging JPEGS without recompression

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
Post Reply
Squarefox
Competition winner
Posts: 117
Joined: Tue Aug 19, 2008 6:46 pm
Location: Delta quadrant, Borg nexus 0001
Contact:

Merging JPEGS without recompression

Post 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
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Merging JPEGS without recompression

Post 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)
"this is not the bottleneck you are looking for"
AReichl
Posts: 270
Joined: Wed Jul 13, 2011 2:34 pm

Re: Merging JPEGS without recompression

Post 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.
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Merging JPEGS without recompression

Post 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.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Merging JPEGS without recompression

Post 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 :)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Merging JPEGS without recompression

Post by Cube_ »

lossless jpegs are typically larger than an equivalent png, and you can't have alpha.
"this is not the bottleneck you are looking for"
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Merging JPEGS without recompression

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply