Patrick Georgi | 8f5053c | 2015-08-09 18:30:44 +0200 | [diff] [blame^] | 1 | /* |
| 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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc. |
| 18 | */ |
| 19 | |
| 20 | #include <stdlib.h> |
| 21 | #include <stdio.h> |
| 22 | #include "jpeg.h" |
| 23 | |
| 24 | const int depth = 16; |
| 25 | |
| 26 | int main(int argc, char **argv) |
| 27 | { |
| 28 | FILE *f = fopen(argv[1], "rb"); |
| 29 | unsigned long len; |
| 30 | |
| 31 | if (!f) |
| 32 | return 1; |
| 33 | if (fseek(f, 0, SEEK_END) != 0) |
| 34 | return 1; |
| 35 | len = ftell(f); |
| 36 | if (fseek(f, 0, SEEK_SET) != 0) |
| 37 | return 1; |
| 38 | |
| 39 | char *buf = malloc(len); |
| 40 | struct jpeg_decdata *decdata = malloc(sizeof(*decdata)); |
| 41 | if (fread(buf, len, 1, f) != 1) |
| 42 | return 1; |
| 43 | fclose(f); |
| 44 | |
| 45 | int width; |
| 46 | int height; |
| 47 | jpeg_fetch_size(buf, &width, &height); |
| 48 | //printf("width: %d, height: %d\n", width, height); |
| 49 | char *pic = malloc(depth / 8 * width * height); |
| 50 | int ret = jpeg_decode(buf, pic, width, height, depth, decdata); |
| 51 | //printf("ret: %x\n", ret); |
| 52 | return ret; |
| 53 | } |