فهرست منبع

Imports for Image

Kajetan Johannes Hammerle 11 ماه پیش
والد
کامیت
f3f8a660d0
2فایلهای تغییر یافته به همراه28 افزوده شده و 20 حذف شده
  1. 9 0
      include/core/Image.h
  2. 19 20
      src/Image.c

+ 9 - 0
include/core/Image.h

@@ -22,4 +22,13 @@ void coreDestroyImage8(CoreImage8* image);
 bool coreInitImage16(CoreImage16* image, const char* path);
 void coreDestroyImage16(CoreImage16* image);
 
+#ifdef IMPORT_CORE
+#define Image8 CoreImage8
+#define Image16 CoreImage16
+#define initImage8 coreInitImage8
+#define destroyImage8 coreDestroyImage8
+#define initImage16 coreInitImage16
+#define destroyImage16 coreDestroyImage16
+#endif
+
 #endif

+ 19 - 20
src/Image.c

@@ -1,48 +1,47 @@
+#define IMPORT_CORE
 #include "core/Image.h"
 
 #include <core/Utility.h>
 #define STB_IMAGE_IMPLEMENTATION
 #define STBI_ONLY_PNG
-#define STBI_MALLOC(n) coreAllocate(n)
-#define STBI_REALLOC(p, n) coreReallocate(p, n)
-#define STBI_FREE(p) coreFree(p)
+#define STBI_MALLOC(n) cAllocate(n)
+#define STBI_REALLOC(p, n) cReallocate(p, n)
+#define STBI_FREE(p) cFree(p)
 #include <core/Logger.h>
 #include <errno.h>
 #include <stb_image.h>
 #include <string.h>
 
 static void printError(const char* path) {
-    CORE_LOG_ERROR("Cannot read image '%s': %s", path, strerror(errno));
+    LOG_ERROR("Cannot read image '%s': %s", path, strerror(errno));
 }
 
-bool coreInitImage8(CoreImage8* image, const char* path) {
-    *image = (CoreImage8){0};
-    image->data =
-        stbi_load(path, &image->width, &image->height, &image->channels, 0);
-    if(image->data == nullptr) {
+bool initImage8(Image8* i, const char* path) {
+    *i = (Image8){0};
+    i->data = stbi_load(path, &i->width, &i->height, &i->channels, 0);
+    if(i->data == nullptr) {
         printError(path);
         return true;
     }
     return false;
 }
 
-void coreDestroyImage8(CoreImage8* image) {
-    stbi_image_free(image->data);
-    *image = (CoreImage8){0};
+void destroyImage8(Image8* i) {
+    stbi_image_free(i->data);
+    *i = (Image8){0};
 }
 
-bool coreInitImage16(CoreImage16* image, const char* path) {
-    *image = (CoreImage16){0};
-    image->data =
-        stbi_load_16(path, &image->width, &image->height, &image->channels, 0);
-    if(image->data == nullptr) {
+bool initImage16(Image16* i, const char* path) {
+    *i = (Image16){0};
+    i->data = stbi_load_16(path, &i->width, &i->height, &i->channels, 0);
+    if(i->data == nullptr) {
         printError(path);
         return true;
     }
     return false;
 }
 
-void coreDestroyImage16(CoreImage16* image) {
-    stbi_image_free(image->data);
-    *image = (CoreImage16){0};
+void destroyImage16(Image16* i) {
+    stbi_image_free(i->data);
+    *i = (Image16){0};
 }