| 1 |
/* |
| 2 |
libheifio TIFF decode unit tests |
| 3 |
|
| 4 |
MIT License |
| 5 |
|
| 6 |
Copyright (c) 2024 Brad Hards <[email protected]> |
| 7 |
|
| 8 |
Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 |
of this software and associated documentation files (the "Software"), to deal |
| 10 |
in the Software without restriction, including without limitation the rights |
| 11 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 |
copies of the Software, and to permit persons to whom the Software is |
| 13 |
furnished to do so, subject to the following conditions: |
| 14 |
|
| 15 |
The above copyright notice and this permission notice shall be included in all |
| 16 |
copies or substantial portions of the Software. |
| 17 |
|
| 18 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 |
SOFTWARE. |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "catch_amalgamated.hpp" |
| 28 |
#include <cstdint> |
| 29 |
#include <iostream> |
| 30 |
#include "heifio/decoder.h" |
| 31 |
#include "heifio/decoder_tiff.h" |
| 32 |
#include "test_utils.h" |
| 33 |
#include "libheif/heif.h" |
| 34 |
#include "libheif/api_structs.h" |
| 35 |
|
| 36 |
#if HAVE_LIBTIFF |
| 37 |
void checkMono(InputImage input_image) { |
| 38 |
REQUIRE(input_image.orientation == heif_orientation_normal); |
| 39 |
REQUIRE(input_image.image != nullptr); |
| 40 |
const heif_image* image = input_image.image.get(); |
| 41 |
REQUIRE(heif_image_get_colorspace(image) == heif_colorspace_monochrome); |
| 42 |
REQUIRE(heif_image_get_chroma_format(image) == heif_chroma_monochrome); |
| 43 |
REQUIRE(heif_image_get_width(image, heif_channel_Y) == 128); |
| 44 |
REQUIRE(heif_image_get_height(image, heif_channel_Y) == 64); |
| 45 |
REQUIRE(heif_image_get_bits_per_pixel(image, heif_channel_Y) == 8); |
| 46 |
REQUIRE(heif_image_get_bits_per_pixel_range(image, heif_channel_Y) == 8); |
| 47 |
REQUIRE(heif_image_has_channel(image, heif_channel_Y) == 1); |
| 48 |
REQUIRE(heif_image_has_channel(image, heif_channel_R) == 0); |
| 49 |
REQUIRE(heif_image_has_channel(image, heif_channel_G) == 0); |
| 50 |
REQUIRE(heif_image_has_channel(image, heif_channel_B) == 0); |
| 51 |
REQUIRE(heif_image_has_channel(image, heif_channel_interleaved) == 0); |
| 52 |
REQUIRE(heif_image_has_channel(image, heif_channel_Cr) == 0); |
| 53 |
REQUIRE(heif_image_has_channel(image, heif_channel_Cb) == 0); |
| 54 |
} |
| 55 |
|
| 56 |
TEST_CASE("mono8") { |
| 57 |
InputImage input_image; |
| 58 |
std::string path = get_path_for_heifio_test_file("mono.tif"); |
| 59 |
heif_error err = loadTIFF(path.c_str(), &input_image); |
| 60 |
REQUIRE(err.code == heif_error_Ok); |
| 61 |
checkMono(input_image); |
| 62 |
} |
| 63 |
|
| 64 |
TEST_CASE("mono8planar") { |
| 65 |
InputImage input_image; |
| 66 |
std::string path = get_path_for_heifio_test_file("mono_planar.tif"); |
| 67 |
heif_error err = loadTIFF(path.c_str(), &input_image); |
| 68 |
REQUIRE(err.code == heif_error_Ok); |
| 69 |
checkMono(input_image); |
| 70 |
} |
| 71 |
|
| 72 |
void checkRGB(InputImage input_image) { |
| 73 |
REQUIRE(input_image.orientation == heif_orientation_normal); |
| 74 |
REQUIRE(input_image.image != nullptr); |
| 75 |
const struct heif_image* image = input_image.image.get(); |
| 76 |
REQUIRE(heif_image_get_colorspace(image) == heif_colorspace_RGB); |
| 77 |
REQUIRE(heif_image_get_chroma_format(image) == heif_chroma_interleaved_RGB); |
| 78 |
REQUIRE(heif_image_get_width(image, heif_channel_interleaved) == 32); |
| 79 |
REQUIRE(heif_image_get_height(image, heif_channel_interleaved) == 10); |
| 80 |
REQUIRE(heif_image_get_bits_per_pixel(image, heif_channel_interleaved) == 24); |
| 81 |
REQUIRE(heif_image_get_bits_per_pixel_range(image, heif_channel_interleaved) == 8); |
| 82 |
REQUIRE(heif_image_has_channel(image, heif_channel_Y) == 0); |
| 83 |
REQUIRE(heif_image_has_channel(image, heif_channel_R) == 0); |
| 84 |
REQUIRE(heif_image_has_channel(image, heif_channel_G) == 0); |
| 85 |
REQUIRE(heif_image_has_channel(image, heif_channel_B) == 0); |
| 86 |
REQUIRE(heif_image_has_channel(image, heif_channel_interleaved) == 1); |
| 87 |
REQUIRE(heif_image_has_channel(image, heif_channel_Cr) == 0); |
| 88 |
REQUIRE(heif_image_has_channel(image, heif_channel_Cb) == 0); |
| 89 |
} |
| 90 |
|
| 91 |
TEST_CASE("rgb") { |
| 92 |
InputImage input_image; |
| 93 |
std::string path = get_path_for_heifio_test_file("rgb.tif"); |
| 94 |
heif_error err = loadTIFF(path.c_str(), &input_image); |
| 95 |
REQUIRE(err.code == heif_error_Ok); |
| 96 |
checkRGB(input_image); |
| 97 |
} |
| 98 |
|
| 99 |
TEST_CASE("rgb_planar") { |
| 100 |
InputImage input_image; |
| 101 |
std::string path = get_path_for_heifio_test_file("rgb_planar.tif"); |
| 102 |
heif_error err = loadTIFF(path.c_str(), &input_image); |
| 103 |
REQUIRE(err.code == heif_error_Ok); |
| 104 |
checkRGB(input_image); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
void checkRGBA(InputImage input_image) { |
| 109 |
REQUIRE(input_image.orientation == heif_orientation_normal); |
| 110 |
REQUIRE(input_image.image != nullptr); |
| 111 |
const heif_image* image = input_image.image.get(); |
| 112 |
REQUIRE(heif_image_get_colorspace(image) == heif_colorspace_RGB); |
| 113 |
REQUIRE(heif_image_get_chroma_format(image) == heif_chroma_interleaved_RGBA); |
| 114 |
REQUIRE(heif_image_get_width(image, heif_channel_interleaved) == 32); |
| 115 |
REQUIRE(heif_image_get_height(image, heif_channel_interleaved) == 10); |
| 116 |
REQUIRE(heif_image_get_bits_per_pixel(image, heif_channel_interleaved) == 32); |
| 117 |
REQUIRE(heif_image_get_bits_per_pixel_range(image, heif_channel_interleaved) == 8); |
| 118 |
REQUIRE(heif_image_has_channel(image, heif_channel_Y) == 0); |
| 119 |
REQUIRE(heif_image_has_channel(image, heif_channel_R) == 0); |
| 120 |
REQUIRE(heif_image_has_channel(image, heif_channel_G) == 0); |
| 121 |
REQUIRE(heif_image_has_channel(image, heif_channel_B) == 0); |
| 122 |
REQUIRE(heif_image_has_channel(image, heif_channel_interleaved) == 1); |
| 123 |
REQUIRE(heif_image_has_channel(image, heif_channel_Cr) == 0); |
| 124 |
REQUIRE(heif_image_has_channel(image, heif_channel_Cb) == 0); |
| 125 |
} |
| 126 |
|
| 127 |
TEST_CASE("rgba") { |
| 128 |
InputImage input_image; |
| 129 |
std::string path = get_path_for_heifio_test_file("rgba.tif"); |
| 130 |
heif_error err = loadTIFF(path.c_str(), &input_image); |
| 131 |
REQUIRE(err.code == heif_error_Ok); |
| 132 |
checkRGBA(input_image); |
| 133 |
} |
| 134 |
|
| 135 |
TEST_CASE("rgba_planar") { |
| 136 |
InputImage input_image; |
| 137 |
std::string path = get_path_for_heifio_test_file("rgba_planar.tif"); |
| 138 |
heif_error err = loadTIFF(path.c_str(), &input_image); |
| 139 |
REQUIRE(err.code == heif_error_Ok); |
| 140 |
checkRGBA(input_image); |
| 141 |
} |
| 142 |
#else |
| 143 |
TEST_CASE("no_tiff dummy") { |
| 144 |
// Dummy test if we don't have the TIFF library, so that testing does not fail with "No test ran". |
| 145 |
} |
| 146 |
#endif // HAVE_LIBTIFF |