| 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 |
#define MINI_FILES \ |
| 35 |
"simple_osm_tile_alpha.avif", "simple_osm_tile_meta.avif" |
| 36 |
|
| 37 |
void check_image_handle_size(struct heif_context *&context) { |
| 38 |
heif_image_handle *handle = get_primary_image_handle(context); |
| 39 |
int ispe_width = heif_image_handle_get_ispe_width(handle); |
| 40 |
REQUIRE(ispe_width == 256); |
| 41 |
int ispe_height = heif_image_handle_get_ispe_height(handle); |
| 42 |
REQUIRE(ispe_height == 256); |
| 43 |
int width = heif_image_handle_get_width(handle); |
| 44 |
REQUIRE(width == 256); |
| 45 |
int height = heif_image_handle_get_height(handle); |
| 46 |
REQUIRE(height == 256); |
| 47 |
|
| 48 |
heif_image_handle_release(handle); |
| 49 |
} |
| 50 |
|
| 51 |
TEST_CASE("check image handle size") { |
| 52 |
auto file = GENERATE(MINI_FILES); |
| 53 |
auto context = get_context_for_test_file(file); |
| 54 |
INFO("file name: " << file); |
| 55 |
check_image_handle_size(context); |
| 56 |
heif_context_free(context); |
| 57 |
} |
| 58 |
|
| 59 |
void check_image_size_heif_mini(struct heif_context *&context) { |
| 60 |
heif_image_handle *handle = get_primary_image_handle(context); |
| 61 |
heif_image *img = get_primary_image_ycbcr(handle, heif_chroma_444); |
| 62 |
|
| 63 |
REQUIRE(heif_image_has_channel(img, heif_channel_Y) == 1); |
| 64 |
REQUIRE(heif_image_has_channel(img, heif_channel_Cb) == 1); |
| 65 |
REQUIRE(heif_image_has_channel(img, heif_channel_Cr) == 1); |
| 66 |
REQUIRE(heif_image_has_channel(img, heif_channel_R) == 0); |
| 67 |
REQUIRE(heif_image_has_channel(img, heif_channel_G) == 0); |
| 68 |
REQUIRE(heif_image_has_channel(img, heif_channel_B) == 0); |
| 69 |
REQUIRE(heif_image_has_channel(img, heif_channel_Alpha) == 0); |
| 70 |
REQUIRE(heif_image_has_channel(img, heif_channel_interleaved) == 0); |
| 71 |
int width = heif_image_get_primary_width(img); |
| 72 |
REQUIRE(width == 128); |
| 73 |
int height = heif_image_get_primary_height(img); |
| 74 |
REQUIRE(height == 128); |
| 75 |
width = heif_image_get_width(img, heif_channel_Y); |
| 76 |
REQUIRE(width == 128); |
| 77 |
height = heif_image_get_height(img, heif_channel_Y); |
| 78 |
REQUIRE(height == 128); |
| 79 |
width = heif_image_get_width(img, heif_channel_Cb); |
| 80 |
REQUIRE(width == 128); |
| 81 |
height = heif_image_get_height(img, heif_channel_Cr); |
| 82 |
REQUIRE(height == 128); |
| 83 |
width = heif_image_get_width(img, heif_channel_Cr); |
| 84 |
REQUIRE(width == 128); |
| 85 |
height = heif_image_get_height(img, heif_channel_Cr); |
| 86 |
REQUIRE(height == 128); |
| 87 |
|
| 88 |
int pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_Y); |
| 89 |
REQUIRE(pixel_depth == 8); |
| 90 |
pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_Cb); |
| 91 |
REQUIRE(pixel_depth == 8); |
| 92 |
pixel_depth = heif_image_get_bits_per_pixel(img, heif_channel_Cr); |
| 93 |
REQUIRE(pixel_depth == 8); |
| 94 |
int pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_Y); |
| 95 |
REQUIRE(pixel_range == 8); |
| 96 |
pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_Cb); |
| 97 |
REQUIRE(pixel_range == 8); |
| 98 |
pixel_range = heif_image_get_bits_per_pixel_range(img, heif_channel_Cr); |
| 99 |
REQUIRE(pixel_range == 8); |
| 100 |
|
| 101 |
heif_image_release(img); |
| 102 |
heif_image_handle_release(handle); |
| 103 |
} |
| 104 |
|
| 105 |
TEST_CASE("check image size HEIF mini") { |
| 106 |
auto context = get_context_for_test_file("lightning_mini.heif"); |
| 107 |
check_image_size_heif_mini(context); |
| 108 |
heif_context_free(context); |
| 109 |
} |