2 * File: simple_dcraw_c.c
3 * Copyright 2008 Alex Tutubalin <lexa@lexa.ru>
4 * Created: Sat Mar 8 , 2008
6 * LibRaw C API mutithreaded sample (emulates call to "dcraw -h [-w] [-a] [-v]")
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
29 #include "libraw/libraw.h"
31 #define HANDLE_ERRORS(ret) do { \
34 fprintf(stderr,"%s: %s\n",fn,libraw_strerror(ret)); \
35 if(LIBRAW_FATAL_ERROR(ret)) \
45 int verbose
=0,use_camera_wb
=0,use_auto_wb
=0,tiff_mode
=0;
50 size_t qsize
=0,qptr
=0;
55 if(!queue
) return NULL
;
56 if(qptr
>=qsize
) return NULL
;
57 pthread_mutex_lock(&qm
);
59 pthread_mutex_unlock(&qm
);
65 int process_files(void *q
)
69 char outfn
[1024], *fn
;
70 libraw_data_t
*iprc
= libraw_init(0);
74 fprintf(stderr
,"Cannot create libraw handle\n");
78 while((fn
= get_next_file()))
81 iprc
->params
.half_size
= 1; /* dcraw -h */
82 iprc
->params
.use_camera_wb
= use_camera_wb
;
83 iprc
->params
.use_auto_wb
= use_auto_wb
;
84 iprc
->params
.output_tiff
= tiff_mode
;
86 ret
= libraw_open_file(iprc
,fn
);
87 if(verbose
) fprintf(stderr
,"%s: %s/%s\n",fn
,iprc
->idata
.make
,iprc
->idata
.model
);
90 ret
= libraw_unpack(iprc
);
93 ret
= libraw_dcraw_process(iprc
);
96 snprintf(outfn
,1023,"%s.ppm",fn
);
98 if(verbose
) fprintf(stderr
,"Writing file %s\n",outfn
);
99 ret
= libraw_dcraw_ppm_tiff_writer(iprc
,outfn
);
107 void usage(const char*p
)
109 printf("%s: Multi-threaded LibRaw sample app. Emulates dcraw -h [-w] [-a]\n",p
);
112 "-J n - set parrallel job coun (default 2)\n"
114 "-w - use camera white balance\n"
115 "-a - average image for white balance\n");
119 int show_files(void *q
)
123 while(p
= get_next_file())
132 int main(int ac
, char *av
[])
134 int i
, thread_count
,max_threads
= 2;
139 queue
= calloc(ac
-1,sizeof(queue
[0]));
145 if(av
[i
][1]=='w') use_camera_wb
= 1;
146 if(av
[i
][1]=='a') use_auto_wb
= 1;
147 if(av
[i
][1]=='v') verbose
= 1;
148 if(av
[i
][1]=='T') tiff_mode
= 1;
151 max_threads
=atoi(av
[++i
]);
154 fprintf(stderr
,"Job count should be at least 1\n");
160 queue
[qsize
++] = av
[i
];
162 pthread_mutex_init(&qm
,NULL
);
163 threads
= calloc(max_threads
,sizeof(threads
[0]));
164 for(i
=0;i
<max_threads
;i
++)
165 pthread_create(&threads
[i
],NULL
,process_files
,NULL
);
166 for(i
=0;i
<max_threads
;i
++)
171 pthread_join(threads
[i
],&iptr
);
173 printf("Thread %d : %d files\n",i
,(int)iptr
);