"Fossies" - the Fresh Open Source Software Archive

Member "libgd-2.3.3/tests/heif/heif_im2im.c" (11 Sep 2021, 1880 Bytes) of package /linux/www/libgd-2.3.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "heif_im2im.c": 2.3.2_vs_2.3.3.

    1 /**
    2  * Check if it's any difference between the original bitmap and a encoded and
    3  * decoded `4:4:4` HEIF lossless image.
    4  */
    5 
    6 
    7 #include "gd.h"
    8 #include "gdtest.h"
    9 
   10 #include <libheif/heif.h>
   11 
   12 int main()
   13 {
   14     gdImagePtr src = NULL, dst = NULL;
   15     int r, g, b;
   16     void *p = NULL;
   17     int size = 0;
   18     CuTestImageResult result = {0, 0};
   19 
   20     if (!gdTestAssertMsg(heif_get_version_number_major() == 1 && heif_get_version_number_minor() >= 9, "changing chroma subsampling is not supported in this libheif version\n"))
   21         return 77;
   22 
   23     if (!gdTestAssertMsg(heif_have_decoder_for_format(heif_compression_HEVC) && heif_have_encoder_for_format(heif_compression_HEVC), "HEVC codec support missing from libheif\n"))
   24         return 77;
   25 
   26     src = gdImageCreateTrueColor(100, 100);
   27     gdTestAssertMsg(src != NULL, "could not create src\n");
   28     /* libheif seems to have some rounding issues */
   29     r = gdImageColorAllocate(src, 0xFE, 0, 0);
   30     g = gdImageColorAllocate(src, 0, 0xFE, 0);
   31     b = gdImageColorAllocate(src, 0, 0, 0xFE);
   32     gdImageFilledRectangle(src, 0, 0, 99, 99, r);
   33     gdImageRectangle(src, 20, 20, 79, 79, g);
   34     gdImageEllipse(src, 70, 25, 30, 20, b);
   35 
   36     p = gdImageHeifPtrEx(src, &size, 200, GD_HEIF_CODEC_HEVC, GD_HEIF_CHROMA_444);
   37     gdTestAssertMsg(p != NULL, "return value of gdImageHeifPtrEx() is null\n");
   38     gdTestAssertMsg(size > 0, "gdImageHeifPtrEx() output size is non-positive\n");
   39 
   40     dst = gdImageCreateFromHeifPtr(size, p);
   41     gdTestAssertMsg(dst != NULL, "return value of gdImageCreateFromHeifPtr() is null\n");
   42 
   43     if (gdTestAssertMsg(src != NULL && dst != NULL, "cannot compare with NULL buffer"))
   44         gdTestImageDiff(src, dst, NULL, &result);
   45     else
   46         result.pixels_changed = 0;
   47     gdTestAssertMsg(result.pixels_changed == 0, "pixels changed: %d\n", result.pixels_changed);
   48 
   49     if (dst != NULL)
   50         gdImageDestroy(dst);
   51     if (p != NULL)
   52         gdFree(p);
   53     if (src != NULL)
   54         gdImageDestroy(src);
   55 
   56     return gdNumFailures();
   57 }