You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. /** @file
  21. *
  22. * PNM self-tests
  23. *
  24. */
  25. /* Forcibly enable assertions */
  26. #undef NDEBUG
  27. #include <string.h>
  28. #include <assert.h>
  29. #include <ipxe/pixbuf.h>
  30. #include <ipxe/pnm.h>
  31. #include <ipxe/test.h>
  32. #include "pixbuf_test.h"
  33. /** Define inline pixel data */
  34. #define DATA(...) { __VA_ARGS__ }
  35. /** PBM ASCII example (from Wikipedia) */
  36. PIX ( pbm_ascii, &pnm_image_type,
  37. "P1\n"
  38. "# This is an example bitmap of the letter \"J\"\n"
  39. "6 10\n"
  40. "0 0 0 0 1 0\n"
  41. "0 0 0 0 1 0\n"
  42. "0 0 0 0 1 0\n"
  43. "0 0 0 0 1 0\n"
  44. "0 0 0 0 1 0\n"
  45. "0 0 0 0 1 0\n"
  46. "1 0 0 0 1 0\n"
  47. "0 1 1 1 0 0\n"
  48. "0 0 0 0 0 0\n"
  49. "0 0 0 0 0 0\n",
  50. 6, 10,
  51. DATA ( 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  52. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  53. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  54. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  55. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  56. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  57. 0x000000, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  58. 0xffffff, 0x000000, 0x000000, 0x000000, 0xffffff, 0xffffff,
  59. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
  60. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff ) );
  61. /** PGM ASCII example (from Wikipedia) */
  62. PIX ( pgm_ascii, &pnm_image_type,
  63. "P2\n"
  64. "# Shows the word \"FEEP\" (example from Netpbm man page on PGM)\n"
  65. "24 7\n"
  66. "15\n"
  67. "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
  68. "0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0\n"
  69. "0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0\n"
  70. "0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0\n"
  71. "0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0\n"
  72. "0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0\n"
  73. "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
  74. , 24, 7,
  75. DATA ( 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  76. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  77. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  78. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  79. 0x000000, 0x333333, 0x333333, 0x333333, 0x333333, 0x000000,
  80. 0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
  81. 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
  82. 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
  83. 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
  84. 0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
  85. 0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
  86. 0x000000, 0xffffff, 0x000000, 0x000000, 0xffffff, 0x000000,
  87. 0x000000, 0x333333, 0x333333, 0x333333, 0x000000, 0x000000,
  88. 0x000000, 0x777777, 0x777777, 0x777777, 0x000000, 0x000000,
  89. 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000, 0x000000,
  90. 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
  91. 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
  92. 0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
  93. 0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
  94. 0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
  95. 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
  96. 0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
  97. 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
  98. 0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
  99. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  100. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  101. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  102. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000 ) );
  103. /** PPM ASCII example (from Wikipedia) */
  104. PIX ( ppm_ascii, &pnm_image_type,
  105. "P3\n"
  106. "# The P3 means colors are in ASCII, then 3 columns and 2 rows,\n"
  107. "# then 255 for max color, then RGB triplets\n"
  108. "3 2\n"
  109. "255\n"
  110. "255 0 0 0 255 0 0 0 255\n"
  111. "255 255 0 255 255 255 0 0 0\n",
  112. 3, 2,
  113. DATA ( 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xffffff, 0x000000 ) );
  114. /** PBM ASCII with no space between pixel values */
  115. PIX ( pbm_ascii_no_space, &pnm_image_type,
  116. "P1\n"
  117. "3 3\n"
  118. "001\n"
  119. "010\n"
  120. "111\n",
  121. 3, 3,
  122. DATA ( 0xffffff, 0xffffff, 0x000000, 0xffffff, 0x000000, 0xffffff,
  123. 0x000000, 0x000000, 0x000000 ) );
  124. /** PBM binary example (converted from Wikipedia) */
  125. PIX ( pbm_binary, &pnm_image_type,
  126. DATA ( 0x50, 0x34, 0x0a, 0x23, 0x20, 0x43, 0x52, 0x45, 0x41, 0x54, 0x4f,
  127. 0x52, 0x3a, 0x20, 0x47, 0x49, 0x4d, 0x50, 0x20, 0x50, 0x4e, 0x4d,
  128. 0x20, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x20, 0x56, 0x65, 0x72,
  129. 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x2e, 0x31, 0x0a, 0x36, 0x20,
  130. 0x31, 0x30, 0x0a, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x88, 0x70,
  131. 0x00, 0x00 ),
  132. 6, 10,
  133. DATA ( 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  134. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  135. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  136. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  137. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  138. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  139. 0x000000, 0xffffff, 0xffffff, 0xffffff, 0x000000, 0xffffff,
  140. 0xffffff, 0x000000, 0x000000, 0x000000, 0xffffff, 0xffffff,
  141. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
  142. 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff ) );
  143. /** PGM binary example (converted from Wikipedia) */
  144. PIX ( pgm_binary, &pnm_image_type,
  145. DATA ( 0x50, 0x35, 0x0a, 0x32, 0x34, 0x20, 0x37, 0x0a, 0x31, 0x35, 0x0a,
  146. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  147. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  148. 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x07, 0x07,
  149. 0x07, 0x07, 0x00, 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x00, 0x0f,
  150. 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
  151. 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00,
  152. 0x00, 0x0f, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x03, 0x03, 0x03, 0x00,
  153. 0x00, 0x00, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x0b, 0x0b, 0x0b,
  154. 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x03, 0x00,
  155. 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b,
  156. 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
  157. 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x00,
  158. 0x00, 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
  159. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  160. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  161. 0x00, 0x00, 0x00 ),
  162. 24, 7,
  163. DATA ( 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  164. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  165. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  166. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  167. 0x000000, 0x333333, 0x333333, 0x333333, 0x333333, 0x000000,
  168. 0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
  169. 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
  170. 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
  171. 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
  172. 0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
  173. 0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
  174. 0x000000, 0xffffff, 0x000000, 0x000000, 0xffffff, 0x000000,
  175. 0x000000, 0x333333, 0x333333, 0x333333, 0x000000, 0x000000,
  176. 0x000000, 0x777777, 0x777777, 0x777777, 0x000000, 0x000000,
  177. 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000, 0x000000,
  178. 0x000000, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x000000,
  179. 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
  180. 0x000000, 0x777777, 0x000000, 0x000000, 0x000000, 0x000000,
  181. 0x000000, 0xbbbbbb, 0x000000, 0x000000, 0x000000, 0x000000,
  182. 0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
  183. 0x000000, 0x333333, 0x000000, 0x000000, 0x000000, 0x000000,
  184. 0x000000, 0x777777, 0x777777, 0x777777, 0x777777, 0x000000,
  185. 0x000000, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0xbbbbbb, 0x000000,
  186. 0x000000, 0xffffff, 0x000000, 0x000000, 0x000000, 0x000000,
  187. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  188. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  189. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  190. 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000 ) );
  191. /** PPM binary example (converted from Wikipedia) */
  192. PIX ( ppm_binary, &pnm_image_type,
  193. DATA ( 0x50, 0x36, 0x0a, 0x33, 0x20, 0x32, 0x0a, 0x32, 0x35, 0x35, 0x0a,
  194. 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
  195. 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 ),
  196. 3, 2,
  197. DATA ( 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xffffff, 0x000000 ) );
  198. /**
  199. * Perform PNM self-test
  200. *
  201. */
  202. static void pnm_test_exec ( void ) {
  203. pixbuf_ok ( &pbm_ascii );
  204. pixbuf_ok ( &pgm_ascii );
  205. pixbuf_ok ( &ppm_ascii );
  206. pixbuf_ok ( &pbm_ascii_no_space );
  207. pixbuf_ok ( &pbm_binary );
  208. pixbuf_ok ( &pgm_binary );
  209. pixbuf_ok ( &ppm_binary );
  210. }
  211. /** PNM self-test */
  212. struct self_test pnm_test __self_test = {
  213. .name = "pnm",
  214. .exec = pnm_test_exec,
  215. };