47c8947577b27ee27507d81b683f693b21765574
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing.Imaging / TestBmpCodec.cs
1 //
2 // BMPCodec class testing unit
3 //
4 // Authors:
5 //      Jordi Mas i Hernàndez (jordi@ximian.com)
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // (C) 2004 Ximian, Inc.  http://www.ximian.com
9 // Copyright (C) 2004-2007 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.Drawing;
33 using System.Drawing.Imaging;
34 using NUnit.Framework;
35 using System.IO;
36 using System.Security.Cryptography;
37 using System.Security.Permissions;
38 using System.Text;
39
40 namespace MonoTests.System.Drawing.Imaging {
41
42         [TestFixture]
43         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
44         public class BmpCodecTest {
45                 
46                 /* Get suffix to add to the filename */
47                 internal string getOutSufix()
48                 {
49                         string s;
50
51                         int p = (int) Environment.OSVersion.Platform;
52                         if ((p == 4) || (p == 128) || (p == 6))
53                                 s = "-unix";
54                         else
55                                 s = "-windows";
56
57                         if (Type.GetType ("Mono.Runtime", false) == null)
58                                 s += "-msnet";
59                         else
60                                 s += "-mono";
61
62                         return s;
63                 }
64
65                 /* Get the input directory depending on the runtime*/
66                 internal string getInFile(string file)
67                 {
68                         string sRslt = Path.GetFullPath ("../System.Drawing/" + file);
69
70                         if (!File.Exists (sRslt))
71                                 sRslt = "Test/System.Drawing/" + file;
72
73                         return sRslt;
74                 }
75
76                 /* Checks bitmap features on a know 1bbp bitmap */
77                 [Test]
78                 public void Bitmap1bitFeatures ()
79                 {
80                         string sInFile = getInFile ("bitmaps/almogaver1bit.bmp");
81                         using (Bitmap bmp = new Bitmap (sInFile)) {
82                                 GraphicsUnit unit = GraphicsUnit.World;
83                                 RectangleF rect = bmp.GetBounds (ref unit);
84
85                                 // ??? why is it a 4bbp ?
86                                 Assert.AreEqual (PixelFormat.Format4bppIndexed, bmp.PixelFormat);
87                                 Assert.AreEqual (173, bmp.Width, "bmp.Width");
88                                 Assert.AreEqual (183, bmp.Height, "bmp.Height");
89
90                                 Assert.AreEqual (0, rect.X, "rect.X");
91                                 Assert.AreEqual (0, rect.Y, "rect.Y");
92                                 Assert.AreEqual (173, rect.Width, "rect.Width");
93                                 Assert.AreEqual (183, rect.Height, "rect.Height");
94
95                                 Assert.AreEqual (173, bmp.Size.Width, "bmp.Size.Width");
96                                 Assert.AreEqual (183, bmp.Size.Height, "bmp.Size.Height");
97                         }
98                 }
99
100                 [Test]
101                 public void Bitmap1bitPixels ()
102                 {
103                         string sInFile = getInFile ("bitmaps/almogaver1bit.bmp");
104                         using (Bitmap bmp = new Bitmap (sInFile)) {
105 #if false
106                                 for (int x = 0; x < bmp.Width; x += 32) {
107                                         for (int y = 0; y < bmp.Height; y += 32)
108                                                 Console.WriteLine ("\t\t\t\tAssert.AreEqual ({0}, bmp.GetPixel ({1}, {2}).ToArgb (), \"{1},{2}\");", bmp.GetPixel (x, y).ToArgb (), x, y);
109                                 }
110 #else
111                                 // sampling values from a well known bitmap
112                                 Assert.AreEqual (-1, bmp.GetPixel (0, 0).ToArgb (), "0,0");
113                                 Assert.AreEqual (-4144960, bmp.GetPixel (0, 32).ToArgb (), "0,32");
114                                 Assert.AreEqual (-1, bmp.GetPixel (0, 64).ToArgb (), "0,64");
115                                 Assert.AreEqual (-1, bmp.GetPixel (0, 96).ToArgb (), "0,96");
116                                 Assert.AreEqual (-4144960, bmp.GetPixel (0, 128).ToArgb (), "0,128");
117                                 Assert.AreEqual (-1, bmp.GetPixel (0, 160).ToArgb (), "0,160");
118                                 Assert.AreEqual (-4144960, bmp.GetPixel (32, 0).ToArgb (), "32,0");
119                                 Assert.AreEqual (-4144960, bmp.GetPixel (32, 32).ToArgb (), "32,32");
120                                 Assert.AreEqual (-1, bmp.GetPixel (32, 64).ToArgb (), "32,64");
121                                 Assert.AreEqual (-4144960, bmp.GetPixel (32, 96).ToArgb (), "32,96");
122                                 Assert.AreEqual (-4144960, bmp.GetPixel (32, 128).ToArgb (), "32,128");
123                                 Assert.AreEqual (-8355712, bmp.GetPixel (32, 160).ToArgb (), "32,160");
124                                 Assert.AreEqual (-16777216, bmp.GetPixel (64, 0).ToArgb (), "64,0");
125                                 Assert.AreEqual (-8355712, bmp.GetPixel (64, 32).ToArgb (), "64,32");
126                                 Assert.AreEqual (-1, bmp.GetPixel (64, 64).ToArgb (), "64,64");
127                                 Assert.AreEqual (-16777216, bmp.GetPixel (64, 96).ToArgb (), "64,96");
128                                 Assert.AreEqual (-8355840, bmp.GetPixel (64, 128).ToArgb (), "64,128");
129                                 Assert.AreEqual (-16777216, bmp.GetPixel (64, 160).ToArgb (), "64,160");
130                                 Assert.AreEqual (-4144960, bmp.GetPixel (96, 0).ToArgb (), "96,0");
131                                 Assert.AreEqual (-8355712, bmp.GetPixel (96, 32).ToArgb (), "96,32");
132                                 Assert.AreEqual (-16777216, bmp.GetPixel (96, 64).ToArgb (), "96,64");
133                                 Assert.AreEqual (-4144960, bmp.GetPixel (96, 96).ToArgb (), "96,96");
134                                 Assert.AreEqual (-8355840, bmp.GetPixel (96, 128).ToArgb (), "96,128");
135                                 Assert.AreEqual (-16777216, bmp.GetPixel (96, 160).ToArgb (), "96,160");
136                                 Assert.AreEqual (-1, bmp.GetPixel (128, 0).ToArgb (), "128,0");
137                                 Assert.AreEqual (-8355712, bmp.GetPixel (128, 32).ToArgb (), "128,32");
138                                 Assert.AreEqual (-1, bmp.GetPixel (128, 64).ToArgb (), "128,64");
139                                 Assert.AreEqual (-4144960, bmp.GetPixel (128, 96).ToArgb (), "128,96");
140                                 Assert.AreEqual (-16777216, bmp.GetPixel (128, 128).ToArgb (), "128,128");
141                                 Assert.AreEqual (-4144960, bmp.GetPixel (128, 160).ToArgb (), "128,160");
142                                 Assert.AreEqual (-4144960, bmp.GetPixel (160, 0).ToArgb (), "160,0");
143                                 Assert.AreEqual (-1, bmp.GetPixel (160, 32).ToArgb (), "160,32");
144                                 Assert.AreEqual (-4144960, bmp.GetPixel (160, 64).ToArgb (), "160,64");
145                                 Assert.AreEqual (-4144960, bmp.GetPixel (160, 96).ToArgb (), "160,96");
146                                 Assert.AreEqual (-4144960, bmp.GetPixel (160, 128).ToArgb (), "160,128");
147                                 Assert.AreEqual (-8355712, bmp.GetPixel (160, 160).ToArgb (), "160,160");
148 #endif
149                         }
150                 }
151
152                 /* Checks bitmap features on a know 8bbp bitmap */
153                 [Test]
154                 public void Bitmap8bitFeatures ()
155                 {
156                         string sInFile = getInFile ("bitmaps/almogaver8bits.bmp");
157                         using (Bitmap bmp = new Bitmap (sInFile)) {
158                                 GraphicsUnit unit = GraphicsUnit.World;
159                                 RectangleF rect = bmp.GetBounds (ref unit);
160
161                                 Assert.AreEqual (PixelFormat.Format8bppIndexed, bmp.PixelFormat);
162                                 Assert.AreEqual (173, bmp.Width, "bmp.Width");
163                                 Assert.AreEqual (183, bmp.Height, "bmp.Height");
164
165                                 Assert.AreEqual (0, rect.X, "rect.X");
166                                 Assert.AreEqual (0, rect.Y, "rect.Y");
167                                 Assert.AreEqual (173, rect.Width, "rect.Width");
168                                 Assert.AreEqual (183, rect.Height, "rect.Height");
169
170                                 Assert.AreEqual (173, bmp.Size.Width, "bmp.Size.Width");
171                                 Assert.AreEqual (183, bmp.Size.Height, "bmp.Size.Height");
172                         }
173                 }
174
175                 [Test]
176                 public void Bitmap8bitPixels ()
177                 {
178                         string sInFile = getInFile ("bitmaps/almogaver8bits.bmp");
179                         using (Bitmap bmp = new Bitmap (sInFile)) {
180 #if false
181                                 for (int x = 0; x < bmp.Width; x += 32) {
182                                         for (int y = 0; y < bmp.Height; y += 32)
183                                                 Console.WriteLine ("\t\t\t\tAssert.AreEqual ({0}, bmp.GetPixel ({1}, {2}).ToArgb (), \"{1},{2}\");", bmp.GetPixel (x, y).ToArgb (), x, y);
184                                 }
185 #else
186                                 // sampling values from a well known bitmap
187                                 Assert.AreEqual (-1040, bmp.GetPixel (0, 0).ToArgb (), "0,0");
188                                 Assert.AreEqual (-4137792, bmp.GetPixel (0, 32).ToArgb (), "0,32");
189                                 Assert.AreEqual (-1040, bmp.GetPixel (0, 64).ToArgb (), "0,64");
190                                 Assert.AreEqual (-1040, bmp.GetPixel (0, 96).ToArgb (), "0,96");
191                                 Assert.AreEqual (-4137792, bmp.GetPixel (0, 128).ToArgb (), "0,128");
192                                 Assert.AreEqual (-1040, bmp.GetPixel (0, 160).ToArgb (), "0,160");
193                                 Assert.AreEqual (-4137792, bmp.GetPixel (32, 0).ToArgb (), "32,0");
194                                 Assert.AreEqual (-4137792, bmp.GetPixel (32, 32).ToArgb (), "32,32");
195                                 Assert.AreEqual (-1040, bmp.GetPixel (32, 64).ToArgb (), "32,64");
196                                 Assert.AreEqual (-4144960, bmp.GetPixel (32, 96).ToArgb (), "32,96");
197                                 Assert.AreEqual (-6250304, bmp.GetPixel (32, 128).ToArgb (), "32,128");
198                                 Assert.AreEqual (-8355712, bmp.GetPixel (32, 160).ToArgb (), "32,160");
199                                 Assert.AreEqual (-12566464, bmp.GetPixel (64, 0).ToArgb (), "64,0");
200                                 Assert.AreEqual (-6258560, bmp.GetPixel (64, 32).ToArgb (), "64,32");
201                                 Assert.AreEqual (-1040, bmp.GetPixel (64, 64).ToArgb (), "64,64");
202                                 Assert.AreEqual (-16777216, bmp.GetPixel (64, 96).ToArgb (), "64,96");
203                                 Assert.AreEqual (-8355776, bmp.GetPixel (64, 128).ToArgb (), "64,128");
204                                 Assert.AreEqual (-16777216, bmp.GetPixel (64, 160).ToArgb (), "64,160");
205                                 Assert.AreEqual (-4137792, bmp.GetPixel (96, 0).ToArgb (), "96,0");
206                                 Assert.AreEqual (-8355712, bmp.GetPixel (96, 32).ToArgb (), "96,32");
207                                 Assert.AreEqual (-12566464, bmp.GetPixel (96, 64).ToArgb (), "96,64");
208                                 Assert.AreEqual (-2039680, bmp.GetPixel (96, 96).ToArgb (), "96,96");
209                                 Assert.AreEqual (-4153280, bmp.GetPixel (96, 128).ToArgb (), "96,128");
210                                 Assert.AreEqual (-12566464, bmp.GetPixel (96, 160).ToArgb (), "96,160");
211                                 Assert.AreEqual (-1040, bmp.GetPixel (128, 0).ToArgb (), "128,0");
212                                 Assert.AreEqual (-6258560, bmp.GetPixel (128, 32).ToArgb (), "128,32");
213                                 Assert.AreEqual (-1040, bmp.GetPixel (128, 64).ToArgb (), "128,64");
214                                 Assert.AreEqual (-4144960, bmp.GetPixel (128, 96).ToArgb (), "128,96");
215                                 Assert.AreEqual (-12566464, bmp.GetPixel (128, 128).ToArgb (), "128,128");
216                                 Assert.AreEqual (-4144960, bmp.GetPixel (128, 160).ToArgb (), "128,160");
217                                 Assert.AreEqual (-4137792, bmp.GetPixel (160, 0).ToArgb (), "160,0");
218                                 Assert.AreEqual (-1040, bmp.GetPixel (160, 32).ToArgb (), "160,32");
219                                 Assert.AreEqual (-4144960, bmp.GetPixel (160, 64).ToArgb (), "160,64");
220                                 Assert.AreEqual (-4137792, bmp.GetPixel (160, 96).ToArgb (), "160,96");
221                                 Assert.AreEqual (-4137792, bmp.GetPixel (160, 128).ToArgb (), "160,128");
222                                 Assert.AreEqual (-8355712, bmp.GetPixel (160, 160).ToArgb (), "160,160");
223 #endif
224                         }
225                 }
226
227
228                 /* Checks bitmap features on a know 24-bits bitmap */
229                 [Test]
230                 public void Bitmap24bitFeatures()
231                 {
232                         string sInFile = getInFile ("bitmaps/almogaver24bits.bmp");
233                         using (Bitmap bmp = new Bitmap (sInFile)) {
234                                 GraphicsUnit unit = GraphicsUnit.World;
235                                 RectangleF rect = bmp.GetBounds (ref unit);
236
237                                 Assert.AreEqual (PixelFormat.Format24bppRgb, bmp.PixelFormat);
238                                 Assert.AreEqual (173, bmp.Width, "bmp.Width");
239                                 Assert.AreEqual (183, bmp.Height, "bmp.Height");
240
241                                 Assert.AreEqual (0, rect.X, "rect.X");
242                                 Assert.AreEqual (0, rect.Y, "rect.Y");
243                                 Assert.AreEqual (173, rect.Width, "rect.Width");
244                                 Assert.AreEqual (183, rect.Height, "rect.Height");
245
246                                 Assert.AreEqual (173, bmp.Size.Width, "bmp.Size.Width");
247                                 Assert.AreEqual (183, bmp.Size.Height, "bmp.Size.Height");
248                         }
249                 }
250
251                 [Test]
252                 public void Bitmap24bitPixels ()
253                 {
254                         string sInFile = getInFile ("bitmaps/almogaver24bits.bmp");
255                         using (Bitmap bmp = new Bitmap (sInFile)) {
256 #if false
257                                 for (int x = 0; x < bmp.Width; x += 32) {
258                                         for (int y = 0; y < bmp.Height; y += 32)
259                                                 Console.WriteLine ("\t\t\t\tAssert.AreEqual ({0}, bmp.GetPixel ({1}, {2}).ToArgb (), \"{1},{2}\");", bmp.GetPixel (x, y).ToArgb (), x, y);
260                                 }
261 #else
262                                 // sampling values from a well known bitmap
263                                 Assert.AreEqual (-1645353, bmp.GetPixel (0, 32).ToArgb (), "0,32");
264                                 Assert.AreEqual (-461332, bmp.GetPixel (0, 64).ToArgb (), "0,64");
265                                 Assert.AreEqual (-330005, bmp.GetPixel (0, 96).ToArgb (), "0,96");
266                                 Assert.AreEqual (-2237489, bmp.GetPixel (0, 128).ToArgb (), "0,128");
267                                 Assert.AreEqual (-1251105, bmp.GetPixel (0, 160).ToArgb (), "0,160");
268                                 Assert.AreEqual (-3024947, bmp.GetPixel (32, 0).ToArgb (), "32,0");
269                                 Assert.AreEqual (-2699070, bmp.GetPixel (32, 32).ToArgb (), "32,32");
270                                 Assert.AreEqual (-2366734, bmp.GetPixel (32, 64).ToArgb (), "32,64");
271                                 Assert.AreEqual (-4538413, bmp.GetPixel (32, 96).ToArgb (), "32,96");
272                                 Assert.AreEqual (-6116681, bmp.GetPixel (32, 128).ToArgb (), "32,128");
273                                 Assert.AreEqual (-7369076, bmp.GetPixel (32, 160).ToArgb (), "32,160");
274                                 Assert.AreEqual (-13024729, bmp.GetPixel (64, 0).ToArgb (), "64,0");
275                                 Assert.AreEqual (-7174020, bmp.GetPixel (64, 32).ToArgb (), "64,32");
276                                 Assert.AreEqual (-51, bmp.GetPixel (64, 64).ToArgb (), "64,64");
277                                 Assert.AreEqual (-16053503, bmp.GetPixel (64, 96).ToArgb (), "64,96");
278                                 Assert.AreEqual (-8224431, bmp.GetPixel (64, 128).ToArgb (), "64,128");
279                                 Assert.AreEqual (-16579326, bmp.GetPixel (64, 160).ToArgb (), "64,160");
280                                 Assert.AreEqual (-2502457, bmp.GetPixel (96, 0).ToArgb (), "96,0");
281                                 Assert.AreEqual (-9078395, bmp.GetPixel (96, 32).ToArgb (), "96,32");
282                                 Assert.AreEqual (-12696508, bmp.GetPixel (96, 64).ToArgb (), "96,64");
283                                 Assert.AreEqual (-70772, bmp.GetPixel (96, 96).ToArgb (), "96,96");
284                                 Assert.AreEqual (-4346279, bmp.GetPixel (96, 128).ToArgb (), "96,128");
285                                 Assert.AreEqual (-11583193, bmp.GetPixel (96, 160).ToArgb (), "96,160");
286                                 Assert.AreEqual (-724763, bmp.GetPixel (128, 0).ToArgb (), "128,0");
287                                 Assert.AreEqual (-7238268, bmp.GetPixel (128, 32).ToArgb (), "128,32");
288                                 Assert.AreEqual (-2169612, bmp.GetPixel (128, 64).ToArgb (), "128,64");
289                                 Assert.AreEqual (-3683883, bmp.GetPixel (128, 96).ToArgb (), "128,96");
290                                 Assert.AreEqual (-12892867, bmp.GetPixel (128, 128).ToArgb (), "128,128");
291                                 Assert.AreEqual (-3750464, bmp.GetPixel (128, 160).ToArgb (), "128,160");
292                                 Assert.AreEqual (-3222844, bmp.GetPixel (160, 0).ToArgb (), "160,0");
293                                 Assert.AreEqual (-65806, bmp.GetPixel (160, 32).ToArgb (), "160,32");
294                                 Assert.AreEqual (-2961726, bmp.GetPixel (160, 64).ToArgb (), "160,64");
295                                 Assert.AreEqual (-2435382, bmp.GetPixel (160, 96).ToArgb (), "160,96");
296                                 Assert.AreEqual (-2501944, bmp.GetPixel (160, 128).ToArgb (), "160,128");
297                                 Assert.AreEqual (-9211799, bmp.GetPixel (160, 160).ToArgb (), "160,160");
298 #endif
299                         }
300                 }
301
302                 [Test]
303                 public void Bitmap24bitData ()
304                 {
305                         string sInFile = getInFile ("bitmaps/almogaver24bits.bmp");
306                         using (Bitmap bmp = new Bitmap (sInFile)) {
307                                 Assert.AreEqual (-3355456, bmp.GetPixel (163, 1).ToArgb (), "163,1");
308                                 BitmapData data = bmp.LockBits (new Rectangle (0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
309                                 try {
310                                         Assert.AreEqual (bmp.Height, data.Height, "Height");
311                                         Assert.AreEqual (bmp.Width, data.Width, "Width");
312                                         Assert.AreEqual (PixelFormat.Format24bppRgb, data.PixelFormat, "PixelFormat");
313                                         Assert.AreEqual (520, data.Stride, "Stride");
314                                         int size = data.Height * data.Stride;
315                                         unsafe {
316                                                 byte* scan = (byte*) data.Scan0;
317 #if false
318                                                 // 1009 is the first prime after 1000 (so we're not affected by a recurring pattern)
319                                                 for (int p = 0; p < size; p += 1009) {
320                                                         Console.WriteLine ("\t\t\t\t\t\tAssert.AreEqual ({0}, *(scan + {1}), \"{1}\");", *(scan + p), p);
321                                                 }
322 #else
323                                                 // sampling values from a well known bitmap
324                                                 Assert.AreEqual (217, *(scan + 0), "0");
325                                                 Assert.AreEqual (192, *(scan + 1009), "1009");
326                                                 Assert.AreEqual (210, *(scan + 2018), "2018");
327                                                 Assert.AreEqual (196, *(scan + 3027), "3027");
328                                                 Assert.AreEqual (216, *(scan + 4036), "4036");
329                                                 Assert.AreEqual (215, *(scan + 5045), "5045");
330                                                 Assert.AreEqual (218, *(scan + 6054), "6054");
331                                                 Assert.AreEqual (218, *(scan + 7063), "7063");
332                                                 Assert.AreEqual (95, *(scan + 8072), "8072");
333                                                 Assert.AreEqual (9, *(scan + 9081), "9081");
334                                                 Assert.AreEqual (247, *(scan + 10090), "10090");
335                                                 Assert.AreEqual (161, *(scan + 11099), "11099");
336                                                 Assert.AreEqual (130, *(scan + 12108), "12108");
337                                                 Assert.AreEqual (131, *(scan + 13117), "13117");
338                                                 Assert.AreEqual (175, *(scan + 14126), "14126");
339                                                 Assert.AreEqual (217, *(scan + 15135), "15135");
340                                                 Assert.AreEqual (201, *(scan + 16144), "16144");
341                                                 Assert.AreEqual (183, *(scan + 17153), "17153");
342                                                 Assert.AreEqual (236, *(scan + 18162), "18162");
343                                                 Assert.AreEqual (242, *(scan + 19171), "19171");
344                                                 Assert.AreEqual (125, *(scan + 20180), "20180");
345                                                 Assert.AreEqual (193, *(scan + 21189), "21189");
346                                                 Assert.AreEqual (227, *(scan + 22198), "22198");
347                                                 Assert.AreEqual (44, *(scan + 23207), "23207");
348                                                 Assert.AreEqual (230, *(scan + 24216), "24216");
349                                                 Assert.AreEqual (224, *(scan + 25225), "25225");
350                                                 Assert.AreEqual (164, *(scan + 26234), "26234");
351                                                 Assert.AreEqual (43, *(scan + 27243), "27243");
352                                                 Assert.AreEqual (200, *(scan + 28252), "28252");
353                                                 Assert.AreEqual (255, *(scan + 29261), "29261");
354                                                 Assert.AreEqual (226, *(scan + 30270), "30270");
355                                                 Assert.AreEqual (230, *(scan + 31279), "31279");
356                                                 Assert.AreEqual (178, *(scan + 32288), "32288");
357                                                 Assert.AreEqual (224, *(scan + 33297), "33297");
358                                                 Assert.AreEqual (233, *(scan + 34306), "34306");
359                                                 Assert.AreEqual (212, *(scan + 35315), "35315");
360                                                 Assert.AreEqual (153, *(scan + 36324), "36324");
361                                                 Assert.AreEqual (143, *(scan + 37333), "37333");
362                                                 Assert.AreEqual (215, *(scan + 38342), "38342");
363                                                 Assert.AreEqual (116, *(scan + 39351), "39351");
364                                                 Assert.AreEqual (26, *(scan + 40360), "40360");
365                                                 Assert.AreEqual (28, *(scan + 41369), "41369");
366                                                 Assert.AreEqual (75, *(scan + 42378), "42378");
367                                                 Assert.AreEqual (50, *(scan + 43387), "43387");
368                                                 Assert.AreEqual (244, *(scan + 44396), "44396");
369                                                 Assert.AreEqual (191, *(scan + 45405), "45405");
370                                                 Assert.AreEqual (200, *(scan + 46414), "46414");
371                                                 Assert.AreEqual (197, *(scan + 47423), "47423");
372                                                 Assert.AreEqual (232, *(scan + 48432), "48432");
373                                                 Assert.AreEqual (186, *(scan + 49441), "49441");
374                                                 Assert.AreEqual (210, *(scan + 50450), "50450");
375                                                 Assert.AreEqual (215, *(scan + 51459), "51459");
376                                                 Assert.AreEqual (155, *(scan + 52468), "52468");
377                                                 Assert.AreEqual (56, *(scan + 53477), "53477");
378                                                 Assert.AreEqual (149, *(scan + 54486), "54486");
379                                                 Assert.AreEqual (137, *(scan + 55495), "55495");
380                                                 Assert.AreEqual (141, *(scan + 56504), "56504");
381                                                 Assert.AreEqual (36, *(scan + 57513), "57513");
382                                                 Assert.AreEqual (39, *(scan + 58522), "58522");
383                                                 Assert.AreEqual (25, *(scan + 59531), "59531");
384                                                 Assert.AreEqual (44, *(scan + 60540), "60540");
385                                                 Assert.AreEqual (12, *(scan + 61549), "61549");
386                                                 Assert.AreEqual (161, *(scan + 62558), "62558");
387                                                 Assert.AreEqual (179, *(scan + 63567), "63567");
388                                                 Assert.AreEqual (181, *(scan + 64576), "64576");
389                                                 Assert.AreEqual (165, *(scan + 65585), "65585");
390                                                 Assert.AreEqual (182, *(scan + 66594), "66594");
391                                                 Assert.AreEqual (186, *(scan + 67603), "67603");
392                                                 Assert.AreEqual (201, *(scan + 68612), "68612");
393                                                 Assert.AreEqual (49, *(scan + 69621), "69621");
394                                                 Assert.AreEqual (161, *(scan + 70630), "70630");
395                                                 Assert.AreEqual (140, *(scan + 71639), "71639");
396                                                 Assert.AreEqual (2, *(scan + 72648), "72648");
397                                                 Assert.AreEqual (15, *(scan + 73657), "73657");
398                                                 Assert.AreEqual (33, *(scan + 74666), "74666");
399                                                 Assert.AreEqual (17, *(scan + 75675), "75675");
400                                                 Assert.AreEqual (0, *(scan + 76684), "76684");
401                                                 Assert.AreEqual (47, *(scan + 77693), "77693");
402                                                 Assert.AreEqual (4, *(scan + 78702), "78702");
403                                                 Assert.AreEqual (142, *(scan + 79711), "79711");
404                                                 Assert.AreEqual (151, *(scan + 80720), "80720");
405                                                 Assert.AreEqual (124, *(scan + 81729), "81729");
406                                                 Assert.AreEqual (81, *(scan + 82738), "82738");
407                                                 Assert.AreEqual (214, *(scan + 83747), "83747");
408                                                 Assert.AreEqual (217, *(scan + 84756), "84756");
409                                                 Assert.AreEqual (30, *(scan + 85765), "85765");
410                                                 Assert.AreEqual (185, *(scan + 86774), "86774");
411                                                 Assert.AreEqual (200, *(scan + 87783), "87783");
412                                                 Assert.AreEqual (37, *(scan + 88792), "88792");
413                                                 Assert.AreEqual (2, *(scan + 89801), "89801");
414                                                 Assert.AreEqual (41, *(scan + 90810), "90810");
415                                                 Assert.AreEqual (16, *(scan + 91819), "91819");
416                                                 Assert.AreEqual (0, *(scan + 92828), "92828");
417                                                 Assert.AreEqual (146, *(scan + 93837), "93837");
418                                                 Assert.AreEqual (163, *(scan + 94846), "94846");
419 #endif
420                                         }
421                                 }
422                                 finally {
423                                         bmp.UnlockBits (data);
424                                 }
425                         }
426                 }
427
428                 /* Checks bitmap features on a know 32-bits bitmap (codec)*/
429                 [Test]
430                 public void Bitmap32bitFeatures ()
431                 {
432                         string sInFile = getInFile ("bitmaps/almogaver32bits.bmp");
433                         using (Bitmap bmp = new Bitmap (sInFile)) {
434                                 GraphicsUnit unit = GraphicsUnit.World;
435                                 RectangleF rect = bmp.GetBounds (ref unit);
436
437                                 Assert.AreEqual (173, bmp.Width, "bmp.Width");
438                                 Assert.AreEqual (183, bmp.Height, "bmp.Height");
439
440                                 Assert.AreEqual (0, rect.X, "rect.X");
441                                 Assert.AreEqual (0, rect.Y, "rect.Y");
442                                 Assert.AreEqual (173, rect.Width, "rect.Width");
443                                 Assert.AreEqual (183, rect.Height, "rect.Height");
444
445                                 Assert.AreEqual (173, bmp.Size.Width, "bmp.Size.Width");
446                                 Assert.AreEqual (183, bmp.Size.Height, "bmp.Size.Height");
447                         }
448                 }
449
450                 [Test]
451                 public void Bitmap32bitPixels ()
452                 {
453                         string sInFile = getInFile ("bitmaps/almogaver32bits.bmp");
454                         using (Bitmap bmp = new Bitmap (sInFile)) {
455                                 Assert.AreEqual (PixelFormat.Format32bppRgb, bmp.PixelFormat, "PixelFormat");
456 #if false
457                                 for (int x = 0; x < bmp.Width; x += 32) {
458                                         for (int y = 0; y < bmp.Height; y += 32)
459                                                 Console.WriteLine ("\t\t\t\tAssert.AreEqual ({0}, bmp.GetPixel ({1}, {2}).ToArgb (), \"{1},{2}\");", bmp.GetPixel (x, y).ToArgb (), x, y);
460                                 }
461 #else
462                                 // sampling values from a well known bitmap
463                                 Assert.AreEqual (-1579559, bmp.GetPixel (0, 0).ToArgb (), "0,0");
464                                 Assert.AreEqual (-1645353, bmp.GetPixel (0, 32).ToArgb (), "0,32");
465                                 Assert.AreEqual (-461332, bmp.GetPixel (0, 64).ToArgb (), "0,64");
466                                 Assert.AreEqual (-330005, bmp.GetPixel (0, 96).ToArgb (), "0,96");
467                                 Assert.AreEqual (-2237489, bmp.GetPixel (0, 128).ToArgb (), "0,128");
468                                 Assert.AreEqual (-1251105, bmp.GetPixel (0, 160).ToArgb (), "0,160");
469                                 Assert.AreEqual (-3024947, bmp.GetPixel (32, 0).ToArgb (), "32,0");
470                                 Assert.AreEqual (-2699070, bmp.GetPixel (32, 32).ToArgb (), "32,32");
471                                 Assert.AreEqual (-2366734, bmp.GetPixel (32, 64).ToArgb (), "32,64");
472                                 Assert.AreEqual (-4538413, bmp.GetPixel (32, 96).ToArgb (), "32,96");
473                                 Assert.AreEqual (-6116681, bmp.GetPixel (32, 128).ToArgb (), "32,128");
474                                 Assert.AreEqual (-7369076, bmp.GetPixel (32, 160).ToArgb (), "32,160");
475                                 Assert.AreEqual (-13024729, bmp.GetPixel (64, 0).ToArgb (), "64,0");
476                                 Assert.AreEqual (-7174020, bmp.GetPixel (64, 32).ToArgb (), "64,32");
477                                 Assert.AreEqual (-51, bmp.GetPixel (64, 64).ToArgb (), "64,64");
478                                 Assert.AreEqual (-16053503, bmp.GetPixel (64, 96).ToArgb (), "64,96");
479                                 Assert.AreEqual (-8224431, bmp.GetPixel (64, 128).ToArgb (), "64,128");
480                                 Assert.AreEqual (-16579326, bmp.GetPixel (64, 160).ToArgb (), "64,160");
481                                 Assert.AreEqual (-2502457, bmp.GetPixel (96, 0).ToArgb (), "96,0");
482                                 Assert.AreEqual (-9078395, bmp.GetPixel (96, 32).ToArgb (), "96,32");
483                                 Assert.AreEqual (-12696508, bmp.GetPixel (96, 64).ToArgb (), "96,64");
484                                 Assert.AreEqual (-70772, bmp.GetPixel (96, 96).ToArgb (), "96,96");
485                                 Assert.AreEqual (-4346279, bmp.GetPixel (96, 128).ToArgb (), "96,128");
486                                 Assert.AreEqual (-11583193, bmp.GetPixel (96, 160).ToArgb (), "96,160");
487                                 Assert.AreEqual (-724763, bmp.GetPixel (128, 0).ToArgb (), "128,0");
488                                 Assert.AreEqual (-7238268, bmp.GetPixel (128, 32).ToArgb (), "128,32");
489                                 Assert.AreEqual (-2169612, bmp.GetPixel (128, 64).ToArgb (), "128,64");
490                                 Assert.AreEqual (-3683883, bmp.GetPixel (128, 96).ToArgb (), "128,96");
491                                 Assert.AreEqual (-12892867, bmp.GetPixel (128, 128).ToArgb (), "128,128");
492                                 Assert.AreEqual (-3750464, bmp.GetPixel (128, 160).ToArgb (), "128,160");
493                                 Assert.AreEqual (-3222844, bmp.GetPixel (160, 0).ToArgb (), "160,0");
494                                 Assert.AreEqual (-65806, bmp.GetPixel (160, 32).ToArgb (), "160,32");
495                                 Assert.AreEqual (-2961726, bmp.GetPixel (160, 64).ToArgb (), "160,64");
496                                 Assert.AreEqual (-2435382, bmp.GetPixel (160, 96).ToArgb (), "160,96");
497                                 Assert.AreEqual (-2501944, bmp.GetPixel (160, 128).ToArgb (), "160,128");
498                                 Assert.AreEqual (-9211799, bmp.GetPixel (160, 160).ToArgb (), "160,160");
499 #endif
500                         }
501                 }
502
503                 private void Save (PixelFormat original, PixelFormat expected, bool colorCheck) 
504                 {                               
505                         string sOutFile = String.Format ("linerect{0}-{1}.bmp", getOutSufix (), expected.ToString ());
506                                                 
507                         // Save         
508                         Bitmap bmp = new Bitmap (100, 100, original);                                           
509                         Graphics gr = Graphics.FromImage (bmp);
510
511                         using (Pen p = new Pen (Color.BlueViolet, 2)) {
512                                 gr.DrawLine (p, 10.0F, 10.0F, 90.0F, 90.0F);
513                                 gr.DrawRectangle (p, 10.0F, 10.0F, 80.0F, 80.0F);
514                         }
515
516                         try {
517                                 bmp.Save (sOutFile, ImageFormat.Bmp);
518
519                                 // Load
520                                 using (Bitmap bmpLoad = new Bitmap (sOutFile)) {
521                                         Assert.AreEqual (expected, bmpLoad.PixelFormat, "PixelFormat");
522                                         if (colorCheck) {
523                                                 Color color = bmpLoad.GetPixel (10, 10);
524                                                 Assert.AreEqual (Color.FromArgb (255, 138, 43, 226), color, "BlueViolet");
525                                         }
526                                 }
527                         }
528                         finally {
529                                 gr.Dispose ();
530                                 bmp.Dispose ();
531                                 try {
532                                         File.Delete (sOutFile);
533                                 }
534                                 catch {
535                                 }
536                         }
537                 }
538
539                 [Test]
540                 public void Save_24bppRgb ()
541                 {
542                         Save (PixelFormat.Format24bppRgb, PixelFormat.Format24bppRgb, true);
543                 }
544
545                 [Test]
546                 public void Save_32bppRgb ()
547                 {
548                         Save (PixelFormat.Format32bppRgb, PixelFormat.Format32bppRgb, true);
549                 }
550
551                 [Test]
552                 public void Save_32bppArgb ()
553                 {
554                         Save (PixelFormat.Format32bppArgb, PixelFormat.Format32bppRgb, true);
555                 }
556
557                 [Test]
558                 public void Save_32bppPArgb ()
559                 {
560                         Save (PixelFormat.Format32bppPArgb, PixelFormat.Format32bppRgb, true);
561                 }
562
563                 [Test]
564                 [Category ("NotWorking")]
565                 public void Save_48bppRgb ()
566                 {
567                         Save (PixelFormat.Format48bppRgb, PixelFormat.Format32bppRgb, false);
568                 }
569
570                 [Test]
571                 [Category ("NotWorking")]
572                 public void Save_64bppArgb ()
573                 {
574                         Save (PixelFormat.Format64bppArgb, PixelFormat.Format64bppArgb, true);
575                 }
576
577                 [Test]
578                 [Category ("NotWorking")]
579                 public void Save_64bppPArgb ()
580                 {
581                         Save (PixelFormat.Format64bppPArgb, PixelFormat.Format64bppArgb, true);
582                 }
583
584                 [Test]
585                 public void NonInvertedBitmap ()
586                 {
587                         // regression check against http://bugzilla.ximian.com/show_bug.cgi?id=80751
588                         string sInFile = getInFile ("bitmaps/non-inverted.bmp");
589                         using (Bitmap bmp = new Bitmap (sInFile)) {
590                                 GraphicsUnit unit = GraphicsUnit.World;
591                                 RectangleF rect = bmp.GetBounds (ref unit);
592
593                                 Assert.AreEqual (90, bmp.Width, "bmp.Width");
594                                 Assert.AreEqual (60, bmp.Height, "bmp.Height");
595
596                                 Assert.AreEqual (0, rect.X, "rect.X");
597                                 Assert.AreEqual (0, rect.Y, "rect.Y");
598                                 Assert.AreEqual (90, rect.Width, "rect.Width");
599                                 Assert.AreEqual (60, rect.Height, "rect.Height");
600
601                                 Assert.AreEqual (90, bmp.Size.Width, "bmp.Size.Width");
602                                 Assert.AreEqual (60, bmp.Size.Height, "bmp.Size.Height");
603
604                                 // sampling values from a well known bitmap
605                                 Assert.AreEqual (-16777216, bmp.GetPixel (12, 21).ToArgb (), "12,21");
606                                 Assert.AreEqual (-1, bmp.GetPixel (21, 37).ToArgb (), "21,37");
607                         }
608                 }
609         }
610 }