Last active
November 4, 2015 02:00
-
-
Save technosaurus/76942ee935bdcc81d1fb to your computer and use it in GitHub Desktop.
2 patches to add stb-image support to jwm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- jwm-master/src/image.c 2015-11-02 20:53:46.000000000 +0800 | |
+++ jwm-stb/src/image.c 2015-11-04 00:14:58.910120109 +0800 | |
@@ -12,11 +12,15 @@ | |
#ifndef MAKE_DEPEND | |
/* We should include png.h here. See jwm.h for an explanation. */ | |
- | |
+#ifdef USE_STB_IMAGE | |
+#define STBI_ASSERT(x) | |
+#define STB_IMAGE_IMPLEMENTATION | |
+#include "stb_image.h" | |
+#endif | |
# ifdef USE_XPM | |
# include <X11/xpm.h> | |
# endif | |
-# ifdef USE_JPEG | |
+# if defined USE_JPEG && !defined USE_STB_IMAGE | |
# include <jpeglib.h> | |
# endif | |
# ifdef USE_CAIRO | |
@@ -39,12 +43,14 @@ | |
static ImageNode *LoadSVGImage(const char *fileName); | |
#endif | |
#endif | |
+#ifndef USE_STB_IMAGE | |
#ifdef USE_JPEG | |
static ImageNode *LoadJPEGImage(const char *fileName); | |
#endif | |
#ifdef USE_PNG | |
static ImageNode *LoadPNGImage(const char *fileName); | |
#endif | |
+#endif | |
#ifdef USE_XPM | |
static ImageNode *LoadXPMImage(const char *fileName); | |
#endif | |
@@ -71,8 +77,23 @@ ImageNode *LoadImage(const char *fileNam | |
return result; | |
} | |
+#ifdef USE_STB_IMAGE | |
+ { | |
+ int n=4; /* depth in bytes 4 = 32bpp */ | |
+ ImageNode *image = CreateImage(0,0,0); | |
+ image->data = | |
+ stbi_load(fileName, &image->width, &image->height, &n, 4); | |
+ if (image->data) { | |
+ unsigned *dp = (unsigned *)image->data; | |
+ size_t i, len = image->width*image->height; | |
+ for(i=0;i<len;i++) | |
+ dp[i]= (dp[i]<<8)|(dp[i]>>24); | |
+ return image; | |
+ } | |
+ } | |
+#else | |
/* Attempt to load the file as a PNG image. */ | |
-#ifdef USE_PNG | |
+#if defined USE_PNG && !defined USE_STB_IMAGE | |
if(nameLength >= 4 && !StrCmpNoCase(&fileName[nameLength - 4], ".png")) { | |
result = LoadPNGImage(fileName); | |
if(result) { | |
@@ -82,7 +103,7 @@ ImageNode *LoadImage(const char *fileNam | |
#endif | |
/* Attempt to load the file as a JPEG image. */ | |
-#ifdef USE_JPEG | |
+#if defined USE_JPEG && !defined USE_STB_IMAGE | |
if( (nameLength >= 4 | |
&& !StrCmpNoCase(&fileName[nameLength - 4], ".jpg")) | |
|| (nameLength >= 5 | |
@@ -93,7 +114,7 @@ ImageNode *LoadImage(const char *fileNam | |
} | |
} | |
#endif | |
- | |
+#endif /* USE_STB_IMAGE */ | |
/* Attempt to load the file as an SVG image. */ | |
#ifdef USE_CAIRO | |
#ifdef USE_RSVG | |
@@ -198,7 +219,7 @@ ImageNode *LoadImageFromDrawable(Drawabl | |
* Since libpng uses longjmp, this function is not reentrant to simplify | |
* the issues surrounding longjmp and local variables. | |
*/ | |
-#ifdef USE_PNG | |
+#if defined USE_PNG && !defined USE_STB_IMAGE | |
ImageNode *LoadPNGImage(const char *fileName) | |
{ | |
@@ -323,7 +344,7 @@ ImageNode *LoadPNGImage(const char *file | |
#endif /* USE_PNG */ | |
/** Load a JPEG image from the specified file. */ | |
-#ifdef USE_JPEG | |
+#if defined USE_JPEG && !defined USE_STB_IMAGE | |
typedef struct { | |
struct jpeg_error_mgr pub; | |
--- jwm-master/src/jwm.h 2015-11-02 20:53:46.000000000 +0800 | |
+++ jwm-stb/src/jwm.h 2015-11-03 09:32:53.210009188 +0800 | |
@@ -26,7 +26,8 @@ | |
* once. The X headers apparently include setjmp.h, so I don't have | |
* any control over the situation. Fortunately png.h can't complain | |
* if it was included first. */ | |
-# ifdef USE_PNG | |
+ | |
+#if defined USE_PNG && !defined USE_STB_IMAGE | |
# include <png.h> | |
# else | |
# include <setjmp.h> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment