Recent

Author Topic: LazPaint and RAW images  (Read 5800 times)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: LazPaint and RAW images
« Reply #15 on: October 17, 2019, 08:37:42 pm »
As Peter said, raw image contain "raw" sensor data (roughly equivalent to an undeveloped negative) along with the camera settings at the time the photo was taken (ISO, white-balance, aperture, shuter speed, etc.).

To convert all that to an image (a "positive") the software have to process the data taking into account the settings saved into the file and/or the ones set by the user (you can, for example, adjust the "exposition", the white balance, etc.).

The point is that, while not extremely complex, it requires some knowledge of DSP programming (it's not as simple as, say, converting a jpeg to a tiff or png) and the formats used to store the information are mostly propietary and can change without notice.

DCRAW does its best to "develop" raw images to an usable format but it can fail to take into account some obscure, changed or obfuscated setting in the file so the result is not always perfect.

That said, it's still one of the best alternatives to propietary software and using it is better (and quicker!) than trying to implement your own decoder.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: LazPaint and RAW images
« Reply #16 on: October 17, 2019, 10:14:10 pm »
Ok so the result of dcraw may not be great but it can still be usable, and that's probably the best opensource option, so if I provide it, that's without any guarantee.
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: LazPaint and RAW images
« Reply #17 on: October 18, 2019, 04:37:35 pm »
Hi folks

I've implemented using dcraw in dev branch of bgrabitmap.

On Linux and MacOS, it requires dcraw to be installed. Like 'sudo apt-get install dcraw'.

On Windows binaries are provided. When you're testing you need to copy the dcraw binary from bin\Windows\dcraw as dcraw.exe in the same folder as lazpaint*.exe.

It all seems to work fine. The thumbnails are a bit slow to load but I guess that's not too bad considering the file sizes. Loading in full definition though takes easily 10 seconds.
Conscience is the debugger of the mind

jus

  • New Member
  • *
  • Posts: 26
Re: LazPaint and RAW images
« Reply #18 on: November 23, 2019, 02:56:17 am »
If you are using Windows you can use the Windows Imaging Component to develop the raw files to bmp. I made very little modifications to the Delphi source from here and it compile in Lazarus.

Code: Pascal  [Select][+][-]
  1. type
  2.   { TForm1 }
  3.  
  4.   TForm1 = class(TForm)
  5.     Button1: TButton;
  6.     Memo1: TMemo;
  7.     procedure Button1Click(Sender: TObject);
  8.   private
  9.     { private declarations }
  10.     FImagingFactory: IWICImagingFactory;
  11.     function JpegToBitmap(const ASource, ATarget: string): Boolean;
  12.   public
  13.     { public declarations }
  14.   end;
  15.  
  16. var
  17.   Form1: TForm1;
  18.  
  19. implementation
  20.  
  21. {$R *.lfm}
  22.  
  23. { TForm1 }
  24.  
  25. procedure TForm1.Button1Click(Sender: TObject);
  26. begin
  27.   JpegToBitmap('C:\a\F14_0254.NEF', 'c:\a\F14_0254.bmp');
  28.  
  29.   showmessage('fertig');
  30. end;
  31.  
  32. function TForm1.JpegToBitmap(const ASource, ATarget: string): Boolean;
  33. var
  34.   FileStream: TFileStream;
  35.   StreamAdapter: TStreamAdapter;
  36.   BitmapInfo: TBitmapInfo;
  37.   BitmapBits: array of Byte;
  38.   BitmapWidth: Cardinal;
  39.   BitmapHeight: Cardinal;
  40.   BitmapOutput: graphics.TBitmap;
  41.   BitmapObject: IWICBitmap;
  42.   BitmapSource: IWICBitmapSource;
  43.   BitmapDecoder: IWICBitmapDecoder;
  44.   BitmapFrame: IWICBitmapFrameDecode;
  45.   i: Integer;
  46.   b: hBitmap;
  47. begin
  48.   if not Assigned(FImagingFactory) then
  49.     CoCreateInstance(CLSID_WICImagingFactory, nil, CLSCTX_INPROC_SERVER or
  50.       CLSCTX_LOCAL_SERVER, IUnknown, FImagingFactory);
  51.  
  52.   FileStream := TFileStream.Create(ASource, fmOpenRead or fmShareDenyWrite);
  53.   try
  54.     FileStream.Position := 0;
  55.     StreamAdapter := TStreamAdapter.Create(FileStream);
  56.  
  57.     OleCheck(FImagingFactory.CreateDecoderFromStream(StreamAdapter, GUID_NULL,
  58.       WICDecodeMetadataCacheOnDemand, BitmapDecoder));
  59.     OleCheck(BitmapDecoder.GetFrame(0, BitmapFrame));
  60.     OleCheck(FImagingFactory.CreateBitmapFromSource(BitmapFrame,
  61.       WICBitmapCacheOnLoad, BitmapObject));
  62.     OleCheck(BitmapObject.GetSize(BitmapWidth, BitmapHeight));
  63.     SetLength(BitmapBits, BitmapWidth * BitmapHeight * 4);
  64.     for i:=0 to 20 do
  65.     begin
  66.       Memo1.Lines.Add(IntToStr(i)+':'+IntToStr(BitmapBits[i]));
  67.     end;
  68.     Memo1.Lines.Add('-------------------------------');
  69.     OleCheck(WICConvertBitmapSource(GUID_WICPixelFormat32bppBGRA, BitmapObject,
  70.       BitmapSource));
  71.     OleCheck(BitmapSource.CopyPixels(nil, BitmapWidth * 4, Length(BitmapBits),
  72.       @BitmapBits[0]));
  73.  
  74.     FillChar(BitmapInfo, SizeOf(BitmapInfo), 0);
  75.     BitmapInfo.bmiHeader.biSize := SizeOf(BitmapInfo);
  76.     BitmapInfo.bmiHeader.biWidth := BitmapWidth;
  77.     BitmapInfo.bmiHeader.biHeight := -BitmapHeight;
  78.     BitmapInfo.bmiHeader.biPlanes := 1;
  79.     BitmapInfo.bmiHeader.biBitCount := 32;
  80.  
  81.     BitmapOutput := TBitmap.Create;
  82.     B := CreateBitmap(BitmapWidth, BitmapHeight, 1, 32, @BitmapBits[0]);
  83.     try
  84.       BitmapOutput.PixelFormat := pf32bit;
  85.       BitmapOutput.SetSize(BitmapWidth, BitmapHeight);
  86.       //SetDIBits(0, BitmapOutput.Handle, 0, BitmapHeight, @BitmapBits[0], BitmapInfo, DIB_RGB_COLORS);
  87.       SetDIBits(0, b, 0, BitmapHeight, @BitmapBits[0], BitmapInfo, DIB_RGB_COLORS);
  88.       //BitmapOutput.AlphaFormat := afDefined;
  89.       BitmapOutput.LoadFromBitmapHandles(b,0);
  90.       //BitmapOutput.CreateFromBitmapHandles(B, 0, Rect(0, 0, BitmapWidth, BitmapHeight))
  91.       BitmapOutput.SaveToFile(ATarget);
  92.     finally
  93.       DeleteObject(b);
  94.       BitmapOutput.Free;
  95.     end;
  96.   finally
  97.     FileStream.Free;
  98.   end;
  99. end;
  100.  
  101. end.
  102.  

Before you use it you have to download your camera raw supportpackage for windows imaging component from your camera manufacturer homepage first.
« Last Edit: November 23, 2019, 03:00:14 am by jus »

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: LazPaint and RAW images
« Reply #19 on: November 28, 2019, 11:53:11 pm »
Interesting, that's worth trying out
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018