Changeset 2873


Ignore:
Timestamp:
10/05/08 22:31:11 (5 years ago)
Author:
sam
Message:

ThePimp?: we can now open and display files.

Location:
libpipi/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/ThePimp/MainWindow.cs

    r2872 r2873  
    2424        Build (); 
    2525        Title += " v" + Libpipi.getVersion(); 
    26  
    27         notebook1.Add(new PictureView(new Pipi.Picture("random:1024x1024"))); 
    28         //scrolledwindow1.Add(new PictureView(new Pipi.Picture("random:1024x1024"))); 
    2926    } 
    3027 
     
    4239        if(p != null) 
    4340        { 
    44             Title += " image " + p.Width + "x" + p.Height; 
    45             notebook1.RemovePage(0); 
    46             notebook1.AppendPage(new PictureView(p), null); 
     41            while(notebook1.NPages > 0) 
     42                notebook1.RemovePage(0); 
     43            int n = notebook1.AppendPage(new PictureView(p), 
     44                                         new Label(p.FileName)); 
     45            notebook1.Page = n; 
    4746        } 
    4847    } 
  • libpipi/trunk/ThePimp/PictureView.cs

    r2872 r2873  
    3838        { 
    3939            bool ret = base.OnExposeEvent(e); 
    40             //Console.WriteLine("expose {0}x{1}+{2}+{3}", e.Area.Width, e.Area.Height, e.Area.X, e.Area.Y); 
    41             GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 40 - (int)_hadj.Value, 40 - (int)_vadj.Value, _l); 
    42             GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 560 - (int)_hadj.Value, 40 - (int)_vadj.Value, _l); 
    43             GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 40 - (int)_hadj.Value, 560 - (int)_vadj.Value, _l); 
    44             GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 560 - (int)_hadj.Value, 560 - (int)_vadj.Value, _l); 
     40 
     41            using (Gdk.GC gc = new Gdk.GC(GdkWindow)) 
     42            { 
     43                int w = e.Area.Width; 
     44                int h = e.Area.Height; 
     45                int x = (int)_hadj.Value + e.Area.X; 
     46                int y = (int)_vadj.Value + e.Area.Y; 
     47                if(x + w > _p.Width) 
     48                    w = _p.Width - x < 0 ? 0 : _p.Width - x; 
     49                if(y + h > _p.Height) 
     50                    h = _p.Height - y < 0 ? 0 : _p.Height - y; 
     51 
     52                byte[] a = _p.GetPixels(w, h, x, y); 
     53                GdkWindow.DrawRgb32Image(gc, e.Area.X, e.Area.Y, w, h, 
     54                                         0 /* no dithering */, a, w * 4); 
     55            } 
     56 
    4557            return ret; 
    4658        } 
     
    4860        protected override void OnRealized() 
    4961        { 
    50             _l = new Pango.Layout(PangoContext); 
    51             _l.Wrap = Pango.WrapMode.Word; 
    52             _l.FontDescription = Pango.FontDescription.FromString("Tahoma 64"); 
    53             _l.SetMarkup("WHAT THE\nFUCK IS\nTHIS SHIT\nLOL ♥ ♥"); 
    5462            base.OnRealized(); 
    5563        } 
  • libpipi/trunk/pipi-sharp/Picture.cs

    r2872 r2873  
    2323        private IntPtr _picture; 
    2424 
     25        public readonly string FileName; 
     26 
    2527        [DllImport("libpipi.dll", CallingConvention=CallingConvention.Cdecl), 
    2628         SuppressUnmanagedCodeSecurity] 
     
    2931        { 
    3032            _picture = pipi_load(s); 
     33            FileName = s; 
    3134        } 
    3235 
     
    6265            get { return pipi_get_image_height(_picture); } 
    6366        } 
     67 
     68        [StructLayout(LayoutKind.Sequential)] 
     69        public struct PixelsStruct 
     70        { 
     71            public IntPtr pixels; 
     72            public Int32 w, h, pitch, bpp; 
     73            public Int64 bytes; 
     74        } 
     75 
     76        [DllImport("libpipi.dll", CallingConvention=CallingConvention.Cdecl), 
     77         SuppressUnmanagedCodeSecurity] 
     78        private static extern IntPtr pipi_getpixels(IntPtr img, int type); 
     79        public byte[] GetPixels(int w, int h, int x, int y) 
     80        { 
     81            byte[] array = new byte[w * h * 4]; 
     82            IntPtr pixels = pipi_getpixels(_picture, 0); 
     83            PixelsStruct p; 
     84            Int64 address; 
     85 
     86            p = (PixelsStruct)Marshal.PtrToStructure(pixels, 
     87                                                     typeof(PixelsStruct)); 
     88            address = p.pixels.ToInt64(); 
     89 
     90            unsafe 
     91            { 
     92                for(int j = 0; j < h; j++) 
     93                { 
     94                    Marshal.Copy((IntPtr)(address + ((j + y) * p.w + x) * 4), 
     95                                 array, j * w * 4, w * 4); 
     96                    for(int i = 0; i < w; i++) 
     97                    { 
     98                        byte c = array[j * w * 4 + i * 4]; 
     99                        array[j * w * 4 + i * 4] = array[j * w * 4 + i * 4 + 2]; 
     100                        array[j * w * 4 + i * 4 + 2] = c; 
     101                    } 
     102                } 
     103            } 
     104 
     105            return array; 
     106        } 
    64107    } 
    65108} 
     109 
Note: See TracChangeset for help on using the changeset viewer.