Document cloning, copying, scaling and interpolation

master
Christoph M. Becker 2016-10-06 15:50:16 +02:00
parent 1b6564cdc8
commit b697bf74db
3 changed files with 237 additions and 58 deletions

190
src/gd.c
View File

@ -2800,9 +2800,19 @@ BGD_DECLARE(void) gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2,
* Group: Cloning and Copying
*/
/*
Function: gdImageClone
*/
/**
* Function: gdImageClone
*
* Clones an image
*
* Creates an exact duplicate of the given image.
*
* Parameters:
* src - The source image.
*
* Returns:
* The cloned image on success, NULL on failure.
*/
BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src) {
gdImagePtr dst;
register int i, x;
@ -2898,9 +2908,25 @@ BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src) {
return dst;
}
/*
Function: gdImageCopy
*/
/**
* Function: gdImageCopy
*
* Copy an area of an image to another image
*
* Parameters:
* dst - The destination image.
* src - The source image.
* dstX - The x-coordinate of the upper left corner to copy to.
* dstY - The y-coordinate of the upper left corner to copy to.
* srcX - The x-coordinate of the upper left corner to copy from.
* srcY - The y-coordinate of the upper left corner to copy from.
* w - The width of the area to copy.
* h - The height of the area to copy.
*
* See also:
* - <gdImageCopyMerge>
* - <gdImageCopyMergeGray>
*/
BGD_DECLARE(void) gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX,
int srcY, int w, int h)
{
@ -2988,12 +3014,32 @@ BGD_DECLARE(void) gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dst
}
}
/*
Function: gdImageCopyMerge
This function is a substitute for real alpha channel operations,
so it doesn't pay attention to the alpha channel.
*/
/**
* Function: gdImageCopyMerge
*
* Copy an area of an image to another image ignoring alpha
*
* The source area will be copied to the destination are by merging the pixels.
*
* Note:
* This function is a substitute for real alpha channel operations,
* so it doesn't pay attention to the alpha channel.
*
* Parameters:
* dst - The destination image.
* src - The source image.
* dstX - The x-coordinate of the upper left corner to copy to.
* dstY - The y-coordinate of the upper left corner to copy to.
* srcX - The x-coordinate of the upper left corner to copy from.
* srcY - The y-coordinate of the upper left corner to copy from.
* w - The width of the area to copy.
* h - The height of the area to copy.
* pct - The percentage in range 0..100.
*
* See also:
* - <gdImageCopy>
* - <gdImageCopyMergeGray>
*/
BGD_DECLARE(void) gdImageCopyMerge (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
int srcX, int srcY, int w, int h, int pct)
{
@ -3036,12 +3082,33 @@ BGD_DECLARE(void) gdImageCopyMerge (gdImagePtr dst, gdImagePtr src, int dstX, in
}
}
/*
Function: gdImageCopyMergeGray
This function is a substitute for real alpha channel operations,
so it doesn't pay attention to the alpha channel.
*/
/**
* Function: gdImageCopyMergeGray
*
* Copy an area of an image to another image ignoring alpha
*
* The source area will be copied to the grayscaled destination area by merging
* the pixels.
*
* Note:
* This function is a substitute for real alpha channel operations,
* so it doesn't pay attention to the alpha channel.
*
* Parameters:
* dst - The destination image.
* src - The source image.
* dstX - The x-coordinate of the upper left corner to copy to.
* dstY - The y-coordinate of the upper left corner to copy to.
* srcX - The x-coordinate of the upper left corner to copy from.
* srcY - The y-coordinate of the upper left corner to copy from.
* w - The width of the area to copy.
* h - The height of the area to copy.
* pct - The percentage of the source color intensity in range 0..100.
*
* See also:
* - <gdImageCopy>
* - <gdImageCopyMerge>
*/
BGD_DECLARE(void) gdImageCopyMergeGray (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
int srcX, int srcY, int w, int h, int pct)
{
@ -3100,9 +3167,30 @@ BGD_DECLARE(void) gdImageCopyMergeGray (gdImagePtr dst, gdImagePtr src, int dstX
}
}
/*
Function: gdImageCopyResized
*/
/**
* Function: gdImageCopyResized
*
* Copy a resized area from an image to another image
*
* If the source and destination area differ in size, the area will be resized
* using nearest-neighbor interpolation.
*
* Parameters:
* dst - The destination image.
* src - The source image.
* dstX - The x-coordinate of the upper left corner to copy to.
* dstY - The y-coordinate of the upper left corner to copy to.
* srcX - The x-coordinate of the upper left corner to copy from.
* srcY - The y-coordinate of the upper left corner to copy from.
* dstW - The width of the area to copy to.
* dstH - The height of the area to copy to.
* srcW - The width of the area to copy from.
* srcH - The height of the area to copy from.
*
* See also:
* - <gdImageCopyResampled>
* - <gdImageScale>
*/
BGD_DECLARE(void) gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX, int dstY,
int srcX, int srcY, int dstW, int dstH, int srcW,
int srcH)
@ -3231,17 +3319,27 @@ BGD_DECLARE(void) gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX,
gdFree (sty);
}
/* gd 2.0.8: gdImageCopyRotated is added. Source
is a rectangle, with its upper left corner at
srcX and srcY. Destination is the *center* of
the rotated copy. Angle is in degrees, same as
gdImageArc. Floating point destination center
coordinates allow accurate rotation of
objects of odd-numbered width or height. */
/*
Function: gdImageCopyRotated
*/
/**
* Function: gdImageCopyRotated
*
* Copy a rotated area from an image to another image
*
* The area is counter-clockwise rotated using nearest-neighbor interpolation.
*
* Parameters:
* dst - The destination image.
* src - The source image.
* dstX - The x-coordinate of the center of the area to copy to.
* dstY - The y-coordinate of the center of the area to copy to.
* srcX - The x-coordinate of the upper left corner to copy from.
* srcY - The y-coordinate of the upper left corner to copy from.
* srcW - The width of the area to copy from.
* srcH - The height of the area to copy from.
* angle - The angle in degrees.
*
* See also:
* - <gdImageRotateInterpolated>
*/
BGD_DECLARE(void) gdImageCopyRotated (gdImagePtr dst,
gdImagePtr src,
double dstX, double dstY,
@ -3325,9 +3423,31 @@ BGD_DECLARE(void) gdImageCopyRotated (gdImagePtr dst,
#define floor2(exp) ((long) exp)
/*#define floor2(exp) floor(exp)*/
/*
Function: gdImageCopyResampled
*/
/**
* Function: gdImageCopyResampled
*
* Copy a resampled area from an image to another image
*
* If the source and destination area differ in size, the area will be resized
* using bilinear interpolation for truecolor images, and nearest-neighbor
* interpolation for palette images.
*
* Parameters:
* dst - The destination image.
* src - The source image.
* dstX - The x-coordinate of the upper left corner to copy to.
* dstY - The y-coordinate of the upper left corner to copy to.
* srcX - The x-coordinate of the upper left corner to copy from.
* srcY - The y-coordinate of the upper left corner to copy from.
* dstW - The width of the area to copy to.
* dstH - The height of the area to copy to.
* srcW - The width of the area to copy from.
* srcH - The height of the area to copy from.
*
* See also:
* - <gdImageCopyResized>
* - <gdImageScale>
*/
BGD_DECLARE(void) gdImageCopyResampled (gdImagePtr dst,
gdImagePtr src,
int dstX, int dstY,

View File

@ -308,8 +308,9 @@ enum gdPaletteQuantizationMethod {
* GD_LINEAR - bilinear interpolation
*
* See also:
* <gdSetInterpolationMethod>
**/
* - <gdImageSetInterpolationMethod>
* - <gdImageGetInterpolationMethod>
*/
typedef enum {
GD_DEFAULT = 0,
GD_BELL,

View File

@ -1604,9 +1604,26 @@ gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width,
return dst;
}
/*
Function: gdImageScale
*/
/**
* Function: gdImageScale
*
* Scale an image
*
* Creates a new image, scaled to the requested size using the current
* <gdInterpolationMethod>.
*
* Parameters:
* src - The source image.
* new_width - The new width.
* new_height - The new height.
*
* Returns:
* The scaled image on success, NULL on failure.
*
* See also:
* - <gdImageCopyResized>
* - <gdImageCopyResampled>
*/
BGD_DECLARE(gdImagePtr) gdImageScale(const gdImagePtr src, const unsigned int new_width, const unsigned int new_height)
{
gdImagePtr im_scaled = NULL;
@ -1779,9 +1796,26 @@ gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor)
return dst;
}
/*
Function: gdImageRotateInterpolated
*/
/**
* Function: gdImageRotateInterpolated
*
* Rotate an image
*
* Creates a new image, counter-clockwise rotated by the requested angle
* using the current <gdInterpolationMethod>. Non-square angles will add a
* border with bgcolor.
*
* Parameters:
* src - The source image.
* angle - The angle in degrees.
* bgcolor - The color to fill the added background with.
*
* Returns:
* The rotated image on success, NULL on failure.
*
* See also:
* - <gdImageCopyRotated>
*/
BGD_DECLARE(gdImagePtr) gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor)
{
/* round to two decimals and keep the 100x multiplication to use it in the common square angles
@ -1849,11 +1883,7 @@ BGD_DECLARE(gdImagePtr) gdImageRotateInterpolated(const gdImagePtr src, const fl
}
/**
* Title: Affine transformation
**/
/**
* Group: Transform
* Group: Affine Transformation
**/
static void gdImageClipRectangle(gdImagePtr im, gdRectPtr r)
@ -2110,9 +2140,26 @@ BGD_DECLARE(int) gdTransformAffineBoundingBox(gdRectPtr src, const double affine
return GD_TRUE;
}
/*
Function: gdImageSetInterpolationMethod
*/
/**
* Group: Interpolation Method
*/
/**
* Function: gdImageSetInterpolationMethod
*
* Set the interpolation method for subsequent operations
*
* Parameters:
* im - The image.
* id - The interpolation method.
*
* Returns:
* Non-zero on success, zero on failure.
*
* See also:
* - <gdInterpolationMethod>
* - <gdImageGetInterpolationMethod>
*/
BGD_DECLARE(int) gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMethod id)
{
if (im == NULL || (uintmax_t)id > GD_METHOD_COUNT) {
@ -2195,13 +2242,24 @@ BGD_DECLARE(int) gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMet
}
/*
Function: gdImageGetInterpolationMethod
Return the interpolation mode set in 'im'. This is here so that
the value can be read via a language or VM with an FFI but no
(portable) way to extract the value from the struct.
*/
/**
* Function: gdImageGetInterpolationMethod
*
* Get the current interpolation method
*
* This is here so that the value can be read via a language or VM with an FFI
* but no (portable) way to extract the value from the struct.
*
* Parameters:
* im - The image.
*
* Returns:
* The current interpolation method.
*
* See also:
* - <gdInterpolationMethod>
* - <gdImageSetInterpolationMethod>
*/
BGD_DECLARE(gdInterpolationMethod) gdImageGetInterpolationMethod(gdImagePtr im)
{
return im->interpolation_id;