TestBmpCodec.cs 26 KB

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