Vom: Sat, 10 Sep 2011 08:13:25 -0700

> > Is there a way to read every image one after another
> 
> Use an iterator.  Here's a code snippet:

Thanks for your answer.
I tried that and it works flawlessly with multi-frame formats (I tested
it with a GIF animation) but it fails with multiple PNGs in the same
stream.

My code looks like this:

c->mw is the MagickWand and 
c->file is the opened FILE stream.


/** read image and write RAW frame into buf */
bool im_read_frame(size_t width, size_t height, char *buf) 
{

        /* is there an image from a previous read? */
        if(MagickHasNextImage(c->mw))
        {
                MagickNextImage(c->mw);
        }
        else
        {
                /* end-of-stream reached? */
                if(feof(c->file))
                        return FALSE;
                
                /* read file */
                if(!MagickReadImageFile(c->mw, c->file))
                {
                        im_error(c->mw);
                        return FALSE;
                }

                /* reset iterator in case we read more than one file */
                MagickResetIterator(c->mw);
        }

        
        /* get raw-buffer from imagemagick */
        if(!(MagickExportImagePixels(c->mw, 
                0, 0, width, height, c->map, c->storage, buf))) 
        {
                im_error(c->mw);
                return FALSE;
        }

        /* free resources */
        if(!MagickHasNextImage(c->mw))
                ClearMagickWand(c->mw);
        
        return TRUE;
}


if c->file is something like fopen("test_stream", "r");
and "test_stream" is something like 
"cat 1.png 2.png 3.png > test_stream"

I only get 1.png and can't read the following images. I wonder if it's
even possible to do that with MagickWand & MagickReadImageFile() or if
it's just supposed to work with multi-image containers (like GIF
animations)

Of course it works if I open/read 1.png, 2.png and 3.png seperatly, but
there are cases where they could be packed inside one stream. I'd love
to support that case if it's possible somehow.



thanks & best regards
-- 
rigid

momentum, n.:
        What you give a person when they are going away.

_______________________________________________
Magick-users mailing list
Magick-users@imagemagick.org
http://studio.imagemagick.org/mailman/listinfo/magick-users
  • ... Daniel Hiepler
    • ... Anthony Thyssen
    • ... da . mihi . sis . bubulae . frustrum . assae . solana . tuberosa . in . modo . gallico . fricta . ac . quassum . lactatum . coagulatum . crassum
      • ... Daniel Hiepler
      • ... Anthony Thyssen
    • ... da . mihi . sis . bubulae . frustrum . assae . solana . tuberosa . in . modo . gallico . fricta . ac . quassum . lactatum . coagulatum . crassum

Reply via email to