Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 8f5053c | 2015-08-09 18:30:44 +0200 | [diff] [blame] | 2 | |
| 3 | #include <stdlib.h> |
| 4 | #include <stdio.h> |
| 5 | #include "jpeg.h" |
| 6 | |
| 7 | const int depth = 16; |
| 8 | |
| 9 | int 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 | |
| 22 | char *buf = malloc(len); |
| 23 | struct jpeg_decdata *decdata = malloc(sizeof(*decdata)); |
| 24 | if (fread(buf, len, 1, f) != 1) |
| 25 | return 1; |
| 26 | fclose(f); |
| 27 | |
| 28 | int width; |
| 29 | int height; |
| 30 | jpeg_fetch_size(buf, &width, &height); |
| 31 | //printf("width: %d, height: %d\n", width, height); |
| 32 | char *pic = malloc(depth / 8 * width * height); |
Nico Huber | 99eee16 | 2023-07-14 00:09:00 +0200 | [diff] [blame] | 33 | int ret = jpeg_decode(buf, pic, width, height, width * depth / 8, depth, decdata); |
Patrick Georgi | 8f5053c | 2015-08-09 18:30:44 +0200 | [diff] [blame] | 34 | //printf("ret: %x\n", ret); |
| 35 | return ret; |
| 36 | } |