| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- //
- // System.Drawing.Imaging.EncoderParameter.cs
- //
- // Author:
- // Ravindra ([email protected])
- //
- // (C) 2004 Novell, Inc. http://www.novell.com
- //
- using System;
- using System.Text;
- namespace System.Drawing.Imaging {
- public sealed class EncoderParameter : IDisposable {
- Encoder encoder;
- Object value;
- int valuesCount;
- EncoderParameterValueType type;
-
- public EncoderParameter (Encoder encoder, byte value)
- {
- this.encoder = encoder;
- this.value = value;
- this.valuesCount = 1;
- this.type = EncoderParameterValueType.ValueTypeByte;
- }
- public EncoderParameter (Encoder encoder, byte[] value)
- {
- this.encoder = encoder;
- this.value = value;
- this.valuesCount = value.Length;
- this.type = EncoderParameterValueType.ValueTypeByte;
- }
- public EncoderParameter (Encoder encoder, short value)
- {
- this.encoder = encoder;
- this.value = value;
- this.valuesCount = 1;
- this.type = EncoderParameterValueType.ValueTypeShort;
- }
- public EncoderParameter (Encoder encoder, short[] value)
- {
- this.encoder = encoder;
- this.value = value;
- this.valuesCount = value.Length;
- this.type = EncoderParameterValueType.ValueTypeShort;
- }
- public EncoderParameter (Encoder encoder, long value)
- {
- this.encoder = encoder;
- this.value = (int) value;
- this.valuesCount = 1;
- this.type = EncoderParameterValueType.ValueTypeLong;
- }
- public EncoderParameter (Encoder encoder, long[] value)
- {
- this.encoder = encoder;
- this.value = convertToIntArr (value);
- this.valuesCount = value.Length;
- this.type = EncoderParameterValueType.ValueTypeLong;
- }
- public EncoderParameter (Encoder encoder, string value)
- {
- this.encoder = encoder;
- ASCIIEncoding ascii = new ASCIIEncoding ();
- int asciiByteCount = ascii.GetByteCount (value);
- byte[] bytes = new byte [asciiByteCount];
- ascii.GetBytes (value, 0, value.Length, bytes, 0);
- this.value = ascii.GetString (bytes);
- this.valuesCount = bytes.Length;
- this.type = EncoderParameterValueType.ValueTypeAscii;
- }
- public EncoderParameter (Encoder encoder, byte value, bool undefined)
- {
- this.encoder = encoder;
- this.value = value;
- this.valuesCount = 1;
- if (undefined)
- this.type = EncoderParameterValueType.ValueTypeUndefined;
- else
- this.type = EncoderParameterValueType.ValueTypeByte;
- }
- public EncoderParameter (Encoder encoder, byte[] value, bool undefined)
- {
- this.encoder = encoder;
- this.value = value;
- this.valuesCount = value.Length;
- if (undefined)
- this.type = EncoderParameterValueType.ValueTypeUndefined;
- else
- this.type = EncoderParameterValueType.ValueTypeByte;
- }
- public EncoderParameter (Encoder encoder, int numerator, int denominator)
- {
- this.encoder = encoder;
- this.value = new int[] {numerator, denominator};
- this.valuesCount = 1;
- this.type = EncoderParameterValueType.ValueTypeRational;
- }
- public EncoderParameter (Encoder encoder, int[] numerator, int[] denominator)
- {
- if (numerator.Length != denominator.Length)
- throw new ArgumentException ("Invalid parameter used.");
- this.encoder = encoder;
- this.value = new int[][] {numerator, denominator};
- this.valuesCount = numerator.Length;
- this.type = EncoderParameterValueType.ValueTypeRational;
- }
- public EncoderParameter (Encoder encoder, long rangebegin, long rangeend)
- {
- this.encoder = encoder;
- this.value = new int[] { (int) rangebegin, (int) rangeend};
- this.valuesCount = 1;
- this.type = EncoderParameterValueType.ValueTypeLongRange;
- }
- public EncoderParameter (Encoder encoder, long[] rangebegin, long[] rangeend)
- {
- if (rangebegin.Length != rangeend.Length)
- throw new ArgumentException ("Invalid parameter used.");
- this.encoder = encoder;
- int[] startRange = convertToIntArr (rangebegin);
- int[] endRange = convertToIntArr (rangeend);
- this.value = new int[][] {startRange, endRange};
- this.valuesCount = rangebegin.Length;
- this.type = EncoderParameterValueType.ValueTypeLongRange;
- }
- public EncoderParameter (Encoder encoder, int numberOfValues, int type, int value)
- {
- this.encoder = encoder;
- this.value = value;
- this.valuesCount = numberOfValues;
- this.type = (EncoderParameterValueType) type;
- }
- public EncoderParameter (Encoder encoder, int numerator1, int denominator1, int numerator2, int denominator2)
- {
- this.encoder = encoder;
- this.value = new int[] {numerator1, denominator1, numerator2, denominator2};
- this.valuesCount = 1;
- this.type = EncoderParameterValueType.ValueTypeRationalRange;
- }
- public EncoderParameter (Encoder encoder, int[] numerator1, int[] denominator1, int[] numerator2, int[] denominator2)
- {
- if (numerator1.Length != denominator1.Length ||
- numerator2.Length != denominator2.Length ||
- numerator1.Length != numerator2.Length)
- throw new ArgumentException ("Invalid parameter used.");
- this.encoder = encoder;
- this.value = new int[][] {numerator1, denominator1, numerator2, denominator2};
- this.valuesCount = numerator1.Length;
- this.type = EncoderParameterValueType.ValueTypeRationalRange;
- }
- public Encoder Encoder {
- get {
- return encoder;
- }
- set {
- encoder = value;
- }
- }
- public int NumberOfValues {
- get {
- return valuesCount;
- }
- }
- public EncoderParameterValueType Type {
- get {
- return type;
- }
- }
- public EncoderParameterValueType ValueType {
- get {
- return type;
- }
- }
- void Dispose (bool disposing) {
- // release the resources
- }
- public void Dispose () {
- Dispose (true);
- }
- ~EncoderParameter () {
- Dispose (false);
- }
- internal Object Value {
- get {
- return value;
- }
- }
- internal int[] convertToIntArr (long[] arr)
- {
- int[] intArr = new int [arr.Length];
- for (int i = 0; i < arr.Length; i++)
- intArr[i] = (int) arr[i];
- return intArr;
- }
- }
- }
|