Skip to content

Commit

Permalink
Dropped premultiplied alpha rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Sep 9, 2012
1 parent 89d57f0 commit 555a9fe
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions posterize.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,6 @@ static void remap(read_info img, const palette *pal, bool dither)
}
}

// usually RGBA images are stored/rendered in "premultiplied" format which is R*A, G*A, B*A
// this causes loss of precision, so it may be a good idea to posterize to this value anyway
inline static unsigned int premultiplied_alpha_rounding(const unsigned int value, const unsigned int alpha)
{
return value * alpha / alpha;
}

// it doesn't count unique colors, only intensity values of all channels
static void intensity_histogram(const read_info img, double histogram[])
{
Expand All @@ -235,9 +228,9 @@ static void intensity_histogram(const read_info img, double histogram[])
// opaque colors get more weight
const double weight = alpha/255.0;

histogram[premultiplied_alpha_rounding(row[x], alpha)] += weight;
histogram[premultiplied_alpha_rounding(row[x+1], alpha)] += weight;
histogram[premultiplied_alpha_rounding(row[x+2], alpha)] += weight;
histogram[row[x]] += weight;
histogram[row[x+1]] += weight;
histogram[row[x+2]] += weight;
histogram[row[x+3]] += 1.0;
}
else histogram[0] += 4.0;
Expand Down

0 comments on commit 555a9fe

Please sign in to comment.