@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
59 lines (44 loc) • 1.61 kB
JavaScript
import { idct8x8_float } from "./idct8x8_float.js";
/**
*
* @param {JpegFrameComponent} component
* @return {Uint8Array[]} lines
*/
export function buildComponentData(component) {
/**
*
* @type {Uint8Array[]}
*/
const lines = [];
const blocks_per_line = component.blocksPerLine;
const blocks_per_column = component.blocksPerColumn;
const samples_per_line = blocks_per_line << 3;
// Only 1 used per invocation of this function and garbage collected after invocation, so no need to account for its memory footprint.
const r = new Uint8Array(64);
let i, j;
for (let block_row = 0; block_row < blocks_per_column; block_row++) {
const scan_line = block_row << 3;
// align memory
const lines_buffer = new ArrayBuffer(samples_per_line * 8);
for (i = 0; i < 8; i++) {
const line = new Uint8Array(lines_buffer, i * samples_per_line, samples_per_line);
lines.push(line);
}
for (let block_col = 0; block_col < blocks_per_line; block_col++) {
idct8x8_float(
component.quantizationTable,
component.blocks[block_row][block_col],
r,
);
let offset = 0;
let sample = block_col << 3;
for (j = 0; j < 8; j++) {
const line = lines[scan_line + j];
for (i = 0; i < 8; i++) {
line[sample + i] = r[offset++];
}
}
}
}
return lines;
}