Skip to content

Commit 7bf49c5

Browse files
authored
Merge pull request #9 from robertkist/staging_20251005
2 parents 8d170a1 + f64c015 commit 7bf49c5

22 files changed

Lines changed: 5095 additions & 4650 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ dist/
33
.idea/
44
.DS_Store
55
.vscode
6+
.vs/
7+
*.vcxproj.*
68

79
# Prerequisites
810
*.d

Makefile

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# default MingW path for Qt 6.3.x:
22
WIN_MINGW_BIN_PATH=C:\\Qt\\Tools\\mingw1310_64\\bin
33

4-
LIB_VERSION=2025.07.07a
4+
LIB_VERSION=2025.10.04a
55

66
LIBNAME=libdither
77
SRCDIR=src/$(LIBNAME)
@@ -23,20 +23,23 @@ CFLAGS=-std=c11 -Wall -Wextra -Wconversion -Wshadow -Wstrict-overflow -Wformat=2
2323

2424
ifdef OS # Windows:
2525
define fn_mkdir
26-
if not exist "$(1)" mkdir "$(1)"
26+
@if not exist "$(1)" mkdir "$(1)"
2727
endef
28+
SHELL=cmd
2829
CP=copy
2930
DELTREE=rd /s /q
3031
CC=SET PATH=$(WIN_MINGW_BIN_PATH);%PATH% && gcc
3132
LIBEXT=dll
3233
SEP=\\
34+
DEMOCMD=cd dist && demo
3335
else # Unix based platforms
3436
define fn_mkdir
3537
@mkdir -p "$(1)"
3638
endef
3739
CP=cp
3840
DELTREE=rm -Rf
3941
SEP=/
42+
DEMOCMD=cd dist && ./demo
4043
ifeq ($(shell uname), Darwin) # macOS
4144
CC=clang
4245
LIBEXT=dylib
@@ -59,7 +62,7 @@ all:
5962
@echo "* libdither_x64 - build macOS x86 library"
6063
@echo "* libdither_arm64 - build macOS apple silicon library"
6164
@echo "* libdither_universal - build universal macOS library"
62-
@echo "* libdither_msvc - build using MSVC on Windows"
65+
@echo "* libdither_msvc - build using MSVC on Windows (run vcvar64.bat first!)"
6366
@echo "* demo - builds a small executable for the current platform to demo libdither's capabilities"
6467
@echo "* clean"
6568

@@ -80,37 +83,44 @@ $(LIBNAME)_arm64: $(LIBNAME)_build
8083
$(LIBNAME): $(LIBNAME)_build
8184

8285
$(LIBNAME)_build: $(OBJDIR)/$(LIBNAME).$(LIBEXT)
83-
$(call fn_mkdir,$(DISTDIR))
86+
-$(call fn_mkdir,$(DISTDIR))
8487
$(CP) $(OBJDIR)$(SEP)$(LIBNAME).$(LIBEXT) $(DISTDIR)$(SEP)$(LIBNAME).$(LIBEXT)
8588
@echo "$(LIBNAME) build successfully $(TARGETARCH)"
8689

8790
$(OBJDIR)/$(LIBNAME).$(LIBEXT): $(OBJ)
8891
cd $(OBJDIR) && $(CC) $(TARGETARCH) -shared $(OBJFILES) -fPIC -o $(LIBNAME).$(LIBEXT)
8992

9093
$(OBJDIR)/%.o: $(addprefix $(SRCDIR)/, %.c)
91-
$(call fn_mkdir,$(OBJDIR))
92-
$(call fn_mkdir,$(OBJDIR)/tetrapal)
93-
$(call fn_mkdir,$(OBJDIR)/kdtree)
94+
-$(call fn_mkdir,$(OBJDIR))
95+
-$(call fn_mkdir,$(OBJDIR)/tetrapal)
96+
-$(call fn_mkdir,$(OBJDIR)/kdtree)
9497
$(CC) $(CFLAGS) $(TARGETARCH) -c -fPIC -c $< -o $@
9598

