Skip to content

Commit

Permalink
Reserved black and white
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Sep 24, 2011
1 parent 24f6b15 commit 97313d9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion posterize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 97313d9

Please sign in to comment.