From bcd98991017f85aff90aee36451970d59edcb95d Mon Sep 17 00:00:00 2001 From: Seth Burgess Date: Sun, 19 Mar 2000 01:47:15 +0000 Subject: [PATCH] Added alpha support to Color To Alpha (allows repeated use) --- ChangeLog | 6 ++++++ plug-ins/common/colortoalpha.c | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 97a9b1630f..ebd4be2127 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2000-03-18 Seth Burgess + + * plug-ins/common/colortoalpha.c: Fixed handling of previously + existing alpha, so it can be run successively now (much more + useful) + 2000-03-18 * pixmaps/linked.xpm: another icon for the L&C&P dialog.. to be diff --git a/plug-ins/common/colortoalpha.c b/plug-ins/common/colortoalpha.c index 05dd49b7d5..31cf654113 100644 --- a/plug-ins/common/colortoalpha.c +++ b/plug-ins/common/colortoalpha.c @@ -212,8 +212,10 @@ colortoalpha (float *a1, float c2, float c3) { - float alpha1, alpha2, alpha3; - + float alpha1, alpha2, alpha3, alpha4; + + alpha4 = *a4; + if ( *a1 > c1 ) alpha1 = (*a1 - c1)/(255.0-c1); else if ( *a1 < c1 ) @@ -250,13 +252,16 @@ colortoalpha (float *a1, { *a4 = alpha3; } + *a4 *= 255.0; + if ( *a4 < 1.0 ) return; *a1 = 255.0 * (*a1-c1)/ *a4 + c1; *a2 = 255.0 * (*a2-c2)/ *a4 + c2; *a3 = 255.0 * (*a3-c3)/ *a4 + c3; + *a4 *= alpha4/255.0; } /* so if a1 > c1, a2 > c2, and a3 > c2 and a1 - c1 > a2-c2, a3-c3, then a1 = b1 * alpha + c1 * (1-alpha) So, maximizing alpha without taking b1 above 1 gives a1 = alpha + c1(1-alpha) and therefore alpha = (a1-c1)/(1-c1).