Read from Blob row-by-row
Read from Blob row-by-row
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
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
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
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)
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
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
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!
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
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
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?
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
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().
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
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
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).