Example #1
0
static enum out_color_mode
guessIndexed(struct FlattenSpec *spec,rgba *allPixels[])
{
  if( allPixels == NULL ) {
    if (spec->gimpish_indexed && colormapLength ) {
      unsigned i ;
      init_palette_hash();
      for( i=0; i<colormapLength; i++ )
        lookup_or_intern(NEWALPHA(colormap[i],255));
      if( lookup_or_intern( FULLALPHA(spec->default_pixel) ?
                            spec->default_pixel : 0 ) >= 0 )
        return COLOR_INDEXED ;
    }
  } else {
    init_palette_hash() ;
    if( palettify_rows(allPixels,spec->dim.width,spec->dim.height) ) {
      /* Might grayscale sometimes be preferred? No, that is what
       * -g is for! */
      return COLOR_INDEXED ;
    }
  }
  return COLOR_BY_CONTENTS ;
}
Example #2
0
int
palettify_row(rgba *row,unsigned ncols)
{
  index_t *newrow = (index_t*)row ;
  assert(sizeof(index_t) <= sizeof(rgba));
  unsigned i ;
  for( i=0; i<ncols; i++ ) {
    int j = lookup_or_intern(row[i]) ;
    if( j < 0 ) {
      unpalettify_row(row,i);
      return 0 ;
    }
    newrow[i] = j ;
  }
  return 1 ;
}