Page 1 of 1

Read from Blob row-by-row

Posted: 2007-02-26T08:52:21-07:00
by igy137
Hello,

Is there a way to read/uncompress Blobs row-by-row?
I use Magick++ with pre-loaded Blobs in memory, and something like this:
Magick::Image img;
try { img.read(*pblob); }

However, I need only a few rows at a time, but from many different images - uncompressing all of them takes quite a time, and if possible I'd like to optimize this by reading only a few rows from each images.

Thanks,
igy137

Re: Read from Blob row-by-row

Posted: 2007-02-26T10:34:18-07:00
by magick
To access a few image rows at a time you need to work directly with pixels. When reading a blob, the entire blob is read and the entire image is created in memory or on disk.

Re: Read from Blob row-by-row

Posted: 2007-02-27T03:01:52-07:00
by igy137
Thanks for the answers!
What a pity...
BTW, By traicing into the sources I saw, that for example gif is decompressed row-by-row (maybe I'm wrong, I just take a quick look at it). What happens if I call read blob from a low priority thread and try to access the image row-by-row from another thread? Is there some mechanism which prevents access of uncompressed parts, or any indication (I use getConstPixels(..) call)

Re: Read from Blob row-by-row

Posted: 2007-02-27T09:14:00-07:00
by magick
D'oh. Forgot to mention the streaming interface which may do exactly what you are asking for. See http://www.imagemagick.org/script/archi ... php#stream.

Re: Read from Blob row-by-row

Posted: 2007-02-27T10:06:06-07:00
by igy137
Thanks, I take a look at it!

Re: Read from Blob row-by-row

Posted: 2007-02-27T14:52:32-07:00
by igy137
This really looks good.
Unfortunately as I was not able to figure out how could I use this from Magick++ (if possible at all).
Can you help me, please? (It's also ok to use MagickCore if it's not possible with Magick++).
Thanks again for the hint!

Re: Read from Blob row-by-row

Posted: 2007-02-27T17:58:41-07:00
by magick
You can use MagickCore from Magick++ by prefixing the methods with MagickLib:: (e.g. MagickLib::ReadStream()). Have fun.

Re: Read from Blob row-by-row

Posted: 2007-03-01T05:07:33-07:00
by igy137
Finally, I got this working :)))
I still have some questions, though:
Is this thingy thread-safe? Can I use multiple threads for simultaneous extraction of different images?
Is there any way to pass some data to the callback function receiving the pixels?

Re: Read from Blob row-by-row

Posted: 2007-03-01T11:03:08-07:00
by magick
Thread safe? Sure, discussed indirectly in the ImageMagick architecture document. Every method in ImageMagick is thread safe except for Acquire/Get/SetImagePixels().

Streaming has a client_data member but apparently there is no method to set it. We will get a patch in ImageMagick 6.3.3 to correct this problem. Most likely SetStreamClientData() and GetStreamClientData().

Re: Read from Blob row-by-row

Posted: 2007-03-01T11:13:18-07:00
by igy137
Great! Although, SetImagePixels is actually called by the decompressor (at least by ReadGIFImage) before I get the stream callback :(

Re: Read from Blob row-by-row

Posted: 2007-03-01T11:21:37-07:00
by magick
We keep things thread safe internally. We're talking about the public API being thread safe (everything but Acquire/Get/SetPixels()). The streaming interface is low level and most of the stream methods are defined in stream-private.h which is not part of the public API. So we'll add SetStreamInfoClientData()/GetStreamInfoClientData() but you will need to include stream-private.h and assume the risk of using a private interface (private methods are subject to signature change although unlikely).