| 1 |
/* |
| 2 |
libheif integration tests for uncompressed decoder |
| 3 |
|
| 4 |
MIT License |
| 5 |
|
| 6 |
Copyright (c) 2023 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 |
#include "catch_amalgamated.hpp" |
| 27 |
#include "libheif/heif.h" |
| 28 |
#include "api_structs.h" |
| 29 |
#include <cstdint> |
| 30 |
#include <stdio.h> |
| 31 |
#include "test_utils.h" |
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
#include "uncompressed_decode.h" |
| 35 |
|
| 36 |
|
| 37 |
void check_image_size_mono(struct heif_context *&context, int expect_alpha) { |
| 38 |
heif_image_handle *handle = get_primary_image_handle(context); |
| 39 |
heif_image *img = get_primary_image_mono(handle); |
| 40 |
|
| 41 |
REQUIRE(heif_image_has_channel(img, heif_channel_Y) == 1); |
| 42 |
REQUIRE(heif_image_has_channel(img, heif_channel_Cb) == 0); |
| 43 |
REQUIRE(heif_image_has_channel(img, heif_channel_Cr) == 0); |
| 44 |
REQUIRE(heif_image_has_channel(img, heif_channel_R) == 0); |
| 45 |
REQUIRE(heif_image_has_channel(img, heif_channel_G) == 0); |
| 46 |
REQUIRE(heif_image_has_channel(img, heif_channel_B) == 0); |
| 47 |
REQUIRE(heif_image_has_channel(img, heif_channel_Alpha) == expect_alpha); |
| 48 |
REQUIRE(heif_image_has_channel(img, heif_channel_interleaved) == 0); |
| 49 |
int width = heif_image_get_primary_width(img); |
| 50 |
REQUIRE(width == 30); |
| 51 |
int height = heif_image_get_primary_height(img); |
| 52 |
REQUIRE(height == 20); |
| 53 |
width = heif_image_get_width(img, heif_channel_Y); |
| 54 |
REQUIRE(width == 30); |
| 55 |
height = heif_image_get_height(img, heif_channel_Y); |
| 56 |
REQUIRE(height == 20); |
| 57 |
if (expect_alpha == 1) { |
| 58 |
width = heif_image_get_width(img, heif_channel_Alpha); |
| 59 |
REQUIRE(width == 30); |
| 60 |
height = heif_image_get_height(img, heif_channel_Alpha); |
| 61 |
REQUIRE(height == 20); |
| 62 |
} |
| 63 |
|
| 64 |
int pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_Y); |
| 65 |
REQUIRE(pixel_depth == 8); |
| 66 |
|
| 67 |
int pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_Y); |
| 68 |
REQUIRE(pixel_range == 8); |
| 69 |
|
| 70 |
heif_image_release(img); |
| 71 |
heif_image_handle_release(handle); |
| 72 |
} |
| 73 |
|
| 74 |
TEST_CASE("check image size mono") { |
| 75 |
auto file = GENERATE(MONO_FILES); |
| 76 |
auto context = get_context_for_test_file(file); |
| 77 |
INFO("file name: " << file); |
| 78 |
int expect_alpha = (strchr(file, 'A') == NULL) ? 0 : 1; |
| 79 |
check_image_size_mono(context, expect_alpha); |
| 80 |
heif_context_free(context); |
| 81 |
} |
| 82 |
|
| 83 |
void check_image_content_mono(struct heif_context *&context) { |
| 84 |
heif_image_handle *handle = get_primary_image_handle(context); |
| 85 |
REQUIRE(handle != nullptr); |
| 86 |
heif_image *img = get_primary_image_mono(handle); |
| 87 |
|
| 88 |
int stride; |
| 89 |
const uint8_t *img_plane = |
| 90 |
heif_image_get_plane_readonly(img, heif_channel_Y, &stride); |
| 91 |
REQUIRE(stride == 64); |
| 92 |
for (int row = 0; row < 4; row++) { |
| 93 |
INFO("row: " << row); |
| 94 |
REQUIRE(((int)(img_plane[stride * row + 0])) == 255); |
| 95 |
REQUIRE(((int)(img_plane[stride * row + 3])) == 255); |
| 96 |
REQUIRE(((int)(img_plane[stride * row + 4])) == 0); |
| 97 |
REQUIRE(((int)(img_plane[stride * row + 7])) == 0); |
| 98 |
REQUIRE(((int)(img_plane[stride * row + 8])) == 0); |
| 99 |
REQUIRE(((int)(img_plane[stride * row + 11])) == 0); |
| 100 |
REQUIRE(((int)(img_plane[stride * row + 12])) == 255); |
| 101 |
REQUIRE(((int)(img_plane[stride * row + 15])) == 255); |
| 102 |
REQUIRE(((int)(img_plane[stride * row + 16])) == 0); |
| 103 |
REQUIRE(((int)(img_plane[stride * row + 19])) == 0); |
| 104 |
REQUIRE(((int)(img_plane[stride * row + 20])) == 255); |
| 105 |
REQUIRE(((int)(img_plane[stride * row + 23])) == 255); |
| 106 |
REQUIRE(((int)(img_plane[stride * row + 24])) == 0); |
| 107 |
REQUIRE(((int)(img_plane[stride * row + 27])) == 0); |
| 108 |
REQUIRE(((int)(img_plane[stride * row + 28])) == 128); |
| 109 |
REQUIRE(((int)(img_plane[stride * row + 29])) == 128); |
| 110 |
} |
| 111 |
for (int row = 4; row < 8; row++) { |
| 112 |
INFO("row: " << row); |
| 113 |
REQUIRE(((int)(img_plane[stride * row + 0])) == 0); |
| 114 |
REQUIRE(((int)(img_plane[stride * row + 3])) == 0); |
| 115 |
REQUIRE(((int)(img_plane[stride * row + 4])) == 0); |
| 116 |
REQUIRE(((int)(img_plane[stride * row + 7])) == 0); |
| 117 |
REQUIRE(((int)(img_plane[stride * row + 8])) == 255); |
| 118 |
REQUIRE(((int)(img_plane[stride * row + 11])) == 255); |
| 119 |
REQUIRE(((int)(img_plane[stride * row + 12])) == 0); |
| 120 |
REQUIRE(((int)(img_plane[stride * row + 15])) == 0); |
| 121 |
REQUIRE(((int)(img_plane[stride * row + 16])) == 255); |
| 122 |
REQUIRE(((int)(img_plane[stride * row + 19])) == 255); |
| 123 |
REQUIRE(((int)(img_plane[stride * row + 20])) == 0); |
| 124 |
REQUIRE(((int)(img_plane[stride * row + 23])) == 0); |
| 125 |
REQUIRE(((int)(img_plane[stride * row + 24])) == 128); |
| 126 |
REQUIRE(((int)(img_plane[stride * row + 27])) == 128); |
| 127 |
REQUIRE(((int)(img_plane[stride * row + 28])) == 255); |
| 128 |
REQUIRE(((int)(img_plane[stride * row + 29])) == 255); |
| 129 |
} |
| 130 |
for (int row = 8; row < 12; row++) { |
| 131 |
INFO("row: " << row); |
| 132 |
REQUIRE(((int)(img_plane[stride * row + 0])) == 0); |
| 133 |
REQUIRE(((int)(img_plane[stride * row + 3])) == 0); |
| 134 |
REQUIRE(((int)(img_plane[stride * row + 4])) == 255); |
| 135 |
REQUIRE(((int)(img_plane[stride * row + 7])) == 255); |
| 136 |
REQUIRE(((int)(img_plane[stride * row + 8])) == 0); |
| 137 |
REQUIRE(((int)(img_plane[stride * row + 11])) == 0); |
| 138 |
REQUIRE(((int)(img_plane[stride * row + 12])) == 255); |
| 139 |
REQUIRE(((int)(img_plane[stride * row + 15])) == 255); |
| 140 |
REQUIRE(((int)(img_plane[stride * row + 16])) == 0); |
| 141 |
REQUIRE(((int)(img_plane[stride * row + 19])) == 0); |
| 142 |
REQUIRE(((int)(img_plane[stride * row + 20])) == 128); |
| 143 |
REQUIRE(((int)(img_plane[stride * row + 23])) == 128); |
| 144 |
REQUIRE(((int)(img_plane[stride * row + 24])) == 255); |
| 145 |
REQUIRE(((int)(img_plane[stride * row + 27])) == 255); |
| 146 |
REQUIRE(((int)(img_plane[stride * row + 28])) == 238); |
| 147 |
REQUIRE(((int)(img_plane[stride * row + 29])) == 238); |
| 148 |
} |
| 149 |
for (int row = 12; row < 16; row++) { |
| 150 |
INFO("row: " << row); |
| 151 |
REQUIRE(((int)(img_plane[stride * row + 0])) == 255); |
| 152 |
REQUIRE(((int)(img_plane[stride * row + 3])) == 255); |
| 153 |
REQUIRE(((int)(img_plane[stride * row + 4])) == 0); |
| 154 |
REQUIRE(((int)(img_plane[stride * row + 7])) == 0); |
| 155 |
REQUIRE(((int)(img_plane[stride * row + 8])) == 255); |
| 156 |
REQUIRE(((int)(img_plane[stride * row + 11])) == 255); |
| 157 |
REQUIRE(((int)(img_plane[stride * row + 12])) == 0); |
| 158 |
REQUIRE(((int)(img_plane[stride * row + 15])) == 0); |
| 159 |
REQUIRE(((int)(img_plane[stride * row + 16])) == 128); |
| 160 |
REQUIRE(((int)(img_plane[stride * row + 19])) == 128); |
| 161 |
REQUIRE(((int)(img_plane[stride * row + 20])) == 255); |
| 162 |
REQUIRE(((int)(img_plane[stride * row + 23])) == 255); |
| 163 |
REQUIRE(((int)(img_plane[stride * row + 24])) == 238); |
| 164 |
REQUIRE(((int)(img_plane[stride * row + 27])) == 238); |
| 165 |
REQUIRE(((int)(img_plane[stride * row + 28])) == 255); |
| 166 |
REQUIRE(((int)(img_plane[stride * row + 29])) == 255); |
| 167 |
} |
| 168 |
for (int row = 16; row < 20; row++) { |
| 169 |
INFO("row: " << row); |
| 170 |
REQUIRE(((int)(img_plane[stride * row + 0])) == 0); |
| 171 |
REQUIRE(((int)(img_plane[stride * row + 3])) == 0); |
| 172 |
REQUIRE(((int)(img_plane[stride * row + 4])) == 255); |
| 173 |
REQUIRE(((int)(img_plane[stride * row + 7])) == 255); |
| 174 |
REQUIRE(((int)(img_plane[stride * row + 8])) == 0); |
| 175 |
REQUIRE(((int)(img_plane[stride * row + 9])) == 0); |
| 176 |
REQUIRE(((int)(img_plane[stride * row + 12])) == 128); |
| 177 |
REQUIRE(((int)(img_plane[stride * row + 15])) == 128); |
| 178 |
REQUIRE(((int)(img_plane[stride * row + 16])) == 255); |
| 179 |
REQUIRE(((int)(img_plane[stride * row + 19])) == 255); |
| 180 |
REQUIRE(((int)(img_plane[stride * row + 20])) == 238); |
| 181 |
REQUIRE(((int)(img_plane[stride * row + 23])) == 238); |
| 182 |
REQUIRE(((int)(img_plane[stride * row + 24])) == 255); |
| 183 |
REQUIRE(((int)(img_plane[stride * row + 27])) == 255); |
| 184 |
REQUIRE(((int)(img_plane[stride * row + 28])) == 0); |
| 185 |
REQUIRE(((int)(img_plane[stride * row + 29])) == 0); |
| 186 |
} |
| 187 |
|
| 188 |
heif_image_handle_release(handle); |
| 189 |
heif_image_release(img); |
| 190 |
} |
| 191 |
|
| 192 |
TEST_CASE("check image content mono") { |
| 193 |
auto file = GENERATE(MONO_FILES); |
| 194 |
auto context = get_context_for_test_file(file); |
| 195 |
INFO("file name: " << file); |
| 196 |
check_image_content_mono(context); |
| 197 |
heif_context_free(context); |
| 198 |
} |
| 199 |
|