blob: 4a925384acfcf880237d80c0040d74c546236748 [file] [log] [blame]
Patrick Georgi7333a112020-05-08 20:48:04 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi8f5053c2015-08-09 18:30:44 +02002
3#include <stdlib.h>
4#include <stdio.h>
5#include "jpeg.h"
6
7const int depth = 16;
8
9int main(int argc, char **argv)
10{
11 FILE *f = fopen(argv[1], "rb");
12 unsigned long len;
13
14 if (!f)
15 return 1;
16 if (fseek(f, 0, SEEK_END) != 0)
17 return 1;
18 len = ftell(f);
19 if (fseek(f, 0, SEEK_SET) != 0)
20 return 1;
21
Patrick Georgi1d029b42023-10-06 20:19:15 +020022 unsigned char *buf = malloc(len);
Patrick Georgi8f5053c2015-08-09 18:30:44 +020023 if (fread(buf, len, 1, f) != 1)
24 return 1;
25 fclose(f);
26
Patrick Georgi1d029b42023-10-06 20:19:15 +020027 unsigned int width;
28 unsigned int height;
29 if (jpeg_fetch_size(buf, len, &width, &height) != 0) {
30 return 1;
31 }
32 if ((width > 6000) || (height > 6000)) {
33 // infeasible data set
34 return 1;
35 }
Patrick Georgi8f5053c2015-08-09 18:30:44 +020036 //printf("width: %d, height: %d\n", width, height);
Patrick Georgi1d029b42023-10-06 20:19:15 +020037 unsigned char *pic = malloc(depth / 8 * width * height);
38 int ret = jpeg_decode(buf, len, pic, width, height, width * depth / 8, depth);
Patrick Georgi8f5053c2015-08-09 18:30:44 +020039 //printf("ret: %x\n", ret);
40 return ret;
41}