From 202fdb7698b3329bd1a01f54780e83a08ae3065c Mon Sep 17 00:00:00 2001 From: Eric Scrivner Date: Sat, 19 Feb 2005 02:30:09 +0000 Subject: Added load function that uses SDL_RWops --- src/resources/image.cpp | 17 +++++++++++++++++ src/resources/image.h | 13 +++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 2ec867ec..2798fa05 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -198,6 +198,23 @@ Image* Image::load(const std::string &filePath, int flags) #endif } +Image* Image::load(const char* buffer, const unsigned int bufferSize) +{ + // Define our RWops structure + SDL_RWops* rw = NULL; + + // Load the raw file data from the buffer + rw = SDL_RWFromMem((void*)buffer, bufferSize); + + // Use SDL_Image to load the raw image data + SDL_Surface* texture = IMG_Load_RW(rw, 1); + + // Now free the SDL_RWops data + //SDL_FreeRW(rw); + + return new Image(texture); +} + void Image::unload() { // Free the image surface. diff --git a/src/resources/image.h b/src/resources/image.h index a92e6cc3..031f6645 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -65,11 +65,20 @@ class Image : public Resource /** * Loads an image. * @param filePath The path to the image file to load. - * @return true if the image was loaded - * false otherwise. + * @return NULL if the an error occurred, a + * valid pointer otherwise. */ static Image *load(const std::string &filePath, int flags); + /** + * Loads an image from a buffer in memory. + * @param buffer The memory buffer containing the image + * data. + * @return NULL if the an error occurred, a + * valid pointer otherwise. + */ + static Image *load(const char* buffer, const unsigned int bufferSize); + /** * Frees the resources created by SDL. */ -- cgit v1.2.3-60-g2f50