mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Port "move pixelate filter to gd_filter.c" (sync with upstream) (GH-17361)
Cf. <0f0894a7dd>.
This commit is contained in:
committed by
GitHub
parent
025cc6f603
commit
a3ef48c265
@@ -233,7 +233,6 @@ if test "$PHP_GD" != "no"; then
|
||||
libgd/gd_io.c
|
||||
libgd/gd_jpeg.c
|
||||
libgd/gd_matrix.c
|
||||
libgd/gd_pixelate.c
|
||||
libgd/gd_png.c
|
||||
libgd/gd_rotate.c
|
||||
libgd/gd_security.c
|
||||
|
||||
@@ -57,7 +57,7 @@ if (PHP_GD != "no") {
|
||||
gdft.c gd_gd2.c gd_gd.c gd_gif_in.c gd_gif_out.c gdhelpers.c gd_io.c gd_io_dp.c \
|
||||
gd_io_file.c gd_io_ss.c gd_jpeg.c gdkanji.c gd_png.c gd_ss.c \
|
||||
gdtables.c gd_topal.c gd_wbmp.c gdxpm.c wbmp.c gd_xbm.c gd_security.c gd_transform.c \
|
||||
gd_filter.c gd_pixelate.c gd_rotate.c gd_color_match.c gd_webp.c gd_avif.c \
|
||||
gd_filter.c gd_rotate.c gd_color_match.c gd_webp.c gd_avif.c \
|
||||
gd_crop.c gd_interpolation.c gd_matrix.c gd_bmp.c gd_tga.c", "gd");
|
||||
AC_DEFINE('HAVE_GD_BUNDLED', 1, "Define to 1 if gd extension uses GD library bundled in PHP.");
|
||||
AC_DEFINE('HAVE_GD_PNG', 1, "Define to 1 if gd extension has PNG support.");
|
||||
|
||||
@@ -110,6 +110,62 @@ int gdImageScatterEx(gdImagePtr im, gdScatterPtr scatter)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
if (block_size <= 0) {
|
||||
return 0;
|
||||
} else if (block_size == 1) {
|
||||
return 1;
|
||||
}
|
||||
switch (mode) {
|
||||
case GD_PIXELATE_UPPERLEFT:
|
||||
for (y = 0; y < im->sy; y += block_size) {
|
||||
for (x = 0; x < im->sx; x += block_size) {
|
||||
if (gdImageBoundsSafe(im, x, y)) {
|
||||
int c = gdImageGetPixel(im, x, y);
|
||||
gdImageFilledRectangle(im, x, y, x + block_size - 1, y + block_size - 1, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GD_PIXELATE_AVERAGE:
|
||||
for (y = 0; y < im->sy; y += block_size) {
|
||||
for (x = 0; x < im->sx; x += block_size) {
|
||||
int a, r, g, b, c;
|
||||
int total;
|
||||
int cx, cy;
|
||||
|
||||
a = r = g = b = c = total = 0;
|
||||
/* sampling */
|
||||
for (cy = 0; cy < block_size; cy++) {
|
||||
for (cx = 0; cx < block_size; cx++) {
|
||||
if (!gdImageBoundsSafe(im, x + cx, y + cy)) {
|
||||
continue;
|
||||
}
|
||||
c = gdImageGetPixel(im, x + cx, y + cy);
|
||||
a += gdImageAlpha(im, c);
|
||||
r += gdImageRed(im, c);
|
||||
g += gdImageGreen(im, c);
|
||||
b += gdImageBlue(im, c);
|
||||
total++;
|
||||
}
|
||||
}
|
||||
/* drawing */
|
||||
if (total > 0) {
|
||||
c = gdImageColorResolveAlpha(im, r / total, g / total, b / total, a / total);
|
||||
gdImageFilledRectangle(im, x, y, x + block_size - 1, y + block_size - 1, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* invert src image */
|
||||
int gdImageNegate(gdImagePtr src)
|
||||
{
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
#include "gd.h"
|
||||
|
||||
int gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
if (block_size <= 0) {
|
||||
return 0;
|
||||
} else if (block_size == 1) {
|
||||
return 1;
|
||||
}
|
||||
switch (mode) {
|
||||
case GD_PIXELATE_UPPERLEFT:
|
||||
for (y = 0; y < im->sy; y += block_size) {
|
||||
for (x = 0; x < im->sx; x += block_size) {
|
||||
if (gdImageBoundsSafe(im, x, y)) {
|
||||
int c = gdImageGetPixel(im, x, y);
|
||||
gdImageFilledRectangle(im, x, y, x + block_size - 1, y + block_size - 1, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GD_PIXELATE_AVERAGE:
|
||||
for (y = 0; y < im->sy; y += block_size) {
|
||||
for (x = 0; x < im->sx; x += block_size) {
|
||||
int a, r, g, b, c;
|
||||
int total;
|
||||
int cx, cy;
|
||||
|
||||
a = r = g = b = c = total = 0;
|
||||
/* sampling */
|
||||
for (cy = 0; cy < block_size; cy++) {
|
||||
for (cx = 0; cx < block_size; cx++) {
|
||||
if (!gdImageBoundsSafe(im, x + cx, y + cy)) {
|
||||
continue;
|
||||
}
|
||||
c = gdImageGetPixel(im, x + cx, y + cy);
|
||||
a += gdImageAlpha(im, c);
|
||||
r += gdImageRed(im, c);
|
||||
g += gdImageGreen(im, c);
|
||||
b += gdImageBlue(im, c);
|
||||
total++;
|
||||
}
|
||||
}
|
||||
/* drawing */
|
||||
if (total > 0) {
|
||||
c = gdImageColorResolveAlpha(im, r / total, g / total, b / total, a / total);
|
||||
gdImageFilledRectangle(im, x, y, x + block_size - 1, y + block_size - 1, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user