Skip to content

Commit 2585636

Browse files
committed
faster jpeg encoding again
1 parent b2e0bb8 commit 2585636

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 3.16.1
4+
5+
### Performance
6+
7+
- `encodeJPEG()` is about 4% faster again: 3.16.0's greyscale JPEG support (for gain maps) had slowed down its block
8+
loop. Output is unchanged, byte for byte.
9+
310
## 3.16.0
411

512
### New

‎src/codecs/jpeg.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,8 @@ export function encode(pixels: Uint8Array, width: number, height: number, qualit
10681068
{ plane: Y, stride: W, h: hmax, v: hmax, blocksX: lumaBlocksX, blocksY: lumaBlocksY, table: 0 },
10691069
{ plane: Cb, stride: CW, h: 1, v: 1, blocksX: chromaBlocksX, blocksY: chromaBlocksY, table: 1 },
10701070
{ plane: Cr, stride: CW, h: 1, v: 1, blocksX: chromaBlocksX, blocksY: chromaBlocksY, table: 1 }
1071-
].slice(0, grey ? 1 : 3);
1071+
];
1072+
const componentCount = grey ? 1 : 3;
10721073

10731074
// quantized blocks in MCU order (Y blocks, then Cb, then Cr), their coefficients in zigzag order, with the index
10741075
// of each block's last nonzero coefficient. MCUs reaching past a component's blocks get dummy blocks (jccoefct.c):
@@ -1083,7 +1084,7 @@ export function encode(pixels: Uint8Array, width: number, height: number, qualit
10831084

10841085
for (let my = 0; my < mcusPerColumn; my++)
10851086
for (let mx = 0; mx < mcusPerLine; mx++)
1086-
for (let c = 0; c < components.length; c++) {
1087+
for (let c = 0; c < componentCount; c++) {
10871088
const { plane, stride, h: ch, v: cv, blocksX, blocksY, table } = components[c];
10881089
const reciprocal = divisors[table];
10891090

0 commit comments

Comments
 (0)