bmp stuff
This commit is contained in:
parent
724b2f30da
commit
42da6582cf
4 changed files with 19 additions and 13 deletions
|
@ -1 +1,2 @@
|
|||
## Add private variables or functions here that you don't want to export.
|
||||
type
|
||||
PixieError* = object of ValueError ## Raised if an operation fails.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import ../images, flatty/binny, chroma
|
||||
import ../images, flatty/binny, chroma, pixie/common
|
||||
|
||||
# See: https://en.wikipedia.org/wiki/BMP_file_format
|
||||
|
||||
|
@ -6,17 +6,22 @@ proc decodeBmp*(data: string): Image =
|
|||
## Decodes bitmap data into an Image.
|
||||
|
||||
# BMP Header
|
||||
doAssert data[0..1] == "BM"
|
||||
let
|
||||
width = data.readInt32(0x12).int
|
||||
height = data.readInt32(0x16).int
|
||||
bits = data.readUint16(0x1C)
|
||||
compression = data.readUint32(0x1E)
|
||||
var
|
||||
offset = data.readUInt32(0xA).int
|
||||
if data[0..1] != "BM":
|
||||
raise newException(PixieError, "Invalid BMP data")
|
||||
|
||||
doAssert bits in {32, 24}
|
||||
doAssert compression in {0, 3}
|
||||
let
|
||||
width = data.readInt32(18).int
|
||||
height = data.readInt32(22).int
|
||||
bits = data.readUint16(28).int
|
||||
compression = data.readUint32(30).int
|
||||
var
|
||||
offset = data.readUInt32(10).int
|
||||
|
||||
if bits notin [32, 24]:
|
||||
raise newException(PixieError, "Invalid BMP data format")
|
||||
|
||||
if compression notin [0, 3]:
|
||||
raise newException(PixieError, "Invalid BMP data format")
|
||||
|
||||
result = newImage(width, height)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import pixie, pixie/fileformats/bmp, chroma, flatty/hexPrint
|
||||
import pixie, pixie/fileformats/bmp, chroma
|
||||
|
||||
block:
|
||||
var image = newImage(4, 2)
|
Loading…
Reference in a new issue