Skip to content
Browse files

[cleanup] remove unused functions in cximage

  • Loading branch information...
1 parent 24f1dc3 commit 4182f7061af155b5655ad916bca6829131a5d570 Jonathan Marshall committed
Showing with 1 addition and 348 deletions.
  1. +1 −336 lib/cximage-6.0/CxImage/DllInterface.cpp
  2. +0 −12 xbmc/pictures/DllImageLib.h
View
337 lib/cximage-6.0/CxImage/DllInterface.cpp
@@ -17,12 +17,6 @@
#define RESAMPLE_QUALITY 0
#undef USE_EXIF_THUMBS
-// MS DirectX routines don't like loading .jpg less than 8x8 pixels.
-#define MIN_THUMB_WIDTH 8
-#define MIN_THUMB_HEIGHT 8
-#define MAX_WIDTH 4096
-#define MAX_HEIGHT 4096
-
extern "C" struct ImageInfo
{
unsigned int width;
@@ -35,13 +29,6 @@ extern "C" struct ImageInfo
BYTE *alpha;
};
-#if defined(_LINUX) || defined(__APPLE__)
-static void DeleteFile(const char* name)
-{
- unlink(name);
-}
-#endif
-
// helper functions
// determines based on file extension the type of file
@@ -110,45 +97,7 @@ int DetectFileType(const BYTE* pBuffer, int nBufSize)
return CXIMAGE_FORMAT_UNKNOWN;
}
-bool CopyFile(const char *src, const char *dest)
-{
- const unsigned int bufferSize = 16384;
- char buffer[bufferSize];
- FILE *hSrc = fopen(src, "rb");
- if (!hSrc) return false;
- FILE *hDest = fopen(dest, "wb");
- if (!hDest)
- {
- fclose(hSrc);
- return false;
- }
- bool ret = true;
- while (ret)
- {
- int sizeRead = fread(buffer, 1, bufferSize, hSrc);
- if (sizeRead > 0)
- {
- int sizeWritten = fwrite(buffer, 1, sizeRead, hDest);
- if (sizeWritten != sizeRead)
- {
- printf("PICTURE:Error writing file in copy");
- ret = false;
- }
- }
- else if (sizeRead < 0)
- {
- printf("PICTURE:Error reading file for copy");
- ret = false;
- }
- else
- break; // we're done
- }
- fclose(hSrc);
- fclose(hDest);
- return ret;
-}
-
-int ResampleKeepAspect(CxImage &image, unsigned int width, unsigned int height, bool checkTooSmall = false)
+int ResampleKeepAspect(CxImage &image, unsigned int width, unsigned int height)
{
bool bResize = false;
float fAspect = ((float)image.GetWidth()) / ((float)image.GetHeight());
@@ -166,18 +115,6 @@ int ResampleKeepAspect(CxImage &image, unsigned int width, unsigned int height,
newheight = height;
newwidth = (DWORD)( fAspect * ( (float)newheight) );
}
- if (checkTooSmall && newwidth < MIN_THUMB_WIDTH)
- {
- bResize = true;
- newwidth = MIN_THUMB_HEIGHT;
- newheight = (DWORD)( ( (float)newwidth) / fAspect);
- }
- if (checkTooSmall && newheight < MIN_THUMB_HEIGHT)
- {
- bResize = true;
- newheight = MIN_THUMB_HEIGHT;
- newwidth = (DWORD)( fAspect * ( (float)newheight) );
- }
if (bResize)
{
if (!image.Resample(newwidth, newheight, RESAMPLE_QUALITY) || !image.IsValid())
@@ -189,70 +126,6 @@ int ResampleKeepAspect(CxImage &image, unsigned int width, unsigned int height,
return bResize ? 1 : 0;
}
-int ResampleKeepAspectArea(CxImage &image, unsigned int area)
-{
- float fAspect = ((float)image.GetWidth()) / ((float)image.GetHeight());
- unsigned int width = (unsigned int)sqrt(area * fAspect);
- unsigned int height = (unsigned int)sqrt(area / fAspect);
- if (width > MAX_WIDTH) width = MAX_WIDTH;
- if (height > MAX_HEIGHT) height = MAX_HEIGHT;
- return ResampleKeepAspect(image, width, height, true);
-}
-
-bool SaveThumb(CxImage &image, const char *file, const char *thumb, int maxWidth, int maxHeight, bool bNeedToConvert = true, bool autoRotate = true)
-{
- // ok, now resample the image down if necessary
- int ret = ResampleKeepAspectArea(image, maxWidth * maxHeight);
- if (ret < 0) return false;
- if (ret) bNeedToConvert = true;
-
- // if we don't have a png but have a < 24 bit image, then convert to 24bits
- if ( image.GetNumColors())
- {
- if (!image.IncreaseBpp(24) || !image.IsValid())
- {
- printf("PICTURE::SaveThumb: Unable to convert to 24bpp: Error:%s\n", image.GetLastError());
- return false;
- }
- bNeedToConvert = true;
- }
-
- if ( autoRotate && image.GetExifInfo()->Orientation > 1)
- {
- image.RotateExif(image.GetExifInfo()->Orientation);
- bNeedToConvert = true;
- }
-
-#ifndef _LINUX
- ::DeleteFile(thumb);
-#else
- unlink(thumb);
-#endif
-
- // only resave the image if we have to (quality of the JPG saver isn't too hot!)
- if (bNeedToConvert)
- {
- // May as well have decent quality thumbs
- image.SetJpegQuality(90);
- if (!image.Save(thumb, image.AlphaIsValid() ? CXIMAGE_FORMAT_PNG : CXIMAGE_FORMAT_JPG))
- {
- printf("PICTURE::SaveThumb: Unable to save image: %s Error:%s\n", thumb, image.GetLastError());
- ::DeleteFile(thumb);
- return false;
- }
- }
- else
- { // Don't need to convert the file - copy it instead
- if (!CopyFile(file, thumb))
- {
- printf("PICTURE::SaveThumb: Unable to copy file %s\n", file);
- ::DeleteFile(thumb);
- return false;
- }
- }
- return true;
-}
-
#ifdef LoadImage
#undef LoadImage
#endif
@@ -344,91 +217,6 @@ extern "C"
return (info->texture != NULL);
};
-
- __declspec(dllexport) bool CreateThumbnail(const char *file, const char *thumb, int maxWidth, int maxHeight, bool rotateExif)
- {
- if (!file || !thumb) return false;
-
- if (IsDir(file))
- return false;
-
- // load the image
- DWORD dwImageType = GetImageType(file);
- CxImage image(dwImageType);
- int actualwidth = maxWidth * maxHeight;
- int actualheight = 0;
- try
- {
- // jpeg's may contain an EXIF preview image
- // we don't use it though, as the resolution is normally too low
-#ifdef USE_EXIF_THUMBS
- if ((dwImageType == CXIMAGE_FORMAT_JPG || dwImageType == CXIMAGE_FORMAT_RAW) && image.GetExifThumbnail(file, thumb, dwImageType))
- {
- return true;
- }
-#endif
-
- if (!image.Load(file, dwImageType, actualwidth, actualheight) || !image.IsValid())
- {
- printf("PICTURE::CreateThumbnail: Unable to open image: %s Error:%s\n", file, image.GetLastError());
- return false;
- }
- }
- catch (...)
- {
- printf("PICTURE::CreateThumbnail: Unable to open image: %s\n", file);
- return false;
- }
-
- // we need to convert if we don't have a jpeg or png.
- bool bNeedToConvert = (dwImageType != CXIMAGE_FORMAT_JPG && dwImageType != CXIMAGE_FORMAT_PNG);
- if (actualwidth > maxWidth || actualheight > maxHeight)
- bNeedToConvert = true;
-
- // save png thumbs as png, but all others as jpeg
- return SaveThumb(image, file, thumb, maxWidth, maxHeight, bNeedToConvert, rotateExif);
- };
-
- __declspec(dllexport) bool CreateThumbnailFromMemory(BYTE *buffer, unsigned int size, const char *ext, const char *thumb, int maxWidth, int maxHeight)
- {
- if (!buffer || !size || !ext || !thumb) return false;
- // load the image
- DWORD dwImageType = CXIMAGE_FORMAT_UNKNOWN;
- if (strlen(ext)) {
- dwImageType = GetImageType(ext);
- if (dwImageType == CXIMAGE_FORMAT_UNKNOWN)
- dwImageType = DetectFileType(buffer, size);
- }
- else
- dwImageType = DetectFileType(buffer, size);
- if (dwImageType == CXIMAGE_FORMAT_UNKNOWN)
- {
- printf("PICTURE::CreateThumbnailFromMemory: Unable to determine image type.");
- return false;
- }
- CxImage image(dwImageType);
- try
- {
- bool success = image.Decode(buffer, size, dwImageType);
- if (!success && dwImageType != CXIMAGE_FORMAT_UNKNOWN)
- { // try to decode with unknown imagetype
- success = image.Decode(buffer, size, CXIMAGE_FORMAT_UNKNOWN);
- }
- if (!success || !image.IsValid())
- {
- printf("PICTURE::CreateThumbnailFromMemory: Unable to decode image. Error:%s\n", image.GetLastError());
- return false;
- }
- }
- catch (...)
- {
- printf("PICTURE::CreateThumbnailFromMemory: Unable to decode image.");
- return false;
- }
-
- 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;
@@ -498,82 +286,6 @@ extern "C"
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;
-
- CxImage folderimage(maxWidth, maxHeight, 32, CXIMAGE_FORMAT_PNG);
- folderimage.AlphaCreate();
- int iWidth = maxWidth / 2;
- int iHeight = maxHeight / 2;
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- int width = iWidth;
- int height = iHeight;
- bool bBlank = false;
- if (strlen(file[i*2 + j]) == 0)
- bBlank = true;
- if (!bBlank)
- {
- CxImage image;
- if (image.Load(file[i*2 + j], CXIMAGE_FORMAT_JPG, width, height))
- {
- // resize image to iWidth
- if (ResampleKeepAspect(image, iWidth - 2, iHeight - 2) >= 0)
- {
- int iOffX = (iWidth - 2 - image.GetWidth()) / 2;
- int iOffY = (iHeight - 2 - image.GetHeight()) / 2;
- for (int x = 0; x < iWidth; x++)
- {
- for (int y = 0; y < iHeight; y++)
- {
- RGBQUAD rgb;
- if (x < iOffX || x >= iOffX + (int)image.GetWidth() || y < iOffY || y >= iOffY + (int)image.GetHeight())
- {
- rgb.rgbBlue = 0; rgb.rgbGreen = 0; rgb.rgbRed = 0; rgb.rgbReserved = 0;
- }
- else
- {
- rgb = image.GetPixelColor(x - iOffX, y - iOffY);
- rgb.rgbReserved = 255;
- }
- folderimage.SetPixelColor(x + j*iWidth, y + (1 - i)*iHeight, rgb, true);
- }
- }
- }
- else
- bBlank = true;
- }
- else
- bBlank = true;
- }
- if (bBlank)
- { // no image - just fill with black alpha
- for (int x = 0; x < iWidth; x++)
- {
- for (int y = 0; y < iHeight; y++)
- {
- RGBQUAD rgb;
- rgb.rgbBlue = 0; rgb.rgbGreen = 0; rgb.rgbRed = 0; rgb.rgbReserved = 0;
- folderimage.SetPixelColor(x + j*iWidth, y + (1 - i)*iHeight, rgb, true);
- }
- }
- }
- }
- }
- ::DeleteFile(thumb);
- if (!folderimage.Save(thumb, CXIMAGE_FORMAT_PNG))
- {
- printf("Unable to save thumb file");
- ::DeleteFile(thumb);
- return false;
- }
- return true;
- };
-
-
__declspec(dllexport) bool CreateThumbnailFromSurface(BYTE *buffer, unsigned int width, unsigned int height, unsigned int stride, const char *thumb)
{
if (!buffer || !thumb) return false;
@@ -618,53 +330,6 @@ extern "C"
}
return true;
};
- __declspec(dllexport) int ConvertFile(const char *srcfile, const char *destfile, float rotateDegrees, int destwidth, int destheight, unsigned int destquality, bool mirror)
- {
- if (!srcfile || !destfile || (destwidth ==-1 && destheight==-1)) return false;
- DWORD dwImageType = GetImageType(srcfile);
- DWORD dwDestImageType = GetImageType(destfile);
- CxImage image(dwImageType);
- try
- {
- if (!image.Load(srcfile, dwImageType) || !image.IsValid())
- {
- printf("PICTURE::ConvertFile: Unable to open image: %s Error:%s\n", srcfile, image.GetLastError());
- return 7;
- }
- }
- catch (...)
- {
- printf("PICTURE::ConvertFile: Unable to open image: %s\n", srcfile);
- return 2;
- }
- if (destheight==-1) {
- destheight = (int) ((float)destwidth * ((float)image.GetHeight()/ (float)image.GetWidth())) ;
- }
- if (destwidth==-1)
- destwidth = (int) ((float)destheight * ((float)image.GetWidth()/(float)image.GetHeight())) ;
- if (!image.Resample(destwidth, destheight, RESAMPLE_QUALITY) || !image.IsValid())
- {
- printf("PICTURE::ConvertFile: Unable to resample picture: Error:%s\n", image.GetLastError());
- return 3;
- }
- if (!rotateDegrees==0.0)
- if (!image.Rotate(rotateDegrees) || !image.IsValid())
- {
- printf("PICTURE::ConvertFile: Unable to rotate picture: Error:%s\n", image.GetLastError());
- return 4;
- }
- if (mirror)
- image.Mirror(false,false);
- if (dwDestImageType==CXIMAGE_FORMAT_JPG)
- image.SetJpegQuality(destquality);
- if (!image.Save(destfile, dwDestImageType))
- {
- printf("PICTURE::ConvertFile: Unable to save image: %s Error:%s\n", destfile, image.GetLastError());
- ::DeleteFile(destfile);
- return 5;
- }
- return 0;
- };
}
#endif
View
12 xbmc/pictures/DllImageLib.h
@@ -93,11 +93,7 @@ class DllImageLibInterface
virtual bool ReleaseImage(ImageInfo *)=0;
virtual bool LoadImage(const char *, unsigned int, unsigned int, ImageInfo *)=0;
virtual bool LoadImageFromMemory(const uint8_t*, unsigned int, const char *, unsigned int, unsigned int, ImageInfo *)=0;
- virtual bool CreateThumbnail(const char *, const char *, int, int, bool)=0;
- virtual bool CreateThumbnailFromMemory(BYTE *, unsigned int, const char *, const char *, int, int)=0;
- virtual bool CreateFolderThumbnail(const char **, const char *, int, int)=0;
virtual bool CreateThumbnailFromSurface(BYTE *, unsigned int, unsigned int, unsigned int, const char *)=0;
- virtual int ConvertFile(const char *, const char *, float, int, int, unsigned int, bool)=0;
};
class DllImageLib : public DllDynamic, DllImageLibInterface
@@ -106,19 +102,11 @@ class DllImageLib : public DllDynamic, DllImageLibInterface
DEFINE_METHOD1(bool, ReleaseImage, (ImageInfo *p1))
DEFINE_METHOD4(bool, LoadImage, (const char * p1, unsigned int p2, unsigned int p3, ImageInfo * p4))
DEFINE_METHOD6(bool, LoadImageFromMemory, (const uint8_t * p1, unsigned int p2, const char *p3, unsigned int p4, unsigned int p5, ImageInfo * p6))
- DEFINE_METHOD5(bool, CreateThumbnail, (const char * p1, const char * p2, int p3, int p4, bool p5))
- DEFINE_METHOD6(bool, CreateThumbnailFromMemory, (BYTE *p1, unsigned int p2, const char * p3, const char * p4, int p5, int p6))
- DEFINE_METHOD4(bool, CreateFolderThumbnail, (const char ** p1, const char * p2, int p3, int p4))
DEFINE_METHOD5(bool, CreateThumbnailFromSurface, (BYTE * p1, unsigned int p2, unsigned int p3, unsigned int p4, const char * p5))
- DEFINE_METHOD7(int, ConvertFile, (const char * p1, const char * p2, float p3, int p4, int p5, unsigned int p6, bool p7))
BEGIN_METHOD_RESOLVE()
RESOLVE_METHOD(ReleaseImage)
RESOLVE_METHOD(LoadImage)
RESOLVE_METHOD(LoadImageFromMemory)
- RESOLVE_METHOD(CreateThumbnail)
- RESOLVE_METHOD(CreateThumbnailFromMemory)
- RESOLVE_METHOD(CreateFolderThumbnail)
RESOLVE_METHOD(CreateThumbnailFromSurface)
- RESOLVE_METHOD(ConvertFile)
END_METHOD_RESOLVE()
};

0 comments on commit 4182f70

Please sign in to comment.
Something went wrong with that request. Please try again.