Add JPG/PNG image loading
This commit is contained in:
@@ -27,11 +27,16 @@
|
|||||||
<files id="lime">
|
<files id="lime">
|
||||||
|
|
||||||
<compilerflag value="-DLIME_SDL" if="LIME_SDL" />
|
<compilerflag value="-DLIME_SDL" if="LIME_SDL" />
|
||||||
<compilerflag value="-I/usr/local/include" />
|
|
||||||
<compilerflag value="-Iinclude" />
|
<compilerflag value="-Iinclude" />
|
||||||
|
|
||||||
<file name="src/ExternalInterface.cpp" />
|
<file name="src/ExternalInterface.cpp" />
|
||||||
|
|
||||||
|
<section if="LIME_JPEG">
|
||||||
|
|
||||||
|
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/jpeg/" />
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
<section if="LIME_NEKO">
|
<section if="LIME_NEKO">
|
||||||
|
|
||||||
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/neko/vm/" />
|
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/neko/vm/" />
|
||||||
@@ -47,6 +52,13 @@
|
|||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section if="LIME_PNG">
|
||||||
|
|
||||||
|
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/png/" />
|
||||||
|
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/zlib/" />
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
<section if="LIME_SDL">
|
<section if="LIME_SDL">
|
||||||
|
|
||||||
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/sdl/include/" />
|
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/sdl/include/" />
|
||||||
@@ -154,11 +166,8 @@
|
|||||||
<vflag name="-framework" value="AppKit" />
|
<vflag name="-framework" value="AppKit" />
|
||||||
<vflag name="-framework" value="OpenAL"/>
|
<vflag name="-framework" value="OpenAL"/>
|
||||||
|
|
||||||
<lib name="-L/usr/local/lib" />
|
|
||||||
<lib name="/opt/local/lib/libgc.a" if="LIME_NEKO" />
|
<lib name="/opt/local/lib/libgc.a" if="LIME_NEKO" />
|
||||||
<lib name="-lm" if="LIME_NEKO" />
|
<lib name="-lm" if="LIME_NEKO" />
|
||||||
<lib name="-lpng" />
|
|
||||||
<lib name="-ljpeg" />
|
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -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 <CoreFoundation/CoreFoundation.h>
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,12 @@ extern "C" {
|
|||||||
|
|
||||||
#include <graphics/ImageData.h>
|
#include <graphics/ImageData.h>
|
||||||
#include <graphics/JPEG.h>
|
#include <graphics/JPEG.h>
|
||||||
|
#include <utils/ByteArray.h>
|
||||||
|
|
||||||
|
|
||||||
namespace lime {
|
namespace lime {
|
||||||
|
|
||||||
|
|
||||||
extern FILE *OpenRead (const char *);
|
|
||||||
|
|
||||||
|
|
||||||
bool JPEG::Decode (const char *path, ImageData *imageData) {
|
bool JPEG::Decode (const char *path, ImageData *imageData) {
|
||||||
|
|
||||||
struct jpeg_decompress_struct cinfo;
|
struct jpeg_decompress_struct cinfo;
|
||||||
|
|||||||
@@ -7,14 +7,12 @@ extern "C" {
|
|||||||
|
|
||||||
#include <graphics/ImageData.h>
|
#include <graphics/ImageData.h>
|
||||||
#include <graphics/PNG.h>
|
#include <graphics/PNG.h>
|
||||||
|
#include <utils/ByteArray.h>
|
||||||
|
|
||||||
|
|
||||||
namespace lime {
|
namespace lime {
|
||||||
|
|
||||||
|
|
||||||
extern FILE *OpenRead (const char *);
|
|
||||||
|
|
||||||
|
|
||||||
bool PNG::Decode (const char *path, ImageData *imageData) {
|
bool PNG::Decode (const char *path, ImageData *imageData) {
|
||||||
|
|
||||||
unsigned char png_sig[PNG_SIG_SIZE];
|
unsigned char png_sig[PNG_SIG_SIZE];
|
||||||
@@ -27,7 +25,7 @@ namespace lime {
|
|||||||
if (!file) return false;
|
if (!file) return false;
|
||||||
|
|
||||||
// verify the PNG signature
|
// 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)) {
|
if (png_sig_cmp (png_sig, 0, PNG_SIG_SIZE)) {
|
||||||
|
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|||||||
Reference in New Issue
Block a user