qoi consistent style pass#356
Conversation
| # allocate a buffer 3/4 the size of the pathological encoding | ||
|
|
||
| result.add(qoiSignature) | ||
| when cpuEndian == bigEndian: |
There was a problem hiding this comment.
no tests, untested. we do not support big endian anywhere else and have not / cannot? ensure this actually is all that is needed. rm.
| inc run | ||
| if run == 62 or off == qoi.data.high: | ||
| result.addUint8(opRun or pred(run)) | ||
| reset run |
There was a problem hiding this comment.
had to look this up, not worth it
| if px == pxPrev: | ||
| inc run | ||
| if run == 62 or off == qoi.data.high: | ||
| result.addUint8(opRun or pred(run)) |
There was a problem hiding this comment.
had to look this up too, not worth it
|
|
||
| result = Qoi( | ||
| data: newSeq[ColorRGBA](int width * height), | ||
| width: int width, |
There was a problem hiding this comment.
we by convention append our type conversions to the end
| copyMem(result.data[0].addr, qoi.data[0].addr, qoi.data.len * 4) | ||
| result.data.toPremultipliedAlpha() | ||
|
|
||
| func toQoi*(img: Image; channels: range[3..4]): Qoi = |
There was a problem hiding this comment.
be consistent with png's raw api, do not take in channels without tests (this is not run in any tests)
| var | ||
| width, height: uint32 | ||
| channels, colorspace: uint8 | ||
| block: |
There was a problem hiding this comment.
see endian comment below
| inc p | ||
| of opRun: | ||
| run = b0 and 0x3f | ||
| else: assert false |
There was a problem hiding this comment.
this seems bad, throw for real?
| px.r = data.readUint8(p+0) | ||
| px.g = data.readUint8(p+1) | ||
| px.b = data.readUint8(p+2) | ||
| inc(p, 3) |
There was a problem hiding this comment.
out of convension we only use inc and dec for +1 and -1, otherwise just use +=
| ## Decodes data in the QOI file format to an `Image`. | ||
| decompressQoi(data).toImage() | ||
|
|
||
| proc decodeQoi*(data: seq[uint8]): Image {.inline, raises: [PixieError].} = |
There was a problem hiding this comment.
gave up on seq[uint8] a long time ago. nim's native representation for bytes is string, see standard lib readFile
| data[pos] = value | ||
| value = rand(255).uint8 | ||
| data[pos] = value.char | ||
| echo &"{i} {pos} {value}" |
There was a problem hiding this comment.
important to echo, so if fuzzing crashes we can reproduce the case immediately
| @@ -1,5 +1,4 @@ | |||
| import std/endians, chroma, flatty/binny | |||
There was a problem hiding this comment.
morepretty does not understand [] imports so we do not use them (support could be added tho, not opposed to them if it is automatic)
Uh oh!
There was an error while loading. Please reload this page.