Filter:   InfoImg
download Image.cs
Language: C#
License: GPL
Copyright: (C) 2003 Southern Storm Software, Pty Ltd.
LOC: 417
Project Info
DotGNU Portable.NET(dotgnu-pnet)
Server: Savannah GNU
Type: cvs
...net\pnetlib\System.Drawing\
   .cvsignore
   Bitmap.cs
   Brush.cs
   Brushes.cs
   CharacterRange.cs
   Color.cs
   ColorConverter.cs
   ColorTranslator.cs
   ContentAlignment.cs
   Font.cs
   FontConverter.cs
   FontFamily.cs
   FontStyle.cs
   Graphics.cs
   GraphicsUnit.cs
   Icon.cs
   IconConverter.cs
   Image.cs
   ImageAnimator.cs
   ImageConverter.cs
   ImageFormatConverter.cs
   KnownColor.cs
   Makefile.am
   Pen.cs
   Pens.cs
   Point.cs
   PointConverter.cs
   PointF.cs
   Rectangle.cs
   RectangleConverter.cs
   RectangleF.cs
   Region.cs
   RotateFlipType.cs
   S.cs
   Size.cs
   SizeConverter.cs
   SizeF.cs
   SolidBrush.cs
   StringAlignment.cs
   StringDigitSubstitute.cs
   StringFormat.cs
   StringFormatFlags.cs
   StringTrimming.cs
   StringUnit.cs
   System.Drawing.build
   SystemBrushes.cs
   SystemColors.cs
   SystemIcons.cs
   SystemPens.cs
   TextureBrush.cs
   TODOAttribute.cs
   ToolboxBitmapAttribute.cs
   XorBrush.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
/*
 * Image.cs - Implementation of the "System.Drawing.Image" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Drawing
{

using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Drawing.Imaging;
using DotGNU.Images;

#if !ECMA_COMPAT
[Serializable]
[ComVisible(true)]
#endif
public abstract class Image
	: MarshalByRefObject, ICloneable, IDisposable
#if CONFIG_SERIALIZATION
	, ISerializable
#endif
{
	// Internal state.
	internal int flags;
#if !ECMA_COMPAT
	internal Guid[] frameDimensionsList;
	internal ImageFormat rawFormat;
#endif
	internal int height;
	internal float horizontalResolution;
	internal ColorPalette palette;
	internal System.Drawing.Imaging.PixelFormat pixelFormat;
	internal int[] propertyIdList;
	internal PropertyItem[] propertyItems;
	internal float verticalResolution;
	internal int width;
	internal DotGNU.Images.Image dgImage;
	internal Toolkit.IToolkitImage toolkitImage;

	// Constructors.
	internal Image() {}
	internal Image(DotGNU.Images.Image dgImage)
			{
				SetDGImage(dgImage);
			}
#if CONFIG_SERIALIZATION
	internal Image(SerializationInfo info, StreamingContext context)
			{
				// Do we need to Handle PixelFormats ?.
				byte[] data = null;
				data = (byte[])info.GetValue("Data", typeof(byte[]));
				MemoryStream stream = new MemoryStream(data,false);
				DotGNU.Images.Image dgImage = new DotGNU.Images.Image();
				dgImage.Load(stream);
				SetDGImage(dgImage);
			}
#endif

	// Destructor.
	~Image()
			{
				Dispose(false);
			}

	// Get this object's properties.
	public int Flags
			{
				get
				{
					return flags;
				}
			}
#if !ECMA_COMPAT
	public Guid[] FrameDimensionsList
			{
				get
				{
					return frameDimensionsList;
				}
			}
#endif
	public int Height
			{
				get
				{
					return height;
				}
			}
	public float HorizontalResolution
			{
				get
				{
					return horizontalResolution;
				}
			}
	public ColorPalette Palette
			{
				get
				{
					return palette;
				}
				set
				{
					palette = value;
				}
			}
	public SizeF PhysicalDimension
			{
				get
				{
					return new SizeF(width, height);
				}
			}
	public System.Drawing.Imaging.PixelFormat PixelFormat
			{
				get
				{
					return pixelFormat;
				}
			}
	public int[] PropertyIdList
			{
				get
				{
					if(propertyIdList == null)
					{
						propertyIdList = new int [0];
					}
					return propertyIdList;
				}
			}
	public PropertyItem[] PropertyItems
			{
				get
				{
					if(propertyItems == null)
					{
						propertyItems = new PropertyItem [0];
					}
					return propertyItems;
				}
			}
#if !ECMA_COMPAT
	public ImageFormat RawFormat
			{
				get
				{
					return rawFormat;
				}
			}
#endif
	public Size Size
			{
				get
				{
					return new Size(width, height);
				}
			}
	public float VerticalResolution
			{
				get
				{
					return verticalResolution;
				}
			}
	public int Width
			{
				get
				{
					return width;
				}
			}

	// Make a copy of this object.
	public virtual Object Clone()
			{
				// TODO
				return null;
			}

	// Dispose of this object.
	public void Dispose()
			{
				Dispose(true);
				GC.SuppressFinalize(this);
			}
	protected virtual void Dispose(bool disposing)
			{
				if(dgImage != null)
				{
					dgImage.Dispose();
					dgImage = null;
				}
			}

	// Load an image from a file.
	public static Image FromFile(String filename)
			{
				return FromFile(filename, false);
			}
	public static Image FromFile
				(String filename, bool useEmbeddedColorManagement)
			{
				DotGNU.Images.Image image = new DotGNU.Images.Image();
				image.Load(filename);
				return new Bitmap(image);
			}

	// Convert a HBITMAP object into an image.
	public static Image FromHbitmap(IntPtr hbitmap)
			{
				return FromHbitmap(hbitmap, IntPtr.Zero);
			}
	[TODO]
	public static Image FromHbitmap(IntPtr hbitmap, IntPtr hpalette)
			{
				// TODO
				return null;
			}

	// Load an image from a particular stream.
	public static Image FromStream(Stream stream)
			{
				return FromStream(stream, false);
			}
	public static Image FromStream
				(Stream stream, bool useEmbeddedColorManagement)
			{
				DotGNU.Images.Image image = new DotGNU.Images.Image();
				image.Load(stream);
				return new Bitmap(image);
			}

	// Get a bounding rectangle for this image.
	[TODO]
	public RectangleF GetBounds(ref GraphicsUnit pageUnit)
			{
				// TODO
				return RectangleF.Empty;
			}

#if !ECMA_COMPAT

	// Get parameter information for a specific encoder.
	[TODO]
	public EncoderParameters GetEncoderParameterList(Guid encoder)
			{
				// TODO
				return null;
			}

	// Get the number of frames in a specific dimension.
	[TODO]
	public int GetFrameCount(FrameDimension dimension)
			{
				// TODO
				return 1;
			}

	// Select a new frame and make it the active one.
	[TODO]
	public int SelectActiveFrame(FrameDimension dimension, int frameIndex)
			{
				// TODO
				return frameIndex;
			}

#endif

	// Get the number of bits per pixel in a specific format.
	public static int GetPixelFormatSize
				(System.Drawing.Imaging.PixelFormat pixfmt)
			{
				switch(pixfmt)
				{
					case System.Drawing.Imaging.PixelFormat.Format1bppIndexed:
						return 1;
					case System.Drawing.Imaging.PixelFormat.Format4bppIndexed:
						return 4;
					case System.Drawing.Imaging.PixelFormat.Format8bppIndexed:
						return 8;
					case System.Drawing.Imaging.PixelFormat.Format16bppRgb555:
					case System.Drawing.Imaging.PixelFormat.Format16bppRgb565:
					case System.Drawing.Imaging.PixelFormat.Format16bppArgb1555:
					case System.Drawing.Imaging.PixelFormat.
							Format16bppGrayScale:	return 16;
					case System.Drawing.Imaging.PixelFormat.Format24bppRgb:
						return 24;
					case System.Drawing.Imaging.PixelFormat.Format32bppRgb:
					case System.Drawing.Imaging.PixelFormat.Format32bppPArgb:
					case System.Drawing.Imaging.PixelFormat.Format32bppArgb:
						return 32;
					case System.Drawing.Imaging.PixelFormat.Format48bppRgb:
						return 48;
					case System.Drawing.Imaging.PixelFormat.Format64bppPArgb:
					case System.Drawing.Imaging.PixelFormat.Format64bppArgb:
						return 64;
				}
				return 0;
			}

	// Get a specific property item
	[TODO]
	public PropertyItem GetPropertyItem(int propid)
			{
				// TODO
				return null;
			}

	// Get a thumbnail version of this image.
	[TODO]
	public Image GetThumbnailImage(int thumbWidth, int thumbHeight,
		     					   GetThumbnailImageAbort callback,
			    				   IntPtr callbackData)
			{
				// TODO
				return null;
			}

	// Delegate for aborting "GetThumbnailImage" prematurely.
	public delegate bool GetThumbnailImageAbort();

	// Check for specific kinds of pixel formats.
	public static bool IsAlphaPixelFormat
				(System.Drawing.Imaging.PixelFormat pixfmt)
			{
				return ((pixfmt &
					System.Drawing.Imaging.PixelFormat.Alpha) != 0);
			}
	public static bool IsCanonicalPixelFormat
				(System.Drawing.Imaging.PixelFormat pixfmt)
			{
				return ((pixfmt &
					System.Drawing.Imaging.PixelFormat.Canonical) != 0);
			}
	public static bool IsExtendedPixelFormat
				(System.Drawing.Imaging.PixelFormat pixfmt)
			{
				return ((pixfmt &
					System.Drawing.Imaging.PixelFormat.Extended) != 0);
			}

	// Remove a specific property.
	[TODO]
	public void RemoveProperty(int propid)
			{
				// TODO
			}

	// Rotate and/or flip this image.
	[TODO]
	public void RotateFlip(RotateFlipType rotateFlipType)
			{
				// TODO
			}

	// Save this image to a file.
	public void Save(String filename)
			{
				dgImage.Save(filename);
			}
#if !ECMA_COMPAT
	public void Save(String filename, ImageFormat format)
			{
				dgImage.Save(filename, ImageFormatToDG(format));
			}
	[TODO]
	public void Save(String filename, ImageCodecInfo encoder,
					 EncoderParameters encoderParameters)
			{
				// TODO
			}

	// Save this image to a stream.
	public void Save(Stream stream, ImageFormat format)
			{
				dgImage.Save(stream, ImageFormatToDG(format));
			}

	private string ImageFormatToDG(ImageFormat format)
			{
				if (format ==ImageFormat.Bmp)
					return "bmp";
				if (format ==ImageFormat.Gif)
					return "gif";
				if (format ==ImageFormat.Icon)
					return "icon";
				if (format ==ImageFormat.Jpeg)
					return "jpeg";
				if (format ==ImageFormat.Png)
					return "png";
				if (format ==ImageFormat.Tiff)
					return "tiff";
				if (format ==ImageFormat.Exif)
					return "exif";
				else
					throw new NotSupportedException(format.ToString());
			}

	[TODO]
	public void Save(Stream stream, ImageCodecInfo encoder,
					 EncoderParameters encoderParameters)
			{
				// TODO
			}

	// Add a frame to the previously saved image file.
	[TODO]
	public void SaveAdd(EncoderParameters encoderParamers)
			{
				// TODO
			}
	[TODO]
	public void SaveAdd(Image image, EncoderParameters encoderParamers)
			{
				// TODO
			}
#endif

	// Set a property on this image.
	[TODO]
	public void SetPropertyItem(PropertyItem propitem)
			{
				// TODO
			}

#if CONFIG_SERIALIZATION

	// Implement the ISerializable interface.
	[TODO]
	void ISerializable.GetObjectData(SerializationInfo info,
									 StreamingContext context)
			{
				// TODO
			}

#endif

	// Set the dgImage field within this object.
	internal void SetDGImage(DotGNU.Images.Image dgImage)
			{
				flags = 0;
			#if !ECMA_COMPAT
				switch(dgImage.LoadFormat)
				{
					case DotGNU.Images.Image.Png:
						rawFormat = ImageFormat.Png; break;
					case DotGNU.Images.Image.Jpeg:
						rawFormat = ImageFormat.Jpeg; break;
					case DotGNU.Images.Image.Gif:
						rawFormat = ImageFormat.Gif; break;
					case DotGNU.Images.Image.Tiff:
						rawFormat = ImageFormat.Tiff; break;
					case DotGNU.Images.Image.Bmp:
						rawFormat = ImageFormat.Bmp; break;
					case DotGNU.Images.Image.Icon:
						rawFormat = ImageFormat.Icon; break;
					case DotGNU.Images.Image.Exif:
						rawFormat = ImageFormat.Exif; break;
				}
				frameDimensionsList = new Guid [0];
				this.dgImage = dgImage;
				// If we are loading an icon, set the size of the image
				// to the size of the first icon
				if (rawFormat == ImageFormat.Icon)
				{
					width = dgImage.GetFrame(0).Width;
					height = dgImage.GetFrame(0).Height;
				}
				else
				{
					width = dgImage.Width;
					height = dgImage.Height;
				}
			#else
				this.dgImage = dgImage;
				width = dgImage.GetFrame(0).Width;
				height = dgImage.GetFrame(0).Height;
			#endif
				horizontalResolution = Graphics.DefaultScreenDpi;
				verticalResolution = Graphics.DefaultScreenDpi;
				pixelFormat = (System.Drawing.Imaging.PixelFormat)
					(dgImage.PixelFormat);
			}

	// This is an internal member and should not be used.
	// Returns a bitmap which is the reformatted (to newFormat) of the image.
	public Image Reformat(System.Drawing.Imaging.PixelFormat newFormat)
			{
				return new Bitmap(dgImage.Reformat((DotGNU.Images.PixelFormat)newFormat));
			}

	// This is an internal member and should not be used.
	// Returns a bitmap which is the resized (to newWidth and newHeight) of the first frame.
	public Image Resize(int newWidth, int newHeight)
			{
				Frame frame = dgImage.GetFrame(0);
				Frame newFrame = frame.AdjustImage(0, 0, width, 0, 0, height, 0, 0, newWidth, 0, 0, newHeight);
				DotGNU.Images.Image newImage = new DotGNU.Images.Image(newWidth, newHeight, newFrame.PixelFormat);
				newImage.AddFrame(newFrame);
				return new Bitmap(newImage);
			}

}; // class Image

}; // namespace System.Drawing