/* -*- C++ -*- * File: simple_dcraw.cpp * Copyright 2008-2009 Alex Tutubalin * Created: Sat Mar 8 , 2008 * * LibRaw simple C++ API (emulates call to "dcraw [-D] [-T] [-v] [-e] [-4]") * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #include #include #include #ifndef WIN32 #include #include #include #include #endif #include "libraw/libraw.h" #ifdef WIN32 #define snprintf _snprintf #endif int my_progress_callback(void *unused_data,enum LibRaw_progress state,int iter, int expected) { if(iter==0) printf("CB: state=%x, expected %d iterations\n",state,expected); return 0; } int main(int ac, char *av[]) { int i, ret, verbose=0, output_thumbs=0,use_mmap=0,msize; void *file_buffer; // don't use fixed size buffers in real apps! char outfn[1024],thumbfn[1024]; LibRaw RawProcessor; if(ac<2) { printf( "simple_dcraw - LibRaw %s sample. Emulates dcraw [-D] [-T] [-v] [-e] [-B]\n" " %d cameras supported\n" "Usage: %s [-D] [-T] [-v] [-e] raw-files....\n" "\t-D - document mode emulation\n" "\t-4 - 16-bit mode\n" "\t-v - verbose output\n" "\t-T - output TIFF files instead of .pgm/ppm\n" #ifndef WIN32 "\t-B - use mmap()-ed I/O (Unix only)\n" #endif "\t-e - extract thumbnails (same as dcraw -e in separate run)\n",LibRaw::version(), LibRaw::cameraCount(), av[0]); return 0; } putenv ((char*)"TZ=UTC"); // dcraw compatibility, affects TIFF datestamp field #define P1 RawProcessor.imgdata.idata #define S RawProcessor.imgdata.sizes #define C RawProcessor.imgdata.color #define T RawProcessor.imgdata.thumbnail #define P2 RawProcessor.imgdata.other #define OUT RawProcessor.imgdata.params for (i=1;i1?"ppm":"pgm")); if(verbose) printf("Writing file %s\n",outfn); if( LIBRAW_SUCCESS != (ret = RawProcessor.dcraw_ppm_tiff_writer(outfn))) fprintf(stderr,"Cannot write %s: %s\n",outfn,libraw_strerror(ret)); #ifndef WIN32 if(use_mmap && file_buffer) { munmap(file_buffer,msize); file_buffer=0; } #endif RawProcessor.recycle(); // just for show this call } return 0; }