r375 - trunk
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Sat Nov 24 01:07:07 EST 2007
Author: icculus
Date: 2007-11-24 01:07:07 -0500 (Sat, 24 Nov 2007)
New Revision: 375
Modified:
trunk/mojosetup.c
trunk/platform.h
trunk/platform_unix.c
trunk/platform_windows.c
trunk/universal.h
Log:
Implement hooks for image decoding into MojoSetup.
Modified: trunk/mojosetup.c
===================================================================
--- trunk/mojosetup.c 2007-11-24 04:46:06 UTC (rev 374)
+++ trunk/mojosetup.c 2007-11-24 06:07:07 UTC (rev 375)
@@ -583,6 +583,34 @@
#endif
+#if SUPPORT_STBIMAGE
+unsigned char *stbi_load_from_memory(unsigned char *buffer, int len, int *x,
+ int *y, int *comp, int req_comp);
+#endif
+
+uint8 *decodeImage(const uint8 *data, uint32 size, uint32 *w, uint32 *h)
+{
+ uint8 *retval = MojoPlatform_decodeImage(data, size, w, h);
+
+ #if SUPPORT_STBIMAGE
+ if (retval == NULL) // try our built-in routines.
+ {
+ const int siz = (int) size;
+ unsigned char *buf = (unsigned char *) data;
+ int x = 0, y = 0, comp = 0;
+ retval = (uint8 *) stbi_load_from_memory(buf, siz, &x, &y, &comp, 4);
+ *w = (uint32) x;
+ *h = (uint32) y;
+ } // if
+ #endif
+
+ if (retval == NULL)
+ *w = *h = 0;
+
+ return retval;
+} // decodeImage
+
+
// This is called from main()/WinMain()/whatever.
int MojoSetup_main(int argc, char **argv)
{
Modified: trunk/platform.h
===================================================================
--- trunk/platform.h 2007-11-24 04:46:06 UTC (rev 374)
+++ trunk/platform.h 2007-11-24 06:07:07 UTC (rev 375)
@@ -239,6 +239,20 @@
// characters. You should supply if needed.
void MojoPlatform_log(const char *str);
+// This tries to decode a graphic file in memory into an RGBA framebuffer.
+// Most platforms return NULL here. No one should call this; use decodeImage()
+// instead, which will try included platform-independent code if this fails.
+// This function is just here to allow a platform with the appropriate
+// functionality to work without compiling in stb_image.c, or supply more
+// formats over the built-in code.
+// (data) points to the compressed data, (size) is the number of bytes
+// of compressed data. (*w) and (*h) will contain the images dimensions on
+// return.
+// Returns NULL on failure (unsupported, etc) and a pointer to the
+// uncompressed data on success. Caller must free() the returned pointer!
+uint8 *MojoPlatform_decodeImage(const uint8 *data, uint32 size,
+ uint32 *w, uint32 *h);
+
// Get the current locale, in the format "xx_YY" where "xx" is the language
// (en, fr, de...) and "_YY" is the country. (_US, _CA, etc). The country
// can be omitted. Don't include encoding, it's always UTF-8 at this time.
Modified: trunk/platform_unix.c
===================================================================
--- trunk/platform_unix.c 2007-11-24 04:46:06 UTC (rev 374)
+++ trunk/platform_unix.c 2007-11-24 06:07:07 UTC (rev 375)
@@ -1017,6 +1017,14 @@
} // MojoPlatform_spawnTerminal
+uint8 *MojoPlatform_decodeImage(const uint8 *data, uint32 size,
+ uint32 *w, uint32 *h)
+{
+ // !!! FIXME: try Quartz APIs on Mac OS X?
+ return NULL; // no platform-specific APIs. Just use the built-in ones.
+} // MojoPlatform_decodeImage
+
+
static void signal_catcher(int sig)
{
static boolean first_shot = true;
Modified: trunk/platform_windows.c
===================================================================
--- trunk/platform_windows.c 2007-11-24 04:46:06 UTC (rev 374)
+++ trunk/platform_windows.c 2007-11-24 06:07:07 UTC (rev 375)
@@ -641,6 +641,13 @@
} // MojoPlatform_spawnTerminal
+uint8 *MojoPlatform_decodeImage(const uint8 *data, uint32 size,
+ uint32 *w, uint32 *h)
+{
+ return NULL; // !!! FIXME: try IPicture?
+} // MojoPlatform_decodeImage
+
+
char *MojoPlatform_currentWorkingDir(void)
{
char *retval = NULL;
Modified: trunk/universal.h
===================================================================
--- trunk/universal.h 2007-11-24 04:46:06 UTC (rev 374)
+++ trunk/universal.h 2007-11-24 06:07:07 UTC (rev 375)
@@ -192,6 +192,15 @@
// profile("Something I did", start);
uint32 profile(const char *what, uint32 start_time);
+// This tries to decode a graphic file in memory into an RGBA framebuffer,
+// first with platform-specific facilities, if any, and then any built-in
+// decoders, if that fails.
+// (data) points to the compressed data, (size) is the number of bytes
+// of compressed data. (*w) and (*h) will contain the images dimensions on
+// return.
+// Returns NULL on failure (unsupported, etc) and a pointer to the
+// uncompressed data on success. Caller must free() the returned pointer!
+uint8 *decodeImage(const uint8 *data, uint32 size, uint32 *w, uint32 *h);
// See if a given flag was on the command line
//
More information about the mojosetup-commits
mailing list