Use ycbcr_converter in YUV4MPEGVideoProvider

This commit is contained in:
Thomas Goyne 2013-08-27 07:37:19 -07:00
parent cddefd8ed9
commit 7a06e08ad0
3 changed files with 22 additions and 18 deletions

View File

@ -28,6 +28,15 @@ VideoFrame::VideoFrame(const unsigned char *data, size_t width, size_t height, s
{
}
VideoFrame::VideoFrame(std::vector<unsigned char>&& data, size_t width, size_t height, size_t pitch, bool flipped)
: data(std::move(data))
, width(width)
, height(height)
, pitch(pitch)
, flipped(flipped)
{
}
namespace {
// We actually have bgr_, not bgra, so we need a custom converter which ignores the alpha channel
struct color_converter {

View File

@ -26,6 +26,7 @@ struct VideoFrame {
bool flipped;
VideoFrame(const unsigned char *data, size_t width, size_t height, size_t pitch, bool fipped);
VideoFrame(std::vector<unsigned char>&& data, size_t width, size_t height, size_t pitch, bool fipped);
};
wxImage GetImage(VideoFrame const& frame);

View File

@ -43,6 +43,7 @@
#include <libaegisub/log.h>
#include <libaegisub/make_unique.h>
#include <libaegisub/util.h>
#include <libaegisub/ycbcr_conv.h>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/filesystem/path.hpp>
@ -130,6 +131,8 @@ class YUV4MPEGVideoProvider final : public VideoProvider {
agi::vfr::Framerate fps;
agi::ycbcr_converter conv{agi::ycbcr_matrix::bt601, agi::ycbcr_range::tv};
/// a list of byte positions detailing where in the file
/// each frame header can be found
std::vector<uint64_t> seek_table;
@ -390,15 +393,6 @@ int YUV4MPEGVideoProvider::IndexFile(uint64_t pos) {
return framecount;
}
// http://bob.allegronetwork.com/prog/tricks.html#clamp
static FORCEINLINE int clamp(int x) {
x &= (~x) >> 31;
x -= 255;
x &= x >> 31;
x += 255;
return x;
}
std::shared_ptr<VideoFrame> YUV4MPEGVideoProvider::GetFrame(int n) {
n = mid(0, n, num_frames - 1);
@ -422,15 +416,15 @@ std::shared_ptr<VideoFrame> YUV4MPEGVideoProvider::GetFrame(int n) {
for (int py = 0; py < h; ++py) {
for (int px = 0; px < w / 2; ++px) {
const int u = *src_u++ - 128;
const int v = *src_v++ - 128;
const uint8_t u = *src_u++;
const uint8_t v = *src_v++;
for (unsigned int i = 0; i < 2; ++i) {
const int y = (*src_y++ - 16) * 298;
*dst++ = clamp((y + 516 * u + 128) >> 8); // Blue
*dst++ = clamp((y - 100 * u - 208 * v + 128) >> 8); // Green
*dst++ = clamp((y + 409 * v + 128) >> 8); // Red
*dst++ = 0; // Alpha
const uint8_t y = *src_y++;
auto rgb = conv.ycbcr_to_rgb({{y, u, v}});
*dst++ = rgb[2];
*dst++ = rgb[1];
*dst++ = rgb[0];
*dst++ = 0;
}
}
@ -441,7 +435,7 @@ std::shared_ptr<VideoFrame> YUV4MPEGVideoProvider::GetFrame(int n) {
}
}
return std::make_shared<VideoFrame>(data.data(), w, h, w * 4, false);
return std::make_shared<VideoFrame>(std::move(data), w, h, w * 4, false);
}
}