From f0b30c6fa17d10cbeb5c09e4ed4d83fd6f20a619 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 21 Feb 2009 14:26:32 +0000 Subject: [PATCH] Properly handle alpha components in the convolution code. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3399 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/filter/convolution.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pipi/filter/convolution.c b/pipi/filter/convolution.c index 9657a70..b427e33 100644 --- a/pipi/filter/convolution.c +++ b/pipi/filter/convolution.c @@ -134,7 +134,7 @@ static pipi_image_t *T(conv)(pipi_image_t *src, int m, int n, double mat[]) { for(x = 0; x < w; x++) { - double R = 0., G = 0., B = 0.; + double R = 0., G = 0., B = 0., A = 0.; double Y = 0.; int x2, y2, off = 4 * (y * w + x); @@ -159,6 +159,7 @@ static pipi_image_t *T(conv)(pipi_image_t *src, int m, int n, double mat[]) R += f * srcdata[(y2 * w + x2) * 4]; G += f * srcdata[(y2 * w + x2) * 4 + 1]; B += f * srcdata[(y2 * w + x2) * 4 + 2]; + A += f * srcdata[(y2 * w + x2) * 4 + 3]; } } } @@ -170,6 +171,7 @@ static pipi_image_t *T(conv)(pipi_image_t *src, int m, int n, double mat[]) dstdata[off] = R < 0.0 ? 0.0 : R > 1.0 ? 1.0 : R; dstdata[off + 1] = G < 0.0 ? 0.0 : G > 1.0 ? 1.0 : G; dstdata[off + 2] = B < 0.0 ? 0.0 : B > 1.0 ? 1.0 : B; + dstdata[off + 3] = A < 0.0 ? 0.0 : A > 1.0 ? 1.0 : A; } } } @@ -204,7 +206,7 @@ static pipi_image_t *T(sepconv)(pipi_image_t *src, { for(x = 0; x < w; x++) { - double R = 0., G = 0., B = 0.; + double R = 0., G = 0., B = 0., A = 0.; double Y = 0.; int x2, off = 4 * (y * w + x); @@ -223,6 +225,7 @@ static pipi_image_t *T(sepconv)(pipi_image_t *src, R += f * srcdata[(y * w + x2) * 4]; G += f * srcdata[(y * w + x2) * 4 + 1]; B += f * srcdata[(y * w + x2) * 4 + 2]; + A += f * srcdata[(y * w + x2) * 4 + 3]; } } @@ -233,6 +236,7 @@ static pipi_image_t *T(sepconv)(pipi_image_t *src, buffer[off] = R; buffer[off + 1] = G; buffer[off + 2] = B; + buffer[off + 3] = A; } } } @@ -241,7 +245,7 @@ static pipi_image_t *T(sepconv)(pipi_image_t *src, { for(x = 0; x < w; x++) { - double R = 0., G = 0., B = 0.; + double R = 0., G = 0., B = 0., A = 0.; double Y = 0.; int y2, off = 4 * (y * w + x); @@ -260,6 +264,7 @@ static pipi_image_t *T(sepconv)(pipi_image_t *src, R += f * buffer[(y2 * w + x) * 4]; G += f * buffer[(y2 * w + x) * 4 + 1]; B += f * buffer[(y2 * w + x) * 4 + 2]; + A += f * buffer[(y2 * w + x) * 4 + 3]; } } @@ -270,6 +275,7 @@ static pipi_image_t *T(sepconv)(pipi_image_t *src, dstdata[off] = R < 0.0 ? 0.0 : R > 1.0 ? 1.0 : R; dstdata[off + 1] = G < 0.0 ? 0.0 : G > 1.0 ? 1.0 : G; dstdata[off + 2] = B < 0.0 ? 0.0 : B > 1.0 ? 1.0 : B; + dstdata[off + 3] = A < 0.0 ? 0.0 : A > 1.0 ? 1.0 : A; } } }