Debian Codegraph @

tests/uncompressed_decode_generic_compression.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(struct heif_context *&context) {
37 heif_image_handle *handle = get_primary_image_handle(context);
38 heif_image *img = get_primary_image(handle);
39
40 REQUIRE(heif_image_has_channel(img, heif_channel_Y) == 0);
41 REQUIRE(heif_image_has_channel(img, heif_channel_Cb) == 0);
42 REQUIRE(heif_image_has_channel(img, heif_channel_Cr) == 0);
43 REQUIRE(heif_image_has_channel(img, heif_channel_R) == 1);
44 REQUIRE(heif_image_has_channel(img, heif_channel_G) == 1);
45 REQUIRE(heif_image_has_channel(img, heif_channel_B) == 1);
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 == 128);
50 int height = heif_image_get_primary_height(img);
51 REQUIRE(height == 72);
52 width = heif_image_get_width(img, heif_channel_R);
53 REQUIRE(width == 128);
54 height = heif_image_get_height(img, heif_channel_R);
55 REQUIRE(height == 72);
56 width = heif_image_get_width(img, heif_channel_G);
57 REQUIRE(width == 128);
58 height = heif_image_get_height(img, heif_channel_G);
59 REQUIRE(height == 72);
60 width = heif_image_get_width(img, heif_channel_B);
61 REQUIRE(width == 128);
62 height = heif_image_get_height(img, heif_channel_B);
63 REQUIRE(height == 72);
64
65 int pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_R);
66 REQUIRE(pixel_depth == 8);
67 pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_G);
68 REQUIRE(pixel_depth == 8);
69 pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_B);
70 REQUIRE(pixel_depth == 8);
71
72 int pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_R);
73 REQUIRE(pixel_range == 8);
74 pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_G);
75 REQUIRE(pixel_range == 8);
76 pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_B);
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") {
84 auto file = GENERATE(FILES_GENERIC_COMPRESSED);
85 auto context = get_context_for_test_file(file);
86 INFO("file name: " << file);
87 check_image_size(context);
88 heif_context_free(context);
89 }
90
91
92 void check_image_content(struct heif_context *&context) {
93 heif_image_handle *handle = get_primary_image_handle(context);
94 heif_image *img = get_primary_image(handle);
95
96 int stride;
97 const uint8_t *img_plane =
98 heif_image_get_plane_readonly(img, heif_channel_R, &stride);
99 REQUIRE(stride == 128);
100 for (int row = 0; row < 24; row++) {
101 INFO("row: " << row);
102 REQUIRE(((int)(img_plane[stride * row + 0])) == 255);
103 REQUIRE(((int)(img_plane[stride * row + 31])) == 255);
104 REQUIRE(((int)(img_plane[stride * row + 32])) == 0);
105 REQUIRE(((int)(img_plane[stride * row + 63])) == 0);
106 REQUIRE(((int)(img_plane[stride * row + 64])) == 0);
107 REQUIRE(((int)(img_plane[stride * row + 95])) == 0);
108 REQUIRE(((int)(img_plane[stride * row + 96])) == 0);
109 REQUIRE(((int)(img_plane[stride * row + 127])) == 0);
110 }
111 for (int row = 24; row < 48; row++) {
112 INFO("row: " << row);
113 REQUIRE(((int)(img_plane[stride * row + 0])) == 255);
114 REQUIRE(((int)(img_plane[stride * row + 31])) == 255);
115 REQUIRE(((int)(img_plane[stride * row + 32])) == 64);
116 REQUIRE(((int)(img_plane[stride * row + 63])) == 64);
117 REQUIRE(((int)(img_plane[stride * row + 64])) == 0);
118 REQUIRE(((int)(img_plane[stride * row + 95])) == 0);
119 REQUIRE(((int)(img_plane[stride * row + 96])) == 255);
120 REQUIRE(((int)(img_plane[stride * row + 127])) == 255);
121 }
122 for (int row = 48; row < 72; row++) {
123 INFO("row: " << row);
124 REQUIRE(((int)(img_plane[stride * row + 0])) == 192);
125 REQUIRE(((int)(img_plane[stride * row + 31])) == 192);
126 REQUIRE(((int)(img_plane[stride * row + 32])) == 255);
127 REQUIRE(((int)(img_plane[stride * row + 63])) == 255);
128 REQUIRE(((int)(img_plane[stride * row + 64])) == 255);
129 REQUIRE(((int)(img_plane[stride * row + 95])) == 255);
130 REQUIRE(((int)(img_plane[stride * row + 96])) == 255);
131 REQUIRE(((int)(img_plane[stride * row + 127])) == 255);
132 }
133
134 img_plane = heif_image_get_plane_readonly(img, heif_channel_G, &stride);
135 REQUIRE(stride == 128);
136 for (int row = 0; row < 24; row++) {
137 INFO("row: " << row);
138 REQUIRE(((int)(img_plane[stride * row + 0])) == 0);
139 REQUIRE(((int)(img_plane[stride * row + 31])) == 0);
140 REQUIRE(((int)(img_plane[stride * row + 32])) == 255);
141 REQUIRE(((int)(img_plane[stride * row + 63])) == 255);
142 REQUIRE(((int)(img_plane[stride * row + 64])) == 0);
143 REQUIRE(((int)(img_plane[stride * row + 95])) == 0);
144 REQUIRE(((int)(img_plane[stride * row + 96])) == 0);
145 REQUIRE(((int)(img_plane[stride * row + 127])) == 0);
146 }
147 for (int row = 24; row < 48; row++) {
148 INFO("row: " << row);
149 REQUIRE(((int)(img_plane[stride * row + 0])) == 255);
150 REQUIRE(((int)(img_plane[stride * row + 31])) == 255);
151 REQUIRE(((int)(img_plane[stride * row + 32])) == 64);
152 REQUIRE(((int)(img_plane[stride * row + 63])) == 64);
153 REQUIRE(((int)(img_plane[stride * row + 64])) == 255);
154 REQUIRE(((int)(img_plane[stride * row + 95])) == 255);
155 REQUIRE(((int)(img_plane[stride * row + 96])) == 0);
156 REQUIRE(((int)(img_plane[stride * row + 127])) == 0);
157 }
158 for (int row = 48; row < 72; row++) {
159 INFO("row: " << row);
160 REQUIRE(((int)(img_plane[stride * row + 0])) == 192);
161 REQUIRE(((int)(img_plane[stride * row + 31])) == 192);
162 REQUIRE(((int)(img_plane[stride * row + 32])) == 255);
163 REQUIRE(((int)(img_plane[stride * row + 63])) == 255);
164 REQUIRE(((int)(img_plane[stride * row + 64])) == 175);
165 REQUIRE(((int)(img_plane[stride * row + 95])) == 175);
166 REQUIRE(((int)(img_plane[stride * row + 96])) == 200);
167 REQUIRE(((int)(img_plane[stride * row + 127])) == 200);
168 }
169
170 img_plane = heif_image_get_plane_readonly(img, heif_channel_B, &stride);
171 REQUIRE(stride == 128);
172 for (int row = 0; row < 24; row++) {
173 INFO("row: " << row);
174 REQUIRE(((int)(img_plane[stride * row + 0])) == 0);
175 REQUIRE(((int)(img_plane[stride * row + 31])) == 0);
176 REQUIRE(((int)(img_plane[stride * row + 32])) == 0);
177 REQUIRE(((int)(img_plane[stride * row + 63])) == 0);
178 REQUIRE(((int)(img_plane[stride * row + 64])) == 255);
179 REQUIRE(((int)(img_plane[stride * row + 95])) == 255);
180 REQUIRE(((int)(img_plane[stride * row + 96])) == 0);
181 REQUIRE(((int)(img_plane[stride * row + 127])) == 0);
182 }
183 for (int row = 24; row < 48; row++) {
184 INFO("row: " << row);
185 REQUIRE(((int)(img_plane[stride * row + 0])) == 255);
186 REQUIRE(((int)(img_plane[stride * row + 31])) == 255);
187 REQUIRE(((int)(img_plane[stride * row + 32])) == 64);
188 REQUIRE(((int)(img_plane[stride * row + 63])) == 64);
189 REQUIRE(((int)(img_plane[stride * row + 64])) == 255);
190 REQUIRE(((int)(img_plane[stride * row + 95])) == 255);
191 REQUIRE(((int)(img_plane[stride * row + 96])) == 255);
192 REQUIRE(((int)(img_plane[stride * row + 127])) == 255);
193 }
194 for (int row = 48; row < 72; row++) {
195 INFO("row: " << row);
196 REQUIRE(((int)(img_plane[stride * row + 0])) == 192);
197 REQUIRE(((int)(img_plane[stride * row + 31])) == 192);
198 REQUIRE(((int)(img_plane[stride * row + 32])) == 0);
199 REQUIRE(((int)(img_plane[stride * row + 63])) == 0);
200 REQUIRE(((int)(img_plane[stride * row + 64])) == 175);
201 REQUIRE(((int)(img_plane[stride * row + 95])) == 175);
202 REQUIRE(((int)(img_plane[stride * row + 96])) == 0);
203 REQUIRE(((int)(img_plane[stride * row + 127])) == 0);
204 }
205
206 heif_image_release(img);
207 heif_image_handle_release(handle);
208 }
209
210 TEST_CASE("check image content") {
211 auto file = GENERATE(FILES_GENERIC_COMPRESSED);
212 auto context = get_context_for_test_file(file);
213 INFO("file name: " << file);
214 check_image_content(context);
215 heif_context_free(context);
216 }