コード例 #1
0
        public override IImage Clone()
        {
            ImageInt32 img = new ImageInt32(this.Width, this.Height);

            img.CloneFrom(this);
            return(img);
        }
コード例 #2
0
ファイル: ImageU8.cs プロジェクト: zpc930/smartimage
        public unsafe ImageInt32 ToImageInt32()
        {
            ImageInt32 img32 = new ImageInt32(this.Width, this.Height);
            Byte *     start = this.Start;
            Byte *     end   = this.Start + this.Length;
            Int32 *    dst   = img32.Start;

            while (start != end)
            {
                *dst = *start;
                start++;
                dst++;
            }
            return(img32);
        }
コード例 #3
0
ファイル: ImageRgb24.cs プロジェクト: zpc930/smartimage
        public unsafe ImageInt32 ToGrayscaleImageInt32(double rCoeff, double gCoeff, double bCoeff)
        {
            ImageInt32 img = new ImageInt32(this.Width, this.Height);
            Rgb24 *    p   = Start;
            Int32 *    to  = img.Start;
            Rgb24 *    end = p + Length;

            if (Length < 1024)
            {
                while (p != end)
                {
                    *to = (Byte)(p->Red * rCoeff + p->Green * gCoeff + p->Blue * bCoeff);
                    p++;
                    to++;
                }
            }
            else
            {
                int *bCache = stackalloc int[256];
                int *gCache = stackalloc int[256];
                int *rCache = stackalloc int[256];

                const int shift  = 1 << 10;
                int       rShift = (int)(rCoeff * shift);
                int       gShift = (int)(gCoeff * shift);
                int       bShift = shift - rShift - gShift;

                int r = 0, g = 0, b = 0;
                for (int i = 0; i < 256; i++)
                {
                    bCache[i] = b;
                    gCache[i] = g;
                    rCache[i] = r;
                    b        += bShift;
                    g        += gShift;
                    r        += rShift;
                }

                while (p != end)
                {
                    *to = (Byte)((bCache[p->Red] + gCache[p->Green] + rCache[p->Red]) >> 10);
                    p++;
                    to++;
                }
            }
            return(img);
        }