2013-07-01 05:15:43 +02:00
|
|
|
// Copyright (c) 2013, Thomas Goyne <plorkyeran@aegisub.org>
|
2007-01-21 07:30:19 +01:00
|
|
|
//
|
2013-07-01 05:15:43 +02:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2007-01-21 07:30:19 +01:00
|
|
|
//
|
2013-07-01 05:15:43 +02:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2007-01-21 07:30:19 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "video_frame.h"
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2013-07-01 05:15:43 +02:00
|
|
|
#include <boost/gil/gil_all.hpp>
|
|
|
|
#include <wx/image.h>
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2013-07-04 17:25:25 +02:00
|
|
|
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()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-07-01 05:15:43 +02:00
|
|
|
wxImage GetImage(VideoFrame const& frame) {
|
|
|
|
using namespace boost::gil;
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2013-07-01 05:15:43 +02:00
|
|
|
wxImage img(frame.width, frame.height);
|
|
|
|
auto src = interleaved_view(frame.width, frame.height, (bgra8_pixel_t*)frame.data.data(), frame.pitch);
|
|
|
|
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);
|
2013-07-04 17:25:25 +02:00
|
|
|
copy_and_convert_pixels(src, dst, color_converter());
|
2010-12-31 22:03:11 +01:00
|
|
|
return img;
|
2007-04-03 04:31:51 +02:00
|
|
|
}
|