Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
6577b4c
Add ASTC decoding support
Erik-White Feb 27, 2026
6e58d6f
Integrate AstcSharp ASTC decoder
Erik-White Feb 27, 2026
0aba876
Use existing test utils for Astc tests
Erik-White Feb 27, 2026
44599c8
Add HDR support
Erik-White Feb 27, 2026
724bd61
Fix overflow issue
Erik-White Feb 27, 2026
abd3b4c
Move KTX1 test images to subdirectories
Erik-White Feb 27, 2026
86ff81a
Remove unused AstcSharp reference
Erik-White Mar 6, 2026
94d0f72
Small fixes and variable naming
Erik-White Mar 6, 2026
e7ce5fa
Astc files are little endian
Erik-White Mar 6, 2026
1d3acec
Update shared infra
Erik-White Mar 6, 2026
438959e
Add more defensive checks for ASTC input
Erik-White Mar 11, 2026
fd19b63
Remove unused decoder overload
Erik-White May 9, 2026
58814e5
Use correct pixel format for VK_FORMAT_R16G16B16A16_SFLOAT
Erik-White May 9, 2026
ee624ca
Add R16G16_SFLOAT, R16G16B16_SFLOAT, R32_SFLOAT, BC3_UNORM_BLOCK sup…
Erik-White May 9, 2026
ccc9737
Add cubemap test extension
Erik-White May 9, 2026
a7a0b55
Use standard library methods for swapping endianess
Erik-White May 9, 2026
a232b62
Avoid partial reads
Erik-White May 9, 2026
42bed20
Guard against malformed cubemaps
Erik-White May 9, 2026
3af005b
Tests for new guards
Erik-White May 9, 2026
42caec4
Validate block lengths and dimensions
Erik-White May 9, 2026
8085dc9
Document sRGB handling
Erik-White May 9, 2026
aaac865
Add explicit handling for vulkan formats
Erik-White May 9, 2026
063f551
Implement support for sfloat block types
Erik-White May 9, 2026
f426588
Add guards for non seekable streams
Erik-White May 9, 2026
c9e3014
Avoid boxing conversions in TryGetBits
Erik-White May 9, 2026
73424dd
Consolidate overlapping endian handlers
Erik-White May 9, 2026
4ca0f94
Prevent buffer corruption in ShiftBuffer
Erik-White May 9, 2026
4d393b4
Correctly handle arraypool semantics
Erik-White May 9, 2026
734dd5c
Address thread safety in BISD and DecimationTable
Erik-White May 9, 2026
1a794cd
Make sure to throw when HDR endpoint is sent to DecodeColorsForMode
Erik-White May 9, 2026
17cc728
Don't silently truncate HDR via LDR API
Erik-White May 9, 2026
f0edcb0
Tighten image comparison tolerances
Erik-White May 9, 2026
b38bfda
Improve readme
Erik-White May 9, 2026
cfc8ef9
Major tidy up of minor details
Erik-White May 9, 2026
f53d718
Fix the astcencodercsharp dependency path
Erik-White May 9, 2026
2a3e400
Combine DecodeBiseValues and DecodeBiseWeights
Erik-White May 9, 2026
af204fd
Combine writer methods for fused LDR/HDR decoders
Erik-White May 9, 2026
cdf6a9e
Fix benchmarks test data path
Erik-White May 10, 2026
b9eb410
Clean up and formatting
Erik-White May 10, 2026
9ce3e3b
Split out test methods from LogicalBlock
Erik-White May 10, 2026
9ba4575
Refactor LogicalBlock tests to remove intrusive, low value tests
Erik-White May 10, 2026
6697e13
Move LnsToSf16 out of LogicalBlock
Erik-White May 10, 2026
db6ae9c
Clean up unused methods in Partition
Erik-White May 10, 2026
a6307c6
Refactor decoder to simplify where possible
Erik-White May 10, 2026
7620476
Refactor large encoding methods to smaller, more understandable units
Erik-White May 10, 2026
e165ec6
Split out private classes
Erik-White May 10, 2026
7d89e04
Continue refactoring to break down large encoding methods
Erik-White May 10, 2026
02e6f8e
Split up and refactor block methods
Erik-White May 10, 2026
f4bd0be
Split up split/search/write phases to separate opeations
Erik-White May 10, 2026
641e14c
Refactor and split up DecodeAllBlocks for LDR/HDR
Erik-White May 10, 2026
5720aaf
Consolidate bit placement logic via ApplyBitPlacements
Erik-White May 10, 2026
d0f25cd
Extract common swap/pack function
Erik-White May 10, 2026
06425f6
Remove IntermediateBlock
Erik-White May 10, 2026
e02a617
remove redundant endpoint.IsHdr branch
Erik-White May 10, 2026
e317acb
Unify DecodeAllBlocks methods
Erik-White May 10, 2026
dcf5c8f
Streamline DecompressBlock methods to thin wrappers
Erik-White May 10, 2026
22b3cf1
Cache partitions across blocks
Erik-White May 10, 2026
163434c
Consolidate interpolation functions
Erik-White May 10, 2026
d909006
Reference ASTC spec in pipeline where possible
Erik-White May 10, 2026
68dcfcd
Consolidate small repeated functions
Erik-White May 10, 2026
28ff800
Reorganize ASTC decoder
Erik-White May 13, 2026
872cb18
Remove state from BIS decoder
Erik-White May 13, 2026
d9806de
Consolidate EndpointCodec API
Erik-White May 13, 2026
36cfc81
Combine LDR and HDR endpoint decode
Erik-White May 14, 2026
053ae6b
Avoid allocating LogicalBlock on the heap
Erik-White May 14, 2026
60dd5e5
Annotate usage of stackalloc
Erik-White May 14, 2026
4d0f25f
Encapsulate block state during decoding
Erik-White May 14, 2026
e153824
Extract HDR/LDR pixel methods from LogicalBlock
Erik-White May 14, 2026
24a5e6d
Invert void extent check
Erik-White May 14, 2026
1badfa0
Simplify bit placement lookup
Erik-White May 14, 2026
a84e5f1
Store ordered encoding modes once
Erik-White May 14, 2026
b0bb03a
Store channel count in single location
Erik-White May 14, 2026
2a01aeb
Calculate BISE block size in one place
Erik-White May 14, 2026
bf49f40
Move blend methods to interpolation
Erik-White May 14, 2026
9801606
TryReadBlockBits no longer needed
Erik-White May 14, 2026
dd517b4
Try to limit mutation of Partition
Erik-White May 14, 2026
6093e2b
Skip redundant bounds checks for bit count
Erik-White May 14, 2026
f51c202
Remove redundant fields on Partition
Erik-White May 14, 2026
380dc90
Clean up BlueContract swap path
Erik-White May 14, 2026
a7bac74
Move Rgba extensions to ColorEncoding
Erik-White May 14, 2026
c408084
Fix potential race in Partition construction
Erik-White May 14, 2026
3fc63b7
Encapsulate IsFusable on BlockInfo
Erik-White May 14, 2026
4eeb587
Build QuantizationMaps from static constructors
Erik-White May 14, 2026
4d88f9b
Clean up redundant methods, properties, arguments
Erik-White May 14, 2026
f378bbc
Don't silently fail on invalid blocks
Erik-White May 14, 2026
b121b1c
Don't return nullable quant maps
Erik-White May 14, 2026
af22aef
Don't need to fully qualify names
Erik-White May 14, 2026
29e3405
Combine unquantize functions
Erik-White May 14, 2026
7dc6da6
return correct mode
Erik-White May 14, 2026
cfcd86e
BISE can be static
Erik-White May 14, 2026
f6e5efb
Small cleanups in BISE
Erik-White May 14, 2026
f9f9aa3
Note swap semantics
Erik-White May 14, 2026
07c91cb
Tiny tidy
Erik-White May 14, 2026
7fde153
BlockInfo should be immutable
Erik-White May 14, 2026
94c15ee
Simplify CopyBlockRect
Erik-White May 14, 2026
3b9bb20
Test for HDR void-extent blocks
Erik-White May 14, 2026
6d7aec2
Add regression tests for multithreaded and block decoding
Erik-White May 14, 2026
ccefd1b
Move references tests to main test project
Erik-White May 14, 2026
2d0d52d
Add LDR/HDR reference benchmarks
Erik-White May 14, 2026
bee1074
Add reference persistence benchmark
Erik-White May 14, 2026
b9363b1
Add larger HDR test files
Erik-White May 14, 2026
4704375
Add fuzzing tests with FuzzSharp
Erik-White May 15, 2026
cb7bf3e
Add support for fuzzing with libfuzzer
Erik-White May 15, 2026
06e8257
Increase fuzzing coverage
Erik-White May 15, 2026
4487d89
Use ImageSharp guards
Erik-White May 15, 2026
ab09b5b
Remove old reference tests project
Erik-White May 15, 2026
6fa49d9
Rename HDR namespace to titlecase for consistency
Erik-White May 15, 2026
11758b9
Merge branch 'main' into implement-astc-decoding
Erik-White May 15, 2026
8e244ec
Reorganize test data for consistency
Erik-White May 15, 2026
cae17ca
Add stream based overloads for AstcDecoder
Erik-White May 15, 2026
845b24e
Use ImageSharp allocator
Erik-White May 15, 2026
c0ff0f6
Improve ktx1 ASTC test coverage
Erik-White May 15, 2026
100aa5c
Fix off-by-one error in LDR quantization
Erik-White May 15, 2026
e999744
Revise doc references and include sources in repo
Erik-White May 16, 2026
35c78e2
Make sure to dispose images in tests
Erik-White May 16, 2026
91317c6
Fix race in test output paths
Erik-White May 16, 2026
d916af9
Consolidate Hdr properties for BlockInfo
Erik-White May 16, 2026
6bf7b5a
Clean up redundant code in DecompressImage
Erik-White May 16, 2026
31a9def
Use integer maths for scale factor
Erik-White May 16, 2026
4933ec1
Simplify partition cache key
Erik-White May 16, 2026
d8ddf54
BlockModeDecoder lookup tables should be static
Erik-White May 16, 2026
07efe2d
Enforce read only properties where possible
Erik-White May 16, 2026
270bdd1
Remove remaining encoding related code
Erik-White May 16, 2026
83c761c
Use centralized value for channel count
Erik-White May 16, 2026
060af19
Remove redundant argument name parameters
Erik-White May 16, 2026
7e20e5f
Combine and simplify reference benchmark cases
Erik-White May 16, 2026
0af7e7a
Avoid buffer allocation overhead for reference decoder benchmark
Erik-White May 16, 2026
83eae61
Use ARM decoder as benchmark baseline
Erik-White May 16, 2026
ecc374e
Write magenta error colour instead of black, or throwing
Erik-White May 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"sharpfuzz.commandline": {
"version": "2.0.2",
"commands": [
"sharpfuzz"
]
}
}
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
*.dds filter=lfs diff=lfs merge=lfs -text
*.ktx filter=lfs diff=lfs merge=lfs -text
*.ktx2 filter=lfs diff=lfs merge=lfs -text
*.astc filter=lfs diff=lfs merge=lfs -text
Comment thread
Erik-White marked this conversation as resolved.
*.pam filter=lfs diff=lfs merge=lfs -text
*.pbm filter=lfs diff=lfs merge=lfs -text
*.pgm filter=lfs diff=lfs merge=lfs -text
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,9 @@ artifacts/

# Tests
**/Images/ActualOutput

# Fuzz harness — libFuzzer-generated artefacts, per-target publish dirs, downloaded driver cache.
tests/ImageSharp.Textures.FuzzTests/findings/
tests/ImageSharp.Textures.FuzzTests/publish/
tests/ImageSharp.Textures.FuzzTests/corpus/
tests/ImageSharp.Textures.FuzzTests/.tools/
69 changes: 60 additions & 9 deletions ImageSharp.Textures.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
# Visual Studio Version 18
VisualStudioVersion = 18.5.11716.220
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Textures", "src\ImageSharp.Textures\ImageSharp.Textures.csproj", "{1588F6C4-2186-4A35-9693-E9F296791393}"
EndProject
Expand Down Expand Up @@ -49,35 +49,78 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\build-and-test.yml = .github\workflows\build-and-test.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageSharp.Textures.FuzzTests", "tests\ImageSharp.Textures.FuzzTests\ImageSharp.Textures.FuzzTests.csproj", "{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{1588f6c4-2186-4a35-9693-e9f296791393}*SharedItemsImports = 5
tests\Images\Images.projitems*{17fcbd4d-d232-45e8-876f-dfbc2fad52cf}*SharedItemsImports = 5
tests\Images\Images.projitems*{18be79b6-6b95-4ed7-a963-ad75f6cb9f3c}*SharedItemsImports = 5
tests\Images\Images.projitems*{68a8cc40-6aed-4e96-b524-31b1158fdeea}*SharedItemsImports = 13
tests\Images\Images.projitems*{b159ffd1-e646-42d0-892c-4abf69103712}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1588F6C4-2186-4A35-9693-E9F296791393}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1588F6C4-2186-4A35-9693-E9F296791393}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1588F6C4-2186-4A35-9693-E9F296791393}.Debug|x64.ActiveCfg = Debug|Any CPU
{1588F6C4-2186-4A35-9693-E9F296791393}.Debug|x64.Build.0 = Debug|Any CPU
{1588F6C4-2186-4A35-9693-E9F296791393}.Debug|x86.ActiveCfg = Debug|Any CPU
{1588F6C4-2186-4A35-9693-E9F296791393}.Debug|x86.Build.0 = Debug|Any CPU
{1588F6C4-2186-4A35-9693-E9F296791393}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1588F6C4-2186-4A35-9693-E9F296791393}.Release|Any CPU.Build.0 = Release|Any CPU
{1588F6C4-2186-4A35-9693-E9F296791393}.Release|x64.ActiveCfg = Release|Any CPU
{1588F6C4-2186-4A35-9693-E9F296791393}.Release|x64.Build.0 = Release|Any CPU
{1588F6C4-2186-4A35-9693-E9F296791393}.Release|x86.ActiveCfg = Release|Any CPU
{1588F6C4-2186-4A35-9693-E9F296791393}.Release|x86.Build.0 = Release|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Debug|x64.ActiveCfg = Debug|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Debug|x64.Build.0 = Debug|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Debug|x86.ActiveCfg = Debug|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Debug|x86.Build.0 = Debug|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Release|Any CPU.Build.0 = Release|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Release|x64.ActiveCfg = Release|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Release|x64.Build.0 = Release|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Release|x86.ActiveCfg = Release|Any CPU
{B159FFD1-E646-42D0-892C-4ABF69103712}.Release|x86.Build.0 = Release|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Debug|x64.ActiveCfg = Debug|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Debug|x64.Build.0 = Debug|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Debug|x86.ActiveCfg = Debug|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Debug|x86.Build.0 = Debug|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Release|Any CPU.Build.0 = Release|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Release|x64.ActiveCfg = Release|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Release|x64.Build.0 = Release|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Release|x86.ActiveCfg = Release|Any CPU
{18BE79B6-6B95-4ED7-A963-AD75F6CB9F3C}.Release|x86.Build.0 = Release|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Debug|x64.ActiveCfg = Debug|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Debug|x64.Build.0 = Debug|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Debug|x86.ActiveCfg = Debug|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Debug|x86.Build.0 = Debug|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Release|Any CPU.Build.0 = Release|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Release|x64.ActiveCfg = Release|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Release|x64.Build.0 = Release|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Release|x86.ActiveCfg = Release|Any CPU
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF}.Release|x86.Build.0 = Release|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Debug|x64.ActiveCfg = Debug|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Debug|x64.Build.0 = Debug|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Debug|x86.ActiveCfg = Debug|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Debug|x86.Build.0 = Debug|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Release|Any CPU.Build.0 = Release|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Release|x64.ActiveCfg = Release|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Release|x64.Build.0 = Release|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Release|x86.ActiveCfg = Release|Any CPU
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -90,8 +133,16 @@ Global
{17FCBD4D-D232-45E8-876F-DFBC2FAD52CF} = {6DF92068-B792-4038-8E3F-5FDF2E026BE7}
{E6224AB7-6987-4BA1-B2A6-ECFB7DA281DE} = {9F1F0B0F-704F-4B71-89EF-EE36042A27C9}
{9F19EBB4-32DB-4AFE-A5E4-722EDFAAE04B} = {E6224AB7-6987-4BA1-B2A6-ECFB7DA281DE}
{AB3955C1-C0BE-4B6E-84A2-32AB59DAB9CE} = {6DF92068-B792-4038-8E3F-5FDF2E026BE7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F1762A0D-74C4-454A-BCB7-C010BB067E58}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{1588f6c4-2186-4a35-9693-e9f296791393}*SharedItemsImports = 5
tests\Images\Images.projitems*{17fcbd4d-d232-45e8-876f-dfbc2fad52cf}*SharedItemsImports = 5
tests\Images\Images.projitems*{18be79b6-6b95-4ed7-a963-ad75f6cb9f3c}*SharedItemsImports = 5
tests\Images\Images.projitems*{68a8cc40-6aed-4e96-b524-31b1158fdeea}*SharedItemsImports = 13
tests\Images\Images.projitems*{b159ffd1-e646-42d0-892c-4abf69103712}*SharedItemsImports = 5
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SixLabors.ImageSharp.Textures

[![Build Status](https://img.shields.io/github/actions/workflow/status/SixLabors/ImageSharp.Textures/build-and-test.yml?branch=main)](https://github.com/SixLabors/ImageSharp.Textures/actions)
[![Code coverage](https://codecov.io/gh/SixLabors/ImageSharp.Textures/branch/main/graph/badge.svg)](https://codecov.io/gh/SixLabors/ImageSharp)
[![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![License: Six Labors Split](https://img.shields.io/badge/license-Six%20Labors%20Split-%23e30183)](https://github.com/SixLabors/ImageSharp/blob/main/LICENSE)
[![Twitter](https://img.shields.io/twitter/url/http/shields.io.svg?style=flat&logo=twitter)](https://twitter.com/intent/tweet?hashtags=imagesharp,dotnet,oss&text=ImageSharp.+A+new+cross-platform+2D+graphics+API+in+C%23&url=https%3a%2f%2fgithub.com%2fSixLabors%2fImageSharp&via=sixlabors)

</div>
Expand All @@ -33,6 +33,7 @@ with the following compressions:
- BC5
- BC6H
- BC7
- ASTC

Encoding textures is **not** yet supported. PR are of course very welcome.

Expand Down
2 changes: 1 addition & 1 deletion shared-infrastructure
5 changes: 3 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
-->

<!-- Import the shared src .props file -->
<Import Project="$(MSBuildThisFileDirectory)..\shared-infrastructure\msbuild\props\SixLabors.Src.props" />
<Import Project="$(MSBuildThisFileDirectory)../shared-infrastructure/msbuild/props/SixLabors.Src.props" />

<!-- Import the solution .props file. -->
<Import Project="$(MSBuildThisFileDirectory)..\Directory.Build.props" />
Expand All @@ -22,9 +22,10 @@
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="SixLabors.ImageSharp.Textures.Benchmarks" Key="$(SixLaborsPublicKey)" />
<InternalsVisibleTo Include="ImageSharp.Textures.Benchmarks" Key="$(SixLaborsPublicKey)" />
<InternalsVisibleTo Include="SixLabors.ImageSharp.Textures.InteractiveTest" Key="$(SixLaborsPublicKey)" />
<InternalsVisibleTo Include="SixLabors.ImageSharp.Textures.Tests" Key="$(SixLaborsPublicKey)" />
<InternalsVisibleTo Include="SixLabors.ImageSharp.Textures.FuzzTests" Key="$(SixLaborsPublicKey)" />
</ItemGroup>

</Project>
69 changes: 43 additions & 26 deletions src/ImageSharp.Textures/Common/Helpers/FloatHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using System;
using System.Runtime.CompilerServices;

namespace SixLabors.ImageSharp.Textures.Common.Helpers
Expand All @@ -14,32 +15,31 @@ internal static class FloatHelper
public static uint PackFloatToFloat32(float value) => Unsafe.As<float, uint>(ref value);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float UnpackFloat16ToFloat(uint value)
{
uint result =
((value >> 15) << 31) |
((((value >> 10) & 0x1f) - 15 + 127) << 23) |
((value & 0x3ff) << 13);
return Unsafe.As<uint, float>(ref result);
}
public static float UnpackFloat16ToFloat(uint value) => (float)BitConverter.UInt16BitsToHalf((ushort)value);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint PackFloatToFloat16(float value)
{
uint temp = Unsafe.As<float, uint>(ref value);
return
((temp >> 31) << 15) |
((((temp >> 23) & 0xff) - 127 + 15) << 10) |
((temp & 0x7fffff) >> 13);
}
public static uint PackFloatToFloat16(float value) => BitConverter.HalfToUInt16Bits((Half)value);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float UnpackFloat10ToFloat(uint value)
public static float UnpackFloat10ToFloat(uint value, uint bias = 10)
{
uint result =
((((value >> 5) & 0x1f) - 10 + 127) << 23) |
((value & 0x1f) << 18);
return Unsafe.As<uint, float>(ref result);
uint e = (value >> 5) & 0x1Fu;
uint m = value & 0x1Fu;

return e switch
{
// Zero
0 when m == 0 => 0f,

// Denormalized
0 => m * BitConverter.UInt32BitsToSingle((128u - bias - 5u) << 23),

// Inf/NaN
31 => BitConverter.UInt32BitsToSingle((0xFFu << 23) | (m << 18)),

// Normalized
_ => BitConverter.UInt32BitsToSingle(((e + 127u - bias) << 23) | (m << 18)),
};
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -52,12 +52,29 @@ public static uint PackFloatToFloat10(float value)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float UnpackFloat11ToFloat(uint value)
public static float UnpackFloat11ToFloat(uint value, uint bias = 11)
{
uint result =
((((value >> 6) & 0x1f) - 11 + 127) << 23) |
((value & 0x3f) << 17);
return Unsafe.As<uint, float>(ref result);
uint e = (value >> 6) & 0x1Fu;
uint m = value & 0x3Fu;

if (e == 0)
{
if (m == 0)
{
return 0f;
}

// Denormalized: m * 2^(1 - bias - 6)
return m * BitConverter.UInt32BitsToSingle((128u - bias - 6u) << 23);
}

if (e == 31)
{
uint ieee = (0xFFu << 23) | (m << 17);
return BitConverter.UInt32BitsToSingle(ieee);
}

return BitConverter.UInt32BitsToSingle(((e + 127u - bias) << 23) | (m << 17));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
Loading
Loading