99+
.PHONY: libdither_msvc
96100
libdither_msvc:
97-
@echo Make sure to run vcvars64.bat or this target will fail...
98-
$(call fn_mkdir,$(OBJDIR))
99-
cd build && cl.exe ..\\src\\libdither\\*.c /LD /DLL /Fe: libdither.dll
100-
cd build && cl.exe ..\\src\\demo\\demo.c ..\src\demo\spng.c libdither.lib /I..\\src\\libdither /L. /Fe: demo.exe
101-
$(call fn_mkdir,$(DISTDIR))
102-
copy src\\demo\\*.bmp $(DISTDIR)
103-
copy build\\demo.exe $(DISTDIR)
104-
copy build\\libdither.dll $(DISTDIR)
105-
106-
demo: libdither
101+
@echo Make sure to run vcvars64.bat (for Visual Studio 2022) or this target will fail...
102+
msbuild libdither.vcxproj /p:Configuration=Release
103+
# building without msbuild:
104+
# cd build && cl.exe ..\\src\\libdither\\*.c ..\\src\\libdither\\tetrapal\\*.c ..\\src\\libdither\\kdtree\\*.c /LD /DLL /Fe: libdither.dll
105+
# cd build && cl.exe ..\\src\\demo\\demo.c ..\src\demo\lodepng.c libdither.lib /I..\\src\\libdither /Fe: demo.exe
106+
107+
.PHONY: demo_msvc
108+
demo_msvc:
109+
msbuild demo.vcxproj /p:Configuration=Release
110+
111+
.PHONY: demo
112+
demo:
107113
cd dist && $(CC) $(UNIXFLAGS) -I../src/libdither -L. ../src/demo/demo.c ../src/demo/lodepng.c -ldither -lm -o demo
108114
$(CP) src$(SEP)demo$(SEP)*.png $(DISTDIR)
109115
$(CP) src$(SEP)demo$(SEP)blue_noise.bmp $(DISTDIR)
110116

111-
demo_run: demo
112-
@cd dist && ./demo
113-
#open -a Preview dist/david_OUT.png
117+
.PHONY: demo_run
118+
demo_run:
119+
$(DEMOCMD)
120+
121+
.PHONY: demo_run_msvc
122+
demo_run_msvc:
123+
cd dist\Release && demo
114124

115125
.PHONY: clean
116126
clean:

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,17 +467,30 @@ Once compiled, you can find the finished library in the ```dist``` directory.
467467
*MacOS notes*:
468468

469469
* Installing the XCode command line tools is all you need for building libdither
470-
* You can choose if you want to build a x64, arm64 or universal library. The demo, however, only builds against the current machine's architecture.
470+
* You can choose if you want to build a x64, arm64 or universal library. The demo, however, only builds against the
471+
current machine's architecture.
471472

472473
*Linux notes*:
473474

474-
* ```gcc``` and ```make``` is all you need to build libdither. E.g. on Ubuntu you should install build-essential via ```apt``` to get these tools.
475+
* ```gcc``` and ```make``` is all you need to build libdither. E.g. on Ubuntu you should install ```build-essential```
476+
via ```apt``` to get these tools.
475477

476-
*Windows notes*:
478+
*Windows notes - MinGW*:
477479

478-
* You can build both MingW and MSVC targets from the Makefile (sorry, no .sln)
479-
* For MingW, open the Makefile and ensure the path (on top of the file) points to your MingW installation directory
480-
* Install make via Chocolatey package manager from chocolatey.org (https://chocolatey.org/, https://chocolatey.org/packages/make)
480+
* Install ```make``` via Chocolatey package manager from chocolatey.org (https://chocolatey.org/, https://chocolatey.org/packages/make)
481+
* Open the Makefile and ensure the path (on top of the file) points to your MingW installation directory.
482+
* Run ```make libdither``` to build using MinGW.
483+
484+
*Windows notes - Microsoft Visual Studio Solution*:
485+
486+
* Open the solution file (```.sln``) in Visual Studio 2022 or newer.
487+
* There are 3 projects you can build: libdither (dynamic ```.dll`` library) and the demo.
488+
489+
*Windows notes - Microsoft Visual Studio (make)*:
490+
491+
* To build using make, install ```make``` via Chocolatey package manager from chocolatey.org (https://chocolatey.org/, https://chocolatey.org/packages/make)
492+
* Run ```make libdither_msvc``` to build (make sure to run Visual Studio's ```vcvars64.bat``` first!)
493+
* OR use the solution file (`.sln`) to build libdither from the Visual Studio IDE (2022 or newer).
481494

482495
Usage
483496
-----

demo.vcxproj

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>17.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{f6e81f36-688c-4c11-aa80-48f68dd62620}</ProjectGuid>
25+
<RootNamespace>ConsoleApplication1</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
74+
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);.\src\libdither</IncludePath>
75+
<LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);.\dist\$(Configuration)</LibraryPath>
76+
<OutDir>.\dist\$(Configuration)\</OutDir>
77+
<IntDir>.\build\demo\$(Configuration)\</IntDir>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
80+
<OutDir>.\dist\$(Configuration)\</OutDir>
81+
<IntDir>.\build\demo\$(Configuration)\</IntDir>
82+
<LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);.\dist\$(Configuration)</LibraryPath>
83+
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);.\src\libdither</IncludePath>
84+
</PropertyGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
86+
<ClCompile>
87+
<WarningLevel>Level3</WarningLevel>
88+
<SDLCheck>true</SDLCheck>
89+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
90+
<ConformanceMode>true</ConformanceMode>
91+
</ClCompile>
92+
<Link>
93+
<SubSystem>Console</SubSystem>
94+
<GenerateDebugInformation>true</GenerateDebugInformation>
95+
</Link>
96+
</ItemDefinitionGroup>
97+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
98+
<ClCompile>
99+
<WarningLevel>Level3</WarningLevel>
100+
<FunctionLevelLinking>true</FunctionLevelLinking>
101+
<IntrinsicFunctions>true</IntrinsicFunctions>
102+
<SDLCheck>true</SDLCheck>
103+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
104+
<ConformanceMode>true</ConformanceMode>
105+
</ClCompile>
106+
<Link>
107+
<SubSystem>Console</SubSystem>
108+
<GenerateDebugInformation>true</GenerateDebugInformation>
109+
</Link>
110+
</ItemDefinitionGroup>
111+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
112+
<ClCompile>
113+
<WarningLevel>Level3</WarningLevel>
114+
<SDLCheck>true</SDLCheck>
115+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
116+
<ConformanceMode>true</ConformanceMode>
117+
</ClCompile>
118+
<Link>
119+
<SubSystem>Console</SubSystem>
120+
<GenerateDebugInformation>true</GenerateDebugInformation>
121+
<AdditionalDependencies>.\dist\$(Configuration)\libdither.lib;%(AdditionalDependencies)</AdditionalDependencies>
122+
</Link>
123+
<PostBuildEvent>
124+
<Command>xcopy /y ".\src\demo\david.png" ".\dist\Debug"</Command>
125+
<Command>xcopy /y ".\src\demo\blue_noise.bmp" ".\dist\Debug"
126+
xcopy /y ".\src\demo\david.png" ".\dist\Debug"</Command>
127+
</PostBuildEvent>
128+
</ItemDefinitionGroup>
129+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
130+
<ClCompile>
131+
<WarningLevel>Level3</WarningLevel>
132+
<FunctionLevelLinking>true</FunctionLevelLinking>
133+
<IntrinsicFunctions>true</IntrinsicFunctions>
134+
<SDLCheck>true</SDLCheck>
135+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
136+
<ConformanceMode>true</ConformanceMode>
137+
</ClCompile>
138+
<Link>
139+
<SubSystem>Console</SubSystem>
140+
<GenerateDebugInformation>true</GenerateDebugInformation>
141+
<AdditionalDependencies>.\dist\$(Configuration)\libdither.lib;%(AdditionalDependencies)</AdditionalDependencies>
142+
</Link>
143+
<PostBuildEvent>
144+
<Command>xcopy /y ".\src\demo\blue_noise.bmp" ".\dist\Release"
145+
xcopy /y ".\src\demo\david.png" ".\dist\Release"</Command>
146+
</PostBuildEvent>
147+
</ItemDefinitionGroup>
148+
<ItemGroup>
149+
<ClCompile Include="src\demo\demo.c" />
150+
<ClCompile Include="src\demo\lodepng.c" />
151+
</ItemGroup>
152+
<ItemGroup>
153+
<ClInclude Include="src\demo\lodepng.h" />
154+
<ClInclude Include="src\demo\palettes.h" />
155+
</ItemGroup>
156+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
157+
<ImportGroup Label="ExtensionTargets">
158+
</ImportGroup>
159+
</Project>

libdither.sln

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36408.4
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdither", "libdither.vcxproj", "{C6ABA7D0-81CE-4467-BFBD-6A7B9AD5F404}"
7+
EndProject
8+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo", "demo.vcxproj", "{F6E81F36-688C-4C11-AA80-48F68DD62620}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|x64 = Debug|x64
13+
Debug|x86 = Debug|x86
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{C6ABA7D0-81CE-4467-BFBD-6A7B9AD5F404}.Debug|x64.ActiveCfg = Debug|x64
19+
{C6ABA7D0-81CE-4467-BFBD-6A7B9AD5F404}.Debug|x64.Build.0 = Debug|x64
20+
{C6ABA7D0-81CE-4467-BFBD-6A7B9AD5F404}.Debug|x86.ActiveCfg = Debug|Win32
21+
{C6ABA7D0-81CE-4467-BFBD-6A7B9AD5F404}.Debug|x86.Build.0 = Debug|Win32
22+
{C6ABA7D0-81CE-4467-BFBD-6A7B9AD5F404}.Release|x64.ActiveCfg = Release|x64
23+
{C6ABA7D0-81CE-4467-BFBD-6A7B9AD5F404}.Release|x64.Build.0 = Release|x64
24+
{C6ABA7D0-81CE-4467-BFBD-6A7B9AD5F404}.Release|x86.ActiveCfg = Release|Win32
25+
{C6ABA7D0-81CE-4467-BFBD-6A7B9AD5F404}.Release|x86.Build.0 = Release|Win32
26+
{F6E81F36-688C-4C11-AA80-48F68DD62620}.Debug|x64.ActiveCfg = Debug|x64
27+
{F6E81F36-688C-4C11-AA80-48F68DD62620}.Debug|x64.Build.0 = Debug|x64
28+
{F6E81F36-688C-4C11-AA80-48F68DD62620}.Debug|x86.ActiveCfg = Debug|Win32
29+
{F6E81F36-688C-4C11-AA80-48F68DD62620}.Debug|x86.Build.0 = Debug|Win32
30+
{F6E81F36-688C-4C11-AA80-48F68DD62620}.Release|x64.ActiveCfg = Release|x64
31+
{F6E81F36-688C-4C11-AA80-48F68DD62620}.Release|x64.Build.0 = Release|x64
32+
{F6E81F36-688C-4C11-AA80-48F68DD62620}.Release|x86.ActiveCfg = Release|Win32
33+
{F6E81F36-688C-4C11-AA80-48F68DD62620}.Release|x86.Build.0 = Release|Win32
34+
EndGlobalSection
35+
GlobalSection(SolutionProperties) = preSolution
36+
HideSolutionNode = FALSE
37+
EndGlobalSection
38+
GlobalSection(ExtensibilityGlobals) = postSolution
39+
SolutionGuid = {48A163FB-D351-42C7-9D74-209C6DB5D269}
40+
EndGlobalSection
41+
EndGlobal

0 commit comments

Comments
 (0)