Fail when channel maks is 0.
This commit is contained in:
parent
294adef29f
commit
ffc1b90c5f
1 changed files with 16 additions and 12 deletions
|
@ -24,16 +24,20 @@ proc decodeBmp*(data: string): Image {.raises: [PixieError].} =
|
||||||
var
|
var
|
||||||
offset = data.readUInt32(10).int
|
offset = data.readUInt32(10).int
|
||||||
# Default channels if header does not contain them:
|
# Default channels if header does not contain them:
|
||||||
redChan = 0x00FF0000.uint32
|
redChannel = 0x00FF0000.uint32
|
||||||
greenChan = 0x0000FF00.uint32
|
greenChannel = 0x0000FF00.uint32
|
||||||
blueChan = 0x000000FF.uint32
|
blueChannel = 0x000000FF.uint32
|
||||||
alphaChan = 0xFF000000.uint32
|
alphaChannel = 0xFF000000.uint32
|
||||||
|
|
||||||
if dibHeader == 108:
|
if dibHeader == 108:
|
||||||
redChan = data.readUInt32(54)
|
redChannel = data.readUInt32(54)
|
||||||
greenChan = data.readUInt32(58)
|
greenChannel = data.readUInt32(58)
|
||||||
blueChan = data.readUInt32(62)
|
blueChannel = data.readUInt32(62)
|
||||||
alphaChan = data.readUInt32(66)
|
alphaChannel = data.readUInt32(66)
|
||||||
|
|
||||||
|
if redChannel == 0 or greenChannel == 0 or
|
||||||
|
blueChannel == 0 or alphaChannel == 0:
|
||||||
|
raise newException(PixieError, "Unsupported 0 channel mask.")
|
||||||
|
|
||||||
if bits notin [32, 24]:
|
if bits notin [32, 24]:
|
||||||
raise newException(PixieError, "Unsupported BMP data format")
|
raise newException(PixieError, "Unsupported BMP data format")
|
||||||
|
@ -52,10 +56,10 @@ proc decodeBmp*(data: string): Image {.raises: [PixieError].} =
|
||||||
var rgba: ColorRGBA
|
var rgba: ColorRGBA
|
||||||
if bits == 32:
|
if bits == 32:
|
||||||
let color = data.readUint32(offset)
|
let color = data.readUint32(offset)
|
||||||
rgba.r = color.colorMaskShift(redChan)
|
rgba.r = color.colorMaskShift(redChannel)
|
||||||
rgba.g = color.colorMaskShift(greenChan)
|
rgba.g = color.colorMaskShift(greenChannel)
|
||||||
rgba.b = color.colorMaskShift(blueChan)
|
rgba.b = color.colorMaskShift(blueChannel)
|
||||||
rgba.a = color.colorMaskShift(alphaChan)
|
rgba.a = color.colorMaskShift(alphaChannel)
|
||||||
offset += 4
|
offset += 4
|
||||||
elif bits == 24:
|
elif bits == 24:
|
||||||
rgba.r = data.readUint8(offset + 2)
|
rgba.r = data.readUint8(offset + 2)
|
||||||
|
|
Loading…
Reference in a new issue