TestJpegCodec.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. //
  2. // JpegCodec 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-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. using System;
  31. using System.Drawing;
  32. using System.Drawing.Imaging;
  33. using NUnit.Framework;
  34. using System.IO;
  35. using System.Security.Permissions;
  36. namespace MonoTests.System.Drawing.Imaging {
  37. [TestFixture]
  38. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  39. public class JpegCodecTest {
  40. /* Get suffix to add to the filename */
  41. internal string getOutSufix ()
  42. {
  43. string s;
  44. int p = (int) Environment.OSVersion.Platform;
  45. if ((p == 4) || (p == 128) || (p == 6))
  46. s = "-unix";
  47. else
  48. s = "-windows";
  49. if (Type.GetType ("Mono.Runtime", false) == null)
  50. s += "-msnet";
  51. else
  52. s += "-mono";
  53. return s;
  54. }
  55. /* Get the input directory depending on the runtime*/
  56. internal string getInFile (string file)
  57. {
  58. string sRslt = Path.GetFullPath ("../System.Drawing/" + file);
  59. if (!File.Exists (sRslt))
  60. sRslt = "Test/System.Drawing/" + file;
  61. return sRslt;
  62. }
  63. [Test]
  64. #if TARGET_JVM
  65. [Ignore ("#8853")]
  66. #endif
  67. public void Bitmap8bbpIndexedGreyscaleFeatures ()
  68. {
  69. string sInFile = getInFile ("bitmaps/nature-greyscale.jpg");
  70. using (Bitmap bmp = new Bitmap (sInFile)) {
  71. GraphicsUnit unit = GraphicsUnit.World;
  72. RectangleF rect = bmp.GetBounds (ref unit);
  73. Assert.AreEqual (PixelFormat.Format8bppIndexed, bmp.PixelFormat, "PixelFormat");
  74. Assert.AreEqual (110, bmp.Width, "bmp.Width");
  75. Assert.AreEqual (100, bmp.Height, "bmp.Height");
  76. Assert.AreEqual (0, rect.X, "rect.X");
  77. Assert.AreEqual (0, rect.Y, "rect.Y");
  78. Assert.AreEqual (110, rect.Width, "rect.Width");
  79. Assert.AreEqual (100, rect.Height, "rect.Height");
  80. Assert.AreEqual (110, bmp.Size.Width, "bmp.Size.Width");
  81. Assert.AreEqual (100, bmp.Size.Height, "bmp.Size.Height");
  82. Assert.AreEqual (110, bmp.PhysicalDimension.Width, "bmp.PhysicalDimension.Width");
  83. Assert.AreEqual (100, bmp.PhysicalDimension.Height, "bmp.PhysicalDimension.Height");
  84. Assert.AreEqual (72, bmp.HorizontalResolution, "HorizontalResolution");
  85. Assert.AreEqual (72, bmp.VerticalResolution, "VerticalResolution");
  86. Assert.AreEqual (77896, bmp.Flags, "Flags");
  87. ColorPalette cp = bmp.Palette;
  88. Assert.AreEqual (256, cp.Entries.Length, "Palette.Entries");
  89. Assert.AreEqual (0, cp.Flags, "Palette.Flags");
  90. for (int i = 0; i < 256; i++) {
  91. Color c = cp.Entries [i];
  92. Assert.AreEqual (0xFF, c.A, "A" + i.ToString ());
  93. Assert.AreEqual (i, c.R, "R" + i.ToString ());
  94. Assert.AreEqual (i, c.G, "G" + i.ToString ());
  95. Assert.AreEqual (i, c.B, "B" + i.ToString ());
  96. }
  97. }
  98. }
  99. [Test]
  100. #if TARGET_JVM
  101. [Category ("NotWorking")]
  102. #endif
  103. public void Bitmap8bbpIndexedGreyscalePixels ()
  104. {
  105. string sInFile = getInFile ("bitmaps/nature-greyscale.jpg");
  106. using (Bitmap bmp = new Bitmap (sInFile)) {
  107. #if false
  108. for (int x = 0; x < bmp.Width; x += 32) {
  109. for (int y = 0; y < bmp.Height; y += 32)
  110. Console.WriteLine ("\t\t\t\tAssert.AreEqual ({0}, bmp.GetPixel ({1}, {2}).ToArgb (), \"{1},{2}\");", bmp.GetPixel (x, y).ToArgb (), x, y);
  111. }
  112. #else
  113. // sampling values from a well known bitmap
  114. Assert.AreEqual (-7697782, bmp.GetPixel (0, 0).ToArgb (), "0,0");
  115. Assert.AreEqual (-12171706, bmp.GetPixel (0, 32).ToArgb (), "0,32");
  116. Assert.AreEqual (-14013910, bmp.GetPixel (0, 64).ToArgb (), "0,64");
  117. Assert.AreEqual (-15132391, bmp.GetPixel (0, 96).ToArgb (), "0,96");
  118. Assert.AreEqual (-328966, bmp.GetPixel (32, 0).ToArgb (), "32,0");
  119. Assert.AreEqual (-9934744, bmp.GetPixel (32, 32).ToArgb (), "32,32");
  120. Assert.AreEqual (-10263709, bmp.GetPixel (32, 64).ToArgb (), "32,64");
  121. Assert.AreEqual (-7368817, bmp.GetPixel (32, 96).ToArgb (), "32,96");
  122. Assert.AreEqual (-1, bmp.GetPixel (64, 0).ToArgb (), "64,0");
  123. Assert.AreEqual (-4276546, bmp.GetPixel (64, 32).ToArgb (), "64,32");
  124. Assert.AreEqual (-9079435, bmp.GetPixel (64, 64).ToArgb (), "64,64");
  125. Assert.AreEqual (-7697782, bmp.GetPixel (64, 96).ToArgb (), "64,96");
  126. Assert.AreEqual (-1, bmp.GetPixel (96, 0).ToArgb (), "96,0");
  127. Assert.AreEqual (-8224126, bmp.GetPixel (96, 32).ToArgb (), "96,32");
  128. Assert.AreEqual (-11053225, bmp.GetPixel (96, 64).ToArgb (), "96,64");
  129. Assert.AreEqual (-9211021, bmp.GetPixel (96, 96).ToArgb (), "96,96");
  130. #endif
  131. }
  132. }
  133. #if !TARGET_JVM
  134. [Test]
  135. public void Bitmap8bbpIndexedGreyscaleData ()
  136. {
  137. string sInFile = getInFile ("bitmaps/nature-greyscale.jpg");
  138. using (Bitmap bmp = new Bitmap (sInFile)) {
  139. BitmapData data = bmp.LockBits (new Rectangle (0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
  140. try {
  141. Assert.AreEqual (bmp.Height, data.Height, "Height");
  142. Assert.AreEqual (bmp.Width, data.Width, "Width");
  143. Assert.AreEqual (PixelFormat.Format24bppRgb, data.PixelFormat, "PixelFormat");
  144. int size = data.Height * data.Stride;
  145. unsafe {
  146. byte* scan = (byte*) data.Scan0;
  147. #if false
  148. // 1009 is the first prime after 1000 (so we're not affected by a recurring pattern)
  149. for (int p = 0; p < size; p += 1009) {
  150. Console.WriteLine ("\t\t\t\t\t\tAssert.AreEqual ({0}, *(scan + {1}), \"{1}\");", *(scan + p), p);
  151. }
  152. #else
  153. // sampling values from a well known bitmap
  154. Assert.AreEqual (138, *(scan + 0), "0");
  155. Assert.AreEqual (203, *(scan + 1009), "1009");
  156. Assert.AreEqual (156, *(scan + 2018), "2018");
  157. Assert.AreEqual (248, *(scan + 3027), "3027");
  158. Assert.AreEqual (221, *(scan + 4036), "4036");
  159. Assert.AreEqual (185, *(scan + 5045), "5045");
  160. Assert.AreEqual (128, *(scan + 6054), "6054");
  161. Assert.AreEqual (205, *(scan + 7063), "7063");
  162. Assert.AreEqual (153, *(scan + 8072), "8072");
  163. Assert.AreEqual (110, *(scan + 9081), "9081");
  164. Assert.AreEqual (163, *(scan + 10090), "10090");
  165. Assert.AreEqual (87, *(scan + 11099), "11099");
  166. Assert.AreEqual (90, *(scan + 12108), "12108");
  167. Assert.AreEqual (81, *(scan + 13117), "13117");
  168. Assert.AreEqual (123, *(scan + 14126), "14126");
  169. Assert.AreEqual (99, *(scan + 15135), "15135");
  170. Assert.AreEqual (153, *(scan + 16144), "16144");
  171. Assert.AreEqual (57, *(scan + 17153), "17153");
  172. Assert.AreEqual (89, *(scan + 18162), "18162");
  173. Assert.AreEqual (71, *(scan + 19171), "19171");
  174. Assert.AreEqual (106, *(scan + 20180), "20180");
  175. Assert.AreEqual (55, *(scan + 21189), "21189");
  176. Assert.AreEqual (75, *(scan + 22198), "22198");
  177. Assert.AreEqual (77, *(scan + 23207), "23207");
  178. Assert.AreEqual (58, *(scan + 24216), "24216");
  179. Assert.AreEqual (69, *(scan + 25225), "25225");
  180. Assert.AreEqual (43, *(scan + 26234), "26234");
  181. Assert.AreEqual (55, *(scan + 27243), "27243");
  182. Assert.AreEqual (74, *(scan + 28252), "28252");
  183. Assert.AreEqual (145, *(scan + 29261), "29261");
  184. Assert.AreEqual (87, *(scan + 30270), "30270");
  185. Assert.AreEqual (85, *(scan + 31279), "31279");
  186. Assert.AreEqual (106, *(scan + 32288), "32288");
  187. #endif
  188. }
  189. }
  190. finally {
  191. bmp.UnlockBits (data);
  192. }
  193. }
  194. }
  195. #endif
  196. /* Checks bitmap features on a known 24-bits bitmap */
  197. [Test]
  198. #if TARGET_JVM
  199. [Category("NotWorking")]
  200. #endif
  201. public void Bitmap24bitFeatures ()
  202. {
  203. string sInFile = getInFile ("bitmaps/nature24bits.jpg");
  204. using (Bitmap bmp = new Bitmap (sInFile)) {
  205. GraphicsUnit unit = GraphicsUnit.World;
  206. RectangleF rect = bmp.GetBounds (ref unit);
  207. Assert.AreEqual (PixelFormat.Format24bppRgb, bmp.PixelFormat, "PixelFormat");
  208. Assert.AreEqual (110, bmp.Width, "bmp.Width");
  209. Assert.AreEqual (100, bmp.Height, "bmp.Height");
  210. Assert.AreEqual (0, rect.X, "rect.X");
  211. Assert.AreEqual (0, rect.Y, "rect.Y");
  212. Assert.AreEqual (110, rect.Width, "rect.Width");
  213. Assert.AreEqual (100, rect.Height, "rect.Height");
  214. Assert.AreEqual (110, bmp.Size.Width, "bmp.Size.Width");
  215. Assert.AreEqual (100, bmp.Size.Height, "bmp.Size.Height");
  216. Assert.AreEqual (110, bmp.PhysicalDimension.Width, "bmp.PhysicalDimension.Width");
  217. Assert.AreEqual (100, bmp.PhysicalDimension.Height, "bmp.PhysicalDimension.Height");
  218. Assert.AreEqual (72, bmp.HorizontalResolution, "HorizontalResolution");
  219. Assert.AreEqual (72, bmp.VerticalResolution, "VerticalResolution");
  220. Assert.AreEqual (77960, bmp.Flags, "Flags");
  221. Assert.AreEqual (0, bmp.Palette.Entries.Length, "Palette.Entries");
  222. /* note: under MS flags aren't constant between executions in this case (no palette) */
  223. }
  224. }
  225. [Test]
  226. public void Bitmap24bitPixels ()
  227. {
  228. string sInFile = getInFile ("bitmaps/nature24bits.jpg");
  229. using (Bitmap bmp = new Bitmap (sInFile)) {
  230. #if false
  231. for (int x = 0; x < bmp.Width; x += 32) {
  232. for (int y = 0; y < bmp.Height; y += 32)
  233. Console.WriteLine ("\t\t\t\tAssert.AreEqual ({0}, bmp.GetPixel ({1}, {2}).ToArgb (), \"{1},{2}\");", bmp.GetPixel (x, y).ToArgb (), x, y);
  234. }
  235. #else
  236. // sampling values from a well known bitmap
  237. Assert.AreEqual (-10447423, bmp.GetPixel (0, 0).ToArgb (), "0,0");
  238. Assert.AreEqual (-12171958, bmp.GetPixel (0, 32).ToArgb (), "0,32");
  239. Assert.AreEqual (-15192259, bmp.GetPixel (0, 64).ToArgb (), "0,64");
  240. Assert.AreEqual (-15131110, bmp.GetPixel (0, 96).ToArgb (), "0,96");
  241. Assert.AreEqual (-395272, bmp.GetPixel (32, 0).ToArgb (), "32,0");
  242. Assert.AreEqual (-10131359, bmp.GetPixel (32, 32).ToArgb (), "32,32");
  243. Assert.AreEqual (-10984322, bmp.GetPixel (32, 64).ToArgb (), "32,64");
  244. Assert.AreEqual (-11034683, bmp.GetPixel (32, 96).ToArgb (), "32,96");
  245. Assert.AreEqual (-1, bmp.GetPixel (64, 0).ToArgb (), "64,0");
  246. Assert.AreEqual (-3163242, bmp.GetPixel (64, 32).ToArgb (), "64,32");
  247. Assert.AreEqual (-7311538, bmp.GetPixel (64, 64).ToArgb (), "64,64");
  248. Assert.AreEqual (-12149780, bmp.GetPixel (64, 96).ToArgb (), "64,96");
  249. Assert.AreEqual (-1, bmp.GetPixel (96, 0).ToArgb (), "96,0");
  250. Assert.AreEqual (-8224378, bmp.GetPixel (96, 32).ToArgb (), "96,32");
  251. Assert.AreEqual (-11053718, bmp.GetPixel (96, 64).ToArgb (), "96,64");
  252. Assert.AreEqual (-12944166, bmp.GetPixel (96, 96).ToArgb (), "96,96");
  253. #endif
  254. }
  255. }
  256. #if !TARGET_JVM
  257. [Test]
  258. public void Bitmap24bitData ()
  259. {
  260. string sInFile = getInFile ("bitmaps/almogaver24bits.bmp");
  261. using (Bitmap bmp = new Bitmap (sInFile)) {
  262. BitmapData data = bmp.LockBits (new Rectangle (0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
  263. try {
  264. Assert.AreEqual (bmp.Height, data.Height, "Height");
  265. Assert.AreEqual (bmp.Width, data.Width, "Width");
  266. Assert.AreEqual (PixelFormat.Format24bppRgb, data.PixelFormat, "PixelFormat");
  267. Assert.AreEqual (520, data.Stride, "Stride");
  268. int size = data.Height * data.Stride;
  269. unsafe {
  270. byte* scan = (byte*) data.Scan0;
  271. #if false
  272. // 1009 is the first prime after 1000 (so we're not affected by a recurring pattern)
  273. for (int p = 0; p < size; p += 1009) {
  274. Console.WriteLine ("\t\t\t\t\t\tAssert.AreEqual ({0}, *(scan + {1}), \"{1}\");", *(scan + p), p);
  275. }
  276. #else
  277. // sampling values from a well known bitmap
  278. Assert.AreEqual (217, *(scan + 0), "0");
  279. Assert.AreEqual (192, *(scan + 1009), "1009");
  280. Assert.AreEqual (210, *(scan + 2018), "2018");
  281. Assert.AreEqual (196, *(scan + 3027), "3027");
  282. Assert.AreEqual (216, *(scan + 4036), "4036");
  283. Assert.AreEqual (215, *(scan + 5045), "5045");
  284. Assert.AreEqual (218, *(scan + 6054), "6054");
  285. Assert.AreEqual (218, *(scan + 7063), "7063");
  286. Assert.AreEqual (95, *(scan + 8072), "8072");
  287. Assert.AreEqual (9, *(scan + 9081), "9081");
  288. Assert.AreEqual (247, *(scan + 10090), "10090");
  289. Assert.AreEqual (161, *(scan + 11099), "11099");
  290. Assert.AreEqual (130, *(scan + 12108), "12108");
  291. Assert.AreEqual (131, *(scan + 13117), "13117");
  292. Assert.AreEqual (175, *(scan + 14126), "14126");
  293. Assert.AreEqual (217, *(scan + 15135), "15135");
  294. Assert.AreEqual (201, *(scan + 16144), "16144");
  295. Assert.AreEqual (183, *(scan + 17153), "17153");
  296. Assert.AreEqual (236, *(scan + 18162), "18162");
  297. Assert.AreEqual (242, *(scan + 19171), "19171");
  298. Assert.AreEqual (125, *(scan + 20180), "20180");
  299. Assert.AreEqual (193, *(scan + 21189), "21189");
  300. Assert.AreEqual (227, *(scan + 22198), "22198");
  301. Assert.AreEqual (44, *(scan + 23207), "23207");
  302. Assert.AreEqual (230, *(scan + 24216), "24216");
  303. Assert.AreEqual (224, *(scan + 25225), "25225");
  304. Assert.AreEqual (164, *(scan + 26234), "26234");
  305. Assert.AreEqual (43, *(scan + 27243), "27243");
  306. Assert.AreEqual (200, *(scan + 28252), "28252");
  307. Assert.AreEqual (255, *(scan + 29261), "29261");
  308. Assert.AreEqual (226, *(scan + 30270), "30270");
  309. Assert.AreEqual (230, *(scan + 31279), "31279");
  310. Assert.AreEqual (178, *(scan + 32288), "32288");
  311. Assert.AreEqual (224, *(scan + 33297), "33297");
  312. Assert.AreEqual (233, *(scan + 34306), "34306");
  313. Assert.AreEqual (212, *(scan + 35315), "35315");
  314. Assert.AreEqual (153, *(scan + 36324), "36324");
  315. Assert.AreEqual (143, *(scan + 37333), "37333");
  316. Assert.AreEqual (215, *(scan + 38342), "38342");
  317. Assert.AreEqual (116, *(scan + 39351), "39351");
  318. Assert.AreEqual (26, *(scan + 40360), "40360");
  319. Assert.AreEqual (28, *(scan + 41369), "41369");
  320. Assert.AreEqual (75, *(scan + 42378), "42378");
  321. Assert.AreEqual (50, *(scan + 43387), "43387");
  322. Assert.AreEqual (244, *(scan + 44396), "44396");
  323. Assert.AreEqual (191, *(scan + 45405), "45405");
  324. Assert.AreEqual (200, *(scan + 46414), "46414");
  325. Assert.AreEqual (197, *(scan + 47423), "47423");
  326. Assert.AreEqual (232, *(scan + 48432), "48432");
  327. Assert.AreEqual (186, *(scan + 49441), "49441");
  328. Assert.AreEqual (210, *(scan + 50450), "50450");
  329. Assert.AreEqual (215, *(scan + 51459), "51459");
  330. Assert.AreEqual (155, *(scan + 52468), "52468");
  331. Assert.AreEqual (56, *(scan + 53477), "53477");
  332. Assert.AreEqual (149, *(scan + 54486), "54486");
  333. Assert.AreEqual (137, *(scan + 55495), "55495");
  334. Assert.AreEqual (141, *(scan + 56504), "56504");
  335. Assert.AreEqual (36, *(scan + 57513), "57513");
  336. Assert.AreEqual (39, *(scan + 58522), "58522");
  337. Assert.AreEqual (25, *(scan + 59531), "59531");
  338. Assert.AreEqual (44, *(scan + 60540), "60540");
  339. Assert.AreEqual (12, *(scan + 61549), "61549");
  340. Assert.AreEqual (161, *(scan + 62558), "62558");
  341. Assert.AreEqual (179, *(scan + 63567), "63567");
  342. Assert.AreEqual (181, *(scan + 64576), "64576");
  343. Assert.AreEqual (165, *(scan + 65585), "65585");
  344. Assert.AreEqual (182, *(scan + 66594), "66594");
  345. Assert.AreEqual (186, *(scan + 67603), "67603");
  346. Assert.AreEqual (201, *(scan + 68612), "68612");
  347. Assert.AreEqual (49, *(scan + 69621), "69621");
  348. Assert.AreEqual (161, *(scan + 70630), "70630");
  349. Assert.AreEqual (140, *(scan + 71639), "71639");
  350. Assert.AreEqual (2, *(scan + 72648), "72648");
  351. Assert.AreEqual (15, *(scan + 73657), "73657");
  352. Assert.AreEqual (33, *(scan + 74666), "74666");
  353. Assert.AreEqual (17, *(scan + 75675), "75675");
  354. Assert.AreEqual (0, *(scan + 76684), "76684");
  355. Assert.AreEqual (47, *(scan + 77693), "77693");
  356. Assert.AreEqual (4, *(scan + 78702), "78702");
  357. Assert.AreEqual (142, *(scan + 79711), "79711");
  358. Assert.AreEqual (151, *(scan + 80720), "80720");
  359. Assert.AreEqual (124, *(scan + 81729), "81729");
  360. Assert.AreEqual (81, *(scan + 82738), "82738");
  361. Assert.AreEqual (214, *(scan + 83747), "83747");
  362. Assert.AreEqual (217, *(scan + 84756), "84756");
  363. Assert.AreEqual (30, *(scan + 85765), "85765");
  364. Assert.AreEqual (185, *(scan + 86774), "86774");
  365. Assert.AreEqual (200, *(scan + 87783), "87783");
  366. Assert.AreEqual (37, *(scan + 88792), "88792");
  367. Assert.AreEqual (2, *(scan + 89801), "89801");
  368. Assert.AreEqual (41, *(scan + 90810), "90810");
  369. Assert.AreEqual (16, *(scan + 91819), "91819");
  370. Assert.AreEqual (0, *(scan + 92828), "92828");
  371. Assert.AreEqual (146, *(scan + 93837), "93837");
  372. Assert.AreEqual (163, *(scan + 94846), "94846");
  373. #endif
  374. }
  375. }
  376. finally {
  377. bmp.UnlockBits (data);
  378. }
  379. }
  380. }
  381. #endif
  382. private void Save (PixelFormat original, PixelFormat expected)
  383. {
  384. string sOutFile = String.Format ("linerect{0}-{1}.jpeg", getOutSufix (), expected.ToString ());
  385. // Save
  386. Bitmap bmp = new Bitmap (100, 100, original);
  387. Graphics gr = Graphics.FromImage (bmp);
  388. using (Pen p = new Pen (Color.Red, 2)) {
  389. gr.DrawLine (p, 10.0F, 10.0F, 90.0F, 90.0F);
  390. gr.DrawRectangle (p, 10.0F, 10.0F, 80.0F, 80.0F);
  391. }
  392. try {
  393. bmp.Save (sOutFile, ImageFormat.Jpeg);
  394. // Load
  395. using (Bitmap bmpLoad = new Bitmap (sOutFile)) {
  396. Assert.AreEqual (expected, bmpLoad.PixelFormat, "PixelFormat");
  397. Color color = bmpLoad.GetPixel (10, 10);
  398. // by default JPEG isn't lossless - so value is "near" read
  399. Assert.IsTrue (color.R >= 200, "Red");
  400. Assert.IsTrue (color.G < 60, "Green");
  401. Assert.IsTrue (color.B < 60, "Blue");
  402. Assert.AreEqual (0xFF, color.A, "Alpha");
  403. }
  404. }
  405. finally {
  406. gr.Dispose ();
  407. bmp.Dispose ();
  408. try {
  409. File.Delete (sOutFile);
  410. }
  411. catch {
  412. }
  413. }
  414. }
  415. [Test]
  416. #if TARGET_JVM
  417. [Category("NotWorking")]
  418. #endif
  419. public void Save_24bppRgb ()
  420. {
  421. Save (PixelFormat.Format24bppRgb, PixelFormat.Format24bppRgb);
  422. }
  423. [Test]
  424. #if TARGET_JVM
  425. [Category("NotWorking")]
  426. #endif
  427. public void Save_32bppRgb ()
  428. {
  429. Save (PixelFormat.Format32bppRgb, PixelFormat.Format24bppRgb);
  430. }
  431. [Test]
  432. #if TARGET_JVM
  433. [Category("NotWorking")]
  434. #endif
  435. public void Save_32bppArgb ()
  436. {
  437. Save (PixelFormat.Format32bppArgb, PixelFormat.Format24bppRgb);
  438. }
  439. [Test]
  440. #if TARGET_JVM
  441. [Category("NotWorking")]
  442. #endif
  443. public void Save_32bppPArgb ()
  444. {
  445. Save (PixelFormat.Format32bppPArgb, PixelFormat.Format24bppRgb);
  446. }
  447. [Test]
  448. [Category ("NotWorking")]
  449. public void Save_48bppRgb ()
  450. {
  451. Save (PixelFormat.Format48bppRgb, PixelFormat.Format24bppRgb);
  452. }
  453. [Test]
  454. [Category ("NotWorking")]
  455. public void Save_64bppArgb ()
  456. {
  457. Save (PixelFormat.Format64bppArgb, PixelFormat.Format24bppRgb);
  458. }
  459. [Test]
  460. [Category ("NotWorking")]
  461. public void Save_64bppPArgb ()
  462. {
  463. Save (PixelFormat.Format64bppPArgb, PixelFormat.Format24bppRgb);
  464. }
  465. }
  466. }