Debian Codegraph @

examples/png2heif.c

raw
1 /**
2 * A short program which converts a .png file into a .avif file -
3 * just to get a little practice with the basic functionality.
4 * We convert losslessly.
5 */
6
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif /* HAVE_CONFIG_H */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 #include "gd.h"
15
16 int main(int argc, char **argv)
17 {
18 gdImagePtr im;
19 FILE *in, *out;
20
21 if (argc != 3) {
22 fprintf(stderr, "Usage: png2avif infile.png outfile.avif\n");
23 exit(1);
24 }
25
26 printf("Reading infile %s\n", argv[1]);
27
28 in = fopen(argv[1], "rb");
29 if (!in) {
30 fprintf(stderr, "Error: input file %s does not exist.\n", argv[1]);
31 exit(1);
32 }
33
34 im = gdImageCreateFromPng(in);
35 fclose(in);
36 if (!im) {
37 fprintf(stderr, "Error: input file %s is not in PNG format.\n", argv[1]);
38 exit(1);
39 }
40 gdImagePaletteToTrueColor(im);
41 if (!gdImagePaletteToTrueColor(im)) {
42 gdImageDestroy(im);
43 exit(1);
44 }
45
46 out = fopen(argv[2], "wb");
47 if (!out) {
48 fprintf(stderr, "Error: can't write to output file %s\n", argv[2]);
49 gdImageDestroy(im);
50 exit(1);
51 }
52
53 fprintf(stderr, "Encoding...\n");
54
55 gdImageHeif(im, out);
56
57 printf("Wrote outfile %s.\n", argv[2]);
58
59 fclose(out);
60 gdImageDestroy(im);
61
62 return 0;
63 }