| 1 |
/* |
| 2 |
libheif unit tests |
| 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 |
|
| 27 |
#include "catch_amalgamated.hpp" |
| 28 |
#include "libheif/heif.h" |
| 29 |
#include "api_structs.h" |
| 30 |
#include "pixelimage.h" |
| 31 |
|
| 32 |
#include "test_utils.h" |
| 33 |
|
| 34 |
#include <string.h> |
| 35 |
|
| 36 |
static heif_encoding_options * set_encoding_options() |
| 37 |
{ |
| 38 |
heif_encoding_options * options = heif_encoding_options_alloc(); |
| 39 |
options->macOS_compatibility_workaround = false; |
| 40 |
options->macOS_compatibility_workaround_no_nclx_profile = true; |
| 41 |
options->image_orientation = heif_orientation_normal; |
| 42 |
return options; |
| 43 |
} |
| 44 |
|
| 45 |
static void do_encode(heif_image* input_image, const char* filename, bool lossless) |
| 46 |
{ |
| 47 |
REQUIRE(input_image != nullptr); |
| 48 |
heif_init(nullptr); |
| 49 |
heif_context *ctx = heif_context_alloc(); |
| 50 |
heif_encoder *encoder; |
| 51 |
heif_error err; |
| 52 |
err = heif_context_get_encoder_for_format(ctx, heif_compression_JPEG2000, &encoder); |
| 53 |
REQUIRE(err.code == heif_error_Ok); |
| 54 |
|
| 55 |
err = heif_encoder_set_lossless(encoder, lossless); |
| 56 |
REQUIRE(err.code == heif_error_Ok); |
| 57 |
|
| 58 |
heif_encoding_options *options = set_encoding_options(); |
| 59 |
|
| 60 |
heif_image_handle *output_image_handle; |
| 61 |
|
| 62 |
err = heif_context_encode_image(ctx, input_image, encoder, options, &output_image_handle); |
| 63 |
REQUIRE(err.code == heif_error_Ok); |
| 64 |
err = heif_context_write_to_file(ctx, filename); |
| 65 |
REQUIRE(err.code == heif_error_Ok); |
| 66 |
|
| 67 |
heif_image_handle_release(output_image_handle); |
| 68 |
heif_encoding_options_free(options); |
| 69 |
heif_encoder_release(encoder); |
| 70 |
heif_image_release(input_image); |
| 71 |
|
| 72 |
heif_context_free(ctx); |
| 73 |
heif_deinit(); |
| 74 |
} |
| 75 |
|
| 76 |
TEST_CASE("Encode JPEG2000 lossy") |
| 77 |
{ |
| 78 |
heif_image *input_image = createImage_RGB_planar(); |
| 79 |
do_encode(input_image, "encode_j2k_rgb_lossy.heif", false); |
| 80 |
} |
| 81 |
|
| 82 |
TEST_CASE("Encode JPEG2000 lossless") |
| 83 |
{ |
| 84 |
heif_image *input_image = createImage_RGB_planar(); |
| 85 |
do_encode(input_image, "encode_j2k_rgb_lossless.heif", true); |
| 86 |
} |