Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. |= dim=@ud
  2. ^- @ux
  3. :: Pixel bytes for 24bpp dim*dim image
  4. :: Note: this calculation does not support padding, so dim%4 must be 0
  5. ::
  6. =/ datasize=@ (mul 3 (mul dim dim))
  7. :: The header is a list of [bytes, value] to be composed into a single blob
  8. ::
  9. =/ header=@
  10. %+ can 3
  11. ^- (list [@ @])
  12. :~
  13. :: BMP header part, 14 bytes
  14. ::
  15. [2 'BM'] :: format ID
  16. [4 (add 54 datasize)] :: file size - 54 byte header + pixel data
  17. [4 0] :: unused
  18. [4 54] :: header size
  19. :: DIB header part, 4 bytes
  20. ::
  21. [4 40] :: DIB header size
  22. [4 dim] :: width
  23. [4 dim] :: height
  24. [2 3] :: number of channels
  25. [2 24] :: bits per pixel
  26. [4 0] :: compression (none; BI_RGB)
  27. [4 datasize] :: pixel data size
  28. [4 2.835] :: print resolution x (72 DPI)
  29. [4 2.835] :: print resolution y (72 DPI)
  30. [8 0] :: palette stuff (unused)
  31. ==
  32. =/ image=@
  33. %+ rap 3
  34. =/ py=@ 0
  35. |-
  36. ^- (list @)
  37. =/ px=@ 0
  38. |-
  39. ^- (list @)
  40. :: Define the image as a BGR888 pixel in terms of x and y
  41. ::
  42. :- (add 128 (div (mul px 256) (mul 2 dim)))
  43. :- 255
  44. :- 255
  45. :: Recurse for all pixels
  46. ::
  47. ?: (lth +(px) dim)
  48. $(px +(px))
  49. ?: (lth +(py) dim)
  50. ^$(py +(py))
  51. ~
  52. %+ can 3
  53. ^- (list [@ @])
  54. :~
  55. [54 header]
  56. [datasize image]
  57. ==
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement