util/: Replace GPLv2 boiler plate with SPDX header
[coreboot.git] / util / fuzz-tests / jpeg-test.c
blobcdd93e9d9089aca887e6d4bfdf910714c1e6db8a
1 /* This file is part of the coreboot project. */
2 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include "jpeg.h"
8 const int depth = 16;
10 int main(int argc, char **argv)
12 FILE *f = fopen(argv[1], "rb");
13 unsigned long len;
15 if (!f)
16 return 1;
17 if (fseek(f, 0, SEEK_END) != 0)
18 return 1;
19 len = ftell(f);
20 if (fseek(f, 0, SEEK_SET) != 0)
21 return 1;
23 char *buf = malloc(len);
24 struct jpeg_decdata *decdata = malloc(sizeof(*decdata));
25 if (fread(buf, len, 1, f) != 1)
26 return 1;
27 fclose(f);
29 int width;
30 int height;
31 jpeg_fetch_size(buf, &width, &height);
32 //printf("width: %d, height: %d\n", width, height);
33 char *pic = malloc(depth / 8 * width * height);
34 int ret = jpeg_decode(buf, pic, width, height, depth, decdata);
35 //printf("ret: %x\n", ret);
36 return ret;