Ejemplo n.º 1
0
        public static void rotateGeneral(ref byte[][] target, TrnsData data, byte[][] G, int hidx, int oldw, int oldh)
        {
            double radian    = data.Angle;
            var    newWidth  = target[0].Length;
            var    newHeight = target.Length;

            double cosRadian = Cos(radian);
            double sinRadian = Sin(radian);


            int centerX = oldw / 2;
            int centerY = oldh / 2;
            int diffX   = (newWidth - oldw) / 2;
            int diffY   = (newHeight - oldh) / 2;

            int isourceX, isourceY;

            int y, x;

            int h = G.Length;

            for (y = 0; y < target.Length; y++)
            {
                for (x = 0; x < target[0].Length; x++)
                {
                    var dx = x - (centerX + diffX);
                    var dy = y - (centerY + diffY);

                    var xres = dx * cosRadian - dy * sinRadian;
                    var yres = dx * sinRadian + dy * cosRadian;

                    var srcX = xres + centerX;
                    var srcY = yres - hidx * h + centerY;


                    isourceX = (int)Math.Round(srcX);
                    isourceY = (int)Math.Round(srcY);

                    try
                    {
                        if (isourceY < G.Length &&
                            isourceY >= 0 &&
                            isourceX < G[0].Length &&
                            isourceX >= 0)

                        {
                            target[y][x] = G[isourceY][isourceX];
                        }
                    }
                    catch (Exception es)
                    {
                        Console.WriteLine(es.ToString());
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// affine pos , w , h
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>

        //   정사각형만 가능
        #region  Transform
        public static void xytransform(ref byte[][] target, TrnsData data, byte[][] src, int hidx, int xmax, int ymax)
        {
            // 현재 소스의 크기는 맥스치로 되어있다.
            //맥스치의 w,h
            var h = src.GetLength(0);
            var w = src[0].GetLength(0);

            //확장 캔버스의 센터 위치
            var tcenterX = (int)xmax / 2;
            var tcenterY = (int)ymax / 2;

            var xshift = (int)(data.XSrcCnter - tcenterX);
            var yshift = (int)(data.YSrcCnter - tcenterY);

            //byte[,] R = new byte[target.GetLength(0),target.GetLength(1)];

            for (int j = 0; j < h; j++)
            {
                for (int i = 0; i < w; i++)
                {
                    if (i - xshift >= 0 &&
                        j - yshift >= 0 &&
                        i - xshift < target[0].Length &&
                        j - yshift < target.Length)
                    {
                        var yidx = (j - yshift + hidx).ToString();
                        var xidx = (i - xshift).ToString();

                        //var str = string.Format("y : {0}   x : {1} = {2}", yidx, xidx, src[j][i]);
                        //Console.WriteLine(str);
                        if (j - yshift + hidx * h < target.Length &&
                            i - xshift < target[0].Length)
                        {
                            target[j - yshift + hidx * h][i - xshift] = src[j][i];
                        }
                    }
                }
            }
            //return R;
        }
Ejemplo n.º 3
0
        public static void rotateGeneral2(ref byte[][] target, TrnsData data, byte[][] G, int hidx, int oldw, int oldh)
        {
            double radian = data.Angle;
            //double radian = 0.785398;
            var newWidth  = target[0].Length;
            var newHeight = target.Length;

            double cosRadian = Cos(radian);
            double sinRadian = Sin(radian);


            int centerX = oldw / 2;
            int centerY = oldh / 2;
            int diffX   = (newWidth - oldw) / 2;
            int diffY   = (newHeight - oldh) / 2;

            //byte[,] R = new byte[newHeight, newWidth];

            double sourceX, sourceY;
            int    isourceX, isourceY;
            int    isourceX2, isourceY2;
            double nw, ne, sw, se, p, q;

            int y, x;
            // -- OK

            int h = G.Length;


            for (y = 0; y < G.Length; y++)
            {
                for (x = 0; x < G[0].Length; x++)
                {
                    sourceX  = (x - centerX) * cosRadian + (y + hidx * h - centerY) * (sinRadian);
                    sourceX += (centerX + diffX);
                    sourceY  = (x - centerX) * -sinRadian + (y + hidx * h - centerY) * cosRadian;
                    sourceY += (centerY + diffY);
                    //  이부분은 ok

                    isourceX = (int)Math.Truncate(sourceX);
                    isourceY = (int)Math.Truncate(sourceY);

                    isourceX2 = (int)Math.Ceiling(sourceX);
                    isourceY2 = (int)Math.Ceiling(sourceY);

                    try
                    {
                        if (isourceY < target.Length &&
                            isourceX < target[0].Length &&
                            isourceY2 < target[0].Length &&
                            isourceX2 < target.Length)
                        {
                            target[isourceY][isourceX]   = G[y][x];
                            target[isourceY2][isourceX2] = G[y][x];
                            target[isourceY][isourceX2]  = G[y][x];
                            target[isourceY2][isourceX]  = G[y][x];
                        }
                    }
                    catch (Exception es)
                    {
                        Console.WriteLine(es.ToString());
                    }
                }
            }
            // return target;
        }