Sdcb.LibRaw 0.21.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Sdcb.LibRaw --version 0.21.1
NuGet\Install-Package Sdcb.LibRaw -Version 0.21.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sdcb.LibRaw" Version="0.21.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sdcb.LibRaw --version 0.21.1
#r "nuget: Sdcb.LibRaw, 0.21.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sdcb.LibRaw as a Cake Addin
#addin nuget:?package=Sdcb.LibRaw&version=0.21.1

// Install Sdcb.LibRaw as a Cake Tool
#tool nuget:?package=Sdcb.LibRaw&version=0.21.1

Sdcb.LibRaw NuGet NuGet GitHub

Advanced raw image processing library in C# based on LibRaw.

NuGet Packages

Package NuGet License Comments
Sdcb.LibRaw NuGet MIT Primary package
Sdcb.LibRaw.runtime.win64 NuGet LGPL-2.1-only OR CDDL-1.0 Windows x64 runtime
Sdcb.LibRaw.runtime.win32 NuGet LGPL-2.1-only OR CDDL-1.0 Windows x86 runtime

High level API Usage

Please note all examples below need install following NuGet packages:

  • Sdcb.LibRaw
  • Sdcb.LibRaw.runtime.win64 (or Sdcb.LibRaw.runtime.win32)

For Linux/MacOS, please install libraw package first.

Convert raw file into bitmap

using Sdcb.LibRaw;

using RawContext r = RawContext.OpenFile(@"C:\Users\ZhouJie\Pictures\a7r3\11030126\DSC02653.ARW");
r.Unpack();
r.DcrawProcess();
using ProcessedImage image = r.MakeDcrawMemoryImage();
using Bitmap bmp = ProcessedImageToBitmap(image);

Bitmap ProcessedImageToBitmap(ProcessedImage rgbImage)
{
	fixed (void* data = rgbImage.GetData<byte>())
	{
		SwapRedAndBlue(rgbImage.GetData<byte>(), rgbImage.Width, rgbImage.Height);
		using Bitmap bmp = new Bitmap(rgbImage.Width, rgbImage.Height, rgbImage.Width * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, (IntPtr)data);
		return new Bitmap(bmp);
	}
}

void SwapRedAndBlue(Span<byte> rgbData, int width, int height)
{
	int totalPixels = width * height;
	for (int i = 0; i < totalPixels; i++)
	{
		int pixelIndex = i * 3;
		byte red = rgbData[pixelIndex];
		byte blue = rgbData[pixelIndex + 2];

		rgbData[pixelIndex] = blue;
		rgbData[pixelIndex + 2] = red;
	}
}

Convert raw file into bitmap with custom settings

using Sdcb.LibRaw;

using RawContext r = RawContext.OpenFile(@"C:\Users\ZhouJie\Pictures\a7r3\11030126\DSC02653.ARW");
// r.ExportRawImage is a shortcut for r.Unpack() + r.DcrawProcess() + r.MakeDcrawMemoryImage()
using ProcessedImage rgbImage = r.ExportRawImage(c =>
{
	c.HalfSize = true;   // half width and half height
	c.UseAutoWb = true;  // use auto white balance
	c.Gamma[0] = 0.55f;  // gamma for inverse power
	c.Gamma[1] = 3.5f;   // gamma for slope
	c.Brightness = 2.2f; // brightness adjustments
});
using Bitmap bmp = ProcessedImageToBitmap(rgbImage);

// ProcessedImageToBitmap is the same as above
// SwapRedAndBlue is the same as above

Get raw file thumbnail

using Sdcb.LibRaw;

using RawContext r = RawContext.OpenFile(@"C:\Users\ZhouJie\Pictures\a7r3\11030126\DSC02653.ARW");
// r.ExportThumbnail() is a shortcut for r.UnpackThumbnail() + r.MakeDcrawMemoryThumbnail()
using ProcessedImage image = r.ExportThumbnail(thumbnailIndex: 0);
using Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(image.GetData<byte>().ToArray()));

Save raw file as tiff into local file

using Sdcb.LibRaw;

using RawContext r = RawContext.OpenFile(@"C:\Users\ZhouJie\Pictures\a7r3\11030126\DSC02653.ARW");
// r.SaveRawImage() is a shortcut for r.Unpack() + r.DcrawProcess() + r.WriteDcrawPpmTiff(fileName)
r.SaveRawImage(@"C:\test\test.tiff", c =>
{
	c.Brightness = 2.2f;
});

Low level API

API mapping reference

You can refer to following 2 pages to find out which C API is mapped to which C# API:

Low level API usage

You can refer to existing unit tests for low level api usage.

License

The primary project(Sdcb.LibRaw) is licensed under the MIT license, but native packages are licensed under LGPL-2.1-only OR CDDL-1.0.

Please refer to LibRaw license for more details.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.21.1.6 382 8/2/2023
0.21.1.2 119 7/31/2023
0.21.1.1 141 6/19/2023
0.21.1 152 6/12/2023
0.21.1-preview.6 90 8/1/2023