Debian Codegraph @

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