remove incorrect rgba conversion

This commit is contained in:
Rasmus Moorats 2022-01-09 17:37:03 +02:00
parent 64cfad16fb
commit 71016b868e
No known key found for this signature in database
GPG key ID: FE14255A6AE7241C

View file

@ -27,7 +27,7 @@ proc decodeHeader(data: string): PpmHeader {.raises: [PixieError].} =
commentMode = false commentMode = false
if not commentMode: if not commentMode:
if c in Whitespace and not readWhitespace: if c in Whitespace and not readWhitespace:
readFields += 1 inc readFields
readWhitespace = true readWhitespace = true
try: try:
case readFields: case readFields:
@ -46,22 +46,22 @@ proc decodeHeader(data: string): PpmHeader {.raises: [PixieError].} =
elif not (c in Whitespace): elif not (c in Whitespace):
field.add(c) field.add(c)
readWhitespace = false readWhitespace = false
i += 1 inc i
result.dataOffset = i result.dataOffset = i
proc decodeP6Data(data: string, maxVal: int): seq[ColorRGBX] {.raises: [].} = proc decodeP6Data(data: string, maxVal: int): seq[ColorRGBX] {.raises: [].} =
let needsUint16 = maxVal > 0xFF let needsUint16 = maxVal > 0xFF
result = newSeq[ColorRGBX](( result = newSeq[ColorRGBX](
if needsUint16: data.len / 6 if needsUint16: data.len div 6
else: data.len / 3 else: data.len div 3
).int) )
# Let's calculate the real maximum value multiplier. # Let's calculate the real maximum value multiplier.
# rgbx() accepts a maximum value of 0xFF. Most of the time, # rgbx() accepts a maximum value of 0xFF. Most of the time,
# maxVal is set to 0xFF as well, so in most cases it is 1 # maxVal is set to 0xFF as well, so in most cases it is 1
let valueMultiplier = (0xFF / maxVal).uint8 let valueMultiplier = (0xFF div maxVal).uint8
# if comparison in for loops is expensive, so let's unroll it # if comparison in for loops is expensive, so let's unroll it
if not needsUint16: if not needsUint16:
@ -124,7 +124,7 @@ proc encodePpm*(image: Image): string {.raises: [].} =
# PPM image data # PPM image data
for y in 0 ..< image.height: for y in 0 ..< image.height:
for x in 0 ..< image.width: for x in 0 ..< image.width:
let rgb = image[x, y].rgba() let rgb = image[x, y]
# Alpha channel is ignored # Alpha channel is ignored
result.addUint8(rgb.r) result.addUint8(rgb.r)
result.addUint8(rgb.g) result.addUint8(rgb.g)