| 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_handle_size(heif_context *&context) { |
| 37 |
heif_image_handle *handle = get_primary_image_handle(context); |
| 38 |
int ispe_width = heif_image_handle_get_ispe_width(handle); |
| 39 |
REQUIRE(ispe_width == 30); |
| 40 |
int ispe_height = heif_image_handle_get_ispe_height(handle); |
| 41 |
REQUIRE(ispe_height == 20); |
| 42 |
int width = heif_image_handle_get_width(handle); |
| 43 |
REQUIRE(width == 30); |
| 44 |
int height = heif_image_handle_get_height(handle); |
| 45 |
REQUIRE(height == 20); |
| 46 |
|
| 47 |
heif_image_handle_release(handle); |
| 48 |
} |
| 49 |
|
| 50 |
TEST_CASE("check image handle size") { |
| 51 |
auto file = GENERATE(FILES, MONO_FILES, YUV_FILES); |
| 52 |
auto context = get_context_for_test_file(file); |
| 53 |
INFO("file name: " << file); |
| 54 |
check_image_handle_size(context); |
| 55 |
heif_context_free(context); |
| 56 |
} |
| 57 |
|
| 58 |
void check_image_handle_size_subsampled(heif_context *&context) { |
| 59 |
heif_image_handle *handle = get_primary_image_handle(context); |
| 60 |
int ispe_width = heif_image_handle_get_ispe_width(handle); |
| 61 |
REQUIRE(ispe_width == 32); |
| 62 |
int ispe_height = heif_image_handle_get_ispe_height(handle); |
| 63 |
REQUIRE(ispe_height == 20); |
| 64 |
int width = heif_image_handle_get_width(handle); |
| 65 |
REQUIRE(width == 32); |
| 66 |
int height = heif_image_handle_get_height(handle); |
| 67 |
REQUIRE(height == 20); |
| 68 |
|
| 69 |
heif_image_handle_release(handle); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
TEST_CASE("check image handle size subsampled") { |
| 74 |
auto file = GENERATE(YUV_422_FILES, YUV_420_FILES, YUV_16BIT_422_FILES, YUV_16BIT_420_FILES); |
| 75 |
auto context = get_context_for_test_file(file); |
| 76 |
INFO("file name: " << file); |
| 77 |
check_image_handle_size_subsampled(context); |
| 78 |
heif_context_free(context); |
| 79 |
} |
| 80 |
|
| 81 |
TEST_CASE("check image handle alpha channel") { |
| 82 |
auto file = GENERATE(FILES, MONO_FILES, ALL_YUV_FILES); |
| 83 |
auto context = get_context_for_test_file(file); |
| 84 |
INFO("file name: " << file); |
| 85 |
int expect_alpha = (strchr(file, 'A') == NULL) ? 0 : 1; |
| 86 |
heif_image_handle *handle = get_primary_image_handle(context); |
| 87 |
int has_alpha = heif_image_handle_has_alpha_channel(handle); |
| 88 |
REQUIRE(has_alpha == expect_alpha); |
| 89 |
|
| 90 |
heif_image_handle_release(handle); |
| 91 |
heif_context_free(context); |
| 92 |
} |
| 93 |
|
| 94 |
void check_image_handle_no_depth_images(heif_context *&context) { |
| 95 |
heif_image_handle *handle = get_primary_image_handle(context); |
| 96 |
|
| 97 |
int has_depth = heif_image_handle_has_depth_image(handle); |
| 98 |
REQUIRE(has_depth == 0); |
| 99 |
|
| 100 |
int numdepth = heif_image_handle_get_number_of_depth_images(handle); |
| 101 |
REQUIRE(numdepth == 0); |
| 102 |
|
| 103 |
heif_image_handle_release(handle); |
| 104 |
} |
| 105 |
|
| 106 |
TEST_CASE("check image handle no depth images") { |
| 107 |
auto file = GENERATE(FILES, MONO_FILES, ALL_YUV_FILES); |
| 108 |
auto context = get_context_for_test_file(file); |
| 109 |
INFO("file name: " << file); |
| 110 |
check_image_handle_no_depth_images(context); |
| 111 |
heif_context_free(context); |
| 112 |
} |
| 113 |
|
| 114 |
void check_image_handle_no_thumbnails(heif_context *&context) { |
| 115 |
heif_image_handle *handle = get_primary_image_handle(context); |
| 116 |
|
| 117 |
int numthumbs = heif_image_handle_get_number_of_thumbnails(handle); |
| 118 |
REQUIRE(numthumbs == 0); |
| 119 |
|
| 120 |
heif_image_handle_release(handle); |
| 121 |
} |
| 122 |
|
| 123 |
TEST_CASE("check image handle no thumbnails") { |
| 124 |
auto file = GENERATE(FILES, MONO_FILES, ALL_YUV_FILES); |
| 125 |
auto context = get_context_for_test_file(file); |
| 126 |
INFO("file name: " << file); |
| 127 |
check_image_handle_no_thumbnails(context); |
| 128 |
heif_context_free(context); |
| 129 |
} |
| 130 |
|
| 131 |
void check_image_handle_no_aux_images(heif_context *&context) { |
| 132 |
heif_image_handle *handle = get_primary_image_handle(context); |
| 133 |
|
| 134 |
int num_aux = heif_image_handle_get_number_of_auxiliary_images(handle, 0); |
| 135 |
REQUIRE(num_aux == 0); |
| 136 |
|
| 137 |
heif_image_handle_release(handle); |
| 138 |
} |
| 139 |
|
| 140 |
TEST_CASE("check image handle no auxiliary images") { |
| 141 |
auto file = GENERATE(FILES, MONO_FILES, ALL_YUV_FILES); |
| 142 |
auto context = get_context_for_test_file(file); |
| 143 |
INFO("file name: " << file); |
| 144 |
check_image_handle_no_aux_images(context); |
| 145 |
heif_context_free(context); |
| 146 |
} |
| 147 |
|
| 148 |
void check_image_handle_no_metadata(heif_context *&context) { |
| 149 |
heif_image_handle *handle = get_primary_image_handle(context); |
| 150 |
|
| 151 |
int num_metadata_blocks = |
| 152 |
heif_image_handle_get_number_of_metadata_blocks(handle, NULL); |
| 153 |
REQUIRE(num_metadata_blocks == 0); |
| 154 |
|
| 155 |
heif_image_handle_release(handle); |
| 156 |
} |
| 157 |
|
| 158 |
TEST_CASE("check image handle no metadata blocks") { |
| 159 |
auto file = GENERATE(FILES, MONO_FILES, ALL_YUV_FILES); |
| 160 |
auto context = get_context_for_test_file(file); |
| 161 |
INFO("file name: " << file); |
| 162 |
check_image_handle_no_metadata(context); |
| 163 |
heif_context_free(context); |
| 164 |
} |
| 165 |
|
| 166 |
TEST_CASE("check uncompressed is advertised") { |
| 167 |
REQUIRE(heif_have_decoder_for_format(heif_compression_uncompressed)); |
| 168 |
} |
| 169 |
|