BmpsuiteTest.php 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <?php
  2. use Mike42\GfxPhp\Image;
  3. use PHPUnit\Framework\TestCase;
  4. /**
  5. * Simple check that files in the BMP Suite can be read, and have the expected dimensions.
  6. */
  7. class BmpsuiteTest extends TestCase
  8. {
  9. function loadImage(string $filename)
  10. {
  11. return Image::fromFile(__DIR__ . "/../resources/bmpsuite/$filename");
  12. }
  13. function test_badbitcount()
  14. {
  15. $this -> expectException(Exception::class);
  16. $img = $this -> loadImage("b/badbitcount.bmp");
  17. }
  18. function test_badbitssize()
  19. {
  20. $img = $this -> loadImage("b/badbitssize.bmp");
  21. $this -> assertEquals(127, $img -> getWidth());
  22. $this -> assertEquals(64, $img -> getHeight());
  23. }
  24. function test_baddens1()
  25. {
  26. $img = $this -> loadImage("b/baddens1.bmp");
  27. $this -> assertEquals(127, $img -> getWidth());
  28. $this -> assertEquals(64, $img -> getHeight());
  29. }
  30. function test_baddens2()
  31. {
  32. $img = $this -> loadImage("b/baddens2.bmp");
  33. $this -> assertEquals(127, $img -> getWidth());
  34. $this -> assertEquals(64, $img -> getHeight());
  35. }
  36. function test_badfilesize()
  37. {
  38. $img = $this -> loadImage("b/badfilesize.bmp");
  39. $this -> assertEquals(127, $img -> getWidth());
  40. $this -> assertEquals(64, $img -> getHeight());
  41. }
  42. function test_badheadersize()
  43. {
  44. $this -> expectException(Exception::class);
  45. $img = $this -> loadImage("b/badheadersize.bmp");
  46. }
  47. function test_badpalettesize()
  48. {
  49. $this -> expectException(Exception::class);
  50. $img = $this -> loadImage("b/badpalettesize.bmp");
  51. }
  52. function test_badplanes()
  53. {
  54. $img = $this -> loadImage("b/badplanes.bmp");
  55. $this -> assertEquals(127, $img -> getWidth());
  56. $this -> assertEquals(64, $img -> getHeight());
  57. }
  58. function test_badrle()
  59. {
  60. $this -> expectException(Exception::class);
  61. $img = $this -> loadImage("b/badrle.bmp");
  62. }
  63. function test_badrle4()
  64. {
  65. $this -> expectException(Exception::class);
  66. $img = $this -> loadImage("b/badrle4.bmp");
  67. }
  68. function test_badrle4bis()
  69. {
  70. $this -> expectException(Exception::class);
  71. $img = $this -> loadImage("b/badrle4bis.bmp");
  72. }
  73. function test_badrle4ter()
  74. {
  75. $this -> expectException(Exception::class);
  76. $img = $this -> loadImage("b/badrle4ter.bmp");
  77. }
  78. function test_badrlebis()
  79. {
  80. $this -> expectException(Exception::class);
  81. $img = $this -> loadImage("b/badrlebis.bmp");
  82. }
  83. function test_badrleter()
  84. {
  85. $this -> expectException(Exception::class);
  86. $img = $this -> loadImage("b/badrleter.bmp");
  87. }
  88. function test_badwidth()
  89. {
  90. $this -> expectException(Exception::class);
  91. $img = $this -> loadImage("b/badwidth.bmp");
  92. }
  93. function test_pal8badindex()
  94. {
  95. $this -> expectException(Exception::class);
  96. $img = $this -> loadImage("b/pal8badindex.bmp");
  97. }
  98. function test_reallybig()
  99. {
  100. $this -> expectException(Exception::class);
  101. $img = $this -> loadImage("b/reallybig.bmp");
  102. }
  103. function test_rgb16_880()
  104. {
  105. $img = $this -> loadImage("b/rgb16-880.bmp");
  106. $this -> assertEquals(127, $img -> getWidth());
  107. $this -> assertEquals(64, $img -> getHeight());
  108. }
  109. function test_rletopdown()
  110. {
  111. $this -> expectException(Exception::class);
  112. $img = $this -> loadImage("b/rletopdown.bmp");
  113. }
  114. function test_shortfile()
  115. {
  116. $this -> expectException(Exception::class);
  117. $img = $this -> loadImage("b/shortfile.bmp");
  118. }
  119. function test_pal1()
  120. {
  121. $img = $this -> loadImage("g/pal1.bmp");
  122. $this -> assertEquals(127, $img -> getWidth());
  123. $this -> assertEquals(64, $img -> getHeight());
  124. }
  125. function test_pal1bg()
  126. {
  127. $img = $this -> loadImage("g/pal1bg.bmp");
  128. $this -> assertEquals(127, $img -> getWidth());
  129. $this -> assertEquals(64, $img -> getHeight());
  130. }
  131. function test_pal1wb()
  132. {
  133. $img = $this -> loadImage("g/pal1wb.bmp");
  134. $this -> assertEquals(127, $img -> getWidth());
  135. $this -> assertEquals(64, $img -> getHeight());
  136. }
  137. function test_pal4()
  138. {
  139. $img = $this -> loadImage("g/pal4.bmp");
  140. $this -> assertEquals(127, $img -> getWidth());
  141. $this -> assertEquals(64, $img -> getHeight());
  142. }
  143. function test_pal4gs()
  144. {
  145. $img = $this -> loadImage("g/pal4gs.bmp");
  146. $this -> assertEquals(127, $img -> getWidth());
  147. $this -> assertEquals(64, $img -> getHeight());
  148. }
  149. function test_pal4rle()
  150. {
  151. $img = $this -> loadImage("g/pal4rle.bmp");
  152. $this -> assertEquals(127, $img -> getWidth());
  153. $this -> assertEquals(64, $img -> getHeight());
  154. }
  155. function test_pal8_0()
  156. {
  157. $img = $this -> loadImage("g/pal8-0.bmp");
  158. $this -> assertEquals(127, $img -> getWidth());
  159. $this -> assertEquals(64, $img -> getHeight());
  160. }
  161. function test_pal8()
  162. {
  163. $img = $this -> loadImage("g/pal8.bmp");
  164. $this -> assertEquals(127, $img -> getWidth());
  165. $this -> assertEquals(64, $img -> getHeight());
  166. }
  167. function test_pal8gs()
  168. {
  169. $img = $this -> loadImage("g/pal8gs.bmp");
  170. $this -> assertEquals(127, $img -> getWidth());
  171. $this -> assertEquals(64, $img -> getHeight());
  172. }
  173. function test_pal8nonsquare()
  174. {
  175. $img = $this -> loadImage("g/pal8nonsquare.bmp");
  176. $this -> assertEquals(127, $img -> getWidth());
  177. $this -> assertEquals(32, $img -> getHeight());
  178. }
  179. function test_pal8os2()
  180. {
  181. $img = $this -> loadImage("g/pal8os2.bmp");
  182. $this -> assertEquals(127, $img -> getWidth());
  183. $this -> assertEquals(64, $img -> getHeight());
  184. }
  185. function test_pal8rle()
  186. {
  187. $img = $this -> loadImage("g/pal8rle.bmp");
  188. $this -> assertEquals(127, $img -> getWidth());
  189. $this -> assertEquals(64, $img -> getHeight());
  190. }
  191. function test_pal8topdown()
  192. {
  193. $img = $this -> loadImage("g/pal8topdown.bmp");
  194. $this -> assertEquals(127, $img -> getWidth());
  195. $this -> assertEquals(64, $img -> getHeight());
  196. }
  197. function test_pal8v4()
  198. {
  199. $img = $this -> loadImage("g/pal8v4.bmp");
  200. $this -> assertEquals(127, $img -> getWidth());
  201. $this -> assertEquals(64, $img -> getHeight());
  202. }
  203. function test_pal8v5()
  204. {
  205. $img = $this -> loadImage("g/pal8v5.bmp");
  206. $this -> assertEquals(127, $img -> getWidth());
  207. $this -> assertEquals(64, $img -> getHeight());
  208. }
  209. function test_pal8w124()
  210. {
  211. $img = $this -> loadImage("g/pal8w124.bmp");
  212. $this -> assertEquals(124, $img -> getWidth());
  213. $this -> assertEquals(61, $img -> getHeight());
  214. }
  215. function test_pal8w125()
  216. {
  217. $img = $this -> loadImage("g/pal8w125.bmp");
  218. $this -> assertEquals(125, $img -> getWidth());
  219. $this -> assertEquals(62, $img -> getHeight());
  220. }
  221. function test_pal8w126()
  222. {
  223. $img = $this -> loadImage("g/pal8w126.bmp");
  224. $this -> assertEquals(126, $img -> getWidth());
  225. $this -> assertEquals(63, $img -> getHeight());
  226. }
  227. function test_rgb16_565()
  228. {
  229. $img = $this -> loadImage("g/rgb16-565.bmp");
  230. $this -> assertEquals(127, $img -> getWidth());
  231. $this -> assertEquals(64, $img -> getHeight());
  232. }
  233. function test_rgb16_565pal()
  234. {
  235. $img = $this -> loadImage("g/rgb16-565pal.bmp");
  236. $this -> assertEquals(127, $img -> getWidth());
  237. $this -> assertEquals(64, $img -> getHeight());
  238. }
  239. function test_rgb16()
  240. {
  241. $img = $this -> loadImage("g/rgb16.bmp");
  242. $this -> assertEquals(127, $img -> getWidth());
  243. $this -> assertEquals(64, $img -> getHeight());
  244. }
  245. function test_rgb16bfdef()
  246. {
  247. $img = $this -> loadImage("g/rgb16bfdef.bmp");
  248. $this -> assertEquals(127, $img -> getWidth());
  249. $this -> assertEquals(64, $img -> getHeight());
  250. }
  251. function test_rgb24()
  252. {
  253. $img = $this -> loadImage("g/rgb24.bmp");
  254. $this -> assertEquals(127, $img -> getWidth());
  255. $this -> assertEquals(64, $img -> getHeight());
  256. }
  257. function test_rgb24pal()
  258. {
  259. $img = $this -> loadImage("g/rgb24pal.bmp");
  260. $this -> assertEquals(127, $img -> getWidth());
  261. $this -> assertEquals(64, $img -> getHeight());
  262. }
  263. function test_rgb32()
  264. {
  265. $img = $this -> loadImage("g/rgb32.bmp");
  266. $this -> assertEquals(127, $img -> getWidth());
  267. $this -> assertEquals(64, $img -> getHeight());
  268. }
  269. function test_rgb32bf()
  270. {
  271. $img = $this -> loadImage("g/rgb32bf.bmp");
  272. $this -> assertEquals(127, $img -> getWidth());
  273. $this -> assertEquals(64, $img -> getHeight());
  274. }
  275. function test_rgb32bfdef()
  276. {
  277. $img = $this -> loadImage("g/rgb32bfdef.bmp");
  278. $this -> assertEquals(127, $img -> getWidth());
  279. $this -> assertEquals(64, $img -> getHeight());
  280. }
  281. function test_pal1huff()
  282. {
  283. $this -> expectException(Exception::class);
  284. $img = $this -> loadImage("q/pal1huff.bmp");
  285. }
  286. function test_pal1p1()
  287. {
  288. $img = $this -> loadImage("q/pal1p1.bmp");
  289. $this -> assertEquals(127, $img -> getWidth());
  290. $this -> assertEquals(64, $img -> getHeight());
  291. }
  292. function test_pal2()
  293. {
  294. $img = $this -> loadImage("q/pal2.bmp");
  295. $this -> assertEquals(127, $img -> getWidth());
  296. $this -> assertEquals(64, $img -> getHeight());
  297. }
  298. function test_pal2color()
  299. {
  300. $img = $this -> loadImage("q/pal2color.bmp");
  301. $this -> assertEquals(127, $img -> getWidth());
  302. $this -> assertEquals(64, $img -> getHeight());
  303. }
  304. function test_pal4rlecut()
  305. {
  306. $img = $this -> loadImage("q/pal4rlecut.bmp");
  307. $this -> assertEquals(127, $img -> getWidth());
  308. $this -> assertEquals(64, $img -> getHeight());
  309. }
  310. function test_pal4rletrns()
  311. {
  312. $img = $this -> loadImage("q/pal4rletrns.bmp");
  313. $this -> assertEquals(127, $img -> getWidth());
  314. $this -> assertEquals(64, $img -> getHeight());
  315. }
  316. function test_pal8offs()
  317. {
  318. $img = $this -> loadImage("q/pal8offs.bmp");
  319. $this -> assertEquals(127, $img -> getWidth());
  320. $this -> assertEquals(64, $img -> getHeight());
  321. }
  322. function test_pal8os2_hs()
  323. {
  324. $img = $this -> loadImage("q/pal8os2-hs.bmp");
  325. $this -> assertEquals(127, $img -> getWidth());
  326. $this -> assertEquals(64, $img -> getHeight());
  327. }
  328. function test_pal8os2_sz()
  329. {
  330. $img = $this -> loadImage("q/pal8os2-sz.bmp");
  331. $this -> assertEquals(127, $img -> getWidth());
  332. $this -> assertEquals(64, $img -> getHeight());
  333. }
  334. function test_pal8os2sp()
  335. {
  336. $img = $this -> loadImage("q/pal8os2sp.bmp");
  337. $this -> assertEquals(127, $img -> getWidth());
  338. $this -> assertEquals(64, $img -> getHeight());
  339. }
  340. function test_pal8os2v2_16()
  341. {
  342. $img = $this -> loadImage("q/pal8os2v2-16.bmp");
  343. $this -> assertEquals(127, $img -> getWidth());
  344. $this -> assertEquals(64, $img -> getHeight());
  345. }
  346. function test_pal8os2v2_40sz()
  347. {
  348. $img = $this -> loadImage("q/pal8os2v2-40sz.bmp");
  349. $this -> assertEquals(127, $img -> getWidth());
  350. $this -> assertEquals(64, $img -> getHeight());
  351. }
  352. function test_pal8os2v2_sz()
  353. {
  354. $img = $this -> loadImage("q/pal8os2v2-sz.bmp");
  355. $this -> assertEquals(127, $img -> getWidth());
  356. $this -> assertEquals(64, $img -> getHeight());
  357. }
  358. function test_pal8os2v2()
  359. {
  360. $img = $this -> loadImage("q/pal8os2v2.bmp");
  361. $this -> assertEquals(127, $img -> getWidth());
  362. $this -> assertEquals(64, $img -> getHeight());
  363. }
  364. function test_pal8oversizepal()
  365. {
  366. $img = $this -> loadImage("q/pal8oversizepal.bmp");
  367. $this -> assertEquals(127, $img -> getWidth());
  368. $this -> assertEquals(64, $img -> getHeight());
  369. }
  370. function test_pal8rlecut()
  371. {
  372. $img = $this -> loadImage("q/pal8rlecut.bmp");
  373. $this -> assertEquals(127, $img -> getWidth());
  374. $this -> assertEquals(64, $img -> getHeight());
  375. }
  376. function test_pal8rletrns()
  377. {
  378. $img = $this -> loadImage("q/pal8rletrns.bmp");
  379. $this -> assertEquals(127, $img -> getWidth());
  380. $this -> assertEquals(64, $img -> getHeight());
  381. }
  382. function test_rgb16_231()
  383. {
  384. $img = $this -> loadImage("q/rgb16-231.bmp");
  385. $this -> assertEquals(127, $img -> getWidth());
  386. $this -> assertEquals(64, $img -> getHeight());
  387. }
  388. function test_rgb16_3103()
  389. {
  390. $img = $this -> loadImage("q/rgb16-3103.bmp");
  391. $this -> assertEquals(127, $img -> getWidth());
  392. $this -> assertEquals(64, $img -> getHeight());
  393. }
  394. function test_rgb16faketrns()
  395. {
  396. $img = $this -> loadImage("q/rgb16faketrns.bmp");
  397. $this -> assertEquals(127, $img -> getWidth());
  398. $this -> assertEquals(64, $img -> getHeight());
  399. }
  400. function test_rgb24jpeg()
  401. {
  402. $this -> expectException(Exception::class);
  403. $img = $this -> loadImage("q/rgb24jpeg.bmp");
  404. $this -> assertEquals(127, $img -> getWidth());
  405. $this -> assertEquals(64, $img -> getHeight());
  406. }
  407. function test_rgb24largepal()
  408. {
  409. $img = $this -> loadImage("q/rgb24largepal.bmp");
  410. $this -> assertEquals(127, $img -> getWidth());
  411. $this -> assertEquals(64, $img -> getHeight());
  412. }
  413. function test_rgb24lprof()
  414. {
  415. $img = $this -> loadImage("q/rgb24lprof.bmp");
  416. $this -> assertEquals(127, $img -> getWidth());
  417. $this -> assertEquals(64, $img -> getHeight());
  418. }
  419. function test_rgb24png()
  420. {
  421. $this -> expectException(Exception::class);
  422. $img = $this -> loadImage("q/rgb24png.bmp");
  423. $this -> assertEquals(127, $img -> getWidth());
  424. $this -> assertEquals(64, $img -> getHeight());
  425. }
  426. function test_rgb24prof()
  427. {
  428. $img = $this -> loadImage("q/rgb24prof.bmp");
  429. $this -> assertEquals(127, $img -> getWidth());
  430. $this -> assertEquals(64, $img -> getHeight());
  431. }
  432. function test_rgb24prof2()
  433. {
  434. $img = $this -> loadImage("q/rgb24prof2.bmp");
  435. $this -> assertEquals(127, $img -> getWidth());
  436. $this -> assertEquals(64, $img -> getHeight());
  437. }
  438. function test_rgb32_111110()
  439. {
  440. $img = $this -> loadImage("q/rgb32-111110.bmp");
  441. $this -> assertEquals(127, $img -> getWidth());
  442. $this -> assertEquals(64, $img -> getHeight());
  443. }
  444. function test_rgb32_7187()
  445. {
  446. $img = $this -> loadImage("q/rgb32-7187.bmp");
  447. $this -> assertEquals(127, $img -> getWidth());
  448. $this -> assertEquals(64, $img -> getHeight());
  449. }
  450. function test_rgb32_xbgr()
  451. {
  452. $img = $this -> loadImage("q/rgb32-xbgr.bmp");
  453. $this -> assertEquals(127, $img -> getWidth());
  454. $this -> assertEquals(64, $img -> getHeight());
  455. }
  456. function test_rgb32fakealpha()
  457. {
  458. $img = $this -> loadImage("q/rgb32fakealpha.bmp");
  459. $this -> assertEquals(127, $img -> getWidth());
  460. $this -> assertEquals(64, $img -> getHeight());
  461. }
  462. function test_rgb32h52()
  463. {
  464. $img = $this -> loadImage("q/rgb32h52.bmp");
  465. $this -> assertEquals(127, $img -> getWidth());
  466. $this -> assertEquals(64, $img -> getHeight());
  467. }
  468. function test_rgba16_1924()
  469. {
  470. $img = $this -> loadImage("q/rgba16-1924.bmp");
  471. $this -> assertEquals(127, $img -> getWidth());
  472. $this -> assertEquals(64, $img -> getHeight());
  473. }
  474. function test_rgba16_4444()
  475. {
  476. $img = $this -> loadImage("q/rgba16-4444.bmp");
  477. $this -> assertEquals(127, $img -> getWidth());
  478. $this -> assertEquals(64, $img -> getHeight());
  479. }
  480. function test_rgba16_5551()
  481. {
  482. $img = $this -> loadImage("q/rgba16-5551.bmp");
  483. $this -> assertEquals(127, $img -> getWidth());
  484. $this -> assertEquals(64, $img -> getHeight());
  485. }
  486. function test_rgba32_1010102()
  487. {
  488. $img = $this -> loadImage("q/rgba32-1010102.bmp");
  489. $this -> assertEquals(127, $img -> getWidth());
  490. $this -> assertEquals(64, $img -> getHeight());
  491. }
  492. function test_rgba32_61754()
  493. {
  494. $img = $this -> loadImage("q/rgba32-61754.bmp");
  495. $this -> assertEquals(127, $img -> getWidth());
  496. $this -> assertEquals(64, $img -> getHeight());
  497. }
  498. function test_rgba32_81284()
  499. {
  500. $img = $this -> loadImage("q/rgba32-81284.bmp");
  501. $this -> assertEquals(127, $img -> getWidth());
  502. $this -> assertEquals(64, $img -> getHeight());
  503. }
  504. function test_rgba32()
  505. {
  506. $img = $this -> loadImage("q/rgba32.bmp");
  507. $this -> assertEquals(127, $img -> getWidth());
  508. $this -> assertEquals(64, $img -> getHeight());
  509. }
  510. function test_rgba32abf()
  511. {
  512. $img = $this -> loadImage("q/rgba32abf.bmp");
  513. $this -> assertEquals(127, $img -> getWidth());
  514. $this -> assertEquals(64, $img -> getHeight());
  515. }
  516. function test_rgba32h56()
  517. {
  518. $img = $this -> loadImage("q/rgba32h56.bmp");
  519. $this -> assertEquals(127, $img -> getWidth());
  520. $this -> assertEquals(64, $img -> getHeight());
  521. }
  522. function test_ba_bm()
  523. {
  524. // Different container format, not recognised as bitmap at all
  525. $this -> expectException(Exception::class);
  526. $img = $this -> loadImage("x/ba-bm.bmp");
  527. }
  528. }