Пример #1
0
        public BicubicInterpolatedImage(Gdi::Bitmap bmp)
        {
            this.bmp    = bmp;
            this.width  = bmp.Width;
            this.height = bmp.Height;

            Gdi::Rectangle rect = new Gdi::Rectangle(Gdi::Point.Empty, bmp.Size);

            this.data = bmp.LockBits(rect, Gdi::Imaging.ImageLockMode.ReadOnly, Gdi::Imaging.PixelFormat.Format24bppRgb);

            this.p0     = (byte *)this.data.Scan0;
            this.stride = this.data.Stride;
        }
Пример #2
0
        public static void WriteToPbm(string input, string output)
        {
            Gdi::Bitmap image = new Gdi::Bitmap(input);
            int         w     = image.Width;
            int         h     = image.Height;

            Gdi::Imaging.BitmapData data = image.LockBits(
                new Gdi::Rectangle(Gdi::Point.Empty, image.Size),
                Gdi::Imaging.ImageLockMode.ReadOnly,
                Gdi::Imaging.PixelFormat.Format24bppRgb);

            System.IO.Stream       str = System.IO.File.OpenWrite(output);
            System.IO.StreamWriter sw  = new System.IO.StreamWriter(str, System.Text.Encoding.ASCII);
            sw.WriteLine("P1");
            sw.WriteLine("{0} {1}", w, h);
            unsafe {
                int i = 0;
                for (int y = 0; y < h; y++)
                {
                    RGB *ppx  = (RGB *)((byte *)data.Scan0 + data.Stride * y);
                    RGB *ppxM = ppx + w;
                    while (ppx < ppxM)
                    {
                        sw.Write((ppx++)->Intensity() > 0x80?"0":"1");
                        if (++i % 64 == 0)
                        {
                            sw.WriteLine();
                        }
                        else
                        {
                            sw.Write(" ");
                        }
                    }
                }
            }
            sw.Close();
            str.Close();

            image.UnlockBits(data);
            image.Dispose();
        }
Пример #3
0
 private static void ImageEnlight(Gdi::Bitmap bmp)
 {
     // 色を薄くする -> これは GetImage の方に追加するべきではないか
     Gdi::Imaging.BitmapData data = bmp.LockBits(
         new Gdi::Rectangle(Gdi::Point.Empty, bmp.Size),
         Gdi::Imaging.ImageLockMode.ReadWrite,
         Gdi::Imaging.PixelFormat.Format24bppRgb
         );
     for (int y = 0; y < bmp.Height; y++)
     {
         unsafe {
             byte *p  = (byte *)data.Scan0 + data.Stride * y;
             byte *pM = p + bmp.Width * 3;
             for (; p < pM; p++)
             {
                 *p += (byte)((255 - *p) / 3 * 2);
                 //*p/=5;
             }
         }
     }
     bmp.UnlockBits(data);
 }
Пример #4
0
        public unsafe static Gdi::Bitmap Transform(
            Gdi::Bitmap src, int width, int height,
            Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4,
            Vector2 q1, Vector2 q2, Vector2 q3, Vector2 q4
            )
        {
            Gdi::Bitmap    dst     = new Gdi::Bitmap(width, height);
            Gdi::Rectangle dstRect = new Gdi::Rectangle(Gdi::Point.Empty, dst.Size);

            Gdi::Imaging.BitmapData dstData = dst.LockBits(dstRect, Gdi::Imaging.ImageLockMode.WriteOnly, Gdi::Imaging.PixelFormat.Format32bppRgb);
            byte *pdst   = (byte *)dstData.Scan0;
            int   stride = dstData.Stride;

            double[] x_st_table1 = new double[width];
            double[] x_st_table2 = new double[width];
            double[] y_st_table1 = new double[height];
            double[] y_st_table2 = new double[height];
            new BezierArcMeasure(p1, p2, q1).InitializeTable(x_st_table1);
            new BezierArcMeasure(p4, p3, q3).InitializeTable(x_st_table2);
            new BezierArcMeasure(p1, p4, q4).InitializeTable(y_st_table1);
            new BezierArcMeasure(p2, p3, q2).InitializeTable(y_st_table2);

            BezierLine p12 = new BezierLine(p1, p2, q1);
            BezierLine p43 = new BezierLine(p4, p3, q3);
            BezierLine p14 = new BezierLine(p1, p4, q4);
            BezierLine p23 = new BezierLine(p2, p3, q2);

            using (BicubicInterpolatedImage srcImage = new BicubicInterpolatedImage(src)){
                for (int ix = 0; ix < width; ix++)
                {
                    double xt1 = x_st_table1[ix];
                    double xt2 = x_st_table2[ix];
                    double dxt = xt2 - xt1;
                    for (int iy = 0; iy < height; iy++)
                    {
                        double yt1 = y_st_table1[iy];
                        double yt2 = y_st_table2[iy];
                        double dyt = yt2 - yt1;
                        double xt  = (xt1 + yt1 * dxt) / (1 - dxt * dyt);
                        double yt  = (yt1 + xt1 * dyt) / (1 - dxt * dyt);

                        // linear interpolation
                        Vector2 pl
                            = (1 - xt1) * (1 - yt1) * p1
                              + xt1 * (1 - yt2) * p2
                              + xt2 * yt2 * p3
                              + (1 - xt2) * yt1 * p4;

                        // bezier interpolation
                        Vector2 pBx = p43.GetPoint(xt2) * yt + p12.GetPoint(xt1) * (1 - yt);
                        Vector2 pBy = p23.GetPoint(yt2) * xt + p14.GetPoint(yt1) * (1 - xt);

                        Vector2 p = pBx + pBy - pl;
                        *(int *)(pdst + 4 * ix + stride * iy) = srcImage.Get(p.x, p.y);
                    }
                }
            }

            dst.UnlockBits(dstData);
            return(dst);
        }