test_core_image.odin 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915
  1. /*
  2. Copyright 2021 Jeroen van Rijn <[email protected]>.
  3. Made available under Odin's BSD-3 license.
  4. List of contributors:
  5. Jeroen van Rijn: Initial implementation.
  6. A test suite for PNG + QOI.
  7. */
  8. package test_core_image
  9. import "core:testing"
  10. import "core:compress"
  11. import "core:image"
  12. import pbm "core:image/netpbm"
  13. import "core:image/png"
  14. import "core:image/qoi"
  15. import "core:image/tga"
  16. import "core:bytes"
  17. import "core:hash"
  18. import "core:fmt"
  19. import "core:strings"
  20. import "core:mem"
  21. import "core:os"
  22. import "core:time"
  23. import "core:runtime"
  24. TEST_SUITE_PATH :: "assets/PNG"
  25. TEST_count := 0
  26. TEST_fail := 0
  27. when ODIN_TEST {
  28. expect :: testing.expect
  29. log :: testing.log
  30. } else {
  31. expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
  32. TEST_count += 1
  33. if !condition {
  34. TEST_fail += 1
  35. fmt.printf("[%v] %v\n", loc, message)
  36. return
  37. }
  38. }
  39. log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
  40. fmt.printf("[%v] ", loc)
  41. fmt.printf("log: %v\n", v)
  42. }
  43. }
  44. I_Error :: image.Error
  45. main :: proc() {
  46. t := testing.T{}
  47. png_test(&t)
  48. fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
  49. if TEST_fail > 0 {
  50. os.exit(1)
  51. }
  52. }
  53. PNG_Test :: struct {
  54. file: string,
  55. tests: []struct {
  56. options: image.Options,
  57. expected_error: image.Error,
  58. dims: PNG_Dims,
  59. hash: u32,
  60. },
  61. }
  62. Default :: image.Options{}
  63. Alpha_Add :: image.Options{.alpha_add_if_missing}
  64. Premul_Drop :: image.Options{.alpha_premultiply, .alpha_drop_if_present}
  65. Just_Drop :: image.Options{.alpha_drop_if_present}
  66. Blend_BG :: image.Options{.blend_background}
  67. Blend_BG_Keep :: image.Options{.blend_background, .alpha_add_if_missing}
  68. Return_Metadata :: image.Options{.return_metadata}
  69. No_Channel_Expansion :: image.Options{.do_not_expand_channels, .return_metadata}
  70. PNG_Dims :: struct {
  71. width: int,
  72. height: int,
  73. channels: int,
  74. depth: int,
  75. }
  76. Basic_PNG_Tests := []PNG_Test{
  77. /*
  78. Basic format tests:
  79. http://www.schaik.com/pngsuite/pngsuite_bas_png.html
  80. */
  81. {
  82. "basn0g01", // Black and white.
  83. {
  84. {Default, nil, {32, 32, 3, 8}, 0x_1d8b_1934},
  85. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_0da2_8714},
  86. },
  87. },
  88. {
  89. "basn0g02", // 2 bit (4 level) grayscale
  90. {
  91. {Default, nil, {32, 32, 3, 8}, 0x_cce2_e274},
  92. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_2e3f_e285},
  93. },
  94. },
  95. {
  96. "basn0g04", // 4 bit (16 level) grayscale
  97. {
  98. {Default, nil, {32, 32, 3, 8}, 0x_e6ed_c27d},
  99. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_8d0f_641b},
  100. },
  101. },
  102. {
  103. "basn0g08", // 8 bit (256 level) grayscale
  104. {
  105. {Default, nil, {32, 32, 3, 8}, 0x_7e0a_8ab4},
  106. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_c395_683c},
  107. },
  108. },
  109. {
  110. "basn0g16", // 16 bit (64k level) grayscale
  111. {
  112. {Default, nil, {32, 32, 3, 16}, 0x_d6ae_7df7},
  113. {Alpha_Add, nil, {32, 32, 4, 16}, 0x_a9da_b1bf},
  114. },
  115. },
  116. {
  117. "basn2c08", // 3x8 bits rgb color
  118. {
  119. {Default, nil, {32, 32, 3, 8}, 0x_7855_b9bf},
  120. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_2fb5_4036},
  121. },
  122. },
  123. {
  124. "basn2c16", // 3x16 bits rgb color
  125. {
  126. {Default, nil, {32, 32, 3, 16}, 0x_8ec6_de79},
  127. {Alpha_Add, nil, {32, 32, 4, 16}, 0x_0a7e_bae6},
  128. },
  129. },
  130. {
  131. "basn3p01", // 1 bit (2 color) paletted
  132. {
  133. {Default, nil, {32, 32, 3, 8}, 0x_31ec_284b},
  134. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_4d84_31a4},
  135. },
  136. },
  137. {
  138. "basn3p02", // 2 bit (4 color) paletted
  139. {
  140. {Default, nil, {32, 32, 3, 8}, 0x_279a_463a},
  141. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_e4db_b6bc},
  142. },
  143. },
  144. {
  145. "basn3p04", // 4 bit (16 color) paletted
  146. {
  147. {Default, nil, {32, 32, 3, 8}, 0x_3a9e_038e},
  148. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_671f_880f},
  149. },
  150. },
  151. {
  152. "basn3p08", // 8 bit (256 color) paletted
  153. {
  154. {Default, nil, {32, 32, 3, 8}, 0x_ff6e_2940},
  155. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_3952_8682},
  156. },
  157. },
  158. {
  159. "basn4a08", // 8 bit grayscale + 8 bit alpha-channel
  160. {
  161. {Default, nil, {32, 32, 4, 8}, 0x_905d_5b60},
  162. {Premul_Drop, nil, {32, 32, 3, 8}, 0x_8c36_b12c},
  163. },
  164. },
  165. {
  166. "basn4a16", // 16 bit grayscale + 16 bit alpha-channel
  167. {
  168. {Default, nil, {32, 32, 4, 16}, 0x_3000_e35c},
  169. {Premul_Drop, nil, {32, 32, 3, 16}, 0x_0276_254b},
  170. },
  171. },
  172. {
  173. "basn6a08", // 3x8 bits rgb color + 8 bit alpha-channel
  174. {
  175. {Default, nil, {32, 32, 4, 8}, 0x_a74d_f32c},
  176. {Premul_Drop, nil, {32, 32, 3, 8}, 0x_3a5b_8b1c},
  177. },
  178. },
  179. {
  180. "basn6a16", // 3x16 bits rgb color + 16 bit alpha-channel
  181. {
  182. {Default, nil, {32, 32, 4, 16}, 0x_087b_e531},
  183. {Premul_Drop, nil, {32, 32, 3, 16}, 0x_de9d_19fd},
  184. },
  185. },
  186. }
  187. Interlaced_PNG_Tests := []PNG_Test{
  188. /*
  189. Interlaced format tests:
  190. http://www.schaik.com/pngsuite/pngsuite_int_png.html
  191. Note that these have the same hash values as the
  192. non-interlaced versionss above. It would be a failure if
  193. they didn't, but we need these tests to exercise Adam-7.
  194. */
  195. {
  196. "basi0g01", // Black and white.
  197. {
  198. {Default, nil, {32, 32, 3, 8}, 0x_1d8b_1934},
  199. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_0da2_8714},
  200. },
  201. },
  202. {
  203. "basi0g02", // 2 bit (4 level) grayscale
  204. {
  205. {Default, nil, {32, 32, 3, 8}, 0x_cce2_e274},
  206. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_2e3f_e285},
  207. },
  208. },
  209. {
  210. "basi0g04", // 4 bit (16 level) grayscale
  211. {
  212. {Default, nil, {32, 32, 3, 8}, 0x_e6ed_c27d},
  213. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_8d0f_641b},
  214. },
  215. },
  216. {
  217. "basi0g08", // 8 bit (256 level) grayscale
  218. {
  219. {Default, nil, {32, 32, 3, 8}, 0x_7e0a_8ab4},
  220. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_c395_683c},
  221. },
  222. },
  223. {
  224. "basi0g16", // 16 bit (64k level) grayscale
  225. {
  226. {Default, nil, {32, 32, 3, 16}, 0x_d6ae_7df7},
  227. {Alpha_Add, nil, {32, 32, 4, 16}, 0x_a9da_b1bf},
  228. },
  229. },
  230. {
  231. "basi2c08", // 3x8 bits rgb color
  232. {
  233. {Default, nil, {32, 32, 3, 8}, 0x_7855_b9bf},
  234. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_2fb5_4036},
  235. },
  236. },
  237. {
  238. "basi2c16", // 3x16 bits rgb color
  239. {
  240. {Default, nil, {32, 32, 3, 16}, 0x_8ec6_de79},
  241. {Alpha_Add, nil, {32, 32, 4, 16}, 0x_0a7e_bae6},
  242. },
  243. },
  244. {
  245. "basi3p01", // 1 bit (2 color) paletted
  246. {
  247. {Default, nil, {32, 32, 3, 8}, 0x_31ec_284b},
  248. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_4d84_31a4},
  249. },
  250. },
  251. {
  252. "basi3p02", // 2 bit (4 color) paletted
  253. {
  254. {Default, nil, {32, 32, 3, 8}, 0x_279a_463a},
  255. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_e4db_b6bc},
  256. },
  257. },
  258. {
  259. "basi3p04", // 4 bit (16 color) paletted
  260. {
  261. {Default, nil, {32, 32, 3, 8}, 0x_3a9e_038e},
  262. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_671f_880f},
  263. },
  264. },
  265. {
  266. "basi3p08", // 8 bit (256 color) paletted
  267. {
  268. {Default, nil, {32, 32, 3, 8}, 0x_ff6e_2940},
  269. {Alpha_Add, nil, {32, 32, 4, 8}, 0x_3952_8682},
  270. },
  271. },
  272. {
  273. "basi4a08", // 8 bit grayscale + 8 bit alpha-channel
  274. {
  275. {Default, nil, {32, 32, 4, 8}, 0x_905d_5b60},
  276. {Premul_Drop, nil, {32, 32, 3, 8}, 0x_8c36_b12c},
  277. },
  278. },
  279. {
  280. "basi4a16", // 16 bit grayscale + 16 bit alpha-channel
  281. {
  282. {Default, nil, {32, 32, 4, 16}, 0x_3000_e35c},
  283. {Premul_Drop, nil, {32, 32, 3, 16}, 0x_0276_254b},
  284. },
  285. },
  286. {
  287. "basi6a08", // 3x8 bits rgb color + 8 bit alpha-channel
  288. {
  289. {Default, nil, {32, 32, 4, 8}, 0x_a74d_f32c},
  290. {Premul_Drop, nil, {32, 32, 3, 8}, 0x_3a5b_8b1c},
  291. },
  292. },
  293. {
  294. "basi6a16", // 3x16 bits rgb color + 16 bit alpha-channel
  295. {
  296. {Default, nil, {32, 32, 4, 16}, 0x_087b_e531},
  297. {Premul_Drop, nil, {32, 32, 3, 16}, 0x_de9d_19fd},
  298. },
  299. },
  300. }
  301. Odd_Sized_PNG_Tests := []PNG_Test{
  302. /*
  303. " PngSuite", // Odd sizes / PNG-files:
  304. http://www.schaik.com/pngsuite/pngsuite_siz_png.html
  305. This tests curious sizes with and without interlacing.
  306. */
  307. {
  308. "s01i3p01", // 1x1 paletted file, interlaced
  309. {
  310. {Default, nil, { 1, 1, 3, 8}, 0x_d243_369f},
  311. },
  312. },
  313. {
  314. "s01n3p01", // 1x1 paletted file, no interlacing
  315. {
  316. {Default, nil, { 1, 1, 3, 8}, 0x_d243_369f},
  317. },
  318. },
  319. {
  320. "s02i3p01", // 2x2 paletted file, interlaced
  321. {
  322. {Default, nil, { 2, 2, 3, 8}, 0x_9e93_1d85},
  323. },
  324. },
  325. {
  326. "s02n3p01", // 2x2 paletted file, no interlacing
  327. {
  328. {Default, nil, { 2, 2, 3, 8}, 0x_9e93_1d85},
  329. },
  330. },
  331. {
  332. "s03i3p01", // 3x3 paletted file, interlaced
  333. {
  334. {Default, nil, { 3, 3, 3, 8}, 0x_6916_380e},
  335. },
  336. },
  337. {
  338. "s03n3p01", // 3x3 paletted file, no interlacing
  339. {
  340. {Default, nil, { 3, 3, 3, 8}, 0x_6916_380e},
  341. },
  342. },
  343. {
  344. "s04i3p01", // 4x4 paletted file, interlaced
  345. {
  346. {Default, nil, { 4, 4, 3, 8}, 0x_c2e0_d49b},
  347. },
  348. },
  349. {
  350. "s04n3p01", // 4x4 paletted file, no interlacing
  351. {
  352. {Default, nil, { 4, 4, 3, 8}, 0x_c2e0_d49b},
  353. },
  354. },
  355. {
  356. "s05i3p02", // 5x5 paletted file, interlaced
  357. {
  358. {Default, nil, { 5, 5, 3, 8}, 0x_1242_b6fb},
  359. },
  360. },
  361. {
  362. "s05n3p02", // 5x5 paletted file, no interlacing
  363. {
  364. {Default, nil, { 5, 5, 3, 8}, 0x_1242_b6fb},
  365. },
  366. },
  367. {
  368. "s06i3p02", // 6x6 paletted file, interlaced
  369. {
  370. {Default, nil, { 6, 6, 3, 8}, 0x_d758_9540},
  371. },
  372. },
  373. {
  374. "s06n3p02", // 6x6 paletted file, no interlacing
  375. {
  376. {Default, nil, { 6, 6, 3, 8}, 0x_d758_9540},
  377. },
  378. },
  379. {
  380. "s07i3p02", // 7x7 paletted file, interlaced
  381. {
  382. {Default, nil, { 7, 7, 3, 8}, 0x_d2cc_f489},
  383. },
  384. },
  385. {
  386. "s07n3p02", // 7x7 paletted file, no interlacing
  387. {
  388. {Default, nil, { 7, 7, 3, 8}, 0x_d2cc_f489},
  389. },
  390. },
  391. {
  392. "s08i3p02", // 8x8 paletted file, interlaced
  393. {
  394. {Default, nil, { 8, 8, 3, 8}, 0x_2ba1_b03e},
  395. },
  396. },
  397. {
  398. "s08n3p02", // 8x8 paletted file, no interlacing
  399. {
  400. {Default, nil, { 8, 8, 3, 8}, 0x_2ba1_b03e},
  401. },
  402. },
  403. {
  404. "s09i3p02", // 9x9 paletted file, interlaced
  405. {
  406. {Default, nil, { 9, 9, 3, 8}, 0x_9762_d2ed},
  407. },
  408. },
  409. {
  410. "s09n3p02", // 9x9 paletted file, no interlacing
  411. {
  412. {Default, nil, { 9, 9, 3, 8}, 0x_9762_d2ed},
  413. },
  414. },
  415. {
  416. "s32i3p04", // 32x32 paletted file, interlaced
  417. {
  418. {Default, nil, {32, 32, 3, 8}, 0x_ad01_f44d},
  419. },
  420. },
  421. {
  422. "s32n3p04", // 32x32 paletted file, no interlacing
  423. {
  424. {Default, nil, {32, 32, 3, 8}, 0x_ad01_f44d},
  425. },
  426. },
  427. {
  428. "s33i3p04", // 33x33 paletted file, interlaced
  429. {
  430. {Default, nil, {33, 33, 3, 8}, 0x_d2f4_ae68},
  431. },
  432. },
  433. {
  434. "s33n3p04", // 33x33 paletted file, no interlacing
  435. {
  436. {Default, nil, {33, 33, 3, 8}, 0x_d2f4_ae68},
  437. },
  438. },
  439. {
  440. "s34i3p04", // 34x34 paletted file, interlaced
  441. {
  442. {Default, nil, {34, 34, 3, 8}, 0x_bbed_a3f7},
  443. },
  444. },
  445. {
  446. "s34n3p04", // 34x34 paletted file, no interlacing
  447. {
  448. {Default, nil, {34, 34, 3, 8}, 0x_bbed_a3f7},
  449. },
  450. },
  451. {
  452. "s35i3p04", // 35x35 paletted file, interlaced
  453. {
  454. {Default, nil, {35, 35, 3, 8}, 0x_9929_3acf},
  455. },
  456. },
  457. {
  458. "s35n3p04", // 35x35 paletted file, no interlacing
  459. {
  460. {Default, nil, {35, 35, 3, 8}, 0x_9929_3acf},
  461. },
  462. },
  463. {
  464. "s36i3p04", // 36x36 paletted file, interlaced
  465. {
  466. {Default, nil, {36, 36, 3, 8}, 0x_f51a_96e0},
  467. },
  468. },
  469. {
  470. "s36n3p04", // 36x36 paletted file, no interlacing
  471. {
  472. {Default, nil, {36, 36, 3, 8}, 0x_f51a_96e0},
  473. },
  474. },
  475. {
  476. "s37i3p04", // 37x37 paletted file, interlaced
  477. {
  478. {Default, nil, {37, 37, 3, 8}, 0x_9207_58a4},
  479. },
  480. },
  481. {
  482. "s37n3p04", // 37x37 paletted file, no interlacing
  483. {
  484. {Default, nil, {37, 37, 3, 8}, 0x_9207_58a4},
  485. },
  486. },
  487. {
  488. "s38i3p04", // 38x38 paletted file, interlaced
  489. {
  490. {Default, nil, {38, 38, 3, 8}, 0x_eb3b_f324},
  491. },
  492. },
  493. {
  494. "s38n3p04", // 38x38 paletted file, no interlacing
  495. {
  496. {Default, nil, {38, 38, 3, 8}, 0x_eb3b_f324},
  497. },
  498. },
  499. {
  500. "s39i3p04", // 39x39 paletted file, interlaced
  501. {
  502. {Default, nil, {39, 39, 3, 8}, 0x_c06d_7da1},
  503. },
  504. },
  505. {
  506. "s39n3p04", // 39x39 paletted file, no interlacing
  507. {
  508. {Default, nil, {39, 39, 3, 8}, 0x_c06d_7da1},
  509. },
  510. },
  511. {
  512. "s40i3p04", // 40x40 paletted file, interlaced
  513. {
  514. {Default, nil, {40, 40, 3, 8}, 0x_0d46_58a0},
  515. },
  516. },
  517. {
  518. "s40n3p04", // 40x40 paletted file, no interlacing
  519. {
  520. {Default, nil, {40, 40, 3, 8}, 0x_0d46_58a0},
  521. },
  522. },
  523. }
  524. PNG_bKGD_Tests := []PNG_Test{
  525. /*
  526. " PngSuite", // Background colors / PNG-files:
  527. http://www.schaik.com/pngsuite/pngsuite_bck_png.html
  528. This tests PNGs with and without a bKGD chunk and how we handle
  529. blending the background.
  530. */
  531. {
  532. "bgai4a08", // 8 bit grayscale, alpha, no background chunk, interlaced
  533. {
  534. {Default, nil, {32, 32, 4, 8}, 0x_905d_5b60},
  535. // No background, therefore no background blending and 3 channels.
  536. {Blend_BG, nil, {32, 32, 4, 8}, 0x_905d_5b60},
  537. },
  538. },
  539. {
  540. "bgai4a16", // 16 bit grayscale, alpha, no background chunk, interlaced
  541. {
  542. {Default, nil, {32, 32, 4, 16}, 0x_3000_e35c},
  543. // No background, therefore no background blending and 3 channels.
  544. {Blend_BG, nil, {32, 32, 4, 16}, 0x_3000_e35c},
  545. },
  546. },
  547. {
  548. "bgan6a08", // 3x8 bits rgb color, alpha, no background chunk
  549. {
  550. {Default, nil, {32, 32, 4, 8}, 0x_a74d_f32c},
  551. // No background, therefore no background blending and 3 channels.
  552. {Blend_BG, nil, {32, 32, 4, 8}, 0x_a74d_f32c},
  553. },
  554. },
  555. {
  556. "bgan6a16", // 3x16 bits rgb color, alpha, no background chunk
  557. {
  558. {Default, nil, {32, 32, 4, 16}, 0x_087b_e531},
  559. // No background, therefore no background blending and 3 channels.
  560. {Blend_BG, nil, {32, 32, 4, 16}, 0x_087b_e531},
  561. },
  562. },
  563. {
  564. "bgbn4a08", // 8 bit grayscale, alpha, black background chunk
  565. {
  566. {Default, nil, {32, 32, 4, 8}, 0x_905d_5b60},
  567. {Blend_BG, nil, {32, 32, 3, 8}, 0x_8c36_b12c},
  568. /*
  569. Blend with background but keep useless alpha channel now set to 255.
  570. */
  571. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_d4a2_3649},
  572. },
  573. },
  574. {
  575. "bggn4a16", // 16 bit grayscale, alpha, gray background chunk
  576. {
  577. {Default, nil, {32, 32, 4, 16}, 0x_3000_e35c},
  578. {Blend_BG, nil, {32, 32, 3, 16}, 0x_0b49_0dc1},
  579. /*
  580. Blend with background but keep useless alpha channel.
  581. */
  582. {Blend_BG_Keep, nil, {32, 32, 4, 16}, 0x_073f_eb13},
  583. },
  584. },
  585. {
  586. "bgwn6a08", // 3x8 bits rgb color, alpha, white background chunk
  587. {
  588. {Default, nil, {32, 32, 4, 8}, 0x_a74d_f32c},
  589. {Blend_BG, nil, {32, 32, 3, 8}, 0x_b60d_d910},
  590. /*
  591. Blend with background but keep useless alpha channel.
  592. */
  593. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_01ce_2ec6},
  594. },
  595. },
  596. {
  597. "bgyn6a16", // 3x16 bits rgb color, alpha, yellow background chunk
  598. {
  599. {Default, nil, {32, 32, 4, 16}, 0x_087b_e531},
  600. {Blend_BG, nil, {32, 32, 3, 16}, 0x_1a16_7d87},
  601. /*
  602. Blend with background but keep useless alpha channel.
  603. */
  604. {Blend_BG_Keep, nil, {32, 32, 4, 16}, 0x_4d73_9955},
  605. },
  606. },
  607. }
  608. PNG_tRNS_Tests := []PNG_Test{
  609. /*
  610. PngSuite - Transparency:
  611. http://www.schaik.com/pngsuite/pngsuite_trn_png.html
  612. This tests PNGs with and without a tRNS chunk and how we handle
  613. keyed transparency.
  614. */
  615. {
  616. "tbbn0g04", // transparent, black background chunk
  617. {
  618. {Default, nil, {32, 32, 4, 8}, 0x_5c8e_af83},
  619. {Blend_BG, nil, {32, 32, 3, 8}, 0x_9b95_ca37},
  620. /*
  621. Blend with background but keep useless alpha channel now set to 255.
  622. */
  623. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_5ea6_fd32},
  624. },
  625. },
  626. {
  627. "tbbn2c16", // transparent, blue background chunk
  628. {
  629. {Default, nil, {32, 32, 4, 16}, 0x_07fe_8090},
  630. {Blend_BG, nil, {32, 32, 3, 16}, 0x_5863_8fa2},
  631. /*
  632. Blend with background but keep useless alpha channel now set to 65535.
  633. */
  634. {Blend_BG_Keep, nil, {32, 32, 4, 16}, 0x_be56_b8fa},
  635. },
  636. },
  637. {
  638. "tbbn3p08", // transparent, black background chunk
  639. {
  640. {Default, nil, {32, 32, 4, 8}, 0x_9d56_cd67},
  641. {Blend_BG, nil, {32, 32, 3, 8}, 0x_8071_0060},
  642. /*
  643. Blend with background but keep useless alpha channel now set to 255.
  644. */
  645. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_c821_11f1},
  646. },
  647. },
  648. {
  649. "tbgn2c16", // transparent, green background chunk
  650. {
  651. {Default, nil, {32, 32, 4, 16}, 0x_07fe_8090},
  652. {Blend_BG, nil, {32, 32, 3, 16}, 0x_70da_708a},
  653. /*
  654. Blend with background but keep useless alpha channel now set to 65535.
  655. */
  656. {Blend_BG_Keep, nil, {32, 32, 4, 16}, 0x_97b3_a190},
  657. },
  658. },
  659. {
  660. "tbbn3p08", // transparent, black background chunk
  661. {
  662. {Default, nil, {32, 32, 4, 8}, 0x_9d56_cd67},
  663. {Blend_BG, nil, {32, 32, 3, 8}, 0x_8071_0060},
  664. /*
  665. Blend with background but keep useless alpha channel now set to 255.
  666. */
  667. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_c821_11f1},
  668. },
  669. },
  670. {
  671. "tbgn3p08", // transparent, light-gray background chunk
  672. {
  673. {Default, nil, {32, 32, 4, 8}, 0x_9d56_cd67},
  674. {Blend_BG, nil, {32, 32, 3, 8}, 0x_078b_74c4},
  675. /*
  676. Blend with background but keep useless alpha channel now set to 255.
  677. */
  678. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_d103_068d},
  679. },
  680. },
  681. {
  682. "tbrn2c08", // transparent, red background chunk
  683. {
  684. {Default, nil, {32, 32, 4, 8}, 0x_0370_ef89},
  685. {Blend_BG, nil, {32, 32, 3, 8}, 0x_6f68_a445},
  686. /*
  687. Blend with background but keep useless alpha channel now set to 255.
  688. */
  689. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_2610_a9b7},
  690. },
  691. },
  692. {
  693. "tbwn0g16", // transparent, white background chunk
  694. {
  695. {Default, nil, {32, 32, 4, 16}, 0x_5386_656a},
  696. {Blend_BG, nil, {32, 32, 3, 16}, 0x_6bdd_8c69},
  697. /*
  698. Blend with background but keep useless alpha channel now set to 65535.
  699. */
  700. {Blend_BG_Keep, nil, {32, 32, 4, 16}, 0x_1157_5f08},
  701. },
  702. },
  703. {
  704. "tbwn3p08", // transparent, white background chunk
  705. {
  706. {Default, nil, {32, 32, 4, 8}, 0x_9d56_cd67},
  707. {Blend_BG, nil, {32, 32, 3, 8}, 0x_4476_4e96},
  708. /*
  709. Blend with background but keep useless alpha channel now set to 255.
  710. */
  711. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_dd92_0d33},
  712. },
  713. },
  714. {
  715. "tbyn3p08", // transparent, yellow background chunk
  716. {
  717. {Default, nil, {32, 32, 4, 8}, 0x_9d56_cd67},
  718. {Blend_BG, nil, {32, 32, 3, 8}, 0x_18b9_da39},
  719. /*
  720. Blend with background but keep useless alpha channel now set to 255.
  721. */
  722. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_b1d4_5c1e},
  723. },
  724. },
  725. {
  726. "tp0n0g08", // not transparent for reference (logo on gray)
  727. {
  728. {Default, nil, {32, 32, 3, 8}, 0x_dfa9_515c},
  729. {Blend_BG, nil, {32, 32, 3, 8}, 0x_dfa9_515c},
  730. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_5796_5874},
  731. },
  732. },
  733. {
  734. "tp0n2c08", // not transparent for reference (logo on gray)
  735. {
  736. {Default, nil, {32, 32, 3, 8}, 0x_b426_b350},
  737. {Blend_BG, nil, {32, 32, 3, 8}, 0x_b426_b350},
  738. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_679d_24b4},
  739. },
  740. },
  741. {
  742. "tp0n3p08", // not transparent for reference (logo on gray)
  743. {
  744. {Default, nil, {32, 32, 3, 8}, 0x_1549_3236},
  745. {Blend_BG, nil, {32, 32, 3, 8}, 0x_1549_3236},
  746. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_130a_a165},
  747. },
  748. },
  749. {
  750. "tp1n3p08", // transparent, but no background chunk
  751. {
  752. {Default, nil, {32, 32, 4, 8}, 0x_9d56_cd67},
  753. {Blend_BG, nil, {32, 32, 4, 8}, 0x_9d56_cd67},
  754. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_9d56_cd67},
  755. },
  756. },
  757. {
  758. "tm3n3p02", // multiple levels of transparency, 3 entries
  759. {
  760. {Default, nil, {32, 32, 4, 8}, 0x_e7da_a7f5},
  761. {Blend_BG, nil, {32, 32, 4, 8}, 0x_e7da_a7f5},
  762. {Blend_BG_Keep, nil, {32, 32, 4, 8}, 0x_e7da_a7f5},
  763. {Just_Drop, nil, {32, 32, 3, 8}, 0x_e7f1_a455},
  764. },
  765. },
  766. }
  767. PNG_Filter_Tests := []PNG_Test{
  768. /*
  769. PngSuite - Image filtering:
  770. http://www.schaik.com/pngsuite/pngsuite_fil_png.html
  771. This tests PNGs filters.
  772. */
  773. {
  774. "f00n0g08", // grayscale, no interlacing, filter-type 0
  775. {
  776. {Default, nil, {32, 32, 3, 8}, 0x_3f6b_9bc5},
  777. },
  778. },
  779. {
  780. "f00n2c08", // color, no interlacing, filter-type 0
  781. {
  782. {Default, nil, {32, 32, 3, 8}, 0x_3f1d_66ad},
  783. },
  784. },
  785. {
  786. "f01n0g08", // grayscale, no interlacing, filter-type 1
  787. {
  788. {Default, nil, {32, 32, 3, 8}, 0x_0ff8_9d6c},
  789. },
  790. },
  791. {
  792. "f01n2c08", // color, no interlacing, filter-type 1
  793. {
  794. {Default, nil, {32, 32, 3, 8}, 0x_11c1_b27e},
  795. },
  796. },
  797. {
  798. "f02n0g08", // grayscale, no interlacing, filter-type 2
  799. {
  800. {Default, nil, {32, 32, 3, 8}, 0x_a86b_4c1d},
  801. },
  802. },
  803. {
  804. "f02n2c08", // color, no interlacing, filter-type 2
  805. {
  806. {Default, nil, {32, 32, 3, 8}, 0x_7f1c_a785},
  807. },
  808. },
  809. {
  810. "f03n0g08", // grayscale, no interlacing, filter-type 3
  811. {
  812. {Default, nil, {32, 32, 3, 8}, 0x_66de_99f1},
  813. },
  814. },
  815. {
  816. "f03n2c08", // color, no interlacing, filter-type 3
  817. {
  818. {Default, nil, {32, 32, 3, 8}, 0x_3164_5d89},
  819. },
  820. },
  821. {
  822. "f04n0g08", // grayscale, no interlacing, filter-type 4
  823. {
  824. {Default, nil, {32, 32, 3, 8}, 0x_f655_bb7d},
  825. },
  826. },
  827. {
  828. "f04n2c08", // color, no interlacing, filter-type 4
  829. {
  830. {Default, nil, {32, 32, 3, 8}, 0x_7705_6a6f},
  831. },
  832. },
  833. {
  834. "f99n0g04", // bit-depth 4, filter changing per scanline
  835. {
  836. {Default, nil, {32, 32, 3, 8}, 0x_d302_6ad9},
  837. },
  838. },
  839. }
  840. PNG_Varied_IDAT_Tests := []PNG_Test{
  841. /*
  842. PngSuite - Chunk ordering:
  843. http://www.schaik.com/pngsuite/pngsuite_ord_png.html
  844. This tests IDAT chunks of varying sizes.
  845. */
  846. {
  847. "oi1n0g16", // grayscale mother image with 1 idat-chunk
  848. {
  849. {Default, nil, {32, 32, 3, 16}, 0x_d6ae_7df7},
  850. },
  851. },
  852. {
  853. "oi1n2c16", // color mother image with 1 idat-chunk
  854. {
  855. {Default, nil, {32, 32, 3, 16}, 0x_8ec6_de79},
  856. },
  857. },
  858. {
  859. "oi2n0g16", // grayscale image with 2 idat-chunks
  860. {
  861. {Default, nil, {32, 32, 3, 16}, 0x_d6ae_7df7},
  862. },
  863. },
  864. {
  865. "oi2n2c16", // color image with 2 idat-chunks
  866. {
  867. {Default, nil, {32, 32, 3, 16}, 0x_8ec6_de79},
  868. },
  869. },
  870. {
  871. "oi4n0g16", // grayscale image with 4 unequal sized idat-chunks
  872. {
  873. {Default, nil, {32, 32, 3, 16}, 0x_d6ae_7df7},
  874. },
  875. },
  876. {
  877. "oi4n2c16", // color image with 4 unequal sized idat-chunks
  878. {
  879. {Default, nil, {32, 32, 3, 16}, 0x_8ec6_de79},
  880. },
  881. },
  882. {
  883. "oi9n0g16", // grayscale image with all idat-chunks length one
  884. {
  885. {Default, nil, {32, 32, 3, 16}, 0x_d6ae_7df7},
  886. },
  887. },
  888. {
  889. "oi9n2c16", // color image with all idat-chunks length one
  890. {
  891. {Default, nil, {32, 32, 3, 16}, 0x_8ec6_de79},
  892. },
  893. },
  894. }
  895. PNG_ZLIB_Levels_Tests := []PNG_Test{
  896. /*
  897. PngSuite - Zlib compression:
  898. http://www.schaik.com/pngsuite/pngsuite_zlb_png.html
  899. This tests varying levels of ZLIB compression.
  900. */
  901. {
  902. "z00n2c08", // color, no interlacing, compression level 0 (none)
  903. {
  904. {Default, nil, {32, 32, 3, 8}, 0x_f8f7_d651},
  905. },
  906. },
  907. {
  908. "z03n2c08", // color, no interlacing, compression level 3
  909. {
  910. {Default, nil, {32, 32, 3, 8}, 0x_f8f7_d651},
  911. },
  912. },
  913. {
  914. "z06n2c08", // color, no interlacing, compression level 6 (default)
  915. {
  916. {Default, nil, {32, 32, 3, 8}, 0x_f8f7_d651},
  917. },
  918. },
  919. {
  920. "z09n2c08", // color, no interlacing, compression level 9 (maximum)
  921. {
  922. {Default, nil, {32, 32, 3, 8}, 0x_f8f7_d651},
  923. },
  924. },
  925. {
  926. "logo-slim", // Odin logo, uses `repl_bytes` repeats at an offset greater than 1.
  927. {
  928. {Default, nil, {500, 260, 4, 8}, 0x_3e75_4e4e},
  929. },
  930. },
  931. }
  932. PNG_sPAL_Tests := []PNG_Test{
  933. /*
  934. PngSuite - Additional palettes:
  935. http://www.schaik.com/pngsuite/pngsuite_pal_png.html
  936. This tests handling of sPAL chunks.
  937. */
  938. {
  939. "pp0n2c16", // six-cube palette-chunk in true-color image
  940. {
  941. {Return_Metadata, nil, {32, 32, 3, 16}, 0x_8ec6_de79},
  942. },
  943. },
  944. {
  945. "pp0n6a08", // six-cube palette-chunk in true-color+alpha image
  946. {
  947. {Return_Metadata, nil, {32, 32, 4, 8}, 0x_0ee0_5c61},
  948. },
  949. },
  950. {
  951. "ps1n0g08", // six-cube suggested palette (1 byte) in grayscale image
  952. {
  953. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_7e0a_8ab4},
  954. },
  955. },
  956. {
  957. "ps1n2c16", // six-cube suggested palette (1 byte) in true-color image
  958. {
  959. {Return_Metadata, nil, {32, 32, 3, 16}, 0x_8ec6_de79},
  960. },
  961. },
  962. {
  963. "ps2n0g08", // six-cube suggested palette (2 bytes) in grayscale image
  964. {
  965. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_7e0a_8ab4},
  966. },
  967. },
  968. {
  969. "ps2n2c16", // six-cube suggested palette (2 bytes) in true-color image
  970. {
  971. {Return_Metadata, nil, {32, 32, 3, 16}, 0x_8ec6_de79},
  972. },
  973. },
  974. }
  975. PNG_Ancillary_Tests := []PNG_Test{
  976. /*
  977. PngSuite" - Ancillary chunks:
  978. http://www.schaik.com/pngsuite/pngsuite_cnk_png.html
  979. This tests various chunk helpers.
  980. */
  981. {
  982. "ccwn2c08", // chroma chunk w:0.3127,0.3290 r:0.64,0.33 g:0.30,0.60 b:0.15,0.06
  983. {
  984. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_61b6_9e8e},
  985. },
  986. },
  987. {
  988. "ccwn3p08", // chroma chunk w:0.3127,0.3290 r:0.64,0.33 g:0.30,0.60 b:0.15,0.06
  989. {
  990. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_2e1d_8ef1},
  991. },
  992. },
  993. {
  994. "cdfn2c08", // physical pixel dimensions, 8x32 flat pixels
  995. {
  996. {Return_Metadata, nil, { 8, 32, 3, 8}, 0x_99af_40a3},
  997. },
  998. },
  999. {
  1000. "cdhn2c08", // physical pixel dimensions, 32x8 high pixels
  1001. {
  1002. {Return_Metadata, nil, {32, 8, 3, 8}, 0x_84a4_ef40},
  1003. },
  1004. },
  1005. {
  1006. "cdsn2c08", // physical pixel dimensions, 8x8 square pixels
  1007. {
  1008. {Return_Metadata, nil, { 8, 8, 3, 8}, 0x_82b2_6daf},
  1009. },
  1010. },
  1011. {
  1012. "cdun2c08", // physical pixel dimensions, 1000 pixels per 1 meter
  1013. {
  1014. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_ee50_e3ca},
  1015. },
  1016. },
  1017. {
  1018. "ch1n3p04", // histogram 15 colors
  1019. {
  1020. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_3a9e_038e},
  1021. },
  1022. },
  1023. {
  1024. "ch2n3p08", // histogram 256 colors
  1025. {
  1026. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_ff6e_2940},
  1027. },
  1028. },
  1029. {
  1030. "cm0n0g04", // modification time, 01-jan-2000 12:34:56
  1031. {
  1032. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_c6bd_1a35},
  1033. },
  1034. },
  1035. {
  1036. "cm7n0g04", // modification time, 01-jan-1970 00:00:00
  1037. {
  1038. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_c6bd_1a35},
  1039. },
  1040. },
  1041. {
  1042. "cm9n0g04", // modification time, 31-dec-1999 23:59:59
  1043. {
  1044. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_c6bd_1a35},
  1045. },
  1046. },
  1047. {
  1048. "cs3n2c16", // color, 13 significant bits
  1049. {
  1050. {Return_Metadata, nil, {32, 32, 3, 16}, 0x_7919_bec4},
  1051. },
  1052. },
  1053. {
  1054. "cs3n3p08", // paletted, 3 significant bits
  1055. {
  1056. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_c472_63e3},
  1057. },
  1058. },
  1059. {
  1060. "cs5n2c08", // color, 5 significant bits
  1061. {
  1062. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_1b16_d169},
  1063. },
  1064. },
  1065. {
  1066. "cs5n3p08", // paletted, 5 significant bits
  1067. {
  1068. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_1b16_d169},
  1069. },
  1070. },
  1071. {
  1072. "cs8n2c08", // color, 8 significant bits (reference)
  1073. {
  1074. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_7306_351c},
  1075. },
  1076. },
  1077. {
  1078. "cs8n3p08", // paletted, 8 significant bits (reference)
  1079. {
  1080. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_7306_351c},
  1081. },
  1082. },
  1083. {
  1084. "ct0n0g04", // no textual data
  1085. {
  1086. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_c6bd_1a35},
  1087. },
  1088. },
  1089. {
  1090. "ct1n0g04", // with textual data
  1091. {
  1092. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_c6bd_1a35},
  1093. },
  1094. },
  1095. {
  1096. "ctzn0g04", // with compressed textual data
  1097. {
  1098. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_c6bd_1a35},
  1099. },
  1100. },
  1101. {
  1102. "cten0g04", // international UTF-8, english
  1103. {
  1104. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_908f_d2b2},
  1105. },
  1106. },
  1107. {
  1108. "ctfn0g04", // international UTF-8, finnish
  1109. {
  1110. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_7f7a_43a7},
  1111. },
  1112. },
  1113. {
  1114. "ctgn0g04", // international UTF-8, greek
  1115. {
  1116. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_0ad1_d3d6},
  1117. },
  1118. },
  1119. {
  1120. "cthn0g04", // international UTF-8, hindi
  1121. {
  1122. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_c461_c896},
  1123. },
  1124. },
  1125. {
  1126. "ctjn0g04", // international UTF-8, japanese
  1127. {
  1128. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_5539_0861},
  1129. },
  1130. },
  1131. {
  1132. "exif2c08", // chunk with jpeg exif data
  1133. {
  1134. {Return_Metadata, nil, {32, 32, 3, 8}, 0x_1a50_22ef},
  1135. },
  1136. },
  1137. }
  1138. Corrupt_PNG_Tests := []PNG_Test{
  1139. /*
  1140. PngSuite - Corrupted files / PNG-files:
  1141. http://www.schaik.com/pngsuite/pngsuite_xxx_png.html
  1142. This test ensures corrupted PNGs are rejected.
  1143. */
  1144. {
  1145. "xs1n0g01", // signature byte 1 MSBit reset to zero
  1146. {
  1147. {Default, .Invalid_Signature, {}, 0x_0000_0000},
  1148. },
  1149. },
  1150. {
  1151. "xs2n0g01", // signature byte 2 is a 'Q'
  1152. {
  1153. {Default, .Invalid_Signature, {}, 0x_0000_0000},
  1154. },
  1155. },
  1156. {
  1157. "xs4n0g01", // signature byte 4 lowercase
  1158. {
  1159. {Default, .Invalid_Signature, {}, 0x_0000_0000},
  1160. },
  1161. },
  1162. {
  1163. "xs7n0g01", // 7th byte a space instead of control-Z
  1164. {
  1165. {Default, .Invalid_Signature, {}, 0x_0000_0000},
  1166. },
  1167. },
  1168. {
  1169. "xcrn0g04", // added cr bytes
  1170. {
  1171. {Default, .Invalid_Signature, {}, 0x_0000_0000},
  1172. },
  1173. },
  1174. {
  1175. "xlfn0g04", // added lf bytes
  1176. {
  1177. {Default, .Invalid_Signature, {}, 0x_0000_0000},
  1178. },
  1179. },
  1180. {
  1181. "xhdn0g08", // incorrect IHDR checksum
  1182. {
  1183. {Default, compress.General_Error.Checksum_Failed, {}, 0x_0000_0000},
  1184. },
  1185. },
  1186. {
  1187. "xc1n0g08", // color type 1
  1188. {
  1189. {Default, .Unknown_Color_Type, {}, 0x_0000_0000},
  1190. },
  1191. },
  1192. {
  1193. "xc9n2c08", // color type 9
  1194. {
  1195. {Default, .Unknown_Color_Type, {}, 0x_0000_0000},
  1196. },
  1197. },
  1198. {
  1199. "xd0n2c08", // bit-depth 0
  1200. {
  1201. {Default, .Invalid_Color_Bit_Depth_Combo, {}, 0x_0000_0000},
  1202. },
  1203. },
  1204. {
  1205. "xd3n2c08", // bit-depth 3
  1206. {
  1207. {Default, .Invalid_Color_Bit_Depth_Combo, {}, 0x_0000_0000},
  1208. },
  1209. },
  1210. {
  1211. "xd9n2c08", // bit-depth 99
  1212. {
  1213. {Default, .Invalid_Color_Bit_Depth_Combo, {}, 0x_0000_0000},
  1214. },
  1215. },
  1216. {
  1217. "xdtn0g01", // missing IDAT chunk
  1218. {
  1219. {Default, .IDAT_Missing, {}, 0x_0000_0000},
  1220. },
  1221. },
  1222. {
  1223. "xcsn0g01", // incorrect IDAT checksum
  1224. {
  1225. {Default, compress.General_Error.Checksum_Failed, {}, 0x_0000_0000},
  1226. },
  1227. },
  1228. }
  1229. No_Postprocesing_Tests := []PNG_Test{
  1230. /*
  1231. These are some custom tests where we skip expanding to RGB(A).
  1232. */
  1233. {
  1234. "ps1n0g08", // six-cube suggested palette (1 byte) in grayscale image
  1235. {
  1236. {No_Channel_Expansion, nil, {32, 32, 1, 8}, 0x784b_4a4e},
  1237. },
  1238. },
  1239. {
  1240. "basn0g16", // 16 bit (64k level) grayscale
  1241. {
  1242. {No_Channel_Expansion, nil, {32, 32, 1, 16}, 0x_2ab1_5133},
  1243. },
  1244. },
  1245. {
  1246. "basn3p04", // 4 bit (16 color) paletted
  1247. {
  1248. {No_Channel_Expansion, nil, {32, 32, 1, 8}, 0x_280e_99f1},
  1249. },
  1250. },
  1251. }
  1252. Text_Title :: "PngSuite"
  1253. Text_Software :: "Created on a NeXTstation color using \"pnmtopng\"."
  1254. Text_Descrption :: "A compilation of a set of images created to test the\nvarious color-types of the PNG format. Included are\nblack&white, color, paletted, with alpha channel, with\ntransparency formats. All bit-depths allowed according\nto the spec are present."
  1255. Expected_Text := map[string]map[string]png.Text {
  1256. // .tEXt
  1257. "ct1n0g04" = map[string]png.Text {
  1258. "Title" = png.Text{
  1259. text=Text_Title,
  1260. },
  1261. "Software" = png.Text{
  1262. text=Text_Software,
  1263. },
  1264. "Description" = png.Text{
  1265. text=Text_Descrption,
  1266. },
  1267. },
  1268. // .zTXt
  1269. "ctzn0g04" = map[string]png.Text {
  1270. "Title" = png.Text{
  1271. text=Text_Title,
  1272. },
  1273. "Software" = png.Text{
  1274. text=Text_Software,
  1275. },
  1276. "Description" = png.Text{
  1277. text=Text_Descrption,
  1278. },
  1279. },
  1280. // .iTXt - international UTF-8, english
  1281. "cten0g04" = map[string]png.Text {
  1282. "Title" = png.Text{
  1283. keyword_localized="Title",
  1284. language="en",
  1285. },
  1286. "Software" = png.Text{
  1287. keyword_localized="Software",
  1288. language="en",
  1289. },
  1290. "Description" = png.Text{
  1291. keyword_localized="Description",
  1292. language="en",
  1293. },
  1294. },
  1295. // .iTXt - international UTF-8, finnish
  1296. "ctfn0g04" = map[string]png.Text {
  1297. "Title" = png.Text{
  1298. keyword_localized = "Otsikko",
  1299. language = "fi",
  1300. text ="PngSuite",
  1301. },
  1302. "Software" = png.Text{
  1303. keyword_localized = "Ohjelmistot",
  1304. language = "fi",
  1305. text = "Luotu NeXTstation väriä \"pnmtopng\".",
  1306. },
  1307. "Description" = png.Text{
  1308. keyword_localized = "Kuvaus",
  1309. language = "fi",
  1310. text = "kokoelma joukon kuvia luotu testata eri väri-tyyppisiä PNG-muodossa. Mukana on mustavalkoinen, väri, paletted, alpha-kanava, avoimuuden muodossa. Kaikki bit-syvyydessä mukaan sallittua spec on ​​läsnä.",
  1311. },
  1312. },
  1313. // .iTXt - international UTF-8, greek
  1314. "ctgn0g04" = map[string]png.Text {
  1315. "Title" = png.Text{
  1316. keyword_localized = "Τίτλος",
  1317. language = "el",
  1318. text ="PngSuite",
  1319. },
  1320. "Software" = png.Text{
  1321. keyword_localized = "Λογισμικό",
  1322. language = "el",
  1323. text = "Δημιουργήθηκε σε ένα χρώμα NeXTstation χρησιμοποιώντας \"pnmtopng\".",
  1324. },
  1325. "Description" = png.Text{
  1326. keyword_localized = "Περιγραφή",
  1327. language = "el",
  1328. text = "Μια συλλογή από ένα σύνολο εικόνων που δημιουργήθηκαν για τη δοκιμή των διαφόρων χρωμάτων-τύπων του μορφή PNG. Περιλαμβάνονται οι ασπρόμαυρες, χρώμα, paletted, με άλφα κανάλι, με μορφές της διαφάνειας. Όλοι λίγο-βάθη επιτρέπεται σύμφωνα με το spec είναι παρόντες.",
  1329. },
  1330. },
  1331. // .iTXt - international UTF-8, hindi
  1332. "cthn0g04" = map[string]png.Text {
  1333. "Title" = png.Text{
  1334. keyword_localized = "शीर्षक",
  1335. language = "hi",
  1336. text ="PngSuite",
  1337. },
  1338. "Software" = png.Text{
  1339. keyword_localized = "सॉफ्टवेयर",
  1340. language = "hi",
  1341. text = "एक NeXTstation \"pnmtopng \'का उपयोग कर रंग पर बनाया गया.",
  1342. },
  1343. "Description" = png.Text{
  1344. keyword_localized = "विवरण",
  1345. language = "hi",
  1346. text = "करने के लिए PNG प्रारूप के विभिन्न रंग प्रकार परीक्षण बनाया छवियों का एक सेट का एक संकलन. शामिल काले और सफेद, रंग, पैलेटेड हैं, अल्फा चैनल के साथ पारदर्शिता स्वरूपों के साथ. सभी बिट गहराई कल्पना के अनुसार की अनुमति दी मौजूद हैं.",
  1347. },
  1348. },
  1349. // .iTXt - international UTF-8, japanese
  1350. "ctjn0g04" = map[string]png.Text {
  1351. "Title" = png.Text{
  1352. keyword_localized = "タイトル",
  1353. language = "ja",
  1354. text ="PngSuite",
  1355. },
  1356. "Software" = png.Text{
  1357. keyword_localized = "ソフトウェア",
  1358. language = "ja",
  1359. text = "\"pnmtopng\"を使用してNeXTstation色上に作成されます。",
  1360. },
  1361. "Description" = png.Text{
  1362. keyword_localized = "概要",
  1363. language = "ja",
  1364. text = "PNG形式の様々な色の種類をテストするために作成されたイメージのセットのコンパイル。含まれているのは透明度のフォーマットで、アルファチャネルを持つ、白黒、カラー、パレットです。すべてのビット深度が存在している仕様に従ったことができました。",
  1365. },
  1366. },
  1367. }
  1368. @test
  1369. png_test :: proc(t: ^testing.T) {
  1370. total_tests := 0
  1371. total_expected := 235
  1372. PNG_Suites := [][]PNG_Test{
  1373. Basic_PNG_Tests,
  1374. Interlaced_PNG_Tests,
  1375. Odd_Sized_PNG_Tests,
  1376. PNG_bKGD_Tests,
  1377. PNG_tRNS_Tests,
  1378. PNG_Filter_Tests,
  1379. PNG_Varied_IDAT_Tests,
  1380. PNG_ZLIB_Levels_Tests,
  1381. PNG_sPAL_Tests,
  1382. PNG_Ancillary_Tests,
  1383. Corrupt_PNG_Tests,
  1384. No_Postprocesing_Tests,
  1385. }
  1386. for suite in PNG_Suites {
  1387. total_tests += run_png_suite(t, suite)
  1388. }
  1389. error := fmt.tprintf("Expected %v PNG tests, %v ran.", total_expected, total_tests)
  1390. expect(t, total_tests == total_expected, error)
  1391. }
  1392. run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) -> (subtotal: int) {
  1393. context = runtime.default_context()
  1394. for file in suite {
  1395. test_file := strings.concatenate({TEST_SUITE_PATH, "/", file.file, ".png"}, context.temp_allocator)
  1396. img: ^png.Image
  1397. err: png.Error
  1398. count := 0
  1399. for test in file.tests {
  1400. count += 1
  1401. subtotal += 1
  1402. passed := false
  1403. track: mem.Tracking_Allocator
  1404. mem.tracking_allocator_init(&track, context.allocator)
  1405. context.allocator = mem.tracking_allocator(&track)
  1406. img, err = png.load(test_file, test.options)
  1407. error := fmt.tprintf("%v failed with %v.", test_file, err)
  1408. passed = (test.expected_error == nil && err == nil) || (test.expected_error == err)
  1409. expect(t, passed, error)
  1410. if err == nil { // No point in running the other tests if it didn't load.
  1411. pixels := bytes.buffer_to_bytes(&img.pixels)
  1412. // This struct compare fails at -opt:2 if PNG_Dims is not #packed.
  1413. dims := PNG_Dims{img.width, img.height, img.channels, img.depth}
  1414. error = fmt.tprintf("%v has %v, expected: %v.", file.file, dims, test.dims)
  1415. dims_pass := test.dims == dims
  1416. expect(t, dims_pass, error)
  1417. passed &= dims_pass
  1418. png_hash := hash.crc32(pixels)
  1419. error = fmt.tprintf("%v test %v hash is %08x, expected %08x with %v.", file.file, count, png_hash, test.hash, test.options)
  1420. expect(t, test.hash == png_hash, error)
  1421. passed &= test.hash == png_hash
  1422. if passed {
  1423. // Roundtrip through QOI to test the QOI encoder and decoder.
  1424. if img.depth == 8 && (img.channels == 3 || img.channels == 4) {
  1425. qoi_buffer: bytes.Buffer
  1426. defer bytes.buffer_destroy(&qoi_buffer)
  1427. qoi_save_err := qoi.save(&qoi_buffer, img)
  1428. error = fmt.tprintf("%v test %v QOI save failed with %v.", file.file, count, qoi_save_err)
  1429. expect(t, qoi_save_err == nil, error)
  1430. if qoi_save_err == nil {
  1431. qoi_img, qoi_load_err := qoi.load(qoi_buffer.buf[:])
  1432. defer qoi.destroy(qoi_img)
  1433. error = fmt.tprintf("%v test %v QOI load failed with %v.", file.file, count, qoi_load_err)
  1434. expect(t, qoi_load_err == nil, error)
  1435. qoi_hash := hash.crc32(qoi_img.pixels.buf[:])
  1436. error = fmt.tprintf("%v test %v QOI load hash is %08x, expected it match PNG's %08x with %v.", file.file, count, qoi_hash, png_hash, test.options)
  1437. expect(t, qoi_hash == png_hash, error)
  1438. }
  1439. }
  1440. // Roundtrip through TGA to test the TGA encoder and decoder.
  1441. if img.depth == 8 && (img.channels == 3 || img.channels == 4) {
  1442. tga_buffer: bytes.Buffer
  1443. defer bytes.buffer_destroy(&tga_buffer)
  1444. tga_save_err := tga.save(&tga_buffer, img)
  1445. error = fmt.tprintf("%v test %v TGA save failed with %v.", file.file, count, tga_save_err)
  1446. expect(t, tga_save_err == nil, error)
  1447. if tga_save_err == nil {
  1448. tga_img, tga_load_err := tga.load(tga_buffer.buf[:])
  1449. defer tga.destroy(tga_img)
  1450. error = fmt.tprintf("%v test %v TGA load failed with %v.", file.file, count, tga_load_err)
  1451. expect(t, tga_load_err == nil, error)
  1452. tga_hash := hash.crc32(tga_img.pixels.buf[:])
  1453. error = fmt.tprintf("%v test %v TGA load hash is %08x, expected it match PNG's %08x with %v.", file.file, count, tga_hash, png_hash, test.options)
  1454. expect(t, tga_hash == png_hash, error)
  1455. }
  1456. }
  1457. {
  1458. // Roundtrip through PBM to test the PBM encoders and decoders - prefer binary
  1459. pbm_buf, pbm_save_err := pbm.save_to_buffer(img)
  1460. defer delete(pbm_buf)
  1461. error = fmt.tprintf("%v test %v PBM save failed with %v.", file.file, count, pbm_save_err)
  1462. expect(t, pbm_save_err == nil, error)
  1463. if pbm_save_err == nil {
  1464. // Try to load it again.
  1465. pbm_img, pbm_load_err := pbm.load(pbm_buf)
  1466. defer pbm.destroy(pbm_img)
  1467. error = fmt.tprintf("%v test %v PBM load failed with %v.", file.file, count, pbm_load_err)
  1468. expect(t, pbm_load_err == nil, error)
  1469. if pbm_load_err == nil {
  1470. pbm_hash := hash.crc32(pbm_img.pixels.buf[:])
  1471. error = fmt.tprintf("%v test %v PBM load hash is %08x, expected it match PNG's %08x with %v.", file.file, count, pbm_hash, png_hash, test.options)
  1472. expect(t, pbm_hash == png_hash, error)
  1473. }
  1474. }
  1475. }
  1476. {
  1477. // Roundtrip through PBM to test the PBM encoders and decoders - prefer ASCII
  1478. pbm_info, pbm_format_selected := pbm.autoselect_pbm_format_from_image(img, false)
  1479. // We already tested the binary formats above.
  1480. if pbm_info.header.format in pbm.ASCII {
  1481. pbm_buf, pbm_save_err := pbm.save_to_buffer(img, pbm_info)
  1482. defer delete(pbm_buf)
  1483. error = fmt.tprintf("%v test %v PBM save failed with %v.", file.file, count, pbm_save_err)
  1484. expect(t, pbm_save_err == nil, error)
  1485. if pbm_save_err == nil {
  1486. // Try to load it again.
  1487. pbm_img, pbm_load_err := pbm.load(pbm_buf)
  1488. defer pbm.destroy(pbm_img)
  1489. error = fmt.tprintf("%v test %v PBM load failed with %v.", file.file, count, pbm_load_err)
  1490. expect(t, pbm_load_err == nil, error)
  1491. if pbm_load_err == nil {
  1492. pbm_hash := hash.crc32(pbm_img.pixels.buf[:])
  1493. error = fmt.tprintf("%v test %v PBM load hash is %08x, expected it match PNG's %08x with %v.", file.file, count, pbm_hash, png_hash, test.options)
  1494. expect(t, pbm_hash == png_hash, error)
  1495. }
  1496. }
  1497. }
  1498. }
  1499. {
  1500. // We still need to test Portable Float Maps
  1501. if (img.channels == 1 || img.channels == 3) && (img.depth == 8 || img.depth == 16) {
  1502. // Make temporary float image
  1503. float_img := new(image.Image)
  1504. defer png.destroy(float_img)
  1505. float_img.width = img.width
  1506. float_img.height = img.height
  1507. float_img.channels = img.channels
  1508. float_img.depth = 32
  1509. buffer_size := image.compute_buffer_size(img.width, img.height, img.channels, 32)
  1510. resize(&float_img.pixels.buf, buffer_size)
  1511. pbm_info := pbm.Info {
  1512. header = {
  1513. width = img.width,
  1514. height = img.height,
  1515. channels = img.channels,
  1516. depth = img.depth,
  1517. maxval = 255 if img.depth == 8 else 65535,
  1518. little_endian = true if ODIN_ENDIAN == .Little else false,
  1519. scale = 1.0,
  1520. format = .Pf if img.channels == 1 else .PF,
  1521. },
  1522. }
  1523. // Transform data...
  1524. orig_float := mem.slice_data_cast([]f32, float_img.pixels.buf[:])
  1525. switch img.depth {
  1526. case 8:
  1527. for v, i in img.pixels.buf {
  1528. orig_float[i] = f32(v) / f32(256)
  1529. }
  1530. case 16:
  1531. wide := mem.slice_data_cast([]u16, img.pixels.buf[:])
  1532. for v, i in wide {
  1533. orig_float[i] = f32(v) / f32(65536)
  1534. }
  1535. }
  1536. float_pbm_buf, float_pbm_save_err := pbm.save_to_buffer(float_img, pbm_info)
  1537. defer delete(float_pbm_buf)
  1538. error = fmt.tprintf("%v test %v save as PFM failed with %v", file.file, count, float_pbm_save_err)
  1539. expect(t, float_pbm_save_err == nil, error)
  1540. if float_pbm_save_err == nil {
  1541. // Load float image and compare.
  1542. float_pbm_img, float_pbm_load_err := pbm.load(float_pbm_buf)
  1543. defer pbm.destroy(float_pbm_img)
  1544. error = fmt.tprintf("%v test %v PFM load failed with %v", file.file, count, float_pbm_load_err)
  1545. expect(t, float_pbm_load_err == nil, error)
  1546. load_float := mem.slice_data_cast([]f32, float_pbm_img.pixels.buf[:])
  1547. error = fmt.tprintf("%v test %v PFM load returned %v floats, expected %v", file.file, count, len(load_float), len(orig_float))
  1548. expect(t, len(load_float) == len(orig_float), error)
  1549. // Compare floats
  1550. equal := true
  1551. for orig, i in orig_float {
  1552. if orig != load_float[i] {
  1553. equal = false
  1554. break
  1555. }
  1556. }
  1557. error = fmt.tprintf("%v test %v PFM loaded floats to match", file.file, count)
  1558. expect(t, equal, error)
  1559. }
  1560. }
  1561. }
  1562. }
  1563. if .return_metadata in test.options {
  1564. if v, ok := img.metadata.(^image.PNG_Info); ok {
  1565. for c in v.chunks {
  1566. #partial switch(c.header.type) {
  1567. case .gAMA:
  1568. switch(file.file) {
  1569. case "pp0n2c16", "pp0n6a08":
  1570. gamma, gamma_ok := png.gamma(c)
  1571. expected_gamma := f32(1.0)
  1572. error = fmt.tprintf("%v test %v gAMA is %v, expected %v.", file.file, count, gamma, expected_gamma)
  1573. expect(t, gamma == expected_gamma && gamma_ok, error)
  1574. }
  1575. case .PLTE:
  1576. switch(file.file) {
  1577. case "pp0n2c16", "pp0n6a08":
  1578. plte, plte_ok := png.plte(c)
  1579. expected_plte_len := u16(216)
  1580. error = fmt.tprintf("%v test %v PLTE length is %v, expected %v.", file.file, count, plte.used, expected_plte_len)
  1581. expect(t, expected_plte_len == plte.used && plte_ok, error)
  1582. }
  1583. case .sPLT:
  1584. switch(file.file) {
  1585. case "ps1n0g08", "ps1n2c16", "ps2n0g08", "ps2n2c16":
  1586. splt, splt_ok := png.splt(c)
  1587. expected_splt_len := u16(216)
  1588. error = fmt.tprintf("%v test %v sPLT length is %v, expected %v.", file.file, count, splt.used, expected_splt_len)
  1589. expect(t, expected_splt_len == splt.used && splt_ok, error)
  1590. expected_splt_name := "six-cube"
  1591. error = fmt.tprintf("%v test %v sPLT name is %v, expected %v.", file.file, count, splt.name, expected_splt_name)
  1592. expect(t, expected_splt_name == splt.name && splt_ok, error)
  1593. png.splt_destroy(splt)
  1594. }
  1595. case .cHRM:
  1596. switch(file.file) {
  1597. case "ccwn2c08", "ccwn3p08":
  1598. chrm, chrm_ok := png.chrm(c)
  1599. expected_chrm := png.cHRM{
  1600. w = png.CIE_1931{x = 0.3127, y = 0.3290},
  1601. r = png.CIE_1931{x = 0.6400, y = 0.3300},
  1602. g = png.CIE_1931{x = 0.3000, y = 0.6000},
  1603. b = png.CIE_1931{x = 0.1500, y = 0.0600},
  1604. }
  1605. error = fmt.tprintf("%v test %v cHRM is %v, expected %v.", file.file, count, chrm, expected_chrm)
  1606. expect(t, expected_chrm == chrm && chrm_ok, error)
  1607. }
  1608. case .pHYs:
  1609. phys, phys_ok := png.phys(c)
  1610. phys_err := "%v test %v cHRM is %v, expected %v."
  1611. switch (file.file) {
  1612. case "cdfn2c08":
  1613. expected_phys := png.pHYs{ppu_x = 1, ppu_y = 4, unit = .Unknown}
  1614. error = fmt.tprintf(phys_err, file.file, count, phys, expected_phys)
  1615. expect(t, expected_phys == phys && phys_ok, error)
  1616. case "cdhn2c08":
  1617. expected_phys := png.pHYs{ppu_x = 4, ppu_y = 1, unit = .Unknown}
  1618. error = fmt.tprintf(phys_err, file.file, count, phys, expected_phys)
  1619. expect(t, expected_phys == phys && phys_ok, error)
  1620. case "cdsn2c08":
  1621. expected_phys := png.pHYs{ppu_x = 1, ppu_y = 1, unit = .Unknown}
  1622. error = fmt.tprintf(phys_err, file.file, count, phys, expected_phys)
  1623. expect(t, expected_phys == phys && phys_ok, error)
  1624. case "cdun2c08":
  1625. expected_phys := png.pHYs{ppu_x = 1000, ppu_y = 1000, unit = .Meter}
  1626. error = fmt.tprintf(phys_err, file.file, count, phys, expected_phys)
  1627. expect(t, expected_phys == phys && phys_ok, error)
  1628. }
  1629. case .hIST:
  1630. hist, hist_ok := png.hist(c)
  1631. hist_err := "%v test %v hIST has %v entries, expected %v."
  1632. switch (file.file) {
  1633. case "ch1n3p04":
  1634. error = fmt.tprintf(hist_err, file.file, count, hist.used, 15)
  1635. expect(t, hist.used == 15 && hist_ok, error)
  1636. case "ch2n3p08":
  1637. error = fmt.tprintf(hist_err, file.file, count, hist.used, 256)
  1638. expect(t, hist.used == 256 && hist_ok, error)
  1639. }
  1640. case .tIME:
  1641. png_time, png_time_ok := png.time(c)
  1642. time_err := "%v test %v tIME was %v, expected %v."
  1643. expected_time: png.tIME
  1644. core_time, core_time_ok := png.core_time(c)
  1645. time_core_err := "%v test %v tIME->core:time is %v, expected %v."
  1646. expected_core: time.Time
  1647. switch(file.file) {
  1648. case "cm0n0g04": // modification time, 01-jan-2000 12:34:56
  1649. expected_time = png.tIME{year = 2000, month = 1, day = 1, hour = 12, minute = 34, second = 56}
  1650. expected_core = time.Time{_nsec = 946730096000000000}
  1651. case "cm7n0g04": // modification time, 01-jan-1970 00:00:00
  1652. expected_time = png.tIME{year = 1970, month = 1, day = 1, hour = 0, minute = 0, second = 0}
  1653. expected_core = time.Time{_nsec = 0}
  1654. case "cm9n0g04": // modification time, 31-dec-1999 23:59:59
  1655. expected_time = png.tIME{year = 1999, month = 12, day = 31, hour = 23, minute = 59, second = 59}
  1656. expected_core = time.Time{_nsec = 946684799000000000}
  1657. }
  1658. error = fmt.tprintf(time_err, file.file, count, png_time, expected_time)
  1659. expect(t, png_time == expected_time && png_time_ok, error)
  1660. error = fmt.tprintf(time_core_err, file.file, count, core_time, expected_core)
  1661. expect(t, core_time == expected_core && core_time_ok, error)
  1662. case .sBIT:
  1663. sbit, sbit_ok := png.sbit(c)
  1664. sbit_err := "%v test %v sBIT was %v, expected %v."
  1665. expected_sbit: [4]u8
  1666. switch (file.file) {
  1667. case "cs3n2c16": // color, 13 significant bits
  1668. expected_sbit = [4]u8{13, 13, 13, 0}
  1669. case "cs3n3p08": // paletted, 3 significant bits
  1670. expected_sbit = [4]u8{ 3, 3, 3, 0}
  1671. case "cs5n2c08": // color, 5 significant bits
  1672. expected_sbit = [4]u8{ 5, 5, 5, 0}
  1673. case "cs5n3p08": // paletted, 5 significant bits
  1674. expected_sbit = [4]u8{ 5, 5, 5, 0}
  1675. case "cs8n2c08": // color, 8 significant bits (reference)
  1676. expected_sbit = [4]u8{ 8, 8, 8, 0}
  1677. case "cs8n3p08": // paletted, 8 significant bits (reference)
  1678. expected_sbit = [4]u8{ 8, 8, 8, 0}
  1679. case "cdfn2c08", "cdhn2c08", "cdsn2c08", "cdun2c08", "ch1n3p04", "basn3p04":
  1680. expected_sbit = [4]u8{ 4, 4, 4, 0}
  1681. }
  1682. error = fmt.tprintf(sbit_err, file.file, count, sbit, expected_sbit)
  1683. expect(t, sbit == expected_sbit && sbit_ok, error)
  1684. case .tEXt, .zTXt:
  1685. text, text_ok := png.text(c)
  1686. defer png.text_destroy(text)
  1687. switch(file.file) {
  1688. case "ct1n0g04": // with textual data
  1689. fallthrough
  1690. case "ctzn0g04": // with compressed textual data
  1691. if file.file in Expected_Text {
  1692. if text.keyword in Expected_Text[file.file] {
  1693. test_text := Expected_Text[file.file][text.keyword].text
  1694. error = fmt.tprintf("%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text.text, test_text)
  1695. expect(t, text.text == test_text && text_ok, error)
  1696. }
  1697. }
  1698. }
  1699. case .iTXt:
  1700. text, text_ok := png.text(c)
  1701. defer png.text_destroy(text)
  1702. switch(file.file) {
  1703. case "cten0g04": // international UTF-8, english
  1704. if file.file in Expected_Text {
  1705. if text.keyword in Expected_Text[file.file] {
  1706. test := Expected_Text[file.file][text.keyword]
  1707. error = fmt.tprintf("%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
  1708. expect(t, text.language == test.language && text_ok, error)
  1709. expect(t, text.keyword_localized == test.keyword_localized && text_ok, error)
  1710. }
  1711. }
  1712. case "ctfn0g04": // international UTF-8, finnish
  1713. if file.file in Expected_Text {
  1714. if text.keyword in Expected_Text[file.file] {
  1715. test := Expected_Text[file.file][text.keyword]
  1716. error = fmt.tprintf("%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
  1717. expect(t, text.text == test.text && text_ok, error)
  1718. expect(t, text.language == test.language && text_ok, error)
  1719. expect(t, text.keyword_localized == test.keyword_localized && text_ok, error)
  1720. }
  1721. }
  1722. case "ctgn0g04": // international UTF-8, greek
  1723. if file.file in Expected_Text {
  1724. if text.keyword in Expected_Text[file.file] {
  1725. test := Expected_Text[file.file][text.keyword]
  1726. error = fmt.tprintf("%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
  1727. expect(t, text.text == test.text && text_ok, error)
  1728. expect(t, text.language == test.language && text_ok, error)
  1729. expect(t, text.keyword_localized == test.keyword_localized && text_ok, error)
  1730. }
  1731. }
  1732. case "cthn0g04": // international UTF-8, hindi
  1733. if file.file in Expected_Text {
  1734. if text.keyword in Expected_Text[file.file] {
  1735. test := Expected_Text[file.file][text.keyword]
  1736. error = fmt.tprintf("%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
  1737. expect(t, text.text == test.text && text_ok, error)
  1738. expect(t, text.language == test.language && text_ok, error)
  1739. expect(t, text.keyword_localized == test.keyword_localized && text_ok, error)
  1740. }
  1741. }
  1742. case "ctjn0g04": // international UTF-8, japanese
  1743. if file.file in Expected_Text {
  1744. if text.keyword in Expected_Text[file.file] {
  1745. test := Expected_Text[file.file][text.keyword]
  1746. error = fmt.tprintf("%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
  1747. expect(t, text.text == test.text && text_ok, error)
  1748. expect(t, text.language == test.language && text_ok, error)
  1749. expect(t, text.keyword_localized == test.keyword_localized && text_ok, error)
  1750. }
  1751. }
  1752. }
  1753. case .eXIf:
  1754. if file.file == "exif2c08" { // chunk with jpeg exif data
  1755. exif, exif_ok := png.exif(c)
  1756. error = fmt.tprintf("%v test %v eXIf byte order '%v', expected 'big_endian'.", file.file, count, exif.byte_order)
  1757. error_len := fmt.tprintf("%v test %v eXIf data length '%v', expected '%v'.", file.file, len(exif.data), 978)
  1758. expect(t, exif.byte_order == .big_endian && exif_ok, error)
  1759. expect(t, len(exif.data) == 978 && exif_ok, error_len)
  1760. }
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. png.destroy(img)
  1767. for _, v in track.allocation_map {
  1768. error = fmt.tprintf("%v test %v leaked %v bytes @ loc %v.", file.file, count, v.size, v.location)
  1769. expect(t, false, error)
  1770. }
  1771. }
  1772. }
  1773. return
  1774. }