Coalesce identical GIF frames on load.

master
Glenn Maynard 6 years ago
parent a094588055
commit bf9b8b185c
  1. 15
      sdk/Windows/SMXGif.cpp
  2. 2
      sdk/Windows/SMXGif.h
  3. 2
      sdk/Windows/SMXPanelAnimation.cpp

@ -47,6 +47,13 @@ void SMXGif::GIFImage::Blit(SMXGif::GIFImage &src, int dst_left, int dst_top, in
get(x + dst_left, y + dst_top) = src.get(x, y);
}
}
bool SMXGif::GIFImage::operator==(const GIFImage &rhs) const
{
return
width == rhs.width &&
height == rhs.height &&
image == rhs.image;
}
class DataStream
{
@ -394,6 +401,14 @@ void GIFDecoder::ReadAllFrames(vector<SMXGif::SMXGifFrame> &frames)
gif_frame.height = global_data.height;
gif_frame.milliseconds = global_data.duration * 10;
gif_frame.frame = frame_image;
// If this frame is identical to the previous one, just extend the previous frame.
if(!frames.empty() && gif_frame.frame == frames.back().frame)
{
frames.back().milliseconds += gif_frame.milliseconds;
continue;
}
frames.push_back(gif_frame);
frame++;

@ -47,6 +47,8 @@ namespace SMXGif
// Copy src into a rectangle in this image.
void Blit(GIFImage &src, int dst_left, int dst_top, int dst_width, int dst_height);
bool operator==(const GIFImage &rhs) const;
private:
std::vector<Color> image;
};

@ -320,7 +320,6 @@ void SMXPanelAnimation::Load(const vector<SMXGif::SMXGifFrame> &frames, int pane
ConvertToPanelGraphic16(gif_frame.frame, panel_graphic, panel);
else
ConvertToPanelGraphic25(gif_frame.frame, panel_graphic, panel);
m_aPanelGraphics.push_back(panel_graphic);
// GIFs have a very low-resolution duration field, with 10ms units.
// The panels run at 30 FPS internally, or 33 1/3 ms, but GIF can only
@ -333,6 +332,7 @@ void SMXPanelAnimation::Load(const vector<SMXGif::SMXGifFrame> &frames, int pane
else
seconds = gif_frame.milliseconds / 1000.0;
m_aPanelGraphics.push_back(panel_graphic);
m_iFrameDurations.push_back(seconds);
}

Loading…
Cancel
Save