Exemplo n.º 1
0
 static Bitmap GetImageFromPixel(byte[] pixel, Color32[] colorTable, bool interlactFlag, int iw, int ih)
 {
     Bitmap img = new Bitmap(iw, ih);
     BitmapData bmpData = img.LockBits(new Rectangle(0, 0, iw, ih), ImageLockMode.ReadWrite, img.PixelFormat);
     unsafe
     {
         Color32* p = (Color32*)bmpData.Scan0.ToPointer();
         Color32* tempPointer = p;
         int offSet = 0;
         if (interlactFlag)
         {
             #region ��֯�洢ģʽ
             int i = 0;
             int pass = 0;//��ǰͨ��
             while (pass < 4)
             {
                 //�ܹ���4��ͨ��
                 if (pass == 1)
                 {
                     p = tempPointer;
                     p += (4 * iw );
                     offSet += 4 * iw;
                 }
                 else if (pass == 2)
                 {
                     p = tempPointer;
                     p += (2 * iw );
                     offSet += 2 * iw;
                 }
                 else if (pass == 3)
                 {
                     p = tempPointer;
                     p += (1 * iw);
                     offSet += 1 * iw;
                 }
                 int rate = 2;
                 if (pass == 0 | pass == 1)
                 {
                     rate = 8;
                 }
                 else if (pass == 2)
                 {
                     rate = 4;
                 }
                 while (i < pixel.Length)
                 {
                     *p++ = colorTable[pixel[i++]];
                     offSet++;
                     if (i % (iw) == 0)
                     {
                         p += (iw * (rate - 1));
                         offSet += (iw * (rate - 1));
                         if ( offSet  >= pixel.Length)
                         {
                             pass++;
                             offSet = 0;
                             break;
                         }
                     }
                 }
             }
             #endregion
         }
         else
         {
             int i = 0;
             for (i = 0; i < pixel.Length; )
             {
                 *p++ = colorTable[pixel[i++]];
             }
         }
     }
     img.UnlockBits(bmpData);
     return img;
 }
Exemplo n.º 2
0
 internal void AddColor(Color32* pixel, int level,OcTree tree)
 {
     //�������Ҷ�ˣ���ʾһ����ɫ����������
     if (this.Leaf)
     {
         Increment(pixel);
         tree.TracePrevious(this);
         return;
     }
     int shift = 7 - level;
     int index = ((pixel->Red & mask[level]) >> (shift - 2)) |
                   ((pixel->Green & mask[level]) >> (shift - 1)) |
                   ((pixel->Blue & mask[level]) >> (shift));
     OcTreeNode child = Children[index];
     if (child == null)
     {
         child = new OcTreeNode(ColorDepth, level+1, tree);
         Children[index] = child;
     }
     child.AddColor(pixel, ++level,tree);
 }
Exemplo n.º 3
0
 internal void GetPalltte( List<Color32> palltte)
 {
     if (Leaf)
     {
         paletteIndex++;
         //����ﵽ��Ҷ�ӣ��������ɫ����
         Color32 color = new Color32();
         color.Alpha = 255;
         color.Red = (byte)(Red / PixelCount);
         color.Green = (byte)(Green / PixelCount);
         color.Blue = (byte)(Blue / PixelCount);
         palltte.Add(color);
     }
     else
     {
         for (int i = 0; i < ColorDepth; i++)
         {
             if (Children[i] != null)
             {
                 Children[i].GetPalltte(palltte);
             }
         }
     }
 }
Exemplo n.º 4
0
 internal void Increment(Color32* pixel)
 {
     Red += pixel->Red;
     Green += pixel->Green;
     Blue += pixel->Blue;
     PixelCount++;
 }
Exemplo n.º 5
0
 internal int GetPaletteIndex(Color32* pixel,int level)
 {
     int pindex = paletteIndex;
     if (!Leaf)
     {
         int shift = 7 - level;
         int index = ((pixel->Red & mask[level]) >> (shift - 2)) |
                       ((pixel->Green & mask[level]) >> (shift - 1)) |
                       ((pixel->Blue & mask[level]) >> (shift));
         OcTreeNode child = Children[index];
         if (child != null)
         {
             child.GetPaletteIndex(pixel, level + 1);
         }
         else
             throw new Exception("����Ԥ�ϵ����鷢����!");
     }
     return pindex;
 }