Add pixel formats tests.
authorCarl Hetherington <cth@carlh.net>
Wed, 1 May 2013 13:16:38 +0000 (14:16 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 1 May 2013 13:16:38 +0000 (14:16 +0100)
src/lib/image.h
test/test.cc

index 00768ee028e5bdcb551f6f1aa2f516e026e7c70c..39d84fcd4c35cee34ff6ba947218d3827cde493b 100644 (file)
@@ -91,6 +91,8 @@ protected:
        virtual void swap (Image &);
        float bytes_per_pixel (int) const;
 
+       friend class pixel_formats_test;
+
 private:
        void yuv_16_black (uint16_t);
        static uint16_t swap_16 (uint16_t);
index 496c915198818753036d2864656cd26aa75693e8..11ca56031df8f22869a06b6d574e665960ecd9a4 100644 (file)
@@ -123,6 +123,59 @@ BOOST_AUTO_TEST_CASE (make_black_test)
        }
 }
 
+
+struct Case
+{
+       Case (AVPixelFormat f, int c, int l0, int l1, int l2, float b0, float b1, float b2)
+               : format(f)
+               , components(c)
+       {
+               lines[0] = l0;
+               lines[1] = l1;
+               lines[2] = l2;
+               bpp[0] = b0;
+               bpp[1] = b1;
+               bpp[2] = b2;
+       }
+       
+       AVPixelFormat format;
+       int components;
+       int lines[3];
+       float bpp[3];
+};
+
+BOOST_AUTO_TEST_CASE (pixel_formats_test)
+{
+       list<Case> cases;
+       cases.push_back(Case(AV_PIX_FMT_RGB24,       1, 480, 480, 480, 3, 0,   0  ));
+       cases.push_back(Case(AV_PIX_FMT_RGBA,        1, 480, 480, 480, 4, 0,   0  ));
+       cases.push_back(Case(AV_PIX_FMT_YUV420P,     3, 480, 240, 240, 1, 0.5, 0.5));
+       cases.push_back(Case(AV_PIX_FMT_YUV422P,     3, 480, 480, 480, 1, 0.5, 0.5));
+       cases.push_back(Case(AV_PIX_FMT_YUV422P10LE, 3, 480, 480, 480, 2, 1,   1  ));
+       cases.push_back(Case(AV_PIX_FMT_YUV422P16LE, 3, 480, 480, 480, 2, 1,   1  ));
+       cases.push_back(Case(AV_PIX_FMT_UYVY422,     1, 480, 480, 480, 2, 2,   2  ));
+       cases.push_back(Case(AV_PIX_FMT_YUV444P,     3, 480, 480, 480, 3, 3,   3  ));
+       cases.push_back(Case(AV_PIX_FMT_YUV444P9BE,  3, 480, 480, 480, 6, 6,   6  ));
+       cases.push_back(Case(AV_PIX_FMT_YUV444P9LE,  3, 480, 480, 480, 6, 6,   6  ));
+       cases.push_back(Case(AV_PIX_FMT_YUV444P10BE, 3, 480, 480, 480, 6, 6,   6  ));
+       cases.push_back(Case(AV_PIX_FMT_YUV444P10LE, 3, 480, 480, 480, 6, 6,   6  ));
+
+       for (list<Case>::iterator i = cases.begin(); i != cases.end(); ++i) {
+               AVFrame* f = av_frame_alloc ();
+               f->width = 640;
+               f->height = 480;
+               f->format = static_cast<int> (i->format);
+               FrameImage t (f);
+               BOOST_CHECK_EQUAL(t.components(), i->components);
+               BOOST_CHECK_EQUAL(t.lines(0), i->lines[0]);
+               BOOST_CHECK_EQUAL(t.lines(1), i->lines[1]);
+               BOOST_CHECK_EQUAL(t.lines(2), i->lines[2]);
+               BOOST_CHECK_EQUAL(t.bytes_per_pixel(0), i->bpp[0]);
+               BOOST_CHECK_EQUAL(t.bytes_per_pixel(1), i->bpp[1]);
+               BOOST_CHECK_EQUAL(t.bytes_per_pixel(2), i->bpp[2]);
+       }
+}
+
 shared_ptr<const Image> trimmer_test_last_video;
 shared_ptr<const AudioBuffers> trimmer_test_last_audio;