:: limine / common / stb_image.patch 2.6 KB raw

1
--- common/lib/stb_image.h	2023-03-05 18:57:03.930649341 +0100
2
+++ common/lib/stb_image.h	2023-03-05 18:55:53.767318782 +0100
3
@@ -127,6 +127,54 @@
4
 #ifndef STBI_INCLUDE_STB_IMAGE_H
5
 #define STBI_INCLUDE_STB_IMAGE_H
6
 
7
+#include <stddef.h>
8
+#include <lib/libc.h>
9
+#include <lib/misc.h>
10
+#include <mm/pmm.h>
11
+
12
+#define STBI_ASSERT(x)
13
+
14
+#define STBI_MALLOC(x) ({ \
15
+    size_t STBI_MALLOC_alloc_size = (x); \
16
+    STBI_MALLOC_alloc_size += 16; \
17
+    void *STBI_MALLOC_buf = ext_mem_alloc(STBI_MALLOC_alloc_size); \
18
+    size_t *STBI_MALLOC_alloc_size_ptr = STBI_MALLOC_buf; \
19
+    *STBI_MALLOC_alloc_size_ptr = STBI_MALLOC_alloc_size; \
20
+    STBI_MALLOC_buf + 16; \
21
+})
22
+
23
+#define STBI_FREE(x) do { \
24
+    void *STBI_FREE_buf = (x); \
25
+    if (STBI_FREE_buf == NULL) { \
26
+        break; \
27
+    } \
28
+    STBI_FREE_buf -= 16; \
29
+    size_t *STBI_FREE_alloc_size_ptr = STBI_FREE_buf; \
30
+    size_t STBI_FREE_alloc_size = *STBI_FREE_alloc_size_ptr; \
31
+    pmm_free(STBI_FREE_buf, STBI_FREE_alloc_size); \
32
+} while (0)
33
+
34
+#define STBI_REALLOC(x, y) ({ \
35
+    void *STBI_REALLOC_buf = (x); \
36
+    size_t STBI_REALLOC_alloc_size = (y); \
37
+    void *STBI_REALLOC_new_buf = STBI_MALLOC(STBI_REALLOC_alloc_size); \
38
+    if (STBI_REALLOC_buf != NULL) { \
39
+        size_t STBI_REALLOC_old_size = (*(size_t *)((void *)STBI_REALLOC_buf - 16)) - 16; \
40
+        memcpy(STBI_REALLOC_new_buf, STBI_REALLOC_buf, \
41
+               MIN(STBI_REALLOC_alloc_size, STBI_REALLOC_old_size)); \
42
+        STBI_FREE(STBI_REALLOC_buf); \
43
+    } \
44
+    STBI_REALLOC_new_buf; \
45
+})
46
+
47
+#define STBI_NO_THREAD_LOCALS
48
+#define STBI_NO_STDIO
49
+#define STBI_NO_SIMD
50
+#define STBI_NO_LINEAR
51
+#define STBI_ONLY_JPEG
52
+#define STBI_ONLY_PNG
53
+#define STBI_ONLY_BMP
54
+
55
 // DOCUMENTATION
56
 //
57
 // Limitations:
58
@@ -381,7 +429,7 @@
59
    STBI_rgb_alpha  = 4
60
 };
61
 
62
-#include <stdlib.h>
63
+// #include <stdlib.h>
64
 typedef unsigned char stbi_uc;
65
 typedef unsigned short stbi_us;
66
 
67
@@ -584,8 +632,8 @@
68
 
69
 #include <stdarg.h>
70
 #include <stddef.h> // ptrdiff_t on osx
71
-#include <stdlib.h>
72
-#include <string.h>
73
+// #include <stdlib.h>
74
+// #include <string.h>
75
 #include <limits.h>
76
 
77
 #if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
78
@@ -1574,10 +1622,12 @@
79
 STBIDEF void   stbi_ldr_to_hdr_scale(float scale) { stbi__l2h_scale = scale; }
80
 #endif
81
 
82
+/*
83
 static float stbi__h2l_gamma_i=1.0f/2.2f, stbi__h2l_scale_i=1.0f;
84
 
85
 STBIDEF void   stbi_hdr_to_ldr_gamma(float gamma) { stbi__h2l_gamma_i = 1/gamma; }
86
 STBIDEF void   stbi_hdr_to_ldr_scale(float scale) { stbi__h2l_scale_i = 1/scale; }
87
+*/
88
 
89
 
90
 //////////////////////////////////////////////////////////////////////////////
tab: 248 wrap: offon