How to add camera support to libraw/darktable?

I was trying to add support for the R5mk2 into libraw and darktable but I must miss a part. Here’s what I did so far.

Adding the colormatrix from Adobe into colordata.cpp:

	{ LIBRAW_CAMERAMAKER_Canon, "EOS R5 Mark II", 0, 0,
	  { 9396,-2598,-1207,-4408,12296,2369,-505,1575,6077 } },

and adding the cameraID to libraw_cameraids.h:

#define CanonID_EOS_R5m2          (0x80000000ULL + 0x496ULL)

adding the camera to canon.cpp in the FF part:

           || (id == CanonID_EOS_R5)
           || (id == CanonID_EOS_R5m2)

adding it to cameralist.cpp:

	"Canon EOS R5",
	"Canon EOS R5 Mark II",

and to normalize_model.cpp:

      { CanonID_EOS_R5,            "EOS R5"},
      { CanonID_EOS_R5m2,          "EOS R5 Mark II"},

in darktable I changed cameras.xml:

	<Camera make="Canon" model="Canon EOS R5m2" supported="no">
		<ID make="Canon" model="EOS R5 Mark II">Canon EOS R5 Mark II</ID>

and imageio_libraw.c:

  {
    .exif_make = "Canon",
    .exif_model = "Canon EOS R5m2",
    .clean_make = "Canon",
    .clean_model = "EOS R5 Mark II",
    .clean_alias = "EOS R5 Mark II"
  },

Finally to get rid of the wb warning I copy pasted another one into wb_presets (will be done as soon as i have the camera myself as well as the noiseprofile). But darktable still says it cant find the color matrix for the raw file I downloaded. Did I miss something or are the preproduction raw files just a little bit different to the final ones?

Firmware 1.0.0 files also don’t seem to work with this.

Files from Canon EOS R5 MK II – Google Drive

Ok as ColorDataSubVer seems to be 64, it most likely needs a new case here:

    case 3656: // R5, R6; ColorDataSubVer: 33
      imCanon.ColorDataVer = 10;
      AsShot_Auto_MeasuredWB(0x0055);
      CR3_ColorData(0x0055);
      break;

    case 3973: // R3; ColorDataSubVer: 34
    case 3778: // R6 Mark II, R7, R8, R10, R50; ColorDataSubVer: 48
      imCanon.ColorDataVer = 11;
      AsShot_Auto_MeasuredWB(0x0069);

      fseek(ifp, save1 + ((0x0069+0x0064) << 1), SEEK_SET);
      Canon_WBpresets(2, 12);
      fseek(ifp, save1 + ((0x0069+0x00c3) << 1), SEEK_SET);
      Canon_WBCTpresets(0);
      offsetChannelBlackLevel2 = save1 + ((0x0069+0x0102) << 1);
      offsetChannelBlackLevel  = save1 + ((0x0069+0x0213) << 1);
      offsetWhiteLevels        = save1 + ((0x0069+0x0217) << 1);
      break;

anyone here willing or has the time to teach me how to find the respective bit positions in the raw file? I guess it’s not that hard but my c++ skills are basically nonexistent.

Ok case seems to be 4528 and just putting it like the R3 does not work so bit positions are likely somewhere else

Ok getting closer. Colors work fine for me, although the white value is not the specular one although I am addressing the correct field

case 4528: // R5 Mark II; ColorDataSubVer: 64
      imCanon.ColorDataVer = 12;
      AsShot_Auto_MeasuredWB(0x0069);     

      //fseek(ifp, save1 + ((0x0069+0x0064) << 1), SEEK_SET);
      //Canon_WBpresets(2, 12);
      //fseek(ifp, save1 + ((0x0069+0x00c3) << 1), SEEK_SET);
      //Canon_WBCTpresets(0);
      offsetChannelBlackLevel2 = save1 + (0x017f << 1); 
      offsetChannelBlackLevel  = save1 + (0x0290 << 1); 
      offsetWhiteLevels        = save1 + (0x0294 << 1); 
      break;

edit: needs to be 294 for it to find the correct white point (reading the few lines afterwards would have helped figuring this out :wink: )

edit2: for WBpresets and WBCTpresets I’m still lost, as exiftool lists all tags as unknown so far unfortunately

Also if someone would explain the 0x0069+0x0102 notation it would be nice. For me this kinda unnecessarily obfuscates the correct address but I am obviously missing something here. Most likely written as offset to the measured WB field.

edit: Changed ColorDateVer back to 11
edit2: Changed ColorDateVer back to 12 according to Add Canon R5m2 Colorinfo

2 Likes

ok, with exiftool supprting the new tags it’s:

    case 4528: // R5 Mark II; ColorDataSubVer: 64
      imCanon.ColorDataVer = 12;
      AsShot_Auto_MeasuredWB(0x0069);     

      fseek(ifp, save1 + (0x006e << 1), SEEK_SET);
      Canon_WBpresets(2, 12);
      fseek(ifp, save1 + (0x0140 << 1), SEEK_SET);
      Canon_WBCTpresets(0);
      offsetChannelBlackLevel2 = save1 + (0x017f << 1); 
      offsetChannelBlackLevel  = save1 + (0x0290 << 1); 
      offsetWhiteLevels        = save1 + (0x0294 << 1); 
      break;
2 Likes

I wrote a short blog post on the process if anyone is interested: Adding new camera support in darktable / LibRaw / ExifTool – Pandas Welt

7 Likes

Thank you @piratenpanda. Your blog post works for me.

2 Likes