Add new comment

Source of test program:

#ifdef WIN32
// suppress sprintf-related warning. sprintf() is permitted in sample code
#define _CRT_SECURE_NO_WARNINGS
#endif
 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#ifndef WIN32
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/time.h>
#endif
 
#include "libraw/libraw.h"
#ifdef WIN32
#define snprintf _snprintf
#include <windows.h>
#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

Any idiot can face a crisis - it's day to day living that wears you out.
Anton Chekov