Skip to content

Commit 40fd74a

Browse files
committed
Updated readme and refactored application flow
1 parent 10007bf commit 40fd74a

9 files changed

Lines changed: 789 additions & 627 deletions

File tree

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
name: CMake
1+
name: Build and Release
22

3-
on: push
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'source/**'
9+
- 'CMakeLists.txt'
410

511
jobs:
612
build:
@@ -25,13 +31,11 @@ jobs:
2531
packages: libglfw3-dev gcc-multilib g++-multilib libvulkan-dev libxkbcommon-dev libxinerama-dev libxcursor-dev libxi-dev
2632
version: 1.0
2733

28-
- if: ${{ matrix.os == 'windows-latest' }}
34+
- if: ${{matrix.os == 'windows-latest'}}
2935
name: Install Vulkan SDK
30-
uses: humbletim/setup-vulkan-sdk@v1.2.0
31-
with:
32-
vulkan-query-version: 1.3.204.0
33-
vulkan-components: Vulkan-Headers, Vulkan-Loader
34-
vulkan-use-cache: true
36+
run: |
37+
curl -O https://sdk.lunarg.com/sdk/download/latest/windows/vulkan_sdk.exe
38+
.\vulkan_sdk.exe --accept-licenses --default-answer --confirm-command install
3539
3640
- if: ${{matrix.os == 'ubuntu-latest'}}
3741
name: Configure for linux
@@ -43,12 +47,16 @@ jobs:
4347
4448
- if: ${{matrix.os == 'windows-latest'}}
4549
name: Configure for windows
46-
run: >
47-
cmake -B build
48-
-G "MinGW Makefiles"
49-
-DCMAKE_BUILD_TYPE=Release
50-
-DCMAKE_CXX_COMPILER=g++
51-
-DCMAKE_C_COMPILER=gcc
50+
run: |
51+
curl -o .\windows.json https://vulkan.lunarg.com/sdk/latest/windows.json
52+
$env:VULKAN_VERSION = (Get-Content windows.json | ConvertFrom-Json).windows
53+
$env:VULKAN_SDK = "C:\VulkanSDK\$env:VULKAN_VERSION"
54+
$env:VK_SDK_PATH = "C:\VulkanSDK\$env:VULKAN_VERSION"
55+
$env:Vulkan_LIBRARY = "C:\VulkanSDK\$env:VULKAN_VERSION\Lib\vulkan-1.lib"
56+
$env:Vulkan_INCLUDE_DIR = "C:\VulkanSDK\$env:VULKAN_VERSION\Include"
57+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
58+
refreshenv
59+
cmake -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc
5260
5361
- name: Build release
5462
run: cmake --build build --config Release

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.cache/
12
.vscode/
23
build/

CMakeLists.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
cmake_minimum_required(VERSION 3.11)
2-
project(FileToByte C CXX)
2+
project(FileToByte CXX)
33

44
set(CMAKE_CXX_STANDARD 23)
55
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
66

77
find_package(Vulkan REQUIRED)
88

99
add_subdirectory(glfw)
10+
include_directories(glfw/include)
1011

1112
set(IMGUI_DIR imgui/)
1213
include_directories(imgui/ imgui/backends imgui/misc/cpp)
1314

14-
file(GLOB sources source/*.cpp source/*.hpp)
15-
add_executable(
16-
FileToByte
17-
${sources}
15+
file(GLOB sources
16+
source/*.cpp
17+
source/*.hpp
18+
source/fonts/*.cpp
19+
source/fonts/*.hpp
1820
imgui/imgui.cpp
1921
imgui/imgui.h
2022
imgui/imgui_draw.cpp
2123
imgui/imgui_tables.cpp
2224
imgui/imgui_widgets.cpp
2325
imgui/backends/imgui_impl_glfw.cpp
26+
imgui/backends/imgui_impl_glfw.h
2427
imgui/backends/imgui_impl_vulkan.cpp
25-
imgui/misc/cpp/imgui_stdlib.cpp)
28+
imgui/backends/imgui_impl_vulkan.h
29+
imgui/misc/cpp/imgui_stdlib.cpp
30+
imgui/misc/cpp/imgui_stdlib.h
31+
)
2632

27-
target_link_libraries(FileToByte PUBLIC Vulkan::Vulkan glfw)
33+
add_executable(FileToByte)
34+
35+
target_sources(FileToByte PRIVATE ${sources})
36+
target_link_libraries(FileToByte PRIVATE glfw Vulkan::Vulkan)
2837

2938
if(WIN32)
3039
set_property(TARGET FileToByte PROPERTY WIN32_EXECUTABLE true)

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
### FileToByte
2-
The FileToByte program is designed to accept a full file path as input and efficiently convert the file into a byte array. This functionality offers versatile capabilities, enabling the convenient storage of fonts and/or images directly in memory.
1+
<div align="center">
32

4-
### Dependencies:
5-
gcc and g++ compilers.
3+
<h1>FileToByte</h1>
64

7-
![CMake](https://cmake.org/) is an open-source, cross-platform family of tools designed to build, test and package software.
5+
</div>
6+
7+
FileToByte is a utility that transforms any file into a C-style array, facilitating its direct incorporation into C++ code for easy in-memory handling.
88

9-
![imgui](https://github.com/ocornut/imgui) is a bloat-free Graphical User interface for C++ with minimal dependencies.
9+
You can download latest binaries from [Releases](https://github.com/gage-lodba/FileToByte/releases/latest).
1010

11-
![GLFW](https://github.com/glfw/glfw) is a multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input.
11+
## Dependencies
12+
13+
![CMake](https://cmake.org/) is an open-source, cross-platform family of tools designed to build, test and package software.
1214

1315
![Vulkan](https://www.vulkan.org/) is a low-overhead, cross-platform API, open standard for 3D graphics and computing.
File renamed without changes.

source/FTB.cpp

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
22
* This is a modified version of binary_to_compressed_c.cpp
3-
* it returns the generated C array as a string.
3+
* from the imgui library see:
4+
* https://github.com/ocornut/imgui/tree/master/misc/fonts
45
*/
56
#include "FTB.hpp"
67

7-
#define _CRT_SECURE_NO_WARNINGS
88
#include <assert.h>
9+
#include <sstream>
910
#include <stdio.h>
1011
#include <stdlib.h>
1112
#include <string.h>
@@ -17,9 +18,15 @@ typedef unsigned char stb_uchar;
1718
stb_uint stb_compress(stb_uchar *out, stb_uchar *in, stb_uint len);
1819

1920
std::string Convert(const char *filename, const char *symbol) {
20-
FILE *f = fopen(filename, "rb");
21+
FILE *f;
22+
errno_t err;
23+
err = fopen_s(&f, filename, "rb");
2124

22-
if (!f) return "";
25+
if (!f)
26+
return "";
27+
28+
if (err != 0)
29+
return "";
2330

2431
int data_sz;
2532

@@ -102,7 +109,8 @@ static stb_uint stb_adler32(stb_uint adler32, stb_uchar *buffer,
102109
buffer += 8;
103110
}
104111

105-
for (; i < blocklen; ++i) s1 += *buffer++, s2 += s1;
112+
for (; i < blocklen; ++i)
113+
s1 += *buffer++, s2 += s1;
106114

107115
s1 %= ADLER_MOD, s2 %= ADLER_MOD;
108116
buflen -= blocklen;
@@ -115,12 +123,11 @@ static unsigned int stb_matchlen(stb_uchar *m1, stb_uchar *m2,
115123
stb_uint maxlen) {
116124
stb_uint i;
117125
for (i = 0; i < maxlen; ++i)
118-
if (m1[i] != m2[i]) return i;
126+
if (m1[i] != m2[i])
127+
return i;
119128
return i;
120129
}
121130

122-
// simple implementation that just takes the source data in a big block
123-
124131
static stb_uchar *stb__out;
125132
static FILE *stb__outfile;
126133
static stb_uint stb__outbytes;
@@ -130,14 +137,12 @@ static void stb__write(unsigned char v) {
130137
++stb__outbytes;
131138
}
132139

133-
// #define stb_out(v) (stb__out ? *stb__out++ = (stb_uchar) (v) :
134-
// stb__write((stb_uchar) (v)))
135-
#define stb_out(v) \
136-
do { \
137-
if (stb__out) \
138-
*stb__out++ = (stb_uchar)(v); \
139-
else \
140-
stb__write((stb_uchar)(v)); \
140+
#define stb_out(v) \
141+
do { \
142+
if (stb__out) \
143+
*stb__out++ = (stb_uchar)(v); \
144+
else \
145+
stb__write((stb_uchar)(v)); \
141146
} while (0)
142147

143148
static void stb_out2(stb_uint v) {
@@ -169,7 +174,7 @@ static void outliterals(stb_uchar *in, int numlit) {
169174
stb_out(0x000020 + numlit - 1);
170175
else if (numlit <= 2048)
171176
stb_out2(0x000800 + numlit - 1);
172-
else /* numlit <= 65536) */
177+
else
173178
stb_out3(0x070000 + numlit - 1);
174179

175180
if (stb__out) {
@@ -179,7 +184,7 @@ static void outliterals(stb_uchar *in, int numlit) {
179184
fwrite(in, 1, numlit, stb__outfile);
180185
}
181186

182-
static int stb__window = 0x40000; // 256K
187+
static int stb__window = 0x40000;
183188

184189
static int stb_not_crap(int best, int dist) {
185190
return ((best > 2 && dist <= 0x00100) || (best > 5 && dist <= 0x04000) ||
@@ -188,8 +193,6 @@ static int stb_not_crap(int best, int dist) {
188193

189194
static stb_uint stb__hashsize = 32768;
190195

191-
// note that you can play with the hashing functions all you
192-
// want without needing to change the decompressor
193196
#define stb__hc(q, h, c) (((h) << 7) + ((h) >> 25) + q[c])
194197
#define stb__hc2(q, h, c, d) (((h) << 14) + ((h) >> 18) + (q[c] << 7) + q[d])
195198
#define stb__hc3(q, c, d, e) ((q[c] << 14) + (q[d] << 7) + q[e])
@@ -207,9 +210,6 @@ static int stb_compress_chunk(stb_uchar *history, stb_uchar *start,
207210

208211
#define STB__SCRAMBLE(h) (((h) + ((h) >> 16)) & mask)
209212

210-
// stop short of the end so we don't scan off the end doing
211-
// the hashing; this means we won't compress the last few bytes
212-
// unless they were part of something longer
213213
while (q < start + length && q + 12 < end) {
214214
int m;
215215
stb_uint h1, h2, h3, h4, h;
@@ -221,45 +221,44 @@ static int stb_compress_chunk(stb_uchar *history, stb_uchar *start,
221221
else
222222
match_max = 65536;
223223

224-
#define stb__nc(b, d) \
224+
#define stb__nc(b, d) \
225225
((d) <= window && ((b) > 9 || stb_not_crap((int)(b), (int)(d))))
226226

227-
#define STB__TRY(t, p) /* avoid retrying a match we already tried */ \
228-
if (p ? dist != (int)(q - t) : 1) \
229-
if ((m = stb_matchlen(t, q, match_max)) > best) \
230-
if (stb__nc(m, q - (t))) best = m, dist = (int)(q - (t))
227+
#define STB__TRY(t, p) \
228+
if (p ? dist != (int)(q - t) : 1) \
229+
if ((m = stb_matchlen(t, q, match_max)) > best) \
230+
if (stb__nc(m, q - (t))) \
231+
best = m, dist = (int)(q - (t))
231232

232-
// rather than search for all matches, only try 4 candidate locations,
233-
// chosen based on 4 different hash functions of different lengths.
234-
// this strategy is inspired by LZO; hashing is unrolled here using the
235-
// 'hc' macro
236233
h = stb__hc3(q, 0, 1, 2);
237234
h1 = STB__SCRAMBLE(h);
238235
t = chash[h1];
239-
if (t) STB__TRY(t, 0);
236+
if (t)
237+
STB__TRY(t, 0);
240238
h = stb__hc2(q, h, 3, 4);
241239
h2 = STB__SCRAMBLE(h);
242240
h = stb__hc2(q, h, 5, 6);
243241
t = chash[h2];
244-
if (t) STB__TRY(t, 1);
242+
if (t)
243+
STB__TRY(t, 1);
245244
h = stb__hc2(q, h, 7, 8);
246245
h3 = STB__SCRAMBLE(h);
247246
h = stb__hc2(q, h, 9, 10);
248247
t = chash[h3];
249-
if (t) STB__TRY(t, 1);
248+
if (t)
249+
STB__TRY(t, 1);
250250
h = stb__hc2(q, h, 11, 12);
251251
h4 = STB__SCRAMBLE(h);
252252
t = chash[h4];
253-
if (t) STB__TRY(t, 1);
253+
if (t)
254+
STB__TRY(t, 1);
254255

255-
// because we use a shared hash table, can only update it
256-
// _after_ we've probed all of them
257256
chash[h1] = chash[h2] = chash[h3] = chash[h4] = q;
258257

259-
if (best > 2) assert(dist > 0);
258+
if (best > 2)
259+
assert(dist > 0);
260260

261-
// see if our best match qualifies
262-
if (best < 3) { // fast path literals
261+
if (best < 3) {
263262
++q;
264263
} else if (best > 2 && best <= 0x80 && dist <= 0x100) {
265264
outliterals(lit_start, (int)(q - lit_start));
@@ -282,7 +281,8 @@ static int stb_compress_chunk(stb_uchar *history, stb_uchar *start,
282281
stb_out3(0x100000 + dist - 1);
283282
stb_out2(best - 1);
284283
} else if (best > 9 && dist <= 0x1000000) {
285-
if (best > 65536) best = 65536;
284+
if (best > 65536)
285+
best = 65536;
286286
outliterals(lit_start, (int)(q - lit_start));
287287
lit_start = (q += best);
288288
if (best <= 0x100) {
@@ -294,15 +294,14 @@ static int stb_compress_chunk(stb_uchar *history, stb_uchar *start,
294294
stb_out3(dist - 1);
295295
stb_out2(best - 1);
296296
}
297-
} else { // fallback literals if no match was a balanced tradeoff
297+
} else {
298298
++q;
299299
}
300300
}
301301

302-
// if we didn't get all the way, add the rest to literals
303-
if (q - start < length) q = start + length;
302+
if (q - start < length)
303+
q = start + length;
304304

305-
// the literals are everything from lit_start to q
306305
*pending_literals = (int)(q - lit_start);
307306

308307
stb__running_adler =
@@ -316,15 +315,17 @@ static int stb_compress_inner(stb_uchar *input, stb_uint length) {
316315

317316
stb_uchar **chash;
318317
chash = (stb_uchar **)malloc(stb__hashsize * sizeof(stb_uchar *));
319-
if (chash == nullptr) return 0; // failure
320-
for (i = 0; i < stb__hashsize; ++i) chash[i] = nullptr;
318+
if (chash == nullptr)
319+
return 0; // failure
320+
for (i = 0; i < stb__hashsize; ++i)
321+
chash[i] = nullptr;
321322

322323
// stream signature
323324
stb_out(0x57);
324325
stb_out(0xbc);
325326
stb_out2(0);
326327

327-
stb_out4(0); // 64-bit length requires 32-bit leading 0
328+
stb_out4(0); // 64-bit length requires 32-bit leading 0
328329
stb_out4(length);
329330
stb_out4(stb__window);
330331

@@ -338,11 +339,11 @@ static int stb_compress_inner(stb_uchar *input, stb_uint length) {
338339

339340
free(chash);
340341

341-
stb_out2(0x05fa); // end opcode
342+
stb_out2(0x05fa); // end opcode
342343

343344
stb_out4(stb__running_adler);
344345

345-
return 1; // success
346+
return 1; // success
346347
}
347348

348349
stb_uint stb_compress(stb_uchar *out, stb_uchar *input, stb_uint length) {

0 commit comments

Comments
 (0)