From 3e204e829f81c543526e25c9d9c20392d62bdd01 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Mon, 16 May 2022 22:29:56 -0500 Subject: [PATCH] ez perf --- src/pixie/fileformats/jpeg.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pixie/fileformats/jpeg.nim b/src/pixie/fileformats/jpeg.nim index 3bb484d..544205f 100644 --- a/src/pixie/fileformats/jpeg.nim +++ b/src/pixie/fileformats/jpeg.nim @@ -895,17 +895,21 @@ proc buildImage(state: var DecoderState): Image = cb = state.components[1].channel cr = state.components[2].channel for y in 0 ..< state.imageHeight: + var channelIndex = cy.dataIndex(0, y) for x in 0 ..< state.imageWidth: result.unsafe[x, y] = yCbCrToRgbx( - cy.unsafe[x, y], - cb.unsafe[x, y], - cr.unsafe[x, y], + cy.data[channelIndex], + cb.data[channelIndex], + cr.data[channelIndex], ) + inc channelIndex elif state.components.len == 1: let cy = state.components[0].channel for y in 0 ..< state.imageHeight: + var channelIndex = cy.dataIndex(0, y) for x in 0 ..< state.imageWidth: - result.unsafe[x, y] = grayScaleToRgbx(cy.unsafe[x, y]) + result.unsafe[x, y] = grayScaleToRgbx(cy.data[channelIndex]) + inc channelIndex else: failInvalid()