summaryrefslogtreecommitdiff
path: root/Build/source/libs/gd/libgd-src/tests/heif/heif_im2im.c
blob: 202d6b3e13f3595dd01b6660eb3f1dbdf61fe7c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
 * Check if it's any difference between the original bitmap and a encoded and
 * decoded `4:4:4` HEIF lossless image.
 */


#include "gd.h"
#include "gdtest.h"

#include <libheif/heif.h>

int main()
{
	gdImagePtr src, dst;
	int r, g, b;
	void *p;
	int size = 0;
	CuTestImageResult result = {0, 0};

	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"))
		return 77;

	src = gdImageCreateTrueColor(100, 100);
	gdTestAssertMsg(src != NULL, "could not create src\n");
	/* libheif seems to have some rounding issues */
	r = gdImageColorAllocate(src, 0xFE, 0, 0);
	g = gdImageColorAllocate(src, 0, 0xFE, 0);
	b = gdImageColorAllocate(src, 0, 0, 0xFE);
	gdImageFilledRectangle(src, 0, 0, 99, 99, r);
	gdImageRectangle(src, 20, 20, 79, 79, g);
	gdImageEllipse(src, 70, 25, 30, 20, b);

	p = gdImageHeifPtrEx(src, &size, 200, GD_HEIF_CODEC_HEVC, GD_HEIF_CHROMA_444);
	gdTestAssertMsg(p != NULL, "return value of gdImageHeifPtrEx() is null\n");
	gdTestAssertMsg(size > 0, "gdImageHeifPtrEx() output size is non-positive\n");

	dst = gdImageCreateFromHeifPtr(size, p);
	gdTestAssertMsg(dst != NULL, "return value of gdImageCreateFromHeifPtr() is null\n");

	if (gdTestAssertMsg(src != NULL && dst != NULL, "cannot compare with NULL buffer"))
		gdTestImageDiff(src, dst, NULL, &result);
	else
		result.pixels_changed = 0;
	gdTestAssertMsg(result.pixels_changed == 0, "pixels changed: %d\n", result.pixels_changed);

	if (dst != NULL)
		gdImageDestroy(dst);
	if (p != NULL)
		gdFree(p);
	if (src != NULL)
		gdImageDestroy(src);

	return gdNumFailures();
}