From 43f6cb06932c99f7ff5aea4426af4ac0ce58f193 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 8 Jul 2014 11:35:04 -0700 Subject: [PATCH] Add JPG/PNG image loading --- project/Build.xml | 17 ++++++++--- project/include/utils/ByteArray.h | 49 +++++++++++++++++++++++++++++++ project/src/graphics/JPEG.cpp | 4 +-- project/src/graphics/PNG.cpp | 6 ++-- 4 files changed, 65 insertions(+), 11 deletions(-) diff --git a/project/Build.xml b/project/Build.xml index 2dcea62a6..a5580d33d 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -27,11 +27,16 @@ - +
+ + + +
+
@@ -47,6 +52,13 @@
+
+ + + + +
+
@@ -154,11 +166,8 @@ - - -
diff --git a/project/include/utils/ByteArray.h b/project/include/utils/ByteArray.h index d588173cb..8450f8dc4 100644 --- a/project/include/utils/ByteArray.h +++ b/project/include/utils/ByteArray.h @@ -51,6 +51,55 @@ namespace lime { }; + #ifdef HX_WINDOWS + typedef wchar_t OSChar; + #define val_os_string val_wstring + #define OpenRead(x) _wfopen(x,L"rb") + #define OpenOverwrite(x) _wfopen(x,L"wb") // [ddc] + + #else + typedef char OSChar; + #define val_os_string val_string + + #if defined(IPHONE) + FILE *OpenRead(const char *inName); + FILE *OpenOverwrite(const char *inName); // [ddc] + extern int gFixedOrientation; + + #elif defined(HX_MACOS) + #include + FILE *OpenRead(const char *inName) + { + FILE *result = fopen(inName,"rb"); + if (!result) { + CFStringRef str = CFStringCreateWithCString(NULL, inName, kCFStringEncodingUTF8); + CFURLRef path = CFBundleCopyResourceURL(CFBundleGetMainBundle(), str, NULL, NULL); + CFRelease(str); + if (path) { + str = CFURLCopyPath(path); + CFIndex maxSize = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str),kCFStringEncodingUTF8); + char *buffer = (char *)malloc(maxSize); + if (CFStringGetCString(str, buffer, maxSize, kCFStringEncodingUTF8)) { + result = fopen(buffer,"rb"); + free(buffer); + } + CFRelease(str); + CFRelease(path); + } + } + return result; + } + #define OpenOverwrite(x) fopen(x,"wb") + #else + #ifdef TIZEN + extern int gFixedOrientation; + #endif + #define OpenRead(x) fopen(x,"rb") + #define OpenOverwrite(x) fopen(x,"wb") // [ddc] + #endif + #endif + + } diff --git a/project/src/graphics/JPEG.cpp b/project/src/graphics/JPEG.cpp index 3ff8e3f3a..46b00ff71 100644 --- a/project/src/graphics/JPEG.cpp +++ b/project/src/graphics/JPEG.cpp @@ -8,14 +8,12 @@ extern "C" { #include #include +#include namespace lime { - extern FILE *OpenRead (const char *); - - bool JPEG::Decode (const char *path, ImageData *imageData) { struct jpeg_decompress_struct cinfo; diff --git a/project/src/graphics/PNG.cpp b/project/src/graphics/PNG.cpp index 982e2c38b..8e861a689 100644 --- a/project/src/graphics/PNG.cpp +++ b/project/src/graphics/PNG.cpp @@ -7,14 +7,12 @@ extern "C" { #include #include +#include namespace lime { - extern FILE *OpenRead (const char *); - - bool PNG::Decode (const char *path, ImageData *imageData) { unsigned char png_sig[PNG_SIG_SIZE]; @@ -27,7 +25,7 @@ namespace lime { if (!file) return false; // verify the PNG signature - fread(png_sig, PNG_SIG_SIZE, 1, file); + int read = fread(png_sig, PNG_SIG_SIZE, 1, file); if (png_sig_cmp (png_sig, 0, PNG_SIG_SIZE)) { fclose (file);