X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Drawing%2FSystem.Drawing.Imaging%2FEncoderParameter.cs;h=f21831faa49f42af62d3669d57a509e58db0957e;hb=0605c47f81b64506d24a11415a2e72381b71e8e1;hp=776c3d6ad44f9f2046748f0a01fae93312b62c26;hpb=e932bf2d0963fc7cc038b97e2a34137edf44f19e;p=mono.git diff --git a/mcs/class/System.Drawing/System.Drawing.Imaging/EncoderParameter.cs b/mcs/class/System.Drawing/System.Drawing.Imaging/EncoderParameter.cs index 776c3d6ad44..f21831faa49 100644 --- a/mcs/class/System.Drawing/System.Drawing.Imaging/EncoderParameter.cs +++ b/mcs/class/System.Drawing/System.Drawing.Imaging/EncoderParameter.cs @@ -8,6 +8,29 @@ // (C) 2004 Novell, Inc. http://www.novell.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.Text; @@ -15,6 +38,7 @@ using System.Runtime.InteropServices; namespace System.Drawing.Imaging { + [StructLayout(LayoutKind.Sequential)] public sealed class EncoderParameter : IDisposable { private Encoder encoder; @@ -62,23 +86,6 @@ namespace System.Drawing.Imaging { Marshal.Copy (value, 0, this.valuePtr, valuesCount); } - public EncoderParameter (Encoder encoder, int value) - { - this.encoder = encoder; - this.valuesCount = 1; - this.type = EncoderParameterValueType.ValueTypeLong; - this.valuePtr = Marshal.AllocHGlobal (4); - Marshal.WriteInt32 (this.valuePtr, value); - } - - public EncoderParameter (Encoder encoder, int[] value) - { - this.encoder = encoder; - this.valuesCount = value.Length; - this.type = EncoderParameterValueType.ValueTypeLong; - this.valuePtr = Marshal.AllocHGlobal (4 * valuesCount); - Marshal.Copy (value, 0, this.valuePtr, valuesCount); - } public EncoderParameter (Encoder encoder, long value) { @@ -158,12 +165,9 @@ namespace System.Drawing.Imaging { this.valuesCount = numerator.Length; this.type = EncoderParameterValueType.ValueTypeRational; this.valuePtr = Marshal.AllocHGlobal (4 * valuesCount * 2); - IntPtr dest = this.valuePtr; for (int i = 0; i < valuesCount; i++) { - Marshal.WriteInt32 (dest, (int) numerator[i]); - dest = (IntPtr) ((int) dest + 4); - Marshal.WriteInt32 (dest, (int) denominator[i]); - dest = (IntPtr) ((int) dest + 4); + Marshal.WriteInt32 (valuePtr, i * 4, (int) numerator[i]); + Marshal.WriteInt32 (valuePtr, (i + 1) * 4, (int) denominator[i]); } } @@ -189,10 +193,8 @@ namespace System.Drawing.Imaging { this.valuePtr = Marshal.AllocHGlobal (4 * valuesCount * 2); IntPtr dest = this.valuePtr; for (int i = 0; i < valuesCount; i++) { - Marshal.WriteInt32 (dest, (int) rangebegin[i]); - dest = (IntPtr) ((int) dest + 4); - Marshal.WriteInt32 (dest, (int) rangeend[i]); - dest = (IntPtr) ((int) dest + 4); + Marshal.WriteInt32 (dest, i * 4, (int) rangebegin[i]); + Marshal.WriteInt32 (dest, (i + 1) * 4, (int) rangeend[i]); } } @@ -228,14 +230,10 @@ namespace System.Drawing.Imaging { this.valuePtr = Marshal.AllocHGlobal (4 * valuesCount * 4); IntPtr dest = this.valuePtr; for (int i = 0; i < valuesCount; i++) { - Marshal.WriteInt32 (dest, numerator1[i]); - dest = (IntPtr) ((int) dest + 4); - Marshal.WriteInt32 (dest, denominator1[i]); - dest = (IntPtr) ((int) dest + 4); - Marshal.WriteInt32 (dest, numerator2[i]); - dest = (IntPtr) ((int) dest + 4); - Marshal.WriteInt32 (dest, denominator2[i]); - dest = (IntPtr) ((int) dest + 4); + Marshal.WriteInt32 (dest, i * 4, numerator1[i]); + Marshal.WriteInt32 (dest, (i + 1) * 4, denominator1[i]); + Marshal.WriteInt32 (dest, (i + 2) * 4, numerator2[i]); + Marshal.WriteInt32 (dest, (i + 3) * 4, denominator2[i]); } } @@ -276,6 +274,7 @@ namespace System.Drawing.Imaging { public void Dispose () { Dispose (true); + GC.SuppressFinalize(this); } ~EncoderParameter () {