Debian Codegraph @

tests/uncompressed_decode_ycbcr420.cc

raw
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_ycbcr_420(heif_context *&context) {
38 heif_image_handle *handle = get_primary_image_handle(context);
39 heif_image *img = get_primary_image_ycbcr(handle, heif_chroma_420);
40
41 REQUIRE(heif_image_has_channel(img, heif_channel_Y) == 1);
42 REQUIRE(heif_image_has_channel(img, heif_channel_Cb) == 1);
43 REQUIRE(heif_image_has_channel(img, heif_channel_Cr) == 1);
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) == 0);
48 REQUIRE(heif_image_has_channel(img, heif_channel_interleaved) == 0);
49 int width = heif_image_get_primary_width(img);
50 REQUIRE(width == 32);
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 == 32);
55 height = heif_image_get_height(img, heif_channel_Y);
56 REQUIRE(height == 20);
57 width = heif_image_get_width(img, heif_channel_Cb);
58 REQUIRE(width == 16);
59 height = heif_image_get_height(img, heif_channel_Cr);
60 REQUIRE(height == 10);
61 width = heif_image_get_width(img, heif_channel_Cr);
62 REQUIRE(width == 16);
63 height = heif_image_get_height(img, heif_channel_Cr);
64 REQUIRE(height == 10);
65
66 int pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_Y);
67 REQUIRE(pixel_depth == 8);
68 pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_Cb);
69 REQUIRE(pixel_depth == 8);
70 pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_Cr);
71 REQUIRE(pixel_depth == 8);
72 int pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_Y);
73 REQUIRE(pixel_range == 8);
74 pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_Cb);
75 REQUIRE(pixel_range == 8);
76 pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_Cr);
77 REQUIRE(pixel_range == 8);
78
79 heif_image_release(img);
80 heif_image_handle_release(handle);
81 }
82
83 TEST_CASE("check image size YCbCr 4:2:0") {
84 auto file = GENERATE(YUV_420_FILES);
85 auto context = get_context_for_test_file(file);
86 INFO("file name: " << file);
87 check_image_size_ycbcr_420(context);
88 heif_context_free(context);
89 }
90
91
92 void check_image_size_ycbcr_420_16bit(heif_context *&context) {
93 heif_image_handle *handle = get_primary_image_handle(context);
94 heif_image *img = get_primary_image_ycbcr(handle, heif_chroma_420);
95
96 REQUIRE(heif_image_has_channel(img, heif_channel_Y) == 1);
97 REQUIRE(heif_image_has_channel(img, heif_channel_Cb) == 1);
98 REQUIRE(heif_image_has_channel(img, heif_channel_Cr) == 1);
99 REQUIRE(heif_image_has_channel(img, heif_channel_R) == 0);
100 REQUIRE(heif_image_has_channel(img, heif_channel_G) == 0);
101 REQUIRE(heif_image_has_channel(img, heif_channel_B) == 0);
102 REQUIRE(heif_image_has_channel(img, heif_channel_Alpha) == 0);
103 REQUIRE(heif_image_has_channel(img, heif_channel_interleaved) == 0);
104 int width = heif_image_get_primary_width(img);
105 REQUIRE(width == 32);
106 int height = heif_image_get_primary_height(img);
107 REQUIRE(height == 20);
108 width = heif_image_get_width(img, heif_channel_Y);
109 REQUIRE(width == 32);
110 height = heif_image_get_height(img, heif_channel_Y);
111 REQUIRE(height == 20);
112 width = heif_image_get_width(img, heif_channel_Cb);
113 REQUIRE(width == 16);
114 height = heif_image_get_height(img, heif_channel_Cr);
115 REQUIRE(height == 10);
116 width = heif_image_get_width(img, heif_channel_Cr);
117 REQUIRE(width == 16);
118 height = heif_image_get_height(img, heif_channel_Cr);
119 REQUIRE(height == 10);
120
121 int pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_Y);
122 REQUIRE(pixel_depth == 16);
123 pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_Cb);
124 REQUIRE(pixel_depth == 16);
125 pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_Cr);
126 REQUIRE(pixel_depth == 16);
127 int pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_Y);
128 REQUIRE(pixel_range == 16);
129 pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_Cb);
130 REQUIRE(pixel_range == 16);
131 pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_Cr);
132 REQUIRE(pixel_range == 16);
133
134 heif_image_release(img);
135 heif_image_handle_release(handle);
136 }
137
138 TEST_CASE("check image size YCbCr 4:2:0 16 bit") {
139 auto file = GENERATE(YUV_16BIT_420_FILES);
140 auto context = get_context_for_test_file(file);
141 INFO("file name: " << file);
142 check_image_size_ycbcr_420_16bit(context);
143 heif_context_free(context);
144 }
145
146 void check_image_content_ycbcr420(heif_context *&context) {
147 heif_image_handle *handle = get_primary_image_handle(context);
148 heif_image *img = get_primary_image_ycbcr(handle, heif_chroma_420);
149
150 int stride;
151 const uint8_t *img_plane =
152 heif_image_get_plane_readonly(img, heif_channel_Y, &stride);
153 REQUIRE(stride == 64);
154 for (int row = 0; row < 4; row++) {
155 INFO("row: " << row);
156 REQUIRE(((int)(img_plane[stride * row + 0])) == 76);
157 REQUIRE(((int)(img_plane[stride * row + 3])) == 76);
158 REQUIRE(((int)(img_plane[stride * row + 4])) == 75);
159 REQUIRE(((int)(img_plane[stride * row + 7])) == 75);
160 REQUIRE(((int)(img_plane[stride * row + 8])) == 29);
161 REQUIRE(((int)(img_plane[stride * row + 11])) == 29);
162 REQUIRE(((int)(img_plane[stride * row + 12])) == 254);
163 REQUIRE(((int)(img_plane[stride * row + 15])) == 254);
164 REQUIRE(((int)(img_plane[stride * row + 16])) == 0);
165 REQUIRE(((int)(img_plane[stride * row + 19])) == 0);
166 REQUIRE(((int)(img_plane[stride * row + 20])) == 225);
167 REQUIRE(((int)(img_plane[stride * row + 23])) == 225);
168 REQUIRE(((int)(img_plane[stride * row + 24])) == 178);
169 REQUIRE(((int)(img_plane[stride * row + 27])) == 178);
170 REQUIRE(((int)(img_plane[stride * row + 28])) == 128);
171 REQUIRE(((int)(img_plane[stride * row + 29])) == 128);
172 }
173 for (int row = 4; row < 8; row++) {
174 INFO("row: " << row);
175 REQUIRE(((int)(img_plane[stride * row + 0])) == 75);
176 REQUIRE(((int)(img_plane[stride * row + 3])) == 75);
177 REQUIRE(((int)(img_plane[stride * row + 4])) == 29);
178 REQUIRE(((int)(img_plane[stride * row + 7])) == 29);
179 REQUIRE(((int)(img_plane[stride * row + 8])) == 254);
180 REQUIRE(((int)(img_plane[stride * row + 11])) == 254);
181 REQUIRE(((int)(img_plane[stride * row + 12])) == 0);
182 REQUIRE(((int)(img_plane[stride * row + 15])) == 0);
183 REQUIRE(((int)(img_plane[stride * row + 16])) == 225);
184 REQUIRE(((int)(img_plane[stride * row + 19])) == 225);
185 REQUIRE(((int)(img_plane[stride * row + 20])) == 178);
186 REQUIRE(((int)(img_plane[stride * row + 23])) == 178);
187 REQUIRE(((int)(img_plane[stride * row + 24])) == 128);
188 REQUIRE(((int)(img_plane[stride * row + 27])) == 128);
189 REQUIRE(((int)(img_plane[stride * row + 28])) == 173);
190 REQUIRE(((int)(img_plane[stride * row + 29])) == 173);
191 }
192 for (int row = 8; row < 12; row++) {
193 INFO("row: " << row);
194 REQUIRE(((int)(img_plane[stride * row + 0])) == 29);
195 REQUIRE(((int)(img_plane[stride * row + 3])) == 29);
196 REQUIRE(((int)(img_plane[stride * row + 4])) == 254);
197 REQUIRE(((int)(img_plane[stride * row + 7])) == 254);
198 REQUIRE(((int)(img_plane[stride * row + 8])) == 0);
199 REQUIRE(((int)(img_plane[stride * row + 11])) == 0);
200 REQUIRE(((int)(img_plane[stride * row + 12])) == 225);
201 REQUIRE(((int)(img_plane[stride * row + 15])) == 225);
202 REQUIRE(((int)(img_plane[stride * row + 16])) == 178);
203 REQUIRE(((int)(img_plane[stride * row + 19])) == 178);
204 REQUIRE(((int)(img_plane[stride * row + 20])) == 128);
205 REQUIRE(((int)(img_plane[stride * row + 23])) == 128);
206 REQUIRE(((int)(img_plane[stride * row + 24])) == 173);
207 REQUIRE(((int)(img_plane[stride * row + 27])) == 173);
208 REQUIRE(((int)(img_plane[stride * row + 28])) == 174);
209 REQUIRE(((int)(img_plane[stride * row + 29])) == 174);
210 }
211 for (int row = 12; row < 16; row++) {
212 INFO("row: " << row);
213 REQUIRE(((int)(img_plane[stride * row + 0])) == 254);
214 REQUIRE(((int)(img_plane[stride * row + 3])) == 254);
215 REQUIRE(((int)(img_plane[stride * row + 4])) == 0);
216 REQUIRE(((int)(img_plane[stride * row + 7])) == 0);
217 REQUIRE(((int)(img_plane[stride * row + 8])) == 225);
218 REQUIRE(((int)(img_plane[stride * row + 11])) == 225);
219 REQUIRE(((int)(img_plane[stride * row + 12])) == 178);
220 REQUIRE(((int)(img_plane[stride * row + 15])) == 178);
221 REQUIRE(((int)(img_plane[stride * row + 16])) == 128);
222 REQUIRE(((int)(img_plane[stride * row + 19])) == 128);
223 REQUIRE(((int)(img_plane[stride * row + 20])) == 173);
224 REQUIRE(((int)(img_plane[stride * row + 23])) == 173);
225 REQUIRE(((int)(img_plane[stride * row + 24])) == 174);
226 REQUIRE(((int)(img_plane[stride * row + 27])) == 174);
227 REQUIRE(((int)(img_plane[stride * row + 28])) == 76);
228 REQUIRE(((int)(img_plane[stride * row + 29])) == 76);
229 }
230 for (int row = 16; row < 20; row++) {
231 INFO("row: " << row);
232 REQUIRE(((int)(img_plane[stride * row + 0])) == 0);
233 REQUIRE(((int)(img_plane[stride * row + 3])) == 0);
234 REQUIRE(((int)(img_plane[stride * row + 4])) == 225);
235 REQUIRE(((int)(img_plane[stride * row + 7])) == 225);
236 REQUIRE(((int)(img_plane[stride * row + 8])) == 178);
237 REQUIRE(((int)(img_plane[stride * row + 9])) == 178);
238 REQUIRE(((int)(img_plane[stride * row + 12])) == 128);
239 REQUIRE(((int)(img_plane[stride * row + 15])) == 128);
240 REQUIRE(((int)(img_plane[stride * row + 16])) == 173);
241 REQUIRE(((int)(img_plane[stride * row + 19])) == 173);
242 REQUIRE(((int)(img_plane[stride * row + 20])) == 174);
243 REQUIRE(((int)(img_plane[stride * row + 23])) == 174);
244 REQUIRE(((int)(img_plane[stride * row + 24])) == 76);
245 REQUIRE(((int)(img_plane[stride * row + 27])) == 76);
246 REQUIRE(((int)(img_plane[stride * row + 28])) == 75);
247 REQUIRE(((int)(img_plane[stride * row + 29])) == 75);
248 }
249 img_plane = heif_image_get_plane_readonly(img, heif_channel_Cb, &stride);
250 REQUIRE(stride == 64);
251 for (int row = 0; row < 2; row++) {
252 INFO("row: " << row);
253 REQUIRE(((int)(img_plane[stride * row + 0])) == 84);
254 REQUIRE(((int)(img_plane[stride * row + 1])) == 84);
255 REQUIRE(((int)(img_plane[stride * row + 2])) == 85);
256 REQUIRE(((int)(img_plane[stride * row + 3])) == 85);
257 REQUIRE(((int)(img_plane[stride * row + 4])) == 254);
258 REQUIRE(((int)(img_plane[stride * row + 5])) == 254);
259 REQUIRE(((int)(img_plane[stride * row + 6])) == 127);
260 REQUIRE(((int)(img_plane[stride * row + 7])) == 127);
261 REQUIRE(((int)(img_plane[stride * row + 8])) == 127);
262 REQUIRE(((int)(img_plane[stride * row + 9])) == 127);
263 REQUIRE(((int)(img_plane[stride * row + 10])) == 0);
264 REQUIRE(((int)(img_plane[stride * row + 11])) == 0);
265 REQUIRE(((int)(img_plane[stride * row + 12])) == 170);
266 REQUIRE(((int)(img_plane[stride * row + 13])) == 170);
267 REQUIRE(((int)(img_plane[stride * row + 14])) == 127);
268 REQUIRE(((int)(img_plane[stride * row + 15])) == 127);
269 }
270 for (int row = 2; row < 4; row++) {
271 INFO("row: " << row);
272 REQUIRE(((int)(img_plane[stride * row + 0])) == 85);
273 REQUIRE(((int)(img_plane[stride * row + 1])) == 85);
274 REQUIRE(((int)(img_plane[stride * row + 2])) == 254);
275 REQUIRE(((int)(img_plane[stride * row + 3])) == 254);
276 REQUIRE(((int)(img_plane[stride * row + 4])) == 127);
277 REQUIRE(((int)(img_plane[stride * row + 5])) == 127);
278 REQUIRE(((int)(img_plane[stride * row + 6])) == 127);
279 REQUIRE(((int)(img_plane[stride * row + 7])) == 127);
280 REQUIRE(((int)(img_plane[stride * row + 8])) == 0);
281 REQUIRE(((int)(img_plane[stride * row + 9])) == 0);
282 REQUIRE(((int)(img_plane[stride * row + 10])) == 170);
283 REQUIRE(((int)(img_plane[stride * row + 11])) == 170);
284 REQUIRE(((int)(img_plane[stride * row + 12])) == 127);
285 REQUIRE(((int)(img_plane[stride * row + 13])) == 127);
286 REQUIRE(((int)(img_plane[stride * row + 14])) == 29);
287 REQUIRE(((int)(img_plane[stride * row + 15])) == 29);
288 }
289 for (int row = 4; row < 6; row++) {
290 INFO("row: " << row);
291 REQUIRE(((int)(img_plane[stride * row + 0])) == 254);
292 REQUIRE(((int)(img_plane[stride * row + 1])) == 254);
293 REQUIRE(((int)(img_plane[stride * row + 2])) == 127);
294 REQUIRE(((int)(img_plane[stride * row + 3])) == 127);
295 REQUIRE(((int)(img_plane[stride * row + 4])) == 127);
296 REQUIRE(((int)(img_plane[stride * row + 5])) == 127);
297 REQUIRE(((int)(img_plane[stride * row + 6])) == 0);
298 REQUIRE(((int)(img_plane[stride * row + 7])) == 0);
299 REQUIRE(((int)(img_plane[stride * row + 8])) == 170);
300 REQUIRE(((int)(img_plane[stride * row + 9])) == 170);
301 REQUIRE(((int)(img_plane[stride * row + 10])) == 127);
302 REQUIRE(((int)(img_plane[stride * row + 11])) == 127);
303 REQUIRE(((int)(img_plane[stride * row + 12])) == 29);
304 REQUIRE(((int)(img_plane[stride * row + 13])) == 29);
305 REQUIRE(((int)(img_plane[stride * row + 14])) == 163);
306 REQUIRE(((int)(img_plane[stride * row + 15])) == 163);
307 }
308 for (int row = 6; row < 8; row++) {
309 INFO("row: " << row);
310 REQUIRE(((int)(img_plane[stride * row + 0])) == 127);
311 REQUIRE(((int)(img_plane[stride * row + 1])) == 127);
312 REQUIRE(((int)(img_plane[stride * row + 2])) == 127);
313 REQUIRE(((int)(img_plane[stride * row + 3])) == 127);
314 REQUIRE(((int)(img_plane[stride * row + 4])) == 0);
315 REQUIRE(((int)(img_plane[stride * row + 5])) == 0);
316 REQUIRE(((int)(img_plane[stride * row + 6])) == 170);
317 REQUIRE(((int)(img_plane[stride * row + 7])) == 170);
318 REQUIRE(((int)(img_plane[stride * row + 8])) == 127);
319 REQUIRE(((int)(img_plane[stride * row + 9])) == 127);
320 REQUIRE(((int)(img_plane[stride * row + 10])) == 29);
321 REQUIRE(((int)(img_plane[stride * row + 11])) == 29);
322 REQUIRE(((int)(img_plane[stride * row + 12])) == 163);
323 REQUIRE(((int)(img_plane[stride * row + 13])) == 163);
324 REQUIRE(((int)(img_plane[stride * row + 14])) == 84);
325 REQUIRE(((int)(img_plane[stride * row + 15])) == 84);
326 }
327 for (int row = 8; row < 10; row++) {
328 INFO("row: " << row);
329 REQUIRE(((int)(img_plane[stride * row + 0])) == 127);
330 REQUIRE(((int)(img_plane[stride * row + 1])) == 127);
331 REQUIRE(((int)(img_plane[stride * row + 2])) == 0);
332 REQUIRE(((int)(img_plane[stride * row + 3])) == 0);
333 REQUIRE(((int)(img_plane[stride * row + 4])) == 170);
334 REQUIRE(((int)(img_plane[stride * row + 5])) == 170);
335 REQUIRE(((int)(img_plane[stride * row + 6])) == 127);
336 REQUIRE(((int)(img_plane[stride * row + 7])) == 127);
337 REQUIRE(((int)(img_plane[stride * row + 8])) == 29);
338 REQUIRE(((int)(img_plane[stride * row + 9])) == 29);
339 REQUIRE(((int)(img_plane[stride * row + 10])) == 163);
340 REQUIRE(((int)(img_plane[stride * row + 11])) == 163);
341 REQUIRE(((int)(img_plane[stride * row + 12])) == 84);
342 REQUIRE(((int)(img_plane[stride * row + 13])) == 84);
343 REQUIRE(((int)(img_plane[stride * row + 14])) == 85);
344 REQUIRE(((int)(img_plane[stride * row + 15])) == 85);
345 }
346 img_plane = heif_image_get_plane_readonly(img, heif_channel_Cr, &stride);
347 REQUIRE(stride == 64);
348 for (int row = 0; row < 2; row++) {
349 INFO("row: " << row);
350 REQUIRE(((int)(img_plane[stride * row + 0])) == 254);
351 REQUIRE(((int)(img_plane[stride * row + 1])) == 254);
352 REQUIRE(((int)(img_plane[stride * row + 2])) == 73);
353 REQUIRE(((int)(img_plane[stride * row + 3])) == 73);
354 REQUIRE(((int)(img_plane[stride * row + 4])) == 106);
355 REQUIRE(((int)(img_plane[stride * row + 5])) == 106);
356 REQUIRE(((int)(img_plane[stride * row + 6])) == 127);
357 REQUIRE(((int)(img_plane[stride * row + 7])) == 127);
358 REQUIRE(((int)(img_plane[stride * row + 8])) == 127);
359 REQUIRE(((int)(img_plane[stride * row + 9])) == 127);
360 REQUIRE(((int)(img_plane[stride * row + 10])) == 148);
361 REQUIRE(((int)(img_plane[stride * row + 11])) == 148);
362 REQUIRE(((int)(img_plane[stride * row + 12])) == 0);
363 REQUIRE(((int)(img_plane[stride * row + 13])) == 0);
364 REQUIRE(((int)(img_plane[stride * row + 14])) == 127);
365 REQUIRE(((int)(img_plane[stride * row + 15])) == 127);
366 }
367 for (int row = 2; row < 4; row++) {
368 INFO("row: " << row);
369 REQUIRE(((int)(img_plane[stride * row + 0])) == 73);
370 REQUIRE(((int)(img_plane[stride * row + 1])) == 73);
371 REQUIRE(((int)(img_plane[stride * row + 2])) == 106);
372 REQUIRE(((int)(img_plane[stride * row + 3])) == 106);
373 REQUIRE(((int)(img_plane[stride * row + 4])) == 127);
374 REQUIRE(((int)(img_plane[stride * row + 5])) == 127);
375 REQUIRE(((int)(img_plane[stride * row + 6])) == 127);
376 REQUIRE(((int)(img_plane[stride * row + 7])) == 127);
377 REQUIRE(((int)(img_plane[stride * row + 8])) == 148);
378 REQUIRE(((int)(img_plane[stride * row + 9])) == 148);
379 REQUIRE(((int)(img_plane[stride * row + 10])) == 0);
380 REQUIRE(((int)(img_plane[stride * row + 11])) == 0);
381 REQUIRE(((int)(img_plane[stride * row + 12])) == 127);
382 REQUIRE(((int)(img_plane[stride * row + 13])) == 127);
383 REQUIRE(((int)(img_plane[stride * row + 14])) == 185);
384 REQUIRE(((int)(img_plane[stride * row + 15])) == 185);
385 }
386 for (int row = 4; row < 6; row++) {
387 INFO("row: " << row);
388 REQUIRE(((int)(img_plane[stride * row + 0])) == 106);
389 REQUIRE(((int)(img_plane[stride * row + 1])) == 106);
390 REQUIRE(((int)(img_plane[stride * row + 2])) == 127);
391 REQUIRE(((int)(img_plane[stride * row + 3])) == 127);
392 REQUIRE(((int)(img_plane[stride * row + 4])) == 127);
393 REQUIRE(((int)(img_plane[stride * row + 5])) == 127);
394 REQUIRE(((int)(img_plane[stride * row + 6])) == 148);
395 REQUIRE(((int)(img_plane[stride * row + 7])) == 148);
396 REQUIRE(((int)(img_plane[stride * row + 8])) == 0);
397 REQUIRE(((int)(img_plane[stride * row + 9])) == 0);
398 REQUIRE(((int)(img_plane[stride * row + 10])) == 127);
399 REQUIRE(((int)(img_plane[stride * row + 11])) == 127);
400 REQUIRE(((int)(img_plane[stride * row + 12])) == 185);
401 REQUIRE(((int)(img_plane[stride * row + 13])) == 185);
402 REQUIRE(((int)(img_plane[stride * row + 14])) == 172);
403 REQUIRE(((int)(img_plane[stride * row + 15])) == 172);
404 }
405 for (int row = 6; row < 8; row++) {
406 INFO("row: " << row);
407 REQUIRE(((int)(img_plane[stride * row + 0])) == 127);
408 REQUIRE(((int)(img_plane[stride * row + 1])) == 127);
409 REQUIRE(((int)(img_plane[stride * row + 2])) == 127);
410 REQUIRE(((int)(img_plane[stride * row + 3])) == 127);
411 REQUIRE(((int)(img_plane[stride * row + 4])) == 148);
412 REQUIRE(((int)(img_plane[stride * row + 5])) == 148);
413 REQUIRE(((int)(img_plane[stride * row + 6])) == 0);
414 REQUIRE(((int)(img_plane[stride * row + 7])) == 0);
415 REQUIRE(((int)(img_plane[stride * row + 8])) == 127);
416 REQUIRE(((int)(img_plane[stride * row + 9])) == 127);
417 REQUIRE(((int)(img_plane[stride * row + 10])) == 185);
418 REQUIRE(((int)(img_plane[stride * row + 11])) == 185);
419 REQUIRE(((int)(img_plane[stride * row + 12])) == 172);
420 REQUIRE(((int)(img_plane[stride * row + 13])) == 172);
421 REQUIRE(((int)(img_plane[stride * row + 14])) == 254);
422 REQUIRE(((int)(img_plane[stride * row + 15])) == 254);
423 }
424 for (int row = 8; row < 10; row++) {
425 INFO("row: " << row);
426 REQUIRE(((int)(img_plane[stride * row + 0])) == 127);
427 REQUIRE(((int)(img_plane[stride * row + 1])) == 127);
428 REQUIRE(((int)(img_plane[stride * row + 2])) == 148);
429 REQUIRE(((int)(img_plane[stride * row + 3])) == 148);
430 REQUIRE(((int)(img_plane[stride * row + 4])) == 0);
431 REQUIRE(((int)(img_plane[stride * row + 5])) == 0);
432 REQUIRE(((int)(img_plane[stride * row + 6])) == 127);
433 REQUIRE(((int)(img_plane[stride * row + 7])) == 127);
434 REQUIRE(((int)(img_plane[stride * row + 8])) == 185);
435 REQUIRE(((int)(img_plane[stride * row + 9])) == 185);
436 REQUIRE(((int)(img_plane[stride * row + 10])) == 172);
437 REQUIRE(((int)(img_plane[stride * row + 11])) == 172);
438 REQUIRE(((int)(img_plane[stride * row + 12])) == 254);
439 REQUIRE(((int)(img_plane[stride * row + 13])) == 254);
440 REQUIRE(((int)(img_plane[stride * row + 14])) == 73);
441 REQUIRE(((int)(img_plane[stride * row + 15])) == 73);
442 }
443
444 heif_image_release(img);
445 heif_image_handle_release(handle);
446 }
447
448 TEST_CASE("check image content YCbCr 4:2:0") {
449 auto file = GENERATE(YUV_420_FILES);
450 auto context = get_context_for_test_file(file);
451 INFO("file name: " << file);
452 check_image_content_ycbcr420(context);
453 heif_context_free(context);
454 }
455
456 void check_image_content_ycbcr420_16bit(heif_context *&context) {
457 heif_image_handle *handle = get_primary_image_handle(context);
458 heif_image *img = get_primary_image_ycbcr(handle, heif_chroma_420);
459
460 int stride;
461 const uint16_t *img_plane =
462 (const uint16_t*)heif_image_get_plane_readonly(img, heif_channel_Y, &stride);
463 REQUIRE(stride == 128);
464
465 stride /= 2;
466
467 for (int row = 0; row < 4; row++) {
468 INFO("row: " << row);
469 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x4C8A);
470 REQUIRE(((int)(img_plane[stride * row + 1])) == 0x4C8A);
471 REQUIRE(((int)(img_plane[stride * row + 2])) == 0x4C8A);
472 REQUIRE(((int)(img_plane[stride * row + 3])) == 0x4C8A);
473 REQUIRE(((int)(img_plane[stride * row + 4])) == 0x4B6D);
474 REQUIRE(((int)(img_plane[stride * row + 5])) == 0x4B6D);
475 REQUIRE(((int)(img_plane[stride * row + 6])) == 0x4B6D);
476 REQUIRE(((int)(img_plane[stride * row + 7])) == 0x4B6D);
477 REQUIRE(((int)(img_plane[stride * row + 8])) == 0x1D2E);
478 REQUIRE(((int)(img_plane[stride * row + 9])) == 0x1D2E);
479 REQUIRE(((int)(img_plane[stride * row + 10])) == 0x1D2E);
480 REQUIRE(((int)(img_plane[stride * row + 11])) == 0x1D2E);
481 REQUIRE(((int)(img_plane[stride * row + 12])) == 0xFFFE);
482 REQUIRE(((int)(img_plane[stride * row + 13])) == 0xFFFE);
483 REQUIRE(((int)(img_plane[stride * row + 14])) == 0xFFFE);
484 REQUIRE(((int)(img_plane[stride * row + 15])) == 0xFFFE);
485 REQUIRE(((int)(img_plane[stride * row + 16])) == 0x0000);
486 REQUIRE(((int)(img_plane[stride * row + 17])) == 0x0000);
487 REQUIRE(((int)(img_plane[stride * row + 18])) == 0x0000);
488 REQUIRE(((int)(img_plane[stride * row + 19])) == 0x0000);
489 REQUIRE(((int)(img_plane[stride * row + 20])) == 0xE2D0);
490 REQUIRE(((int)(img_plane[stride * row + 21])) == 0xE2D0);
491 REQUIRE(((int)(img_plane[stride * row + 22])) == 0xE2D0);
492 REQUIRE(((int)(img_plane[stride * row + 23])) == 0xE2D0);
493 REQUIRE(((int)(img_plane[stride * row + 24])) == 0xB374);
494 REQUIRE(((int)(img_plane[stride * row + 25])) == 0xB374);
495 REQUIRE(((int)(img_plane[stride * row + 26])) == 0xB374);
496 REQUIRE(((int)(img_plane[stride * row + 27])) == 0xB374);
497 REQUIRE(((int)(img_plane[stride * row + 28])) == 0x8080);
498 REQUIRE(((int)(img_plane[stride * row + 29])) == 0x8080);
499 REQUIRE(((int)(img_plane[stride * row + 30])) == 0x8080);
500 REQUIRE(((int)(img_plane[stride * row + 31])) == 0x8080);
501 }
502 for (int row = 4; row < 8; row++) {
503 INFO("row: " << row);
504 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x4B6D);
505 REQUIRE(((int)(img_plane[stride * row + 2])) == 0x4B6D);
506 REQUIRE(((int)(img_plane[stride * row + 4])) == 0x1D2E);
507 REQUIRE(((int)(img_plane[stride * row + 8])) == 0xFFFE);
508 REQUIRE(((int)(img_plane[stride * row + 12])) == 0x0000);
509 REQUIRE(((int)(img_plane[stride * row + 16])) == 0xE2D0);
510 REQUIRE(((int)(img_plane[stride * row + 20])) == 0xB374);
511 REQUIRE(((int)(img_plane[stride * row + 24])) == 0x8080);
512 REQUIRE(((int)(img_plane[stride * row + 28])) == 0xADC6);
513 }
514 for (int row = 8; row < 12; row++) {
515 INFO("row: " << row);
516 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x1D2E);
517 REQUIRE(((int)(img_plane[stride * row + 4])) == 0xFFFE);
518 REQUIRE(((int)(img_plane[stride * row + 8])) == 0x0000);
519 REQUIRE(((int)(img_plane[stride * row + 12])) == 0xE2D0);
520 REQUIRE(((int)(img_plane[stride * row + 16])) == 0xB374);
521 REQUIRE(((int)(img_plane[stride * row + 20])) == 0x8080);
522 REQUIRE(((int)(img_plane[stride * row + 24])) == 0xADC6);
523 REQUIRE(((int)(img_plane[stride * row + 28])) == 0xAF49);
524 }
525 for (int row = 12; row < 16; row++) {
526 INFO("row: " << row);
527 REQUIRE(((int)(img_plane[stride * row + 0])) == 0xFFFE);
528 REQUIRE(((int)(img_plane[stride * row + 4])) == 0x0000);
529 REQUIRE(((int)(img_plane[stride * row + 8])) == 0xE2D0);
530 REQUIRE(((int)(img_plane[stride * row + 12])) == 0xB374);
531 REQUIRE(((int)(img_plane[stride * row + 16])) == 0x8080);
532 REQUIRE(((int)(img_plane[stride * row + 20])) == 0xADC6);
533 REQUIRE(((int)(img_plane[stride * row + 24])) == 0xAF49);
534 REQUIRE(((int)(img_plane[stride * row + 28])) == 0x4C8A);
535 }
536 for (int row = 16; row < 20; row++) {
537 INFO("row: " << row);
538 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x0000);
539 REQUIRE(((int)(img_plane[stride * row + 4])) == 0xE2D0);
540 REQUIRE(((int)(img_plane[stride * row + 8])) == 0xB374);
541 REQUIRE(((int)(img_plane[stride * row + 12])) == 0x8080);
542 REQUIRE(((int)(img_plane[stride * row + 16])) == 0xADC6);
543 REQUIRE(((int)(img_plane[stride * row + 20])) == 0xAF49);
544 REQUIRE(((int)(img_plane[stride * row + 24])) == 0x4C8A);
545 REQUIRE(((int)(img_plane[stride * row + 28])) == 0x4B6D);
546 }
547 img_plane = (const uint16_t*)heif_image_get_plane_readonly(img, heif_channel_Cb, &stride);
548 REQUIRE(stride == 128);
549 stride/=2;
550 for (int row = 0; row < 2; row++) {
551 INFO("row: " << row);
552 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x54BC);
553 REQUIRE(((int)(img_plane[stride * row + 1])) == 0x54BC);
554 REQUIRE(((int)(img_plane[stride * row + 2])) == 0x5576);
555 REQUIRE(((int)(img_plane[stride * row + 3])) == 0x5576);
556 REQUIRE(((int)(img_plane[stride * row + 4])) == 0xFFBD);
557 REQUIRE(((int)(img_plane[stride * row + 5])) == 0xFFBD);
558 REQUIRE(((int)(img_plane[stride * row + 6])) == 0x7FBD);
559 REQUIRE(((int)(img_plane[stride * row + 7])) == 0x7FBD);
560 REQUIRE(((int)(img_plane[stride * row + 8])) == 0x7FFF);
561 REQUIRE(((int)(img_plane[stride * row + 9])) == 0x7FFF);
562 REQUIRE(((int)(img_plane[stride * row + 10])) == 0x0000);
563 REQUIRE(((int)(img_plane[stride * row + 11])) == 0x0000);
564 REQUIRE(((int)(img_plane[stride * row + 12])) == 0xAB01);
565 REQUIRE(((int)(img_plane[stride * row + 13])) == 0xAB01);
566 REQUIRE(((int)(img_plane[stride * row + 14])) == 0x7FDE);
567 REQUIRE(((int)(img_plane[stride * row + 15])) == 0x7FDE);
568 }
569 for (int row = 2; row < 4; row++) {
570 INFO("row: " << row);
571 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x5576);
572 REQUIRE(((int)(img_plane[stride * row + 2])) == 0xFFBD);
573 REQUIRE(((int)(img_plane[stride * row + 4])) == 0x7FBD);
574 REQUIRE(((int)(img_plane[stride * row + 6])) == 0x7FFF);
575 REQUIRE(((int)(img_plane[stride * row + 8])) == 0x0000);
576 REQUIRE(((int)(img_plane[stride * row + 10])) == 0xAB01);
577 REQUIRE(((int)(img_plane[stride * row + 12])) == 0x7FDE);
578 REQUIRE(((int)(img_plane[stride * row + 14])) == 0x1DE8);
579 }
580 for (int row = 4; row < 6; row++) {
581 INFO("row: " << row);
582 REQUIRE(((int)(img_plane[stride * row + 0])) == 0xFFBD);
583 REQUIRE(((int)(img_plane[stride * row + 2])) == 0x7FBD);
584 REQUIRE(((int)(img_plane[stride * row + 4])) == 0x7FFF);
585 REQUIRE(((int)(img_plane[stride * row + 6])) == 0x0000);
586 REQUIRE(((int)(img_plane[stride * row + 8])) == 0xAB01);
587 REQUIRE(((int)(img_plane[stride * row + 10])) == 0x7FDE);
588 REQUIRE(((int)(img_plane[stride * row + 12])) == 0x1DE8);
589 REQUIRE(((int)(img_plane[stride * row + 14])) == 0xA3A5);
590 }
591 for (int row = 6; row < 8; row++) {
592 INFO("row: " << row);
593 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x7FBD);
594 REQUIRE(((int)(img_plane[stride * row + 2])) == 0x7FFF);
595 REQUIRE(((int)(img_plane[stride * row + 4])) == 0x0000);
596 REQUIRE(((int)(img_plane[stride * row + 6])) == 0xAB01);
597 REQUIRE(((int)(img_plane[stride * row + 8])) == 0x7FDE);
598 REQUIRE(((int)(img_plane[stride * row + 10])) == 0x1DE8);
599 REQUIRE(((int)(img_plane[stride * row + 12])) == 0xA3A5);
600 REQUIRE(((int)(img_plane[stride * row + 14])) == 0x54BC);
601 }
602 for (int row = 8; row < 10; row++) {
603 INFO("row: " << row);
604 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x7FFF);
605 REQUIRE(((int)(img_plane[stride * row + 2])) == 0x0000);
606 REQUIRE(((int)(img_plane[stride * row + 4])) == 0xAB01);
607 REQUIRE(((int)(img_plane[stride * row + 6])) == 0x7FDE);
608 REQUIRE(((int)(img_plane[stride * row + 8])) == 0x1DE8);
609 REQUIRE(((int)(img_plane[stride * row + 10])) == 0xA3A5);
610 REQUIRE(((int)(img_plane[stride * row + 12])) == 0x54BC);
611 REQUIRE(((int)(img_plane[stride * row + 14])) == 0x5576);
612 }
613 img_plane = (uint16_t*)heif_image_get_plane_readonly(img, heif_channel_Cr, &stride);
614 REQUIRE(stride == 128);
615 stride/=2;
616 for (int row = 0; row < 2; row++) {
617 INFO("row: " << row);
618 REQUIRE(((int)(img_plane[stride * row + 0])) == 0xFFBD);
619 REQUIRE(((int)(img_plane[stride * row + 1])) == 0xFFBD);
620 REQUIRE(((int)(img_plane[stride * row + 2])) == 0x4A48);
621 REQUIRE(((int)(img_plane[stride * row + 3])) == 0x4A48);
622 REQUIRE(((int)(img_plane[stride * row + 4])) == 0x6B2F);
623 REQUIRE(((int)(img_plane[stride * row + 5])) == 0x6B2F);
624 REQUIRE(((int)(img_plane[stride * row + 6])) == 0x7FEB);
625 REQUIRE(((int)(img_plane[stride * row + 7])) == 0x7FEB);
626 REQUIRE(((int)(img_plane[stride * row + 8])) == 0x7FFF);
627 REQUIRE(((int)(img_plane[stride * row + 9])) == 0x7FFF);
628 REQUIRE(((int)(img_plane[stride * row + 10])) == 0x94BB);
629 REQUIRE(((int)(img_plane[stride * row + 11])) == 0x94BB);
630 REQUIRE(((int)(img_plane[stride * row + 12])) == 0x002D);
631 REQUIRE(((int)(img_plane[stride * row + 13])) == 0x002D);
632 REQUIRE(((int)(img_plane[stride * row + 14])) == 0x7FF5);
633 REQUIRE(((int)(img_plane[stride * row + 15])) == 0x7FF5);
634 }
635 for (int row = 2; row < 4; row++) {
636 INFO("row: " << row);
637 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x4A48);
638 REQUIRE(((int)(img_plane[stride * row + 2])) == 0x6B2F);
639 REQUIRE(((int)(img_plane[stride * row + 4])) == 0x7FEB);
640 REQUIRE(((int)(img_plane[stride * row + 6])) == 0x7FFF);
641 REQUIRE(((int)(img_plane[stride * row + 8])) == 0x94BB);
642 REQUIRE(((int)(img_plane[stride * row + 10])) == 0x002D);
643 REQUIRE(((int)(img_plane[stride * row + 12])) == 0x7FF5);
644 REQUIRE(((int)(img_plane[stride * row + 14])) == 0xBA80);
645 }
646 for (int row = 4; row < 6; row++) {
647 INFO("row: " << row);
648 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x6B2F);
649 REQUIRE(((int)(img_plane[stride * row + 2])) == 0x7FEB);
650 REQUIRE(((int)(img_plane[stride * row + 4])) == 0x7FFF);
651 REQUIRE(((int)(img_plane[stride * row + 6])) == 0x94BB);
652 REQUIRE(((int)(img_plane[stride * row + 8])) == 0x002D);
653 REQUIRE(((int)(img_plane[stride * row + 10])) == 0x7FF5);
654 REQUIRE(((int)(img_plane[stride * row + 12])) == 0xBA80);
655 REQUIRE(((int)(img_plane[stride * row + 14])) == 0xAD3F);
656 }
657 for (int row = 6; row < 8; row++) {
658 INFO("row: " << row);
659 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x7FEB);
660 REQUIRE(((int)(img_plane[stride * row + 2])) == 0x7FFF);
661 REQUIRE(((int)(img_plane[stride * row + 4])) == 0x94BB);
662 REQUIRE(((int)(img_plane[stride * row + 6])) == 0x002D);
663 REQUIRE(((int)(img_plane[stride * row + 8])) == 0x7FF5);
664 REQUIRE(((int)(img_plane[stride * row + 10])) == 0xBA80);
665 REQUIRE(((int)(img_plane[stride * row + 12])) == 0xAD3F);
666 REQUIRE(((int)(img_plane[stride * row + 14])) == 0xFFBD);
667 }
668 for (int row = 8; row < 10; row++) {
669 INFO("row: " << row);
670 REQUIRE(((int)(img_plane[stride * row + 0])) == 0x7FFF);
671 REQUIRE(((int)(img_plane[stride * row + 2])) == 0x94BB);
672 REQUIRE(((int)(img_plane[stride * row + 4])) == 0x002D);
673 REQUIRE(((int)(img_plane[stride * row + 6])) == 0x7FF5);
674 REQUIRE(((int)(img_plane[stride * row + 8])) == 0xBA80);
675 REQUIRE(((int)(img_plane[stride * row + 10])) == 0xAD3F);
676 REQUIRE(((int)(img_plane[stride * row + 12])) == 0xFFBD);
677 REQUIRE(((int)(img_plane[stride * row + 14])) == 0x4A48);
678 }
679
680 heif_image_release(img);
681 heif_image_handle_release(handle);
682 }
683
684 TEST_CASE("check image content YCbCr 4:2:0 16 bit") {
685 auto file = GENERATE(YUV_16BIT_420_FILES);
686 auto context = get_context_for_test_file(file);
687 INFO("file name: " << file);
688 check_image_content_ycbcr420_16bit(context);
689 heif_context_free(context);
690 }