2 * File: simple_dcraw_c.c
3 * Copyright 2008 Alex Tutubalin <lexa@lexa.ru>
4 * Created: Sat Mar 8 , 2008
6 * LibRaw C API sample (emulates call to "dcraw -h")
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 #include "libraw/libraw.h"
31 #define HANDLE_FATAL_ERROR(ret)\
34 fprintf(stderr,"%s: libraw %s\n",av[i],libraw_strerror(ret));\
35 if(LIBRAW_FATAL_ERROR(ret))\
39 #define HANDLE_ALL_ERRORS(ret)\
42 fprintf(stderr,"%s: libraw %s\n",av[i],libraw_strerror(ret));\
47 int main(int ac, char *av[])
50 libraw_data_t
*iprc
= libraw_init(0);
54 fprintf(stderr
,"Cannot create libraw handle\n");
58 iprc
->params
.half_size
= 1; /* dcraw -h */
63 int ret
= libraw_open_file(iprc
,av
[i
]);
64 HANDLE_ALL_ERRORS(ret
);
66 printf("Processing %s (%s %s)\n",av
[i
],iprc
->idata
.make
,iprc
->idata
.model
);
68 ret
= libraw_unpack(iprc
);
69 HANDLE_ALL_ERRORS(ret
);
71 ret
= libraw_dcraw_process(iprc
);
72 HANDLE_ALL_ERRORS(ret
);
76 printf("Writing to %s\n",outfn
);
78 ret
= libraw_dcraw_ppm_tiff_writer(iprc
,outfn
);
79 HANDLE_FATAL_ERROR(ret
);