Read from Blob row-by-row

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
igy137

Read from Blob row-by-row

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read from Blob row-by-row

Post 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.
igy137

Re: Read from Blob row-by-row

Post 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)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read from Blob row-by-row

Post 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.
igy137

Re: Read from Blob row-by-row

Post by igy137 »

Thanks, I take a look at it!
igy137

Re: Read from Blob row-by-row

Post 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!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read from Blob row-by-row

Post by magick »

You can use MagickCore from Magick++ by prefixing the methods with MagickLib:: (e.g. MagickLib::ReadStream()). Have fun.
igy137

Re: Read from Blob row-by-row

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read from Blob row-by-row

Post 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().
igy137

Re: Read from Blob row-by-row

Post by igy137 »

Great! Although, SetImagePixels is actually called by the decompressor (at least by ReadGIFImage) before I get the stream callback :(
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read from Blob row-by-row

Post 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).
Post Reply