public static int[] Palette2rgb(ImageLine line, PngChunkPLTE pal, PngChunkTRNS trns, int[] buf)
        {
            bool flag = trns != null;
            int  num  = flag ? 4 : 3;
            int  num2 = line.ImgInfo.Cols * num;

            if (buf == null || buf.Length < num2)
            {
                buf = new int[num2];
            }
            if (!line.SamplesUnpacked)
            {
                line = line.unpackToNewImageLine();
            }
            bool flag2 = line.SampleType == ImageLine.ESampleType.BYTE;
            int  num3  = (trns != null) ? trns.GetPalletteAlpha().Length : 0;

            for (int i = 0; i < line.ImgInfo.Cols; i++)
            {
                int num4 = flag2 ? (line.ScanlineB[i] & 0xFF) : line.Scanline[i];
                pal.GetEntryRgb(num4, buf, i * num);
                if (flag)
                {
                    int num5 = buf[i * num + 3] = ((num4 < num3) ? trns.GetPalletteAlpha()[num4] : 255);
                }
            }
            return(buf);
        }
Example #2
0
        /// <summary>
        /// Given an indexed line with a palette, unpacks as a RGB array
        /// </summary>
        /// <param name="line">ImageLine as returned from PngReader</param>
        /// <param name="pal">Palette chunk</param>
        /// <param name="trns">TRNS chunk (optional)</param>
        /// <param name="buf">Preallocated array, optional</param>
        /// <returns>R G B (one byte per sample)</returns>
        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);
        }
Example #3
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;
 }