How to use demosaic packs?

I'm currently writing a Python wrapper around libraw (https://github.com/neothemachine/rawpy) and wanted to play with the various GPLd demosaic algorithms. From the README it seems like there is some kind of integration, but then I couldn't find anything in libraw's API on how to use these algorithms together with libraw. I would be glad for some advice.

Thanks
Maik

Forums: 

1) You need to compile LibRaw

1) You need to compile LibRaw with demosaic packs
2) Just set imgdata.params.quality to needed demosaic method:
0 - linear, 1 - VNG, 2 - PPG, 3 - AHD, 4 - DCB 5 - modified AHD,6 - AFD (5pass), 7 - VCD, 8 - VCD+AHD, 9 - LMMSE

-- Alex Tutubalin

I have a little problem. It

I have a little problem. It seems as if the integer for user_qual is ignored. Maybe I'm doing something wrong. The output image is always exactly identical (checked with md5).
Basically I first create a LibRaw instance, then open_file(), then unpack(), then I set imgdata.params.user_qual=n, then I cal dcraw_process(), and finally dcraw_make_mem_image(). And the last three steps I'm doing in a loop (over n=0 to 10). Is that somehow wrong? Can I set the parameters only at the beginning?

Have you tried dcraw_emu with

Have you tried dcraw_emu with different -q [value] settings?

Also, if you set imgdata.params.half_size to non-zero, all demosaic code is turned off.

-- Alex Tutubalin

Using dcraw_emu it works, but

Using dcraw_emu it works, but I really don't know what I'm doing wrong. I'm not setting any params in my code except user_qual. Also, I wondered, are the params initialized to some default values? (different from the C integer defaults like 0 etc.)

Just tested this sample code

Just tested this sample code with LibRaw 0.16, everything looks OK (md5 of resulting PPMs are differ):

#include "libraw/libraw.h"
 
int main(int ac, char *av[])
{
  LibRaw libraw;
  if(ac<2) return 0;
  if(libraw.open_file(av[1]) != LIBRAW_SUCCESS) return 1;
  if(libraw.unpack() != LIBRAW_SUCCESS) return 2;
  for (int qual=0; qual <=9; qual++)
    {
      char fname[1024];
      libraw.imgdata.params.user_qual = qual;
      snprintf(fname,1023,"%s.%d.ppm",av[1],qual);
      printf("Processing qual=%d =>  %s\n",qual,fname);
      if(libraw.dcraw_process() != LIBRAW_SUCCESS) break;
      libraw_processed_image_t *img = libraw.dcraw_make_mem_image();
      if(img)
        {
          FILE *ofp = fopen(fname,"wb");
          if(!ofp) break;
          fprintf (ofp, "P%d\n%d %d\n%d\n",img->colors/2+5,img->width,img->height,(1<<img->bits)-1);
          fwrite(img->data,img->data_size,1,ofp);
          fclose(ofp);
          libraw.dcraw_clear_mem(img);
        }
    }
  return 0;
}

-- Alex Tutubalin

I found the problem in my

I found the problem in my code... I was assigning imgdata.params to a separate variable and set the values on that. But I didn't use a pointer for that, so it actually created a copy. Thanks for your support, I appreciate it :)