コード例 #1
0
 /// <summary>
 /// Finds the mask.
 /// </summary>
 /// <param name="mask">The mask.</param>
 /// <returns></returns>
 private static int FindMask(int mask)
 {
     for (int i = 0; i < 0x20; i++)
     {
         if ((mask & 1) == 1)
         {
             return(mask);
         }
         mask = Image.USR(mask, 1);
     }
     return(mask);
 }
コード例 #2
0
        /// <summary>
        /// Finds the shift.
        /// </summary>
        /// <param name="mask">The mask.</param>
        /// <returns></returns>
        private static int FindShift(int mask)
        {
            int num = 0;

            while (num < 0x20)
            {
                if ((mask & 1) == 1)
                {
                    return(num);
                }
                mask = Image.USR(mask, 1);
                num++;
            }
            return(num);
        }
コード例 #3
0
ファイル: PngImage.cs プロジェクト: Daoting/dt
        /// <summary>
        /// Gets the pixel.
        /// </summary>
        /// <param name="curr">The curr.</param>
        /// <returns></returns>
        private int[] GetPixel(byte[] curr)
        {
            switch (this.bitDepth)
            {
            case 8:
            {
                int[] numArray = new int[curr.Length];
                for (int j = 0; j < numArray.Length; j++)
                {
                    numArray[j] = curr[j] & 0xff;
                }
                return(numArray);
            }

            case 0x10:
            {
                int[] numArray2 = new int[curr.Length / 2];
                for (int k = 0; k < numArray2.Length; k++)
                {
                    numArray2[k] = ((curr[k * 2] & 0xff) << 8) + (curr[(k * 2) + 1] & 0xff);
                }
                return(numArray2);
            }
            }
            int[] numArray3 = new int[(curr.Length * 8) / this.bitDepth];
            int   num3      = 0;
            int   num4      = 8 / this.bitDepth;
            int   num5      = (((int)1) << this.bitDepth) - 1;

            for (int i = 0; i < curr.Length; i++)
            {
                for (int m = num4 - 1; m >= 0; m--)
                {
                    numArray3[num3++] = Image.USR(curr[i], this.bitDepth * m) & num5;
                }
            }
            return(numArray3);
        }
コード例 #4
0
ファイル: PngImage.cs プロジェクト: Daoting/dt
        /// <summary>
        /// Processes the pixels.
        /// </summary>
        /// <param name="curr">The curr.</param>
        /// <param name="xOffset">The x offset.</param>
        /// <param name="step">The step.</param>
        /// <param name="y">The y.</param>
        /// <param name="w">The w.</param>
        private void ProcessPixels(byte[] curr, int xOffset, int step, int y, int w)
        {
            int num;
            int num2;

            int[] pixel = this.GetPixel(curr);
            int   size  = 0;

            switch (this.colorType)
            {
            case 0:
            case 3:
            case 4:
                size = 1;
                break;

            case 2:
            case 6:
                size = 3;
                break;
            }
            if (this.image != null)
            {
                num2 = xOffset;
                int bytesPerRow = (((size * this.width) * ((this.bitDepth == 0x10) ? 8 : this.bitDepth)) + 7) / 8;
                for (num = 0; num < w; num++)
                {
                    SetPixel(this.image, pixel, this.inputBands * num, size, num2, y, this.bitDepth, bytesPerRow);
                    num2 += step;
                }
            }
            if (this.palShades)
            {
                if ((this.colorType & 4) != 0)
                {
                    if (this.bitDepth == 0x10)
                    {
                        for (int i = 0; i < w; i++)
                        {
                            int index = (i * this.inputBands) + size;
                            pixel[index] = Image.USR(pixel[index], 8);
                        }
                    }
                    int width = this.width;
                    num2 = xOffset;
                    for (num = 0; num < w; num++)
                    {
                        SetPixel(this.smask, pixel, (this.inputBands * num) + size, 1, num2, y, 8, width);
                        num2 += step;
                    }
                }
                else
                {
                    int   num8 = this.width;
                    int[] data = new int[1];
                    num2 = xOffset;
                    for (num = 0; num < w; num++)
                    {
                        int num9 = pixel[num];
                        if (num9 < this.trans.Length)
                        {
                            data[0] = this.trans[num9];
                        }
                        SetPixel(this.smask, data, 0, 1, num2, y, 8, num8);
                        num2 += step;
                    }
                }
            }
            else if (this.genBWMask)
            {
                switch (this.colorType)
                {
                case 0:
                {
                    int   num12     = (this.width + 7) / 8;
                    int[] numArray4 = new int[1];
                    num2 = xOffset;
                    num  = 0;
                    while (num < w)
                    {
                        int num13 = pixel[num];
                        numArray4[0] = (num13 == this.transRedGray) ? 1 : 0;
                        SetPixel(this.smask, numArray4, 0, 1, num2, y, 1, num12);
                        num2 += step;
                        num++;
                    }
                    return;
                }

                case 1:
                    break;

                case 2:
                {
                    int   num14     = (this.width + 7) / 8;
                    int[] numArray5 = new int[1];
                    num2 = xOffset;
                    num  = 0;
                    while (num < w)
                    {
                        int num15 = this.inputBands * num;
                        numArray5[0] = (((pixel[num15] == this.transRedGray) && (pixel[num15 + 1] == this.transGreen)) && (pixel[num15 + 2] == this.transBlue)) ? 1 : 0;
                        SetPixel(this.smask, numArray5, 0, 1, num2, y, 1, num14);
                        num2 += step;
                        num++;
                    }
                    break;
                }

                case 3:
                {
                    int   num10     = (this.width + 7) / 8;
                    int[] numArray3 = new int[1];
                    num2 = xOffset;
                    for (num = 0; num < w; num++)
                    {
                        int num11 = pixel[num];
                        if (num11 < this.trans.Length)
                        {
                            numArray3[0] = (this.trans[num11] == 0) ? 1 : 0;
                        }
                        SetPixel(this.smask, numArray3, 0, 1, num2, y, 1, num10);
                        num2 += step;
                    }
                    return;
                }

                default:
                    return;
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Read1632s the bit.
        /// </summary>
        /// <param name="is32">if set to <c>true</c> [is32].</param>
        /// <returns></returns>
        private Image Read1632Bit(bool is32)
        {
            int num14;
            int num  = FindMask(this.redMask);
            int num2 = FindShift(this.redMask);
            int num3 = num + 1;
            int num4 = FindMask(this.greenMask);
            int num5 = FindShift(this.greenMask);
            int num6 = num4 + 1;
            int num7 = FindMask(this.blueMask);
            int num8 = FindShift(this.blueMask);
            int num9 = num7 + 1;

            byte[] data  = new byte[(this.width * this.height) * 3];
            int    num10 = 0;

            if (!is32)
            {
                int num11 = this.width * 0x10;
                if ((num11 % 0x20) != 0)
                {
                    num10 = (((num11 / 0x20) + 1) * 0x20) - num11;
                    num10 = (int)Math.Ceiling((double)(((double)num10) / 8.0));
                }
            }
            if (((int)this.imageSize) == 0)
            {
                int num12 = (int)(this.bitmapFileSize - this.bitmapOffset);
            }
            int num13 = 0;

            if (this.isBottomUp)
            {
                for (int i = this.height - 1; i >= 0; i--)
                {
                    num13 = (this.width * 3) * i;
                    for (int j = 0; j < this.width; j++)
                    {
                        if (is32)
                        {
                            num14 = (int)ReadDWord(this.inputStream);
                        }
                        else
                        {
                            num14 = ReadWord(this.inputStream);
                        }
                        data[num13++] = (byte)(((Image.USR(num14, num2) & num) * 0x100) / num3);
                        data[num13++] = (byte)(((Image.USR(num14, num5) & num4) * 0x100) / num6);
                        data[num13++] = (byte)(((Image.USR(num14, num8) & num7) * 0x100) / num9);
                    }
                    for (int k = 0; k < num10; k++)
                    {
                        this.inputStream.ReadByte();
                    }
                }
            }
            else
            {
                for (int m = 0; m < this.height; m++)
                {
                    for (int n = 0; n < this.width; n++)
                    {
                        if (is32)
                        {
                            num14 = (int)ReadDWord(this.inputStream);
                        }
                        else
                        {
                            num14 = ReadWord(this.inputStream);
                        }
                        data[num13++] = (byte)(((Image.USR(num14, num2) & num) * 0x100) / num3);
                        data[num13++] = (byte)(((Image.USR(num14, num5) & num4) * 0x100) / num6);
                        data[num13++] = (byte)(((Image.USR(num14, num8) & num7) * 0x100) / num9);
                    }
                    for (int num20 = 0; num20 < num10; num20++)
                    {
                        this.inputStream.ReadByte();
                    }
                }
            }
            return(new RawImage(this.width, this.height, 3, 8, data));
        }