Esempio n. 1
0
 /// <summary>
 /// creates an exact palette based on the colors in the array
 /// </summary>
 public void MakePalette(ColorBgra[] value)
 {
     if (value == null || value.Length != _maxcolors)
     {
         throw new ArgumentException("invalid", "value");
     }
     _octree = Octree.FromColorArray(value);
 }
Esempio n. 2
0
 /// <summary>
 /// constructs a indexed icon image from a stream,
 /// not accessible outside the dll
 /// </summary>
 internal IconImageIndexed(Stream str, Size sz, short bpp)
 {
     using (SimpleReader rdr = new SimpleReader(str))
     {
         #region read palette
         int         colorcount = Quantizer.LengthOfPalette(bpp);
         ColorBgra[] palette    = new ColorBgra[colorcount];
         for (int i = 0; i < palette.Length; i++)
         {
             palette[i].A = 255;
             palette[i].B = rdr.ReadByte();
             palette[i].G = rdr.ReadByte();
             palette[i].R = rdr.ReadByte();
             rdr.ReadByte();                    //reserved
         }
         _octree = Octree.FromColorArray(palette);
         #endregion
         #region read indexed data
         //create bitmap and lock it
         _bitmap = new Bitmap(sz.Width, sz.Height, PixelFormat.Format32bppArgb);
         BitmapData bd = _bitmap.LockBits(
             new Rectangle(Point.Empty, _bitmap.Size),
             ImageLockMode.ReadOnly,
             PixelFormat.Format32bppArgb);
         ColorBgra *scan0 = (ColorBgra *)bd.Scan0;
         //read pixels
         int indexmask = (1 << bpp) - 1;
         scan0 += bd.Width * bd.Height;
         for (int y = 0; y < bd.Height; y++)
         {
             scan0 -= bd.Width;
             int indexpos = 8 - bpp,
                 data     = rdr.ReadInt32();
             for (int x = 0; x < bd.Width; x++)
             {
                 if (indexpos >= 32)
                 {
                     data      = rdr.ReadInt32();
                     indexpos -= 32;
                 }
                 scan0[x] = palette[indexmask & (data >> indexpos)];
                 if (indexpos % 8 == 0)
                 {
                     indexpos += 16 - bpp;
                 }
                 else
                 {
                     indexpos -= bpp;
                 }
             }
         }
         ANDMap.StampToBitmapData(rdr, bd);
         _bitmap.UnlockBits(bd);
         #endregion
     }
     _bitsperpixel = bpp;
 }