From ede16bc46803940dff6dfe1ce3a1dd2d88dfdb32 Mon Sep 17 00:00:00 2001 From: "H. Utku Maden" Date: Fri, 14 Jun 2024 18:24:38 +0300 Subject: [PATCH] Remove all references to Quik. --- .gitmodules | 6 +- CMakeLists.txt | 4 +- NativeTypeNameAttribute.cs | 2 +- Quik.Common | 1 - README.md | 6 +- ....StbImage.csproj => ReFuel.StbImage.csproj | 5 +- Quik.StbImage.sln => ReFuel.StbImage.sln | 17 ++-- StbImage.cs | 94 +++++++++++++++++- Stbi.Manual.cs | 18 +--- Stbi.cs | 97 +++++++++---------- StbiImageFormat.cs | 2 +- StbiStreamWrapper.cs | 22 +++-- build_native.sh | 2 +- docker-compose.yaml | 12 +-- docker-cross-compiler | 1 + quik_stbi.c | 4 - quik_stbi.h | 13 --- rf_stbi.c | 7 ++ rf_stbi.h | 13 +++ clangsharp.rsp => stb_image.rsp | 10 +- stb_image_write.rsp | 30 ++++++ 21 files changed, 237 insertions(+), 129 deletions(-) delete mode 160000 Quik.Common rename Quik.StbImage.csproj => ReFuel.StbImage.csproj (94%) rename Quik.StbImage.sln => ReFuel.StbImage.sln (50%) create mode 160000 docker-cross-compiler delete mode 100644 quik_stbi.c delete mode 100644 quik_stbi.h create mode 100644 rf_stbi.c create mode 100644 rf_stbi.h rename clangsharp.rsp => stb_image.rsp (78%) create mode 100644 stb_image_write.rsp diff --git a/.gitmodules b/.gitmodules index e2d2a6a..95ac235 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "stb"] path = stb url = https://github.com/nothings/stb.git -[submodule "Quik.Common"] - path = Quik.Common - url = https://git.mixedup.dev/QUIK/Quik.Common.git +[submodule "docker-cross-compiler"] + path = docker-cross-compiler + url = https://git.mixedup.dev/ReFuel/docker-cross-compiler diff --git a/CMakeLists.txt b/CMakeLists.txt index 82cad4f..3649203 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required(VERSION 3.0) -project(quik_stbi LANGUAGES C VERSION 1.0) +project(rf_stbi LANGUAGES C VERSION 1.0) if (NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")) add_compile_options(-static-libgcc -static-libstdc++ -fno-exceptions) endif() -add_library(stbi SHARED "quik_stbi.c") +add_library(stbi SHARED "rf_stbi.c") install( TARGETS stbi RUNTIME DESTINATION . diff --git a/NativeTypeNameAttribute.cs b/NativeTypeNameAttribute.cs index becb962..fe5b75a 100644 --- a/NativeTypeNameAttribute.cs +++ b/NativeTypeNameAttribute.cs @@ -1,6 +1,6 @@ using System; -namespace Quik.Stb.Image +namespace Quik.Stb { [AttributeUsage(System.AttributeTargets.All, Inherited = false, AllowMultiple = true)] internal sealed class NativeTypeNameAttribute : System.Attribute diff --git a/Quik.Common b/Quik.Common deleted file mode 160000 index fdfac9d..0000000 --- a/Quik.Common +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fdfac9d95134fb5637bb2a9ec98ee11fe188230e diff --git a/README.md b/README.md index 9851043..9be7897 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -Quik.StbImage +ReFuel.StbImage ============= -Quik.StbImage is a binary distribution of the popular stb_image.h single header +ReFuel.StbImage is a binary distribution of the popular stb_image.h single header library. Existing packages were either bad source ports, had odd wrappers or weren't up to date. Originally intended for my own purposes, however feel free to view the code at -https://git.mixedup.dev/QUIK/Quik.StbImage, and shoot me patch files through +https://git.mixedup.dev/ReFuel/ReFuel.StbImage, and shoot me patch files through email. diff --git a/Quik.StbImage.csproj b/ReFuel.StbImage.csproj similarity index 94% rename from Quik.StbImage.csproj rename to ReFuel.StbImage.csproj index 0bf596e..45d1523 100644 --- a/Quik.StbImage.csproj +++ b/ReFuel.StbImage.csproj @@ -6,16 +6,17 @@ 7.3 True linux-arm;linux-arm64;linux-x64;win-x86;win-x64;osx-arm64;osx-x64 + ReFuel.Stb True - Quik.StbImage + ReFuel.StbImage 1.1.3 STBI Authors, H. Utku Maden - A C# wrapper for the ubiquitous Stb Image library. + A C# wrapper for the ubiquitous stb_image.h and stb_image_write.h library. README.md images\icon.png diff --git a/Quik.StbImage.sln b/ReFuel.StbImage.sln similarity index 50% rename from Quik.StbImage.sln rename to ReFuel.StbImage.sln index 6b44dac..e50073f 100644 --- a/Quik.StbImage.sln +++ b/ReFuel.StbImage.sln @@ -1,25 +1,22 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.5.002.0 +VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Quik.StbImage", "Quik.StbImage.csproj", "{C808B4BC-C3AF-4682-8EDA-EAAC780800C3}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReFuel.StbImage", "ReFuel.StbImage.csproj", "{413ACBF4-3851-416F-B2A2-F7157EC306B2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C808B4BC-C3AF-4682-8EDA-EAAC780800C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C808B4BC-C3AF-4682-8EDA-EAAC780800C3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C808B4BC-C3AF-4682-8EDA-EAAC780800C3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C808B4BC-C3AF-4682-8EDA-EAAC780800C3}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B04E5FBA-41E6-4B0B-BC31-F996BE353F5A} + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {413ACBF4-3851-416F-B2A2-F7157EC306B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {413ACBF4-3851-416F-B2A2-F7157EC306B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {413ACBF4-3851-416F-B2A2-F7157EC306B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {413ACBF4-3851-416F-B2A2-F7157EC306B2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/StbImage.cs b/StbImage.cs index e2af68f..b1bdc82 100644 --- a/StbImage.cs +++ b/StbImage.cs @@ -2,7 +2,7 @@ using System; using System.IO; using System.Runtime.InteropServices; -namespace Quik.Stb +namespace ReFuel.Stb { /// /// A class that encompasses all features of stb_image.h in a safe way. @@ -31,6 +31,9 @@ namespace Quik.Stb /// Internal image format. /// public StbiImageFormat Format { get; } + /// + /// True if the image is a floating point image. + /// public bool IsFloat { get; } private StbImage(IntPtr image, int x, int y, StbiImageFormat format, bool isFloat) @@ -112,6 +115,42 @@ namespace Quik.Stb } } + /// + /// Try loading an image, without raising exceptions. + /// + /// The resulting image. + /// Source memory span. + /// The desired image format. + /// True on success. + public static bool TryLoad(out StbImage image, ReadOnlySpan span, StbiImageFormat format = StbiImageFormat.Default, bool isFloat = false) + where T : unmanaged + { + IntPtr imagePtr = IntPtr.Zero; + int x, y, iFormat; + fixed (byte *ptr = MemoryMarshal.AsBytes(span)) + { + if (isFloat) + { + imagePtr = (IntPtr)Stbi.loadf_from_memory(ptr, span.Length * sizeof(T), &x, &y, &iFormat, (int)format); + } + else + { + imagePtr = (IntPtr)Stbi.load_from_memory(ptr, span.Length * sizeof(T), &x, &y, &iFormat, (int)format); + } + + if (imagePtr != IntPtr.Zero) + { + image = new StbImage(imagePtr, x, y, (StbiImageFormat)iFormat, isFloat); + return true; + } + else + { + image = null; + return false; + } + } + } + /// /// Load an image. /// @@ -129,7 +168,33 @@ namespace Quik.Stb throw new Exception($"Failed to load image: {reason}"); } - public bool IsLoadable(Stream stream) + /// + /// Load an image. + /// + /// The span of memory to load from. + /// The desired image format. + /// The image object. + public static StbImage Load(ReadOnlySpan span, StbiImageFormat format = StbiImageFormat.Default, bool isFloat = false) + where T : unmanaged + { + if (TryLoad(out StbImage image, span, format, isFloat)) + { + return image; + } + + string reason = Marshal.PtrToStringUTF8((IntPtr)Stbi.failure_reason()); + throw new Exception($"Failed to load image: {reason}"); + } + + /// + /// Peek image info from a stream. + /// + /// The stream to peek into. + /// Width of the image. + /// Height of the image. + /// The image format. + /// True if the stream contained an image. + public static bool PeekInfo(Stream stream, out int width, out int height, out StbiImageFormat format) { int x, y, iFormat; StbiStreamWrapper wrapper = new StbiStreamWrapper(stream, true); @@ -138,7 +203,32 @@ namespace Quik.Stb stream.Position = 0; int result = Stbi.info_from_callbacks(&cb, null, &x, &y, &iFormat); + width = x; + height = y; + format = (StbiImageFormat)iFormat; + return result != 0; } + + /// + /// Peek image info from a span. + /// + /// The span to peek into. + /// Width of the image. + /// Height of the image. + /// The image format. + /// True if the stream contained an image. + public static bool PeekInfo(ReadOnlySpan span, out int width, out int height, out StbiImageFormat format) where T : unmanaged + { + fixed (byte* ptr = MemoryMarshal.AsBytes(span)) + { + int x, y, iFormat; + int result = Stbi.info_from_memory(ptr, span.Length * sizeof(T), &x, &y, &iFormat); + width = x; + height = y; + format = (StbiImageFormat)iFormat; + return result != 0; + } + } } } \ No newline at end of file diff --git a/Stbi.Manual.cs b/Stbi.Manual.cs index 59b11cf..2a14ad9 100644 --- a/Stbi.Manual.cs +++ b/Stbi.Manual.cs @@ -4,7 +4,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Reflection; -namespace Quik.Stb +namespace ReFuel.Stb { public unsafe static partial class Stbi { @@ -29,8 +29,6 @@ namespace Quik.Stb static Stbi() { NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), Resolver); - - // quik_stbi_failed_assert_store(Marshal.GetFunctionPointerForDelegate(FailedAssert)); } private static IntPtr Resolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) @@ -48,19 +46,5 @@ namespace Quik.Stb return NativeLibrary.Load(libraryName); } - - private static void FailedAssert(byte *expression, byte *file, int line, byte *function) - { - string expr = expression == null ? string.Empty : Marshal.PtrToStringUTF8((IntPtr)expression); - string f = file == null ? string.Empty : Marshal.PtrToStringUTF8((IntPtr)file); - string func = function == null ? string.Empty : Marshal.PtrToStringUTF8((IntPtr)function); - - Exception ex = new Exception("Assert failed in native stbi code."); - ex.Data.Add("Expression", expr); - ex.Data.Add("File", f); - ex.Data.Add("Line", line); - ex.Data.Add("Function", func); - throw ex; - } } } \ No newline at end of file diff --git a/Stbi.cs b/Stbi.cs index 0a9510c..66481ad 100644 --- a/Stbi.cs +++ b/Stbi.cs @@ -1,10 +1,8 @@ using System; using System.Runtime.InteropServices; -using Quik.Stb.Image; -namespace Quik.Stb +namespace ReFuel.Stb { - [NativeTypeName("unsigned int")] public enum StbiEnum : uint { STBI_default = 0, @@ -16,65 +14,62 @@ namespace Quik.Stb public partial struct stbi_io_callbacks { - [NativeTypeName("int (*)(void *, char *, int)")] public IntPtr read; - [NativeTypeName("void (*)(void *, int)")] public IntPtr skip; - [NativeTypeName("int (*)(void *)")] public IntPtr eof; } public static unsafe partial class Stbi { [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_from_memory", ExactSpelling = true)] - [return: NativeTypeName("stbi_uc *")] - public static extern byte* load_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len, int* x, int* y, int* channels_in_file, int desired_channels); + + public static extern byte* load_from_memory(byte* buffer, int len, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_from_callbacks", ExactSpelling = true)] - [return: NativeTypeName("stbi_uc *")] - public static extern byte* load_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user, int* x, int* y, int* channels_in_file, int desired_channels); + + public static extern byte* load_from_callbacks(stbi_io_callbacks* clbk, void* user, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load", ExactSpelling = true)] - [return: NativeTypeName("stbi_uc *")] - public static extern byte* load([NativeTypeName("const char *")] sbyte* filename, int* x, int* y, int* channels_in_file, int desired_channels); + + public static extern byte* load(sbyte* filename, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_from_file", ExactSpelling = true)] - [return: NativeTypeName("stbi_uc *")] - public static extern byte* load_from_file([NativeTypeName("FILE *")] void* f, int* x, int* y, int* channels_in_file, int desired_channels); + + public static extern byte* load_from_file(void* f, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_gif_from_memory", ExactSpelling = true)] - [return: NativeTypeName("stbi_uc *")] - public static extern byte* load_gif_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len, int** delays, int* x, int* y, int* z, int* comp, int req_comp); + + public static extern byte* load_gif_from_memory(byte* buffer, int len, int** delays, int* x, int* y, int* z, int* comp, int req_comp); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_16_from_memory", ExactSpelling = true)] - [return: NativeTypeName("stbi_us *")] - public static extern ushort* load_16_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len, int* x, int* y, int* channels_in_file, int desired_channels); + + public static extern ushort* load_16_from_memory(byte* buffer, int len, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_16_from_callbacks", ExactSpelling = true)] - [return: NativeTypeName("stbi_us *")] - public static extern ushort* load_16_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user, int* x, int* y, int* channels_in_file, int desired_channels); + + public static extern ushort* load_16_from_callbacks(stbi_io_callbacks* clbk, void* user, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_16", ExactSpelling = true)] - [return: NativeTypeName("stbi_us *")] - public static extern ushort* load_16([NativeTypeName("const char *")] sbyte* filename, int* x, int* y, int* channels_in_file, int desired_channels); + + public static extern ushort* load_16(sbyte* filename, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_from_file_16", ExactSpelling = true)] - [return: NativeTypeName("stbi_us *")] - public static extern ushort* load_from_file_16([NativeTypeName("FILE *")] void* f, int* x, int* y, int* channels_in_file, int desired_channels); + + public static extern ushort* load_from_file_16(void* f, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_loadf_from_memory", ExactSpelling = true)] - public static extern float* loadf_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len, int* x, int* y, int* channels_in_file, int desired_channels); + public static extern float* loadf_from_memory(byte* buffer, int len, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_loadf_from_callbacks", ExactSpelling = true)] - public static extern float* loadf_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user, int* x, int* y, int* channels_in_file, int desired_channels); + public static extern float* loadf_from_callbacks(stbi_io_callbacks* clbk, void* user, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_loadf", ExactSpelling = true)] - public static extern float* loadf([NativeTypeName("const char *")] sbyte* filename, int* x, int* y, int* channels_in_file, int desired_channels); + public static extern float* loadf(sbyte* filename, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_loadf_from_file", ExactSpelling = true)] - public static extern float* loadf_from_file([NativeTypeName("FILE *")] void* f, int* x, int* y, int* channels_in_file, int desired_channels); + public static extern float* loadf_from_file(void* f, int* x, int* y, int* channels_in_file, int desired_channels); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_hdr_to_ldr_gamma", ExactSpelling = true)] public static extern void hdr_to_ldr_gamma(float gamma); @@ -89,47 +84,47 @@ namespace Quik.Stb public static extern void ldr_to_hdr_scale(float scale); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_hdr_from_callbacks", ExactSpelling = true)] - public static extern int is_hdr_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user); + public static extern int is_hdr_from_callbacks(stbi_io_callbacks* clbk, void* user); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_hdr_from_memory", ExactSpelling = true)] - public static extern int is_hdr_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len); + public static extern int is_hdr_from_memory(byte* buffer, int len); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_hdr", ExactSpelling = true)] - public static extern int is_hdr([NativeTypeName("const char *")] sbyte* filename); + public static extern int is_hdr(sbyte* filename); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_hdr_from_file", ExactSpelling = true)] - public static extern int is_hdr_from_file([NativeTypeName("FILE *")] void* f); + public static extern int is_hdr_from_file(void* f); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_failure_reason", ExactSpelling = true)] - [return: NativeTypeName("const char *")] + public static extern sbyte* failure_reason(); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_image_free", ExactSpelling = true)] public static extern void image_free(void* retval_from_stbi_load); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_info_from_memory", ExactSpelling = true)] - public static extern int info_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len, int* x, int* y, int* comp); + public static extern int info_from_memory(byte* buffer, int len, int* x, int* y, int* comp); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_info_from_callbacks", ExactSpelling = true)] - public static extern int info_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user, int* x, int* y, int* comp); + public static extern int info_from_callbacks(stbi_io_callbacks* clbk, void* user, int* x, int* y, int* comp); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_16_bit_from_memory", ExactSpelling = true)] - public static extern int is_16_bit_from_memory([NativeTypeName("const stbi_uc *")] byte* buffer, int len); + public static extern int is_16_bit_from_memory(byte* buffer, int len); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_16_bit_from_callbacks", ExactSpelling = true)] - public static extern int is_16_bit_from_callbacks([NativeTypeName("const stbi_io_callbacks *")] stbi_io_callbacks* clbk, void* user); + public static extern int is_16_bit_from_callbacks(stbi_io_callbacks* clbk, void* user); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_info", ExactSpelling = true)] - public static extern int info([NativeTypeName("const char *")] sbyte* filename, int* x, int* y, int* comp); + public static extern int info(sbyte* filename, int* x, int* y, int* comp); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_info_from_file", ExactSpelling = true)] - public static extern int info_from_file([NativeTypeName("FILE *")] void* f, int* x, int* y, int* comp); + public static extern int info_from_file(void* f, int* x, int* y, int* comp); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_16_bit", ExactSpelling = true)] - public static extern int is_16_bit([NativeTypeName("const char *")] sbyte* filename); + public static extern int is_16_bit(sbyte* filename); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_is_16_bit_from_file", ExactSpelling = true)] - public static extern int is_16_bit_from_file([NativeTypeName("FILE *")] void* f); + public static extern int is_16_bit_from_file(void* f); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_set_unpremultiply_on_load", ExactSpelling = true)] public static extern void set_unpremultiply_on_load(int flag_true_if_should_unpremultiply); @@ -150,25 +145,25 @@ namespace Quik.Stb public static extern void set_flip_vertically_on_load_thread(int flag_true_if_should_flip); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_malloc_guesssize", ExactSpelling = true)] - [return: NativeTypeName("char *")] - public static extern sbyte* zlib_decode_malloc_guesssize([NativeTypeName("const char *")] sbyte* buffer, int len, int initial_size, int* outlen); + + public static extern sbyte* zlib_decode_malloc_guesssize(sbyte* buffer, int len, int initial_size, int* outlen); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_malloc_guesssize_headerflag", ExactSpelling = true)] - [return: NativeTypeName("char *")] - public static extern sbyte* zlib_decode_malloc_guesssize_headerflag([NativeTypeName("const char *")] sbyte* buffer, int len, int initial_size, int* outlen, int parse_header); + + public static extern sbyte* zlib_decode_malloc_guesssize_headerflag(sbyte* buffer, int len, int initial_size, int* outlen, int parse_header); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_malloc", ExactSpelling = true)] - [return: NativeTypeName("char *")] - public static extern sbyte* zlib_decode_malloc([NativeTypeName("const char *")] sbyte* buffer, int len, int* outlen); + + public static extern sbyte* zlib_decode_malloc(sbyte* buffer, int len, int* outlen); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_buffer", ExactSpelling = true)] - public static extern int zlib_decode_buffer([NativeTypeName("char *")] sbyte* obuffer, int olen, [NativeTypeName("const char *")] sbyte* ibuffer, int ilen); + public static extern int zlib_decode_buffer(sbyte* ibuffer, int ilen); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_noheader_malloc", ExactSpelling = true)] - [return: NativeTypeName("char *")] - public static extern sbyte* zlib_decode_noheader_malloc([NativeTypeName("const char *")] sbyte* buffer, int len, int* outlen); + + public static extern sbyte* zlib_decode_noheader_malloc(sbyte* buffer, int len, int* outlen); [DllImport("stbi", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_zlib_decode_noheader_buffer", ExactSpelling = true)] - public static extern int zlib_decode_noheader_buffer([NativeTypeName("char *")] sbyte* obuffer, int olen, [NativeTypeName("const char *")] sbyte* ibuffer, int ilen); + public static extern int zlib_decode_noheader_buffer(sbyte* ibuffer, int ilen); } } diff --git a/StbiImageFormat.cs b/StbiImageFormat.cs index a4c0c61..adbad9a 100644 --- a/StbiImageFormat.cs +++ b/StbiImageFormat.cs @@ -1,4 +1,4 @@ -namespace Quik.Stb +namespace ReFuel.Stb { public enum StbiImageFormat { diff --git a/StbiStreamWrapper.cs b/StbiStreamWrapper.cs index 4038c48..e417916 100644 --- a/StbiStreamWrapper.cs +++ b/StbiStreamWrapper.cs @@ -2,17 +2,21 @@ using System; using System.IO; using System.Runtime.InteropServices; -namespace Quik.Stb +namespace ReFuel.Stb { + public unsafe delegate int StbiReadProc(void *userdata, byte* buffer, int count); + public unsafe delegate void StbiSkipProc(void *userdata, int count); + public unsafe delegate int StbiEofProc(void *userdata); + public unsafe class StbiStreamWrapper : IDisposable { private Stream _stream; private bool _keepOpen; private bool _isDisposed; - private delegate int ReadProc(void *userdata, byte* buffer, int count); - private delegate void SkipProc(void *userdata, int count); - private delegate int Eof(void *userdata); + private StbiReadProc _readCb; + private StbiSkipProc _skipCb; + private StbiEofProc _eofCb; public StbiStreamWrapper(Stream stream, bool keepOpen = false) { @@ -20,14 +24,18 @@ namespace Quik.Stb _stream = stream; _keepOpen = keepOpen; + + _readCb = ReadCb; + _skipCb = SkipCb; + _eofCb = EofCb; } public void CreateCallbacks(out stbi_io_callbacks cb) { cb = default; - cb.read = Marshal.GetFunctionPointerForDelegate(ReadCb); - cb.skip = Marshal.GetFunctionPointerForDelegate(SkipCb); - cb.eof = Marshal.GetFunctionPointerForDelegate(EofCb); + cb.read = Marshal.GetFunctionPointerForDelegate(_readCb); + cb.skip = Marshal.GetFunctionPointerForDelegate(_skipCb); + cb.eof = Marshal.GetFunctionPointerForDelegate(_eofCb); } private int ReadCb(void *userdata, byte* buffer, int count) diff --git a/build_native.sh b/build_native.sh index eb77add..88bc725 100755 --- a/build_native.sh +++ b/build_native.sh @@ -1,4 +1,4 @@ #!/bin/bash cd $(dirname "$0") -./Quik.Common/sh/quik_build_native.sh . +./docker-cross-compiler/sh/build_native.sh . dotnet build diff --git a/docker-compose.yaml b/docker-compose.yaml index c73e8d6..b2fd83a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,15 +2,15 @@ version: "2" services: build: - image: git.mixedup.dev/quik/docker-cross-compiler - command: "/home/quik/src/build_native.sh" + image: git.mixedup.dev/refuel/docker-cross-compiler + command: "/home/refuel/src/build_native.sh" volumes: - - .:/home/quik/src + - .:/home/refuel/src publish: - image: git.mixedup.dev/quik/docker-cross-compiler - command: "/home/quik/src/publish.sh" + image: git.mixedup.dev/refuel/docker-cross-compiler + command: "/home/refuel/src/publish.sh" environment: QUIK_API_KEY: ${QUIK_API_KEY} volumes: - - .:/home/quik/src + - .:/home/refuel/src \ No newline at end of file diff --git a/docker-cross-compiler b/docker-cross-compiler new file mode 160000 index 0000000..caafc89 --- /dev/null +++ b/docker-cross-compiler @@ -0,0 +1 @@ +Subproject commit caafc898f366d4f642c22d5ccdc940e6a25f32f0 diff --git a/quik_stbi.c b/quik_stbi.c deleted file mode 100644 index 312c61b..0000000 --- a/quik_stbi.c +++ /dev/null @@ -1,4 +0,0 @@ -#include "quik_stbi.h" - -#define STB_IMAGE_IMPLEMENTATION 1 -#include "stb/stb_image.h" diff --git a/quik_stbi.h b/quik_stbi.h deleted file mode 100644 index 521fe27..0000000 --- a/quik_stbi.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _QUIK_STBI_H_ -#define _QUIK_STBI_H_ - -#include "Quik.Common/include/quik_common.h" - -#define STBIDEF QEXTERN - -#define STBI_NO_THREAD_LOCALS 1 -#define STBI_NO_FAILURE_STRINGS 1 -#define STBI_THREAD_LOCAL -#include "stb/stb_image.h" - -#endif diff --git a/rf_stbi.c b/rf_stbi.c new file mode 100644 index 0000000..a49262e --- /dev/null +++ b/rf_stbi.c @@ -0,0 +1,7 @@ +#include "rf_stbi.h" + +#define STB_IMAGE_IMPLEMENTATION 1 +#include "stb/stb_image.h" + +#define STB_IMAGE_WRITE_IMPLEMENTATION 1 +#include "stb/stb_image_write.h" diff --git a/rf_stbi.h b/rf_stbi.h new file mode 100644 index 0000000..bdeeee3 --- /dev/null +++ b/rf_stbi.h @@ -0,0 +1,13 @@ +#ifndef _REFUEL_STBI_H_ +#define _REFUEL_STBI_H_ + +#include "docker-cross-compiler/include/rf_common.h" + +#define STBIDEF RFEXTERN +#define STBI_NO_THREAD_LOCALS 1 +#include "stb/stb_image.h" + +#define STBI_WRITE_NO_STDIO 1 +#include "stb/stb_image_write.h" + +#endif diff --git a/clangsharp.rsp b/stb_image.rsp similarity index 78% rename from clangsharp.rsp rename to stb_image.rsp index d0ebfed..4bb4247 100644 --- a/clangsharp.rsp +++ b/stb_image.rsp @@ -10,18 +10,18 @@ generate-setslastsystemerror-attribute unix-types --include-directory - ../lib + stb --include-directory - ../Quik.StbImage + . --include-directory /usr/lib/llvm-14/lib/clang/14.0.6/include --file - ../Quik.StbImage.redist/quik_stbi.h - ../lib/stb/stb_image.h + rf_stbi.h + stb/stb_image.h --methodClassName Stbi --namespace - Quik.Stb + ReFuel.Stb --output Stbi.cs --prefixStrip diff --git a/stb_image_write.rsp b/stb_image_write.rsp new file mode 100644 index 0000000..7fdd3f8 --- /dev/null +++ b/stb_image_write.rsp @@ -0,0 +1,30 @@ +-x + c +-l + stbi +--config + compatible-codegen + single-file + exclude-fnptr-codegen + generate-aggressive-inlining + generate-setslastsystemerror-attribute + unix-types +--include-directory + stb +--include-directory + . +--include-directory + /usr/lib/llvm-14/lib/clang/14.0.6/include +--file + rf_stbi.h + stb/stb_image_write.h +--methodClassName + StbiWrite +--namespace + ReFuel.Stb +--output + StbiWrite.cs +--prefixStrip + stbi_write_ +--with-type + FILE=void