| 1 |
/* |
| 2 |
libheif integration tests for extended type (uuid) boxes |
| 3 |
|
| 4 |
MIT License |
| 5 |
|
| 6 |
Copyright (c) 2024 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 |
|
| 27 |
#include "catch_amalgamated.hpp" |
| 28 |
#include "api_structs.h" |
| 29 |
#include "libheif/heif.h" |
| 30 |
#include "test-config.h" |
| 31 |
#include "test_utils.h" |
| 32 |
#include <cstddef> |
| 33 |
#include <cstdint> |
| 34 |
#include <cstring> |
| 35 |
|
| 36 |
|
| 37 |
TEST_CASE("make extended type") { |
| 38 |
heif_image *input_image = createImage_RGB_planar(); |
| 39 |
heif_init(nullptr); |
| 40 |
heif_context *ctx = heif_context_alloc(); |
| 41 |
heif_encoder *encoder; |
| 42 |
heif_error err; |
| 43 |
encoder = get_encoder_or_skip_test(heif_compression_HEVC); |
| 44 |
|
| 45 |
heif_encoding_options *options = heif_encoding_options_alloc(); |
| 46 |
|
| 47 |
heif_image_handle *output_image_handle; |
| 48 |
|
| 49 |
err = heif_context_encode_image(ctx, input_image, encoder, nullptr, &output_image_handle); |
| 50 |
UNSCOPED_INFO("heif_context_encode_image: " << err.message); |
| 51 |
REQUIRE(err.code == heif_error_Ok); |
| 52 |
|
| 53 |
heif_item_id itemId; |
| 54 |
err = heif_context_get_primary_image_ID(ctx, &itemId); |
| 55 |
REQUIRE(err.code == heif_error_Ok); |
| 56 |
|
| 57 |
const uint8_t uuid[] = {0x13, 0x7a, 0x17, 0x42, 0x75, 0xac, 0x47, 0x47, 0x82, 0xbc, 0x65, 0x95, 0x76, 0xe8, 0x67, 0x5b}; |
| 58 |
std::vector<uint8_t> body {0x00, 0x00, 0x00, 0x01, 0xfa, 0xde, 0x99, 0x04}; |
| 59 |
heif_property_id propertyId; |
| 60 |
err = heif_item_add_raw_property(ctx, itemId, heif_item_property_type_uuid, &uuid[0], body.data(), body.size(), 0, &propertyId); |
| 61 |
REQUIRE(err.code == heif_error_Ok); |
| 62 |
REQUIRE(propertyId == 4); |
| 63 |
err = heif_context_write_to_file(ctx, "with_uuid.heif"); |
| 64 |
REQUIRE(err.code == heif_error_Ok); |
| 65 |
|
| 66 |
uint8_t extended_type[16]; |
| 67 |
err = heif_item_get_property_uuid_type(ctx, itemId, propertyId, &extended_type[0]); |
| 68 |
REQUIRE(err.code == heif_error_Ok); |
| 69 |
for (int i = 0; i < 16; i++) { |
| 70 |
REQUIRE(extended_type[i] == uuid[i]); |
| 71 |
} |
| 72 |
|
| 73 |
size_t size = 0; |
| 74 |
err = heif_item_get_property_raw_size(ctx, itemId, propertyId, &size); |
| 75 |
REQUIRE(err.code == heif_error_Ok); |
| 76 |
REQUIRE(size == 8); |
| 77 |
|
| 78 |
uint8_t data[8]; |
| 79 |
err = heif_item_get_property_raw_data(ctx, itemId, propertyId, &data[0]); |
| 80 |
REQUIRE(err.code == heif_error_Ok); |
| 81 |
for (int i = 0; i < 8; i++) { |
| 82 |
REQUIRE(data[i] == body[i]); |
| 83 |
} |
| 84 |
|
| 85 |
heif_image_handle_release(output_image_handle); |
| 86 |
heif_encoding_options_free(options); |
| 87 |
heif_encoder_release(encoder); |
| 88 |
heif_image_release(input_image); |
| 89 |
|
| 90 |
heif_context_free(ctx); |
| 91 |
heif_deinit(); |
| 92 |
} |
| 93 |
|