PDA

View Full Version : ReaderImage can Read a huge image (10000*40000 format jpeg), how it wrok ?



huifeidmeng
7th January 2016, 01:45
Hi , man ,i'm new boy in here , i test some picture with qimage ,yeah , it's work well, but for huge qimage (>200M ), it's just like dog shit.
so i change my way to using ReaderImage to Read a huge image(format like jpeg ) with setScaledSize(), omg , it's work like a angle , but i want to know ReaderImage how to do that ? , for another word , what the theory it is ? it's like riddle around me again and again ! man , do you konw ?

yeye_olive
7th January 2016, 09:27
By ReaderImage, you mean QImageReader, right?

QImage loads the whole image, which explains the limitations you have run into.
By contrast, QImageReader probably keeps only a small region of the image in memory at a given time. This is only possible for algorithms which are inherently local, such as scaling. In order to compute the value of a pixel of the scaled image, you only need to inspect the region of the original image in the same relative position. When you are done, you can move to another region of the original image and reuse the same buffer in memory.

huifeidmeng
7th January 2016, 09:38
Yeah , i went to proof for minutes ago , the data like this , it's cost litter memory , so i'm curious about how it got this way ! do you have good article introduce for me !
11625

thsk for much.
by gxjun

yeye_olive
7th January 2016, 10:02
I am sorry, but I have no idea what you mean.

huifeidmeng
7th January 2016, 10:09
i'mean that , do you know QImageRead Based on what algorithm to deal huge image( &jpeg),?

ChrisW67
7th January 2016, 10:50
QImage reads the entire image into RAM and keeps an editable data structure. This structure is typically much larger than the file size.

QImageReader reads the image data a piece at a time, processes the current piece, and then discards it. In your case, the reader reads a portion of the source image big enough to determine the pixels of the first portion of the scaled result, computes that scaled image portion, and then discards the input. In this way it never needs to hold the entire source in memory and can build a much smaller result.

yeye_olive
7th January 2016, 10:53
Again, it's QImageReader. Please use the correct name so that other users can search the forum more efficiently.

Have a look into QImageReader's source code. You'll see that the algorithms depend on the format of the image; the internal class QJpegHandler implements those algorithms for JPEG images. QJpegHandler in turn delegates the work to libjpeg (http://libjpeg.sourceforge.net/). libjpeg's maintainers may be able to answer your question.

What is so mysterious about this scaling algorithm? I explained how its local nature allowed implementations that kept a small region of the image in memory. I haven't checked libjpeg, but I suppose it must work this way (except that image data must be decompressed on the fly, too).