// (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;
namespace System.Drawing.Imaging {
+ [StructLayout(LayoutKind.Sequential)]
public sealed class EncoderParameter : IDisposable {
private Encoder encoder;
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)
{
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]);
}
}
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]);
}
}
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]);
}
}
public void Dispose () {
Dispose (true);
+ GC.SuppressFinalize(this);
}
~EncoderParameter () {