Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- |= dim=@ud
- ^- @ux
- :: Pixel bytes for 24bpp dim*dim image
- :: Note: this calculation does not support padding, so dim%4 must be 0
- ::
- =/ datasize=@ (mul 3 (mul dim dim))
- :: The header is a list of [bytes, value] to be composed into a single blob
- ::
- =/ header=@
- %+ can 3
- ^- (list [@ @])
- :~
- :: BMP header part, 14 bytes
- ::
- [2 'BM'] :: format ID
- [4 (add 54 datasize)] :: file size - 54 byte header + pixel data
- [4 0] :: unused
- [4 54] :: header size
- :: DIB header part, 4 bytes
- ::
- [4 40] :: DIB header size
- [4 dim] :: width
- [4 dim] :: height
- [2 3] :: number of channels
- [2 24] :: bits per pixel
- [4 0] :: compression (none; BI_RGB)
- [4 datasize] :: pixel data size
- [4 2.835] :: print resolution x (72 DPI)
- [4 2.835] :: print resolution y (72 DPI)
- [8 0] :: palette stuff (unused)
- ==
- =/ image=@
- %+ rap 3
- =/ py=@ 0
- |-
- ^- (list @)
- =/ px=@ 0
- |-
- ^- (list @)
- :: Define the image as a BGR888 pixel in terms of x and y
- ::
- :- (add 128 (div (mul px 256) (mul 2 dim)))
- :- 255
- :- 255
- :: Recurse for all pixels
- ::
- ?: (lth +(px) dim)
- $(px +(px))
- ?: (lth +(py) dim)
- ^$(py +(py))
- ~
- %+ can 3
- ^- (list [@ @])
- :~
- [54 header]
- [datasize image]
- ==
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement