diff options
author | Jonathan Marshall <jmarshall@never.you.mind> | 2012-06-24 20:46:27 +1200 |
---|---|---|
committer | Jonathan Marshall <jmarshall@never.you.mind> | 2012-07-04 11:54:57 +1200 |
commit | 6f4ce3e394afddf46564690538a9889237ad77ba (patch) | |
tree | 1eb464f7fff7fff8850b2f8d9d5c51bd36b37631 /lib | |
parent | cc5ed3c2474084ebc0373a3046410e6f766e03f4 (diff) |
[imageloader] adds LoadFromFileInMemory to CBaseTexture
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cximage-6.0/CxImage/DllInterface.cpp | 69 | ||||
-rw-r--r-- | lib/cximage-6.0/CxImage/ximaenc.cpp | 8 | ||||
-rw-r--r-- | lib/cximage-6.0/CxImage/ximage.h | 9 |
3 files changed, 85 insertions, 1 deletions
diff --git a/lib/cximage-6.0/CxImage/DllInterface.cpp b/lib/cximage-6.0/CxImage/DllInterface.cpp index 01d5928bd4..c49103a83e 100644 --- a/lib/cximage-6.0/CxImage/DllInterface.cpp +++ b/lib/cximage-6.0/CxImage/DllInterface.cpp @@ -429,6 +429,75 @@ extern "C" return SaveThumb(image, "", thumb, maxWidth, maxHeight); }; + __declspec(dllexport) bool LoadImageFromMemory(const BYTE *buffer, unsigned int size, const char *mime, unsigned int maxwidth, unsigned int maxheight, ImageInfo *info) + { + if (!buffer || !size || !mime || !info) return false; + + // load the image + DWORD dwImageType = CXIMAGE_FORMAT_UNKNOWN; + if (strlen(mime)) + dwImageType = GetImageType(mime); + if (dwImageType == CXIMAGE_FORMAT_UNKNOWN) + dwImageType = DetectFileType(buffer, size); + if (dwImageType == CXIMAGE_FORMAT_UNKNOWN) + { + printf("PICTURE::LoadImageFromMemory: Unable to determine image type."); + return false; + } + + CxImage *image = new CxImage(dwImageType); + if (!image) + return false; + + int actualwidth = maxwidth; + int actualheight = maxheight; + + try + { + bool success = image->Decode((BYTE*)buffer, size, dwImageType, actualwidth, actualheight); + if (!success && dwImageType != CXIMAGE_FORMAT_UNKNOWN) + { // try to decode with unknown imagetype + success = image->Decode((BYTE*)buffer, size, CXIMAGE_FORMAT_UNKNOWN); + } + if (!success || !image->IsValid()) + { + printf("PICTURE::LoadImageFromMemory: Unable to decode image. Error:%s\n", image->GetLastError()); + delete image; + return false; + } + } + catch (...) + { + printf("PICTURE::LoadImageFromMemory: Unable to decode image."); + delete image; + return false; + } + + // ok, now resample the image down if necessary + if (ResampleKeepAspect(*image, maxwidth, maxheight) < 0) + { + printf("PICTURE::LoadImage: Unable to resample picture\n"); + delete image; + return false; + } + + // make sure our image is 24bit minimum + image->IncreaseBpp(24); + + // fill in our struct + info->width = image->GetWidth(); + info->height = image->GetHeight(); + info->originalwidth = actualwidth; + info->originalheight = actualheight; + memcpy(&info->exifInfo, image->GetExifInfo(), sizeof(EXIFINFO)); + + // create our texture + info->context = image; + info->texture = image->GetBits(); + info->alpha = image->AlphaGetBits(); + return (info->texture != NULL); + }; + __declspec(dllexport) bool CreateFolderThumbnail(const char **file, const char *thumb, int maxWidth, int maxHeight) { if (!file || !file[0] || !file[1] || !file[2] || !file[3] || !thumb) return false; diff --git a/lib/cximage-6.0/CxImage/ximaenc.cpp b/lib/cximage-6.0/CxImage/ximaenc.cpp index 8f6c94f001..14e7890019 100644 --- a/lib/cximage-6.0/CxImage/ximaenc.cpp +++ b/lib/cximage-6.0/CxImage/ximaenc.cpp @@ -695,11 +695,19 @@ CxImage::CxImage(BYTE * buffer, DWORD size, DWORD imagetype) * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS * \return true if everything is ok */ +#ifdef XBMC +bool CxImage::Decode(BYTE * buffer, DWORD size, DWORD imagetype, int &width, int &height) +{ + CxMemFile file(buffer,size); + return Decode(&file,imagetype,width,height); +} +#else bool CxImage::Decode(BYTE * buffer, DWORD size, DWORD imagetype) { CxMemFile file(buffer,size); return Decode(&file,imagetype); } +#endif //////////////////////////////////////////////////////////////////////////////// /** * Loads an image from file handle. diff --git a/lib/cximage-6.0/CxImage/ximage.h b/lib/cximage-6.0/CxImage/ximage.h index fe20ce8a19..26341d99cb 100644 --- a/lib/cximage-6.0/CxImage/ximage.h +++ b/lib/cximage-6.0/CxImage/ximage.h @@ -520,6 +520,7 @@ public: bool Load(const char * filename, DWORD imagetype, int &iWidth, int &iHeight); bool Decode(FILE * hFile, DWORD imagetype, int &iWidth, int &iHeight); bool Decode(CxFile * hFile, DWORD imagetype, int &iWidth, int &iHeight); + bool Decode(BYTE *buffer, DWORD size, DWORD imagetype, int &iWidth, int &iHeight); bool Load(const char * filename, DWORD imagetype) { int iWidth=0; @@ -538,12 +539,18 @@ public: int iHeight=0; return Decode(hFile, imagetype, iWidth, iHeight); }; + bool Decode(BYTE *buffer, unsigned int size, DWORD imagetype) + { + int iWidth=0; + int iHeight=0; + return Decode(buffer, size, imagetype, iWidth, iHeight); + }; #else bool Load(const char * filename, DWORD imagetype); bool Decode(FILE * hFile, DWORD imagetype); bool Decode(CxFile * hFile, DWORD imagetype); -#endif bool Decode(BYTE * buffer, DWORD size, DWORD imagetype); +#endif bool CheckFormat(CxFile * hFile, DWORD imagetype = 0); bool CheckFormat(BYTE * buffer, DWORD size, DWORD imagetype = 0); |