Add new comment

Support of monochromatic DNG in LibRAW

Hello,

First of all, thanks for your great work.

I have an issue with reading monochromatic DNG image. The result is pretty weird. I can't figure out if there are problems with the source DNG image itself, or with LibRaw. Maybe I'm using it wrong, but usually DNG images are loaded pretty well. But not this one.

In the attachement there is comparison image just to take a quick look at the problem.

I'm using LibRaw 0.17.3, but I've tried latest LibRaw 0.20 beta, with the same results.

My LibRaw-related code (slightly simplified):

  1. LibRaw rawProcessor;
  2. int errCode = 0;
  3. errCode = rawProcessor.open_file(fileName.toUtf8().data());
  4.  
  5. if (errCode != LIBRAW_SUCCESS) {
  6. setLastError(QString("Can not open raw image: %1").arg(QString(libraw_strerror(errCode))));
  7. return nullptr;
  8. }
  9.  
  10. rawProcessor.imgdata.params.use_camera_wb = applyWhiteBalance;
  11. rawProcessor.imgdata.params.use_auto_wb = 0;
  12. rawProcessor.imgdata.params.no_auto_bright = 1;
  13. rawProcessor.imgdata.params.no_interpolation = 0;
  14. rawProcessor.imgdata.params.use_camera_matrix = applyColorMatrix;
  15. rawProcessor.imgdata.params.output_color = 0; // Raw
  16. rawProcessor.imgdata.params.output_bps = 16; // 16 bits per sample
  17. rawProcessor.imgdata.params.user_qual = 12; // AHD interpolation
  18.  
  19. if ((errCode = rawProcessor.unpack()) != LIBRAW_SUCCESS) {
  20. setLastError(QString("Can not unpack raw image: %1").arg(QString(libraw_strerror(errCode))));
  21. return nullptr;
  22. }
  23.  
  24. errCode = rawProcessor.dcraw_process();
  25.  
  26. if (errCode != LIBRAW_SUCCESS) {
  27. qDebug() << "LibRaw dcraw error:" << libraw_strerror(errCode);
  28. if (LIBRAW_FATAL_ERROR(errCode)) {
  29. setLastError(QString("Can not process raw image: %1").arg(QString(libraw_strerror(errCode))));
  30. return nullptr;
  31. }
  32. }
  33.  
  34. libraw_processed_image_t *rawImage = rawProcessor.dcraw_make_mem_image(&errCode);
  35.  
  36. if (!rawImage) {
  37. setLastError(QString("Can not unpack raw image: %1").arg(QString(libraw_strerror(errCode))));
  38. return nullptr;
  39. }
  40.  
  41. if (rawImage->type != LIBRAW_IMAGE_BITMAP) {
  42. setLastError("LibRaw unpacked image into JPEG instead of bitmap, this is not supported yet.");
  43. LibRaw::dcraw_clear_mem(rawImage);
  44. return nullptr;
  45. }
  46.  
  47. if (rawImage->bits == 8) {
  48. // ... No sense for this case ...
  49. } else { // rawImage->bits == 16
  50. RgbBufferFloat *realBuf = new RgbBufferFloat(QSize(rawImage->width, rawImage->height));
  51. if (realBuf->data() == nullptr) {
  52. setLastError("Out of memory");
  53. return nullptr;
  54. }
  55. float *imgPtr = realBuf->data();
  56. unsigned short *rawPtr = reinterpret_cast<unsigned short *>(rawImage->data);
  57. for (unsigned i = 0; i < rawImage->data_size; i += 2) {
  58. *(imgPtr++) = *(rawPtr++) / 65535.0f; // Convert into floating point values normalized to 0..1
  59. }
  60. return realBuf;
  61. }

Forums: