Sdcb.LibRaw 0.21.1.6

Prefix Reserved
dotnet add package Sdcb.LibRaw --version 0.21.1.6                
NuGet\Install-Package Sdcb.LibRaw -Version 0.21.1.6                
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.6" />                
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.6                
#r "nuget: Sdcb.LibRaw, 0.21.1.6"                
#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.6

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

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
Sdcb.LibRaw.runtime.linux64 NuGet LGPL-2.1-only OR CDDL-1.0 Ubuntu 22.04 x64 runtime

Install

Please note all examples below need install following NuGet packages:

  • Sdcb.LibRaw
  • Sdcb.LibRaw.runtime.win64
  • Sdcb.LibRaw.runtime.win32
  • Sdcb.LibRaw.runtime.linux-64 (for Ubuntu22.04 support)

All native packages are pre-compiled using vcpkg.

Please note the Sdcb.LibRaw.runtime.linux-64 package is only support Ubuntu22.04, if you using .NET in Docker, you should append jammy when write docker file, for example, you should write:

FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy

Instead of:

FROM mcr.microsoft.com/dotnet/sdk:6.0

if you want to use in other Linux distros without docker, please install libraw using OS provided package manager, for example, in Debian 11, you can install by running following bash command to install:

echo "deb http://deb.debian.org/debian experimental main" | tee -a /etc/apt/sources.list
echo "deb-src http://deb.debian.org/debian experimental main" | tee -a /etc/apt/sources.list
apt-get update
apt-get -t experimental install libraw-dev

Likewise in MacOS, you also need to install libraw using MacOS provided package manager.

High level API Usage

For high level API usage, I created RawContext class to wrap all LibRaw native functions, you can refer to following examples for more details.

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()
r.Gamma[0] = 0.55f; // gamma for inverse power
r.Gamma[1] = 3.5f;  // gamma for slope
using ProcessedImage rgbImage = r.ExportRawImage();
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");

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 1,176 8/2/2023
0.21.1.2 147 7/31/2023
0.21.1.1 175 6/19/2023
0.21.1 183 6/12/2023
0.21.1-preview.6 101 8/1/2023