blob: 82967ddb4eeba59cf2d6d48a76165e0e634bcca4 [file] [log] [blame]
Patrick Georgi8f5053c2015-08-09 18:30:44 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2015 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Patrick Georgi8f5053c2015-08-09 18:30:44 +020014 */
15
16#include <stdlib.h>
17#include <stdio.h>
18#include "jpeg.h"
19
20const int depth = 16;
21
22int main(int argc, char **argv)
23{
24 FILE *f = fopen(argv[1], "rb");
25 unsigned long len;
26
27 if (!f)
28 return 1;
29 if (fseek(f, 0, SEEK_END) != 0)
30 return 1;
31 len = ftell(f);
32 if (fseek(f, 0, SEEK_SET) != 0)
33 return 1;
34
35 char *buf = malloc(len);
36 struct jpeg_decdata *decdata = malloc(sizeof(*decdata));
37 if (fread(buf, len, 1, f) != 1)
38 return 1;
39 fclose(f);
40
41 int width;
42 int height;
43 jpeg_fetch_size(buf, &width, &height);
44 //printf("width: %d, height: %d\n", width, height);
45 char *pic = malloc(depth / 8 * width * height);
46 int ret = jpeg_decode(buf, pic, width, height, depth, decdata);
47 //printf("ret: %x\n", ret);
48 return ret;
49}