Skip to content

Commit a9bee39

Browse files
authored
Version 2 upgrade (#2)
* Updated to NET 10.0 * Moved texture names to SA3D.Modeling * Using Amicitia.IO for binary IO now * Textures, Index Textures, Palettes and Palettes now available as interfaces * Readonly classes available to prevent data from being modified * Improved Image reading/loading system, now supporting more formats * Added mipmap support and utilities for safe texture data handling
1 parent 826e94c commit a9bee39

35 files changed

Lines changed: 2425 additions & 1544 deletions

.github/workflows/build-and-publish.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ on:
88
- "[0-9]+.[0-9]+.[0-9]+"
99

1010
jobs:
11-
build:
11+
build-and-publish:
1212
runs-on: ubuntu-latest
1313

14+
permissions:
15+
id-token: write
16+
contents: write
17+
1418
steps:
1519
- name: Checkout Code
16-
uses: actions/checkout@v3
20+
uses: actions/checkout@v7
1721
with:
1822
fetch-depth: 0
1923
submodules: 'recursive'
@@ -24,9 +28,15 @@ jobs:
2428
- name: Build
2529
run: dotnet build -c Release ./src
2630

31+
- name: NuGet login
32+
uses: NuGet/login@v1
33+
id: login
34+
with:
35+
user: ${{ secrets.NUGET_USER }}
36+
2737
- name: "Upload Packages"
2838
uses: X-Hax/SA3D.ProjectConfigurations/.github/actions/upload-packages@main
2939
with:
30-
nuget-key: ${{ secrets.NUGET_KEY }}
40+
nuget-key: ${{ steps.login.outputs.NUGET_API_KEY }}
3141
is-release: ${{ startsWith(github.ref, 'refs/tags/') }}
32-
release-tag: ${{ github.ref_name }}
42+
release-tag: ${{ github.ref_name }}

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
steps:
1717
- name: Checkout Code
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v7
1919
with:
2020
fetch-depth: 0
2121
submodules: 'recursive'
@@ -24,4 +24,4 @@ jobs:
2424
uses: X-Hax/SA3D.ProjectConfigurations/.github/actions/setup-sdks-components@main
2525

2626
- name: Build
27-
run: dotnet build -c Release ./src
27+
run: dotnet build -c Release ./src

src/SA3D.Texturing/ColorTexture.cs

Lines changed: 0 additions & 150 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
3+
namespace SA3D.Texturing
4+
{
5+
/// <summary>
6+
/// Index texture interface
7+
/// </summary>
8+
public interface IIndexTexture : ITexture
9+
{
10+
/// <summary>
11+
/// Palette used to generate colored image data. If none is passed, grayscale values will be used
12+
/// </summary>
13+
public ITexturePalette? Palette { get; set; }
14+
15+
/// <summary>
16+
/// Color-row-index of the palette to use (Row size of 16 when <see cref="IsIndex4"/>, otherwise 256).
17+
/// </summary>
18+
public int PaletteRow { get; set; }
19+
20+
/// <summary>
21+
/// Whether the indices are actually 4 bits big, instead of 8 bits.
22+
/// <br/> When setting to <see langword="true"/>, the lower 4 bits of every byte will be ignored.
23+
/// </summary>
24+
public bool IsIndex4 { get; }
25+
26+
TextureType ITexture.TextureType => IsIndex4 ? TextureType.Index4 : TextureType.Index8;
27+
28+
29+
/// <summary>
30+
/// Returns the image index pixel data, where each pixel is 1 byte
31+
/// </summary>+
32+
/// <param name="mipMapLevel">Mip map level of which to get the data</param>
33+
public ReadOnlySpan<byte> GetIndexPixelData(int mipMapLevel = 0);
34+
35+
ReadOnlySpan<byte> ITexture.GetRGBA32Data(int mipmaplevel)
36+
{
37+
return TextureUtilities.ApplyPaletteToIndexTexture(this.GetUsedPaletteColors(), GetIndexPixelData(mipmaplevel), IsIndex4);
38+
}
39+
}
40+
41+
/// <summary>
42+
/// Index texture extensions
43+
/// </summary>
44+
public static class IndexTextureExtensions
45+
{
46+
/// <summary>
47+
/// Gets palette color data that will actually be used by the texture
48+
/// </summary>
49+
/// <returns></returns>
50+
public static ReadOnlySpan<byte> GetUsedPaletteColors(this IIndexTexture texture)
51+
{
52+
ReadOnlySpan<byte> colorData = (texture.Palette ?? ITexturePalette.GetDefaultPalette(texture.IsIndex4)).GetColorData();
53+
int paletteSize = (texture.IsIndex4 ? 16 : 256) * 4;
54+
ReadOnlySpan<byte> result = colorData[(paletteSize * texture.PaletteRow % colorData.Length)..];
55+
56+
if(result.Length > paletteSize)
57+
{
58+
result = result[..paletteSize];
59+
}
60+
61+
return result;
62+
}
63+
}
64+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
namespace SA3D.Texturing.IO
2+
{
3+
/// <summary>
4+
/// Image formats
5+
/// </summary>
6+
public enum ImageFormat
7+
{
8+
/// <summary>
9+
/// Portable network graphic
10+
/// </summary>
11+
PNG,
12+
13+
/// <summary>
14+
/// Bitmap
15+
/// </summary>
16+
BMP,
17+
18+
/// <summary>
19+
/// Joint photographic (experts) group
20+
/// </summary>
21+
JPG,
22+
23+
/// <summary>
24+
/// Portable bitmap
25+
/// </summary>
26+
PBM,
27+
28+
/// <summary>
29+
/// Quite OK Image Format
30+
/// </summary>
31+
QOI,
32+
33+
/// <summary>
34+
/// Truevision Graphics Adapter
35+
/// </summary>
36+
TGA,
37+
38+
/// <summary>
39+
/// Tagged Image File Format
40+
/// </summary>
41+
TIFF,
42+
43+
/// <summary>
44+
/// Web-picture
45+
/// </summary>
46+
WEBP,
47+
48+
/// <summary>
49+
/// DirectDraw Surface
50+
/// </summary>
51+
DDS
52+
}
53+
}

0 commit comments

Comments
 (0)