Merge pull request #1506 from akoeplinger/fix-paste-test
[mono.git] / mcs / class / System.Drawing / System.Drawing.Imaging / ColorPalette.cs
old mode 100755 (executable)
new mode 100644 (file)
index c13a90a..28599a7
@@ -7,6 +7,29 @@
 //   Miguel de Icaza (miguel@ximian.com)
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
 using System.Drawing;
 using System.Runtime.InteropServices;
@@ -27,7 +50,6 @@ namespace System.Drawing.Imaging
                //
                internal ColorPalette ()
                {
-                       flags = 0;
                        entries = new Color [0];
                }
 
@@ -47,7 +69,6 @@ namespace System.Drawing.Imaging
                                return flags;
                        }
                }
-               
                /* Caller should call FreeHGlobal*/
                internal IntPtr getGDIPalette() 
                {
@@ -63,21 +84,32 @@ namespace System.Drawing.Imaging
                        int[] values = new int[palette.Count];
                        
                        for (int i = 0; i < values.Length; i++) {
-                               values[i] = entries[i].ToArgb(); 
-                               //Console.Write("{0:X} ;", values[i]);                  
-                       }                       
-                       
-                       //Console.WriteLine("pal size " + Marshal.SizeOf (palette) + " native " + NativeObject);                        
+                               values[i] = entries[i].ToArgb();                                
+                       }                       
                        
                        Marshal.StructureToPtr (palette, lfBuffer, false);      
-                       Marshal.Copy (values, 0, (IntPtr) (lfBuffer.ToInt32() + Marshal.SizeOf (palette)), values.Length);                                                                                                              
+                       Marshal.Copy (values, 0, (IntPtr) (lfBuffer.ToInt64() + Marshal.SizeOf (palette)), values.Length);
                        
                        return lfBuffer;
                }
-               
-               internal void setFromGDIPalette(IntPtr palette) 
-               {
                        
+               internal void setFromGDIPalette (IntPtr palette)
+               {
+                       IntPtr ptr = palette;
+                       int cnt, color;
+                       int offset;
+
+                       flags = Marshal.ReadInt32 (ptr); ptr = (IntPtr) (ptr.ToInt64() + 4);
+                       cnt = Marshal.ReadInt32 (ptr); ptr = (IntPtr) (ptr.ToInt64() + 4);
+                                               
+                       entries = new Color [cnt];                      
+                                               
+                       offset = 0;
+                       for (int i = 0; i < cnt; i++) {
+                               color = Marshal.ReadInt32 (ptr, offset);
+                               entries[i] = Color.FromArgb (color);
+                               offset += 4;
+                       }
                }
        }
 }