- Timestamp:
- Oct 5, 2008, 10:31:11 PM (12 years ago)
- Location:
- libpipi/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libpipi/trunk/ThePimp/MainWindow.cs
r2872 r2873 24 24 Build (); 25 25 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")));29 26 } 30 27 … … 42 39 if(p != null) 43 40 { 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; 47 46 } 48 47 } -
libpipi/trunk/ThePimp/PictureView.cs
r2872 r2873 38 38 { 39 39 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 45 57 return ret; 46 58 } … … 48 60 protected override void OnRealized() 49 61 { 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 ♥ ♥");54 62 base.OnRealized(); 55 63 } -
libpipi/trunk/pipi-sharp/Picture.cs
r2872 r2873 23 23 private IntPtr _picture; 24 24 25 public readonly string FileName; 26 25 27 [DllImport("libpipi.dll", CallingConvention=CallingConvention.Cdecl), 26 28 SuppressUnmanagedCodeSecurity] … … 29 31 { 30 32 _picture = pipi_load(s); 33 FileName = s; 31 34 } 32 35 … … 62 65 get { return pipi_get_image_height(_picture); } 63 66 } 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 } 64 107 } 65 108 } 109
Note: See TracChangeset
for help on using the changeset viewer.