summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/pixops
diff options
context:
space:
mode:
authorMatthias Clasen <maclas@gmx.de>2003-07-17 22:47:10 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2003-07-17 22:47:10 +0000
commitec28241e8c1e55c2b558c0816ed973a4dfeb2d3e (patch)
treee0ec521f2feb268a2a482a56135b82578041621a /gdk-pixbuf/pixops
parent8c44f09a172b8682f7d6bcf9b340987d6e024fcb (diff)
downloadgdk-pixbuf-ec28241e8c1e55c2b558c0816ed973a4dfeb2d3e.tar.gz
Split correction into multiple pieces if no single weight is large enough
2003-07-18 Matthias Clasen <maclas@gmx.de> * pixops/pixops.c (correct_total): Split correction into multiple pieces if no single weight is large enough to apply the unsplit correction. (#117431, problem reported by Tomas Ă–gren)
Diffstat (limited to 'gdk-pixbuf/pixops')
-rw-r--r--gdk-pixbuf/pixops/pixops.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/gdk-pixbuf/pixops/pixops.c b/gdk-pixbuf/pixops/pixops.c
index 04a429d29..548d48ee1 100644
--- a/gdk-pixbuf/pixops/pixops.c
+++ b/gdk-pixbuf/pixops/pixops.c
@@ -952,18 +952,21 @@ correct_total (int *weights,
double overall_alpha)
{
int correction = (int)(0.5 + 65536 * overall_alpha) - total;
-
+ int remaining, c, d, i;
+
if (correction != 0)
{
- int i;
- for (i = n_x * n_y - 1; i >= 0; i--)
- {
- if (*(weights + i) + correction >= 0)
- {
- *(weights + i) += correction;
- break;
- }
- }
+ remaining = correction;
+ for (d = 1, c = correction; c != 0 && remaining != 0; d++, c = correction / d)
+ for (i = n_x * n_y - 1; i >= 0 && c != 0 && remaining != 0; i--)
+ if (*(weights + i) + c >= 0)
+ {
+ *(weights + i) += c;
+ remaining -= c;
+ if ((0 < remaining && remaining < c) ||
+ (0 > remaining && remaining > c))
+ c = remaining;
+ }
}
}