Skip to content

Commit

Permalink
Merge pull request #1 from vvvv/compression
Browse files Browse the repository at this point in the history
Adds Compression options to the TextureWriter node
  • Loading branch information
torinos-yt authored Jun 23, 2024
2 parents 2133c41 + 534e64e commit 79deb11
Show file tree
Hide file tree
Showing 12 changed files with 821 additions and 656 deletions.
1,080 changes: 533 additions & 547 deletions VL.OpenEXR.vl

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions help/Example Write an exr texture.vl
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns:p="property" xmlns:r="reflection" Id="Rcu3NDFVVYdL9QMaVXfuME" LanguageVersion="2024.6.5" Version="0.128">
<Patch Id="QcyBSDz9jgYPBJjrZl6tIT">
<Canvas Id="Rh5YsOfHFh6OF2E4UspMnI" DefaultCategory="Main" BordersChecked="false" CanvasType="FullCategory" />
<!--
************************ Application ************************
-->
<Node Name="Application" Bounds="100,100" Id="NTBERjcNhjLO8rcRA0jTNZ">
<p:NodeReference>
<Choice Kind="ContainerDefinition" Name="Process" />
<FullNameCategoryReference ID="Primitive" />
</p:NodeReference>
<Patch Id="VnWWozZYndyMf9NPJEvbkF">
<Canvas Id="T1zaEIgktPTLw8Ay7gGZG7" CanvasType="Group">
<Node Bounds="250,183,67,19" Id="NxMcZdR9aATNw6KSEAFsQA">
<p:NodeReference LastCategoryFullName="OpenEXR" LastDependency="VL.OpenEXR.vl">
<Choice Kind="NodeFlag" Name="Node" Fixed="true" />
<Choice Kind="ProcessAppFlag" Name="FileTexture" />
</p:NodeReference>
<Pin Id="UFGjZuAmflENCfRr7wS9m2" Name="Node Context" Kind="InputPin" IsHidden="true" />
<Pin Id="ML8YvE0AjJSPFyKwUExW7y" Name="Path" Kind="InputPin" DefaultValue="..\resources\IndoorHDRI001_2K-HDR.exr" />
<Pin Id="SWgMEBbp3dePvfqwHMvdLp" Name="Reload" Kind="InputPin" DefaultValue="False" />
<Pin Id="AdhWUJ9jsMZNLHfnLJhtxp" Name="Texture" Kind="OutputPin" />
</Node>
<Pad Id="IMhNuRY6vk8PERDo13zTKI" Comment="Path" Bounds="252,150,165,15" ShowValueBox="true" isIOBox="true" Value="..\resources\OutdoorHDRI016_2K-HDR.exr">
<p:TypeAnnotation LastCategoryFullName="IO" LastDependency="CoreLibBasics.vl">
<Choice Kind="TypeFlag" Name="Path" />
</p:TypeAnnotation>
</Pad>
<Pad Id="QPjSFjOgiUtN8XBR5gF6U7" Comment="Texture" Bounds="252,236,190,132" ShowValueBox="true" isIOBox="true" />
<Node Bounds="988,1195,67,19" Id="HaboswqnLTeO2OWHB9JYdO">
<p:NodeReference LastCategoryFullName="OpenEXR" LastDependency="VL.OpenEXR.vl">
<Choice Kind="NodeFlag" Name="Node" Fixed="true" />
<Choice Kind="ProcessAppFlag" Name="FileTexture" />
</p:NodeReference>
<Pin Id="RAKhSDu4FSSOlQhaZ2Ybqz" Name="Node Context" Kind="InputPin" IsHidden="true" />
<Pin Id="EzFLvelmvDuLEDCOHMYKf9" Name="Path" Kind="InputPin" DefaultValue="..\resources\Out_OutdoorHDRI016_2K-HDR.exr" />
<Pin Id="QXLCmzRyXusMiaoh91L6e1" Name="Reload" Kind="InputPin" />
<Pin Id="DWUt4jKnZzBLHH2KKHVil4" Name="Texture" Kind="OutputPin" />
</Node>
<Node Bounds="250,495,79,19" Id="E3c764duVfPL3uks4hKCc5">
<p:NodeReference LastCategoryFullName="OpenEXR" LastDependency="VL.OpenEXR.vl">
<Choice Kind="NodeFlag" Name="Node" Fixed="true" />
<CategoryReference Kind="Category" Name="OpenEXR" NeedsToBeDirectParent="true" />
<Choice Kind="ProcessAppFlag" Name="TextureWriter" />
</p:NodeReference>
<p:HelpFocus p:Assembly="VL.Lang" p:Type="VL.Model.HelpPriority">High</p:HelpFocus>
<Pin Id="Sm1cwBQaoChLaqlSIv7opF" Name="Node Context" Kind="InputPin" IsHidden="true" />
<Pin Id="NYhuKOLhEPoP1GrifWOCEV" Name="Input" Kind="InputPin" />
<Pin Id="VcODYgZiKElLelnNOUIae2" Name="Filename" Kind="InputPin" />
<Pin Id="BHx2p6H4fx6QJEr4gczV83" Name="Compression" Kind="InputPin" />
<Pin Id="HHTLaeSr9yrL47bpQoO8ID" Name="Write" Kind="InputPin" />
</Node>
<Pad Id="JqOp7PzPifpOlpV3KT0K6Q" Comment="Compression" Bounds="302,432,104,15" ShowValueBox="true" isIOBox="true" Value="FastLossless">
<p:TypeAnnotation LastCategoryFullName="OpenEXR" LastDependency="VL.OpenEXR.vl">
<Choice Kind="TypeFlag" Name="ExrEncoding" />
</p:TypeAnnotation>
</Pad>
<Pad Id="IeyU8uz8xMRLHQ10vCNIMn" Comment="Filename" Bounds="277,402,140,15" ShowValueBox="true" isIOBox="true" Value="c:\temp\foo.exr">
<p:TypeAnnotation LastCategoryFullName="IO" LastDependency="VL.CoreLib.vl">
<Choice Kind="TypeFlag" Name="Path" />
</p:TypeAnnotation>
</Pad>
<Pad Id="G9OlV0FildwL4P9NYZwgNF" Comment="Write" Bounds="352,465,35,35" ShowValueBox="true" isIOBox="true" Value="false">
<p:TypeAnnotation LastCategoryFullName="Primitive" LastDependency="VL.CoreLib.vl">
<Choice Kind="ImmutableTypeFlag" Name="Boolean" />
</p:TypeAnnotation>
<p:ValueBoxSettings>
<p:buttonmode p:Assembly="VL.UI.Forms" p:Type="VL.HDE.PatchEditor.Editors.ButtonModeEnum">Bang</p:buttonmode>
</p:ValueBoxSettings>
</Pad>
<Pad Id="PWpVUUdOSr7Mf5FyhObH6a" Bounds="507,451,202,19" ShowValueBox="true" isIOBox="true" Value="https://openexr.com/en/latest/TechnicalIntroduction.html#data-compression">
<p:TypeAnnotation LastCategoryFullName="Primitive" LastDependency="VL.CoreLib.vl">
<Choice Kind="TypeFlag" Name="String" />
</p:TypeAnnotation>
<p:ValueBoxSettings>
<p:fontsize p:Type="Int32">9</p:fontsize>
<p:stringtype p:Assembly="VL.Core" p:Type="VL.Core.StringType">Link</p:stringtype>
</p:ValueBoxSettings>
</Pad>
<Pad Id="I85VsVlMMFTLJ9NfuI9HuZ" Bounds="507,427,191,19" ShowValueBox="true" isIOBox="true" Value="Compression options in detail:">
<p:TypeAnnotation LastCategoryFullName="Primitive" LastDependency="VL.CoreLib.vl">
<Choice Kind="TypeFlag" Name="String" />
</p:TypeAnnotation>
<p:ValueBoxSettings>
<p:fontsize p:Type="Int32">9</p:fontsize>
<p:stringtype p:Assembly="VL.Core" p:Type="VL.Core.StringType">Comment</p:stringtype>
</p:ValueBoxSettings>
</Pad>
</Canvas>
<Patch Id="O9xJLBchsLVNYbUACiJ0lm" Name="Create" />
<Patch Id="Ki1hvooTsWhP2jkewEfAY9" Name="Update" />
<ProcessDefinition Id="T5CpdTz91PqOqfcR4PWEEa">
<Fragment Id="KJFhfXxEy2gNanBUEW08Lt" Patch="O9xJLBchsLVNYbUACiJ0lm" Enabled="true" />
<Fragment Id="OxnmvCXqvkyPKxUgs7KK4v" Patch="Ki1hvooTsWhP2jkewEfAY9" Enabled="true" />
</ProcessDefinition>
<Link Id="D1xJOMK5kFlOqJ7sqtlB0r" Ids="IMhNuRY6vk8PERDo13zTKI,ML8YvE0AjJSPFyKwUExW7y" />
<Link Id="Ih5p89ne8k4P40LYcvK67i" Ids="AdhWUJ9jsMZNLHfnLJhtxp,QPjSFjOgiUtN8XBR5gF6U7" />
<Link Id="VxbbZvb2qkAMWqTKwWKXry" Ids="QPjSFjOgiUtN8XBR5gF6U7,NYhuKOLhEPoP1GrifWOCEV" />
<Link Id="UVGWmbU5YRrLIEDaR6JAPG" Ids="JqOp7PzPifpOlpV3KT0K6Q,BHx2p6H4fx6QJEr4gczV83" />
<Link Id="PndPtEkbACqNZn9pKy6DqA" Ids="IeyU8uz8xMRLHQ10vCNIMn,VcODYgZiKElLelnNOUIae2" />
<Link Id="KLAPe0pLNaOMq3I2V77gbL" Ids="G9OlV0FildwL4P9NYZwgNF,HHTLaeSr9yrL47bpQoO8ID" />
</Patch>
</Node>
</Patch>
<NugetDependency Id="TugQA41hz6gMTQv2Ue3Tha" Location="VL.CoreLib" Version="2024.6.5" />
<DocumentDependency Id="PKrJRPztKCDOettEG9UaO7" Location="../VL.OpenEXR.vl" />
<NugetDependency Id="EARv94p4Aj5N8NlvBot5uY" Location="VL.Stride" Version="2024.6.5" />
<NugetDependency Id="DrlANwRD6NILKp7OcAxxLc" Location="VL.Stride.Runtime" Version="2024.6.5" />
<NugetDependency Id="HyCxtVKd8vZNcARB9XVHUU" Location="VL.Stride.TextureFX" Version="2024.6.5" />
</Document>
Binary file removed lib/native/VL.OpenEXR.Native.dll
Binary file not shown.
Binary file added lib/net8.0/VL.OpenEXR.dll
Binary file not shown.
Binary file removed lib/netstandard2.0/VL.OpenEXR.dll
Binary file not shown.
Binary file added runtimes/win-x64/native/VL.OpenEXR.Native.dll
Binary file not shown.
50 changes: 28 additions & 22 deletions src/VL.OpenEXR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ enum ExrPixelFormat
RGBF32 = 3
}

public enum ExrEncoding {
Uncompressed = 0,
RLE = 1,
ZIP1 = 2,
ZIP16 = 3,
PIZ = 4,
}

public static class ExrLoader
{
#pragma warning disable CA5393
Expand All @@ -21,7 +29,7 @@ public static class ExrLoader
[DllImport("../native/VL.OpenEXR.Native.dll")]
static extern IntPtr load_from_path(string path, out int width, out int height, out ExrPixelFormat format);

public static Texture LoadFromPath(string path, GraphicsDevice device, CommandList commandList)
public static Texture LoadFromPath(string path, GraphicsDevice device)
{
ExrPixelFormat exrFormat;
PixelFormat format;
Expand All @@ -32,7 +40,7 @@ public static Texture LoadFromPath(string path, GraphicsDevice device, CommandLi
format = PixelFormat.None;
return null;
}

int sizeInBytes = 0;
bool hasAlpha = true;
(format, sizeInBytes, hasAlpha) = exrFormat switch
Expand All @@ -44,26 +52,33 @@ public static Texture LoadFromPath(string path, GraphicsDevice device, CommandLi
_ => (PixelFormat.None, 0, false),
};

var dataPointer = new DataPointer(ptr, width * height * (hasAlpha?4:3) * sizeInBytes);
var rowPitch = width * (hasAlpha ? 4 : 3) * sizeInBytes;

var texture = Texture.New2D(device, width, height, format);
texture.SetData(commandList, dataPointer);
var texture = Texture.New(
device,
TextureDescription.New2D(width, height, format, usage: GraphicsResourceUsage.Immutable),
new DataBox(ptr, rowPitch, rowPitch * height));

Marshal.FreeCoTaskMem(ptr);

return texture;
}
}

public static class ExrWriter
public static unsafe class ExrWriter
{
#pragma warning disable CA5393
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]

[DllImport("../native/VL.OpenEXR.Native.dll")]
static extern void write_texture(string path, int width, int height, ExrPixelFormat format, IntPtr data);

public static void WriteTexture(byte[] data, string path, int width, int height, PixelFormat format)
static extern int write_texture(string path, int width, int height, ExrPixelFormat format, ExrEncoding encoding, IntPtr data);

public static int WriteTexture(byte[] data, string path, int width, int height, PixelFormat format, ExrEncoding encoding)
{
return WriteTexture((ReadOnlySpan<byte>)data, path, width, height, format, encoding);
}

public static int WriteTexture(ReadOnlySpan<byte> data, string path, int width, int height, PixelFormat format, ExrEncoding encoding)
{
ExrPixelFormat exrFormat = format switch
{
Expand All @@ -73,20 +88,11 @@ public static void WriteTexture(byte[] data, string path, int width, int height,
_ => ExrPixelFormat.Unknown
};

if(exrFormat == ExrPixelFormat.Unknown) return;
if(exrFormat == ExrPixelFormat.Unknown) return 1; //return with error

GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
try
{
write_texture(path, width, height, exrFormat, handle.AddrOfPinnedObject());
}
catch(Exception e)
{
Console.WriteLine(e);
}
finally
{
handle.Free();
fixed (byte* pointer = data)
{
return write_texture(path, width, height, exrFormat, encoding, new IntPtr(pointer));
}
}
}
Expand Down
20 changes: 5 additions & 15 deletions src/VL.OpenEXR.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<OutputPath>..\lib</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<Reference Include="Stride">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Stride.dll</HintPath>
</Reference>
<Reference Include="Stride.Core">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Stride.Core.dll</HintPath>
</Reference>
<Reference Include="Stride.Graphics">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Steide.Graphics.dll</HintPath>
</Reference>
<PackageReference Include="Stride.Graphics" Version="4.2.0.2149" PrivateAssets="all" />
</ItemGroup>

</Project>
50 changes: 25 additions & 25 deletions src/VL.OpenEXR.sln
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31129.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VL.OpenEXR", "VL.OpenEXR.csproj", "{FDC6242A-4830-412E-8A76-BF776C864EF9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FDC6242A-4830-412E-8A76-BF776C864EF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDC6242A-4830-412E-8A76-BF776C864EF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDC6242A-4830-412E-8A76-BF776C864EF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDC6242A-4830-412E-8A76-BF776C864EF9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3C82B099-E534-4942-8049-DCF7C225D615}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VL.OpenEXR", "VL.OpenEXR.csproj", "{FDC6242A-4830-412E-8A76-BF776C864EF9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FDC6242A-4830-412E-8A76-BF776C864EF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDC6242A-4830-412E-8A76-BF776C864EF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDC6242A-4830-412E-8A76-BF776C864EF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDC6242A-4830-412E-8A76-BF776C864EF9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3C82B099-E534-4942-8049-DCF7C225D615}
EndGlobalSection
EndGlobal
13 changes: 13 additions & 0 deletions src/native/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#paths = ["/home/arturo/Code/na"]

[build]
target-dir = "./target"
#rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics"]
#rustflags = ["-Clink-arg=-fuse-ld=lld"]
#rustflags = ["-Clink-arg=-fuse-ld=mold"]
#pipelining = true

[target.x86_64-unknown-linux-gnu]
linker = "clang"
#rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold", "-Zshare-generics"]
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold"]
2 changes: 1 addition & 1 deletion src/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "vl_openexr_native"
crate-type = ["cdylib"]

[dependencies]
exr = "1.4.1"
exr = "1.72.0"
radiant = "0.3.0"

[profile.release]
Expand Down
Loading

0 comments on commit 79deb11

Please sign in to comment.