bool ReadPalette( PngChunkPLTE _palette )
    {
        int[] rgb = new int[ 4 ];
        int c;
        for( c=0; c<m_coloursInPalette; c++ )
        {
            int c2 = c;
            if( m_config.m_colorRemapSourceToDest.ContainsKey( c ))
                c2 = m_config.m_colorRemapSourceToDest[ c ];

            _palette.GetEntryRgb( c2, rgb );
            float fr = ((float)rgb[ 0 ]) / 255.0f;
            float fg = ((float)rgb[ 1 ]) / 255.0f;
            float fb = ((float)rgb[ 2 ]) / 255.0f;
            //float fa = ((float)a) / 255.0f;
            float fa = 1.0f;

            /*
            if((c%16) == 0 )
                fa = 0.0f;
            else
                fa = 1.0f;
                */

            Color col = new Color( fr, fg, fb, fa );
            m_palette.Add( col );
            m_colorUsed.Add( false );
        }

        while( c < 16 )
        {
            m_palette.Add( new Color( 1.0f, 0.0f, 1.0f, 1.0f ));
            m_colorUsed.Add( false );
            c++;
        }

        return true;
    }
Exemple #2
0
 public static int[] Palette2rgb( ImageLine line, PngChunkPLTE pal, PngChunkTRNS trns, int [] buf )
 {
     bool isalpha = trns != null;
     int channels = isalpha ? 4 : 3;
     int nsamples = line.ImgInfo.Cols * channels;
     if ( buf == null || buf.Length < nsamples )
         buf = new int [ nsamples ];
     if ( !line.SamplesUnpacked )
         line = line.unpackToNewImageLine ();
     bool isbyte = line.SampleType == Hjg.Pngcs.ImageLine.ESampleType.BYTE;
     int nindexesWithAlpha = trns != null ? trns.GetPalletteAlpha ().Length : 0;
     for ( int c = 0; c < line.ImgInfo.Cols; c++ )
     {
         int index = isbyte ? ( line.ScanlineB [ c ] & 0xFF ) : line.Scanline [ c ];
         pal.GetEntryRgb ( index, buf, c * channels );
         if ( isalpha )
         {
             int alpha = index < nindexesWithAlpha ? trns.GetPalletteAlpha () [ index ] : 255;
             buf [ c * channels + 3 ] = alpha;
         }
     }
     return buf;
 }