Permalink
Browse files

Reserved black and white

  • Loading branch information...
1 parent 24f6b15 commit 97313d912ec5c93ceae1ba58c48172d48618130a @pornel committed Sep 24, 2011
Showing with 5 additions and 1 deletion.
  1. +5 −1 posterize.c
View
@@ -86,7 +86,7 @@ void reduce(const int maxcolors, float histogram[], int palette[])
int nextval=0;
int lastval=0;
- palette[255]=255;
+ palette[255]=255; // 0 and 255 are always included
for(int val=0; val < 256; val++)
{
if (palette[val]==val) {
@@ -128,6 +128,10 @@ int main(int argc, char *argv[])
}
}
+ // reserve colors for black and white
+ if (histogram[0] && maxcolors>2) maxcolors--;
+ if (histogram[255] && maxcolors>2) maxcolors--;
+
int palette[256] = {0};
reduce(maxcolors, histogram, palette);

0 comments on commit 97313d9

Please sign in to comment.