views:

179

answers:

2

I'm trying to generate ImageMagick images from SDL pixel data. Here's what the GIF looks like so far. (This GIF is slower than the one below on purpose.)

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.

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);
+2  A: 

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.

What do you mean by "DWORD aligned?"
Scott
Nevermind. I figured it out. The format needed to be RAW instead of RGB.
Scott
A: 

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.

Blindy