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.
This commit is contained in:
Thomas Goyne 2013-07-04 08:25:25 -07:00
parent cb3b72af36
commit ecc08f5e77

View file

@ -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 <typename P1, typename P2>
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) { wxImage GetImage(VideoFrame const& frame) {
using namespace boost::gil; 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); auto dst = interleaved_view(frame.width, frame.height, (rgb8_pixel_t*)img.GetData(), 3 * frame.width);
if (frame.flipped) if (frame.flipped)
src = flipped_up_down_view(src); src = flipped_up_down_view(src);
copy_and_convert_pixels(src, dst); copy_and_convert_pixels(src, dst, color_converter());
return img; return img;
} }