/* -*- C++ -*- * File: dcraw_emu.cpp * Copyright 2008-2010 LibRaw LLC (info@libraw.org) * Created: Sun Mar 23, 2008 * * LibRaw simple C++ API sample: almost complete dcraw emulator * LibRaw is free software; you can redistribute it and/or modify it under the terms of the one of three licenses as you choose: 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 (See file LICENSE.LGPL provided in LibRaw distribution archive for details). 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 (See file LICENSE.CDDL provided in LibRaw distribution archive for details). 3. LibRaw Software License 27032010 (See file LICENSE.LibRaw.pdf provided in LibRaw distribution archive for details). */ #ifdef WIN32 // suppress sprintf-related warning. sprintf() is permitted in sample code #define _CRT_SECURE_NO_WARNINGS #endif #include #include #include #include #include #ifndef WIN32 #include #include #include #include #include #endif #include "libraw/libraw.h" #ifdef WIN32 #define snprintf _snprintf #include #endif void write_ppm(libraw_processed_image_t *img, const char *basename) { if(!img) return; // type SHOULD be LIBRAW_IMAGE_BITMAP, but we'll check if(img->type != LIBRAW_IMAGE_BITMAP) return; // only 3-color images supported... if(img->colors != 3) return; char fn[1024]; snprintf(fn,1024,"%s.ppm",basename); FILE *f = fopen(fn,"wb"); if(!f) return; fprintf (f, "P6\n%d %d\n%d\n", img->width, img->height, (1 << img->bits)-1); /* NOTE: data in img->data is not converted to network byte order. So, we should swap values on some architectures for dcraw compatibility (unfortunately, xv cannot display 16-bit PPMs with network byte order data #define SWAP(a,b) { a ^= b; a ^= (b ^= a); } if (img->bits == 16 && htons(0x55aa) != 0x55aa) for(unsigned i=0; i< img->data_size; i+=2) SWAP(img->data[i],img->data[i+1]); #undef SWAP */ fwrite(img->data,img->data_size,1,f); fclose(f); } int main(int argc, char *argv[]) { char filename[] = "raw_canon_550d.cr2"; LibRaw rawProcessor_; int rc; for (int i = 0; i < 10; i++) { libraw_processed_image_t* rawImg = NULL; rc = rawProcessor_.open_file(filename); rc = rawProcessor_.unpack(); rawProcessor_.imgdata.params.filtering_mode = LIBRAW_FILTERING_AUTOMATIC; rawProcessor_.imgdata.params.output_bps = 16; // Write 16 bits per color value // rawProcessor_.imgdata.params.gamm[0] = rawProcessor_.imgdata.params.gamm[1] = 1.0; // linear gamma curve // rawProcessor_.imgdata.params.no_auto_bright = 1; // Don't use automatic increase of brightness by histogram. rawProcessor_.imgdata.params.document_mode = 0; // standard processing (with white balance) rawProcessor_.imgdata.params.use_camera_wb = 1; // If possible, use the white balance from the camera. rawProcessor_.imgdata.params.half_size = 1; rc = rawProcessor_.dcraw_process(); rawImg = rawProcessor_.dcraw_make_mem_image(&rc); char ppmfname[128]; snprintf(ppmfname,1024,"%04i",i); write_ppm(rawImg, ppmfname); rawProcessor_.dcraw_clear_mem(rawImg); rawProcessor_.recycle(); } return 0; } //not truncated