| 1 |
|
|---|
| 2 | /******************************************************************************
|
|---|
| 3 | * __LICENCE_BEGIN__
|
|---|
| 4 | *
|
|---|
| 5 | * __LICENCE_END__
|
|---|
| 6 | *****************************************************************************/
|
|---|
| 7 |
|
|---|
| 8 | ///@file
|
|---|
| 9 | ///@brief Test that RGBA images are detected by the TIFF reader.
|
|---|
| 10 | ///
|
|---|
| 11 | ///@author john.femiani@asu.edu
|
|---|
| 12 | ///
|
|---|
| 13 | ///
|
|---|
| 14 |
|
|---|
| 15 | #include <boost/test/unit_test.hpp>
|
|---|
| 16 |
|
|---|
| 17 | #include <boost/gil/gil_all.hpp>
|
|---|
| 18 | #include <boost/gil/extension/io/tiff_io.hpp>
|
|---|
| 19 |
|
|---|
| 20 | namespace gil = boost::gil;
|
|---|
| 21 |
|
|---|
| 22 | BOOST_AUTO_TEST_CASE(test_tiff_read_rgba8_image){
|
|---|
| 23 | gil::rgba8_image_t rgb;
|
|---|
| 24 | ::boost::gil::tiff_read_image("images/rgba.tif", rgb);
|
|---|
| 25 |
|
|---|
| 26 | BOOST_CHECK_MESSAGE(rgb.width() == 86,
|
|---|
| 27 | "rgb.width() == 86 failed: Was " << rgb.width());
|
|---|
| 28 | BOOST_CHECK_MESSAGE(rgb.height() == 64,
|
|---|
| 29 | "rgb.height() == 64 failed: Was " << rgb.width());
|
|---|
| 30 |
|
|---|
| 31 | for (int y = 0; y < rgb.height(); ++y){
|
|---|
| 32 | for (int x = 0; x < rgb.width(); ++x){
|
|---|
| 33 | gil::rgba8_pixel_t pix = view(rgb)(x,y);
|
|---|
| 34 | BOOST_REQUIRE_MESSAGE(pix == gil::rgba8_pixel_t(128,128,128,255),
|
|---|
| 35 | "pix!=128,128,128,255 found pix=" <<
|
|---|
| 36 | (int)pix[0] << "," <<
|
|---|
| 37 | (int)pix[1] << "," <<
|
|---|
| 38 | (int)pix[2] << "," <<
|
|---|
| 39 | (int)pix[3] <<
|
|---|
| 40 | " at x="<<x<<", y=" << y << ".");
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | BOOST_AUTO_TEST_CASE(test_tiff_read_rgb8_image_fails_on_rgba){
|
|---|
| 47 |
|
|---|
| 48 | try {
|
|---|
| 49 | gil::rgb8_image_t rgb;
|
|---|
| 50 | ::boost::gil::tiff_read_image("images/rgba.tif", rgb);
|
|---|
| 51 | BOOST_FAIL("Reading an rgb image from an rgba tif should fail.");
|
|---|
| 52 | } catch (std::ios_base::failure& err ){
|
|---|
| 53 | //Good, we should have an io error!
|
|---|
| 54 | }
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|