git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2873 92316355-f0b4-4df1-b90c-862c8a59935fremotes/tiles
| @@ -23,9 +23,6 @@ public partial class MainWindow: Gtk.Window | |||||
| { | { | ||||
| Build (); | Build (); | ||||
| Title += " v" + Libpipi.getVersion(); | Title += " v" + Libpipi.getVersion(); | ||||
| notebook1.Add(new PictureView(new Pipi.Picture("random:1024x1024"))); | |||||
| //scrolledwindow1.Add(new PictureView(new Pipi.Picture("random:1024x1024"))); | |||||
| } | } | ||||
| protected void OnDeleteEvent (object sender, DeleteEventArgs a) | protected void OnDeleteEvent (object sender, DeleteEventArgs a) | ||||
| @@ -41,9 +38,11 @@ public partial class MainWindow: Gtk.Window | |||||
| open.Destroy(); | open.Destroy(); | ||||
| if(p != null) | if(p != null) | ||||
| { | { | ||||
| Title += " image " + p.Width + "x" + p.Height; | |||||
| notebook1.RemovePage(0); | |||||
| notebook1.AppendPage(new PictureView(p), null); | |||||
| while(notebook1.NPages > 0) | |||||
| notebook1.RemovePage(0); | |||||
| int n = notebook1.AppendPage(new PictureView(p), | |||||
| new Label(p.FileName)); | |||||
| notebook1.Page = n; | |||||
| } | } | ||||
| } | } | ||||
| @@ -37,20 +37,28 @@ namespace ThePimp | |||||
| protected override bool OnExposeEvent(Gdk.EventExpose e) | protected override bool OnExposeEvent(Gdk.EventExpose e) | ||||
| { | { | ||||
| bool ret = base.OnExposeEvent(e); | bool ret = base.OnExposeEvent(e); | ||||
| //Console.WriteLine("expose {0}x{1}+{2}+{3}", e.Area.Width, e.Area.Height, e.Area.X, e.Area.Y); | |||||
| GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 40 - (int)_hadj.Value, 40 - (int)_vadj.Value, _l); | |||||
| GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 560 - (int)_hadj.Value, 40 - (int)_vadj.Value, _l); | |||||
| GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 40 - (int)_hadj.Value, 560 - (int)_vadj.Value, _l); | |||||
| GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), 560 - (int)_hadj.Value, 560 - (int)_vadj.Value, _l); | |||||
| using (Gdk.GC gc = new Gdk.GC(GdkWindow)) | |||||
| { | |||||
| int w = e.Area.Width; | |||||
| int h = e.Area.Height; | |||||
| int x = (int)_hadj.Value + e.Area.X; | |||||
| int y = (int)_vadj.Value + e.Area.Y; | |||||
| if(x + w > _p.Width) | |||||
| w = _p.Width - x < 0 ? 0 : _p.Width - x; | |||||
| if(y + h > _p.Height) | |||||
| h = _p.Height - y < 0 ? 0 : _p.Height - y; | |||||
| byte[] a = _p.GetPixels(w, h, x, y); | |||||
| GdkWindow.DrawRgb32Image(gc, e.Area.X, e.Area.Y, w, h, | |||||
| 0 /* no dithering */, a, w * 4); | |||||
| } | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| protected override void OnRealized() | protected override void OnRealized() | ||||
| { | { | ||||
| _l = new Pango.Layout(PangoContext); | |||||
| _l.Wrap = Pango.WrapMode.Word; | |||||
| _l.FontDescription = Pango.FontDescription.FromString("Tahoma 64"); | |||||
| _l.SetMarkup("WHAT THE\nFUCK IS\nTHIS SHIT\nLOL ♥ ♥"); | |||||
| base.OnRealized(); | base.OnRealized(); | ||||
| } | } | ||||
| @@ -22,12 +22,15 @@ namespace Pipi | |||||
| { | { | ||||
| private IntPtr _picture; | private IntPtr _picture; | ||||
| public readonly string FileName; | |||||
| [DllImport("libpipi.dll", CallingConvention=CallingConvention.Cdecl), | [DllImport("libpipi.dll", CallingConvention=CallingConvention.Cdecl), | ||||
| SuppressUnmanagedCodeSecurity] | SuppressUnmanagedCodeSecurity] | ||||
| private static extern IntPtr pipi_load(string s); | private static extern IntPtr pipi_load(string s); | ||||
| public Picture(string s) | public Picture(string s) | ||||
| { | { | ||||
| _picture = pipi_load(s); | _picture = pipi_load(s); | ||||
| FileName = s; | |||||
| } | } | ||||
| [DllImport("libpipi.dll", CallingConvention=CallingConvention.Cdecl), | [DllImport("libpipi.dll", CallingConvention=CallingConvention.Cdecl), | ||||
| @@ -61,5 +64,46 @@ namespace Pipi | |||||
| { | { | ||||
| get { return pipi_get_image_height(_picture); } | get { return pipi_get_image_height(_picture); } | ||||
| } | } | ||||
| [StructLayout(LayoutKind.Sequential)] | |||||
| public struct PixelsStruct | |||||
| { | |||||
| public IntPtr pixels; | |||||
| public Int32 w, h, pitch, bpp; | |||||
| public Int64 bytes; | |||||
| } | |||||
| [DllImport("libpipi.dll", CallingConvention=CallingConvention.Cdecl), | |||||
| SuppressUnmanagedCodeSecurity] | |||||
| private static extern IntPtr pipi_getpixels(IntPtr img, int type); | |||||
| public byte[] GetPixels(int w, int h, int x, int y) | |||||
| { | |||||
| byte[] array = new byte[w * h * 4]; | |||||
| IntPtr pixels = pipi_getpixels(_picture, 0); | |||||
| PixelsStruct p; | |||||
| Int64 address; | |||||
| p = (PixelsStruct)Marshal.PtrToStructure(pixels, | |||||
| typeof(PixelsStruct)); | |||||
| address = p.pixels.ToInt64(); | |||||
| unsafe | |||||
| { | |||||
| for(int j = 0; j < h; j++) | |||||
| { | |||||
| Marshal.Copy((IntPtr)(address + ((j + y) * p.w + x) * 4), | |||||
| array, j * w * 4, w * 4); | |||||
| for(int i = 0; i < w; i++) | |||||
| { | |||||
| byte c = array[j * w * 4 + i * 4]; | |||||
| array[j * w * 4 + i * 4] = array[j * w * 4 + i * 4 + 2]; | |||||
| array[j * w * 4 + i * 4 + 2] = c; | |||||
| } | |||||
| } | |||||
| } | |||||
| return array; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||