From ecc08f5e7784872af3c1ccfcdda8c5e4ec84c80e Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 4 Jul 2013 08:25:25 -0700 Subject: [PATCH] Fix conversion of video frames to RGB Video frames aren't actually BGRA; the alpha channel is actually just garbage since CSRI uses 0 for opaque and other things use 255. To work around this, add a custom colorspace converter. Fixes the subtitles preview in the style editor and copying frames to the clipboard/saving them. Closes #1621. --- aegisub/src/video_frame.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/aegisub/src/video_frame.cpp b/aegisub/src/video_frame.cpp index 6497f1a2a..2ed01695b 100644 --- a/aegisub/src/video_frame.cpp +++ b/aegisub/src/video_frame.cpp @@ -30,6 +30,20 @@ VideoFrame::VideoFrame(const unsigned char *data, size_t width, size_t height, s { } +namespace { + // We actually have bgr_, not bgra, so we need a custom converter which ignores the alpha channel + struct color_converter { + template + void operator()(P1 const& src, P2& dst) const { + using namespace boost::gil; + dst = rgb8_pixel_t( + get_color(src, red_t()), + get_color(src, green_t()), + get_color(src, blue_t())); + } + }; +} + wxImage GetImage(VideoFrame const& frame) { using namespace boost::gil; @@ -38,6 +52,6 @@ wxImage GetImage(VideoFrame const& frame) { auto dst = interleaved_view(frame.width, frame.height, (rgb8_pixel_t*)img.GetData(), 3 * frame.width); if (frame.flipped) src = flipped_up_down_view(src); - copy_and_convert_pixels(src, dst); + copy_and_convert_pixels(src, dst, color_converter()); return img; }