update
[kdegraphics.git] / libs / libkdcraw / libraw / samples / dcraw_half.c
blob15f1996e6fd71c3dc4eaf6a874210ecf16663453
1 /* -*- C++ -*-
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)
11 * any later version.
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
21 * 02111-1307, USA.
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <math.h>
28 #include "libraw/libraw.h"
31 #define HANDLE_FATAL_ERROR(ret)\
32 if(ret)\
34 fprintf(stderr,"%s: libraw %s\n",av[i],libraw_strerror(ret));\
35 if(LIBRAW_FATAL_ERROR(ret))\
36 exit(1); \
39 #define HANDLE_ALL_ERRORS(ret)\
40 if(ret)\
42 fprintf(stderr,"%s: libraw %s\n",av[i],libraw_strerror(ret));\
43 continue; \
47 int main(int ac, char *av[])
49 int i;
50 libraw_data_t *iprc = libraw_init(0);
52 if(!iprc)
54 fprintf(stderr,"Cannot create libraw handle\n");
55 exit(1);
58 iprc->params.half_size = 1; /* dcraw -h */
60 for (i=1;i<ac;i++)
62 char outfn[1024];
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);
74 strcpy(outfn,av[i]);
75 strcat(outfn,".ppm");
76 printf("Writing to %s\n",outfn);
78 ret = libraw_dcraw_ppm_tiff_writer(iprc,outfn);
79 HANDLE_FATAL_ERROR(ret);
81 libraw_close(iprc);
82 return 0;