Page 1 of 1

Creating a Blob

Posted: 2008-07-12T21:08:12-07:00
by kh263
Does someone know how to create a Magick++ Blob with raw image data such as RGBA? If someone has a code sniplet, that would be great too.

Re: Creating a Blob

Posted: 2008-07-15T13:27:20-07:00
by Moschops
I know how to read raw data from file into a Magick::Blob object . Is that what you're after, or do you mean create the raw data from scratch?

Re: Creating a Blob

Posted: 2008-07-15T15:19:17-07:00
by kh263
Yes read raw data from a file and/or from memory. Thanks.

Re: Creating a Blob

Posted: 2008-07-16T02:40:12-07:00
by Moschops
Here's some example code that reads from a raw uyvy image into a Blob, and then into an Image. It's lacking headers etc. and it uses naked arrays, but its mechanism should be clear to you.

Code: Select all

     
        char buffer1[4147200];   // enough for exactly one image's worth of bytes in this example
        void* data1 = &buffer1[0];   // A void pointer to be passed to the Blob constructor
          
        // Open image file
        std::ifstream input_file("frame1.uyvy", std::ios::in | std::ios::binary);

        // Read data into buffer
         input_file.read (&buffer1, 4147200);
            

            // Create Blob with data from buffer        
            Magick::Blob tempDataStore1(data1, 4147200);

            // Create image from Blob
            Magick::Image image1(tempDataStore1, "1920x1080", 3, "UYVY");

            // Write that image as a png file
            image1.write( "fromBlob.png");
        
'Chops

Re: Creating a Blob

Posted: 2008-07-16T08:39:49-07:00
by kh263
Are you using a depth of 3 in this example? If so, why?

Re: Creating a Blob

Posted: 2008-07-16T10:31:53-07:00
by magick
You can also look at the ImageMagick source distribution for Magick++/tests/readWriteBlob.cpp. It is an example program that reads and writes blobs.

Re: Creating a Blob

Posted: 2008-07-16T13:48:49-07:00
by Moschops
kh263 wrote:Are you using a depth of 3 in this example? If so, why?
Yes, I am. I'm using it because that's a depth appropriate to the raw images I wrote this code for.