Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImageToolkit/Resize.cpp view on Meta::CPAN
FIBITMAP *tmp = NULL;
if (src_width != dst_width) {
// source and destination widths are different so, we must
// filter horizontally
if (src_height != dst_height) {
// source and destination heights are also different so, we need
// a temporary image
tmp = FreeImage_AllocateT(image_type, dst_width, src_height, dst_bpp_s1, 0, 0, 0);
if (!tmp) {
FreeImage_Unload(dst);
return NULL;
}
} else {
// source and destination heights are equal so, we can directly
// scale into destination image (second filter method will not
// be invoked)
tmp = dst;
}
// scale source image horizontally into temporary (or destination) image
horizontalFilter(src, src_height, src_width, src_offset_x, src_offset_y, src_pal, tmp, dst_width);
// set x and y offsets to zero for the second filter method
// invocation (the temporary image only contains the portion of
// the image to be rescaled with no offsets)
src_offset_x = 0;
src_offset_y = 0;
// also ensure, that the second filter method gets no source
// palette (the temporary image is palletized only, if it is
// greyscale; in that case, it is an 8-bit image with a linear
// palette so, the source palette is not needed or will even be
// mismatching, if the source palette is unordered)
src_pal = NULL;
} else {
// source and destination widths are equal so, just copy the
// image pointer
tmp = src;
}
if (src_height != dst_height) {
// source and destination heights are different so, scale
// temporary (or source) image vertically into destination image
verticalFilter(tmp, dst_width, src_height, src_offset_x, src_offset_y, src_pal, dst, dst_height);
}
// free temporary image, if not pointing to either src or dst
if (tmp != src && tmp != dst) {
FreeImage_Unload(tmp);
}
} else {
// yx filtering
// -------------
// Remark:
// The yx filtering branch could be more optimized by taking into,
// account that (src_width != dst_width) is always true, which
// follows from the above condition, which selects filtering order.
// Since (dst_width <= src_width) == TRUE selects xy filtering,
// both widths must be different when performing yx filtering.
// However, to make the code more robust, not depending on that
// condition and more symmetric to the xy filtering case, these
// (src_width != dst_width) conditions are still in place.
FIBITMAP *tmp = NULL;
if (src_height != dst_height) {
// source and destination heights are different so, we must
// filter vertically
if (src_width != dst_width) {
// source and destination widths are also different so, we need
// a temporary image
tmp = FreeImage_AllocateT(image_type, src_width, dst_height, dst_bpp_s1, 0, 0, 0);
if (!tmp) {
FreeImage_Unload(dst);
return NULL;
}
} else {
// source and destination widths are equal so, we can directly
// scale into destination image (second filter method will not
// be invoked)
tmp = dst;
}
// scale source image vertically into temporary (or destination) image
verticalFilter(src, src_width, src_height, src_offset_x, src_offset_y, src_pal, tmp, dst_height);
// set x and y offsets to zero for the second filter method
// invocation (the temporary image only contains the portion of
// the image to be rescaled with no offsets)
src_offset_x = 0;
src_offset_y = 0;
// also ensure, that the second filter method gets no source
// palette (the temporary image is palletized only, if it is
// greyscale; in that case, it is an 8-bit image with a linear
// palette so, the source palette is not needed or will even be
// mismatching, if the source palette is unordered)
src_pal = NULL;
} else {
// source and destination heights are equal so, just copy the
// image pointer
tmp = src;
}
if (src_width != dst_width) {
// source and destination heights are different so, scale
// temporary (or source) image horizontally into destination image
horizontalFilter(tmp, dst_height, src_width, src_offset_x, src_offset_y, src_pal, dst, dst_width);
}
// free temporary image, if not pointing to either src or dst
if (tmp != src && tmp != dst) {
FreeImage_Unload(tmp);
}
}
return dst;
( run in 0.459 second using v1.01-cache-2.11-cpan-d7f47b0818f )