From c9b733ba0f05c011d6880ffe3aae2a87e292d106 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 23 Feb 2013 21:36:08 +0000 Subject: Throw an exception rather than asserting when unable to handle a pixel format (#65). --- src/lib/exceptions.h | 13 +++++++++++++ src/lib/image.cc | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index 6de8806e4..277355117 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -28,6 +28,9 @@ #include #include #include +extern "C" { +#include +} #include "compose.hpp" /** @class StringError @@ -220,6 +223,14 @@ public: {} }; +class PixelFormatError : public StringError +{ +public: + PixelFormatError (std::string o, AVPixelFormat f) + : StringError (String::compose ("Cannot handle pixel format %1 during %2", f, o)) + {} +}; + class ExceptionStore { public: @@ -245,4 +256,6 @@ private: mutable boost::mutex _mutex; }; + + #endif diff --git a/src/lib/image.cc b/src/lib/image.cc index 73d499fe8..ae87304c2 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -70,7 +70,7 @@ Image::lines (int n) const case PIX_FMT_YUV422P: return size().height; default: - assert (false); + throw PixelFormatError ("lines()", _pixel_format); } return 0; @@ -89,7 +89,7 @@ Image::components () const case PIX_FMT_RGBA: return 1; default: - assert (false); + throw PixelFormatError ("components()", _pixel_format); } return 0; @@ -202,7 +202,7 @@ Image::post_process (string pp, bool aligned) const pp_format = PP_FORMAT_422; break; default: - assert (false); + throw PixelFormatError ("post_process", pixel_format()); } pp_mode* mode = pp_get_mode_by_name_and_quality (pp.c_str (), PP_QUALITY_MAX); -- cgit v1.2.3 From f7a38b76ea50c62624972994f6a7ea9feaaf4f6b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 23 Feb 2013 21:40:08 +0000 Subject: Support YUV444P pixels (#66). --- src/lib/image.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/lib') diff --git a/src/lib/image.cc b/src/lib/image.cc index ae87304c2..f38d44185 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -68,6 +68,7 @@ Image::lines (int n) const case PIX_FMT_RGBA: case PIX_FMT_YUV422P10LE: case PIX_FMT_YUV422P: + case PIX_FMT_YUV444P: return size().height; default: throw PixelFormatError ("lines()", _pixel_format); @@ -84,6 +85,7 @@ Image::components () const case PIX_FMT_YUV420P: case PIX_FMT_YUV422P10LE: case PIX_FMT_YUV422P: + case PIX_FMT_YUV444P: return 3; case PIX_FMT_RGB24: case PIX_FMT_RGBA: @@ -201,6 +203,8 @@ Image::post_process (string pp, bool aligned) const case PIX_FMT_YUV422P: pp_format = PP_FORMAT_422; break; + case PIX_FMT_YUV444P: + pp_format = PP_FORMAT_444; default: throw PixelFormatError ("post_process", pixel_format()); } @@ -254,6 +258,7 @@ Image::make_black () switch (_pixel_format) { case PIX_FMT_YUV420P: case PIX_FMT_YUV422P: + case PIX_FMT_YUV444P: memset (data()[0], 0, lines(0) * stride()[0]); memset (data()[1], 0x7f, lines(1) * stride()[1]); memset (data()[2], 0x7f, lines(2) * stride()[2]); @@ -375,6 +380,8 @@ Image::bytes_per_pixel (int c) const } else { return 1; } + case PIX_FMT_YUV444P: + return 3; default: assert (false); } -- cgit v1.2.3 From bbd352c3a0acf312e66b8be0d8bfb475275102d6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 24 Feb 2013 10:29:41 +0000 Subject: Tweak job progress reporting. --- src/lib/job.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/job.cc b/src/lib/job.cc index bde2c8cfd..bfad65a0a 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -272,10 +272,11 @@ Job::status () const } stringstream s; - if (!finished () && p >= 0 && t > 10 && r > 0) { - s << pc << "%; " << seconds_to_approximate_hms (r) << " remaining"; - } else if (!finished () && (t <= 10 || r == 0)) { + if (!finished ()) { s << pc << "%"; + if (p >= 0 && t > 10 && r > 0) { + s << "; " << seconds_to_approximate_hms (r) << " remaining"; + } } else if (finished_ok ()) { s << "OK (ran for " << seconds_to_hms (_ran_for) << ")"; } else if (finished_in_error ()) { -- cgit v1.2.3 From 8cc4b5f514795a52ad13c8d6e8527061da14a0d2 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 26 Feb 2013 16:02:15 +0000 Subject: Speculative support for some new YVU444 pixel formats. --- src/lib/image.cc | 71 ++++++++++++++++++++++++++++++++++++++++++++++++-------- src/lib/image.h | 5 +++- test/test.cc | 47 +++++++++++-------------------------- 3 files changed, 78 insertions(+), 45 deletions(-) (limited to 'src/lib') diff --git a/src/lib/image.cc b/src/lib/image.cc index f38d44185..b7ac13ab1 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -69,6 +69,10 @@ Image::lines (int n) const case PIX_FMT_YUV422P10LE: case PIX_FMT_YUV422P: case PIX_FMT_YUV444P: + case PIX_FMT_YUV444P9BE: + case PIX_FMT_YUV444P9LE: + case PIX_FMT_YUV444P10BE: + case PIX_FMT_YUV444P10LE: return size().height; default: throw PixelFormatError ("lines()", _pixel_format); @@ -86,6 +90,10 @@ Image::components () const case PIX_FMT_YUV422P10LE: case PIX_FMT_YUV422P: case PIX_FMT_YUV444P: + case PIX_FMT_YUV444P9BE: + case PIX_FMT_YUV444P9LE: + case PIX_FMT_YUV444P10BE: + case PIX_FMT_YUV444P10LE: return 3; case PIX_FMT_RGB24: case PIX_FMT_RGBA: @@ -204,6 +212,10 @@ Image::post_process (string pp, bool aligned) const pp_format = PP_FORMAT_422; break; case PIX_FMT_YUV444P: + case PIX_FMT_YUV444P9BE: + case PIX_FMT_YUV444P9LE: + case PIX_FMT_YUV444P10BE: + case PIX_FMT_YUV444P10LE: pp_format = PP_FORMAT_444; default: throw PixelFormatError ("post_process", pixel_format()); @@ -252,9 +264,37 @@ Image::crop (Crop crop, bool aligned) const return out; } +/** Blacken a YUV image whose bits per pixel is rounded up to 16 */ +void +Image::yuv_16_black (uint16_t v) +{ + memset (data()[0], 0, lines(0) * stride()[0]); + for (int i = 1; i < 3; ++i) { + int16_t* p = reinterpret_cast (data()[i]); + for (int y = 0; y < size().height; ++y) { + for (int x = 0; x < line_size()[i] / 2; ++x) { + p[x] = v; + } + p += stride()[i] / 2; + } + } +} + +uint16_t +Image::swap_16 (uint16_t v) +{ + return ((v >> 8) & 0xff) | ((v & 0xff) << 8); +} + void Image::make_black () { + /* U/V black value for 9-bit colour */ + static uint16_t const nine_bit_uv = (1 << 8) - 1; + + /* U/V black value for 10-bit colour */ + static uint16_t const ten_bit_uv = (1 << 9) - 1; + switch (_pixel_format) { case PIX_FMT_YUV420P: case PIX_FMT_YUV422P: @@ -264,19 +304,25 @@ Image::make_black () memset (data()[2], 0x7f, lines(2) * stride()[2]); break; + case PIX_FMT_YUV422P9LE: + case PIX_FMT_YUV444P9LE: + yuv_16_black (nine_bit_uv); + break; + + case PIX_FMT_YUV422P9BE: + case PIX_FMT_YUV444P9BE: + yuv_16_black (swap_16 (nine_bit_uv)); + break; + case PIX_FMT_YUV422P10LE: - memset (data()[0], 0, lines(0) * stride()[0]); - for (int i = 1; i < 3; ++i) { - int16_t* p = reinterpret_cast (data()[i]); - for (int y = 0; y < size().height; ++y) { - for (int x = 0; x < line_size()[i] / 2; ++x) { - p[x] = (1 << 9) - 1; - } - p += stride()[i] / 2; - } - } + case PIX_FMT_YUV444P10LE: + yuv_16_black (ten_bit_uv); break; + case PIX_FMT_YUV444P10BE: + case PIX_FMT_YUV422P10BE: + yuv_16_black (swap_16 (ten_bit_uv)); + case PIX_FMT_RGB24: memset (data()[0], 0, lines(0) * stride()[0]); break; @@ -382,6 +428,11 @@ Image::bytes_per_pixel (int c) const } case PIX_FMT_YUV444P: return 3; + case PIX_FMT_YUV444P9BE: + case PIX_FMT_YUV444P9LE: + case PIX_FMT_YUV444P10LE: + case PIX_FMT_YUV444P10BE: + return 6; default: assert (false); } diff --git a/src/lib/image.h b/src/lib/image.h index f40ea9280..6b9ade99e 100644 --- a/src/lib/image.h +++ b/src/lib/image.h @@ -92,7 +92,10 @@ protected: virtual void swap (Image &); float bytes_per_pixel (int) const; -private: +private: + void yuv_16_black (uint16_t); + static uint16_t swap_16 (uint16_t); + AVPixelFormat _pixel_format; ///< FFmpeg's way of describing the pixel format of this Image }; diff --git a/test/test.cc b/test/test.cc index 386aead2e..8cfc6e467 100644 --- a/test/test.cc +++ b/test/test.cc @@ -94,25 +94,18 @@ BOOST_AUTO_TEST_CASE (make_black_test) libdcp::Size in_size (512, 512); libdcp::Size out_size (1024, 1024); - { - /* Plain RGB input */ - boost::shared_ptr foo (new SimpleImage (AV_PIX_FMT_RGB24, in_size, true)); - foo->make_black (); - boost::shared_ptr bar = foo->scale_and_convert_to_rgb (out_size, 0, Scaler::from_id ("bicubic"), true); - - uint8_t* p = bar->data()[0]; - for (int y = 0; y < bar->size().height; ++y) { - uint8_t* q = p; - for (int x = 0; x < bar->line_size()[0]; ++x) { - BOOST_CHECK_EQUAL (*q++, 0); - } - p += bar->stride()[0]; - } - } - - { - /* YUV420P input */ - boost::shared_ptr foo (new SimpleImage (AV_PIX_FMT_YUV420P, in_size, true)); + list pix_fmts; + pix_fmts.push_back (AV_PIX_FMT_RGB24); + pix_fmts.push_back (AV_PIX_FMT_YUV420P); + pix_fmts.push_back (AV_PIX_FMT_YUV422P10LE); + pix_fmts.push_back (AV_PIX_FMT_YUV444P9LE); + pix_fmts.push_back (AV_PIX_FMT_YUV444P9BE); + pix_fmts.push_back (AV_PIX_FMT_YUV444P10LE); + pix_fmts.push_back (AV_PIX_FMT_YUV444P10BE); + + int N = 0; + for (list::const_iterator i = pix_fmts.begin(); i != pix_fmts.end(); ++i) { + boost::shared_ptr foo (new SimpleImage (*i, in_size, true)); foo->make_black (); boost::shared_ptr bar = foo->scale_and_convert_to_rgb (out_size, 0, Scaler::from_id ("bicubic"), true); @@ -124,22 +117,8 @@ BOOST_AUTO_TEST_CASE (make_black_test) } p += bar->stride()[0]; } - } - { - /* YUV422P10LE input */ - boost::shared_ptr foo (new SimpleImage (AV_PIX_FMT_YUV422P10LE, in_size, true)); - foo->make_black (); - boost::shared_ptr bar = foo->scale_and_convert_to_rgb (out_size, 0, Scaler::from_id ("bicubic"), true); - - uint8_t* p = bar->data()[0]; - for (int y = 0; y < bar->size().height; ++y) { - uint8_t* q = p; - for (int x = 0; x < bar->line_size()[0]; ++x) { - BOOST_CHECK_EQUAL (*q++, 0); - } - p += bar->stride()[0]; - } + ++N; } } -- cgit v1.2.3