Decoding a BIG Jpeg (Or part of it)

Sep 24, 2009 at 10:53 AM
Edited Sep 24, 2009 at 5:06 PM

Hi,

First of all I would like to congratulate you on this great piece of code. I've been looking for a source code for JPEG decoder for quite some time now.

I have a very big JPEG (30000x30000) that consist of many images, around 500 (Compressing a large image that is made up of small images is much smaller than compressing each image to a JPEG)

As you can imagine, opening such a file eats up allot of memory.

Is it possible to supply the coordinates and decode only part of the image? Although the JPEG is very BIG, the file size is around 6MB. I haven't found this feature in any of the Image components around.

Another direction I thought about is having multiple frames in a single JPEG. When multiple frames are used, do they use the same Huffman table or each frame has its own ?

I tried your code to compile a JPEG with multiple frames. It didn't seem to work:

            ImageTools.IO.Jpeg.JpegDecoder JD = new ImageTools.IO.Jpeg.JpegDecoder();            
            
            ImageTools.Image Im1 = null;                        
            using (FileStream FS = new FileStream(@"E:\f1.jpg", FileMode.Open)) {
                Im1 = new ImageTools.Image();
                JD.Decode(Im1, FS);
            }

            ImageTools.Image Im2 = null;
            using (FileStream FS = new FileStream(@"E:\f2.jpg", FileMode.Open)) {
                Im2 = new ImageTools.Image();
                JD.Decode(Im2, FS);
            }                                    
            
            ImageTools.ImageFrame F1 = new ImageTools.ImageFrame();
            F1.SetPixels(Im1.Width, Im1.Height, Im1.GetPixels());
            ImageTools.ImageFrame F2 = new ImageTools.ImageFrame();
            F2.SetPixels(Im2.Width, Im2.Height, Im2.GetPixels());
            
            ImageTools.Image Fr = new ImageTools.Image(200,200);
            Fr.Frames.Add(F1);
            Fr.Frames.Add(F2);
            
            using (FileStream FS = new FileStream(@"E:\Fr.jpg", FileMode.Create)) {
                ImageTools.IO.Jpeg.JpegEncoder JE = new ImageTools.IO.Jpeg.JpegEncoder();
                JE.Quality = 60;
                JE.Encode(Fr, FS);
            }

 

Last question I want to ask is regarding progressive encoded JPEG. Is it possible to decode the first layer of the JPEG even if the whole file hasn't finished downloading ?

Thanks for your help.

Gilad.

 

Coordinator
Sep 25, 2009 at 11:48 AM

Hi,

as far as I understand the jpeg format, it is not possible only to load a part of the image without decoding the other parts. I would go a different way with such a big image.

I would go another way with such big images. Just divide it in parts of 500x500 pixels. Together they are not as small asthis big picture but they can loaded step by step and the first parts can be rendered when the others will be still loaded in the background.

 

About frames:

Frames are for animations, but because of the fact that the Jpeg format does not support animations, they will be ignored when encoding them. If you want to have another behaviour it would be nice to give a comment, so I can implement it if it makes sense for me ;)

Thanks for your interest.

Sebastian

 

Mar 11, 2014 at 3:48 AM
We know, JPEG 2000 is one of the most advanced and flexible image compression solution, which adopts one of the most effective image compression and decompression methods called "discrete wavelet transformation". With a mature jpeg decoder, we can detect, encode and decode images at fast speed.

Dim jpeg As JpegDecoder =
CType(RegisteredDecoders.GetDecoderFromType(typeof(JpegDecoder)), JpegDecoder);
jpeg.ScaleFactor = JpegScaleFactor.Half
Apr 8, 2014 at 4:20 AM
Decoding a BIG JPEG

I am also quite interested in jpeg format and all your talk.