From 76b86227951fdb5096572c36a256f07aee76def3 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Mon, 18 May 2015 07:31:16 +0000 Subject: git-svn-id: http://svn.miranda-ng.org/main/trunk@13671 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AdvaImg/src/FreeImageToolkit/Rescale.cpp | 41 ++++++++++++++++++------ 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'plugins/AdvaImg/src/FreeImageToolkit/Rescale.cpp') diff --git a/plugins/AdvaImg/src/FreeImageToolkit/Rescale.cpp b/plugins/AdvaImg/src/FreeImageToolkit/Rescale.cpp index 0c8bbc2787..4f885c29a5 100644 --- a/plugins/AdvaImg/src/FreeImageToolkit/Rescale.cpp +++ b/plugins/AdvaImg/src/FreeImageToolkit/Rescale.cpp @@ -22,11 +22,27 @@ #include "Resize.h" -FIBITMAP * DLL_CALLCONV -FreeImage_Rescale(FIBITMAP *src, int dst_width, int dst_height, FREE_IMAGE_FILTER filter) { +FIBITMAP * DLL_CALLCONV +FreeImage_RescaleRect(FIBITMAP *src, int dst_width, int dst_height, int src_left, int src_top, int src_right, int src_bottom, FREE_IMAGE_FILTER filter, unsigned flags) { FIBITMAP *dst = NULL; - if (!FreeImage_HasPixels(src) || (dst_width <= 0) || (dst_height <= 0) || (FreeImage_GetWidth(src) <= 0) || (FreeImage_GetHeight(src) <= 0)) { + const int src_width = FreeImage_GetWidth(src); + const int src_height = FreeImage_GetHeight(src); + + if (!FreeImage_HasPixels(src) || (dst_width <= 0) || (dst_height <= 0) || (src_width <= 0) || (src_height <= 0)) { + return NULL; + } + + // normalize the rectangle + if (src_right < src_left) { + INPLACESWAP(src_left, src_right); + } + if (src_bottom < src_top) { + INPLACESWAP(src_top, src_bottom); + } + + // check the size of the sub image + if((src_left < 0) || (src_right > src_width) || (src_top < 0) || (src_bottom > src_height)) { return NULL; } @@ -59,17 +75,24 @@ FreeImage_Rescale(FIBITMAP *src, int dst_width, int dst_height, FREE_IMAGE_FILTE CResizeEngine Engine(pFilter); - dst = Engine.scale(src, dst_width, dst_height, 0, 0, - FreeImage_GetWidth(src), FreeImage_GetHeight(src)); + dst = Engine.scale(src, dst_width, dst_height, src_left, src_top, + src_right - src_left, src_bottom - src_top, flags); delete pFilter; - // copy metadata from src to dst - FreeImage_CloneMetadata(dst, src); - + if ((flags & FI_RESCALE_OMIT_METADATA) != FI_RESCALE_OMIT_METADATA) { + // copy metadata from src to dst + FreeImage_CloneMetadata(dst, src); + } + return dst; } +FIBITMAP * DLL_CALLCONV +FreeImage_Rescale(FIBITMAP *src, int dst_width, int dst_height, FREE_IMAGE_FILTER filter) { + return FreeImage_RescaleRect(src, dst_width, dst_height, 0, 0, FreeImage_GetWidth(src), FreeImage_GetHeight(src), filter, FI_RESCALE_DEFAULT); +} + FIBITMAP * DLL_CALLCONV FreeImage_MakeThumbnail(FIBITMAP *dib, int max_pixel_size, BOOL convert) { FIBITMAP *thumbnail = NULL; @@ -164,6 +187,6 @@ FreeImage_MakeThumbnail(FIBITMAP *dib, int max_pixel_size, BOOL convert) { // copy metadata from src to dst FreeImage_CloneMetadata(thumbnail, dib); - + return thumbnail; } -- cgit v1.2.3