开发者

Magick++ animation generation via SDL pixel data

I'm trying to generate I开发者_开发问答mageMagick images from SDL pixel data. Here's what the GIF looks like so far. (This GIF is slower than the one below on purpose.)

http://www.starlon.net/images/combo.gif

Here's what it's supposed to look like. Notice in the above image that the pixels seem to be overlayed on top of other pixels.

http://www.starlon.net/images/combo2.gif

Here's where the GIF is actually created.

void DrvSDL::WriteGif() {
    std::list<Magick::Image> gif;

    for(std::list<Magick::Blob>::iterator it = image_.begin(); it != image_.end(); it++) {
        Magick::Geometry geo(cols_ * pixels.x, rows_ * pixels.y);
        Magick::Image image(*it, geo, 32, "RGB");
        gif.push_back(image);
        LCDError("image");
    }
    for_each(gif.begin(), gif.end(), Magick::animationDelayImage(ani_speed_));
    Magick::writeImages(gif.begin(), gif.end(), gif_file_);
}

And here's where the Blob is packed.

image_.push_back(Magick::Blob(surface_->pixels, rows_ * pixels.y * surface_->pitch));

And here's how I initialize the SDL surface.

surface_ = SDL_SetVideoMode(cols_ * pixels.x, rows_ * pixels.y, 32, SDL_SWSURFACE);


The top image is normally caused by a misaligned buffer. The SDL buffer is probably not DWORD aligned and the ImageMagick routines expect the buffer to be aligned on a DWORD. This is very common in bitmap processing. The popular image processing library - Leadtools, commonly, requires DWORD aligned data. This is mostly case with monochrome and 32 bit color but can be the case for any color depth.

What you need to do is write out a DWORD aligned bitmap from your SDL buffer or at least create a buffer that is DWORD aligned.

The ImageMagick API documentation may be able to help clarify this further.


Another thing you might want to try is to clear the buffers to make sure there isn't any data already there. I don't really know IM's API, but pixels overlayed on top of other pixels usually indicates a dirty buffer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