Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import type { ByteArray } from 'dicom-parser'; export default function ( imageFrame: ByteArray, colorBuffer: ByteArray, useRGBA: boolean ): void { if (imageFrame === undefined) { throw new Error('convertYBRFullByPlane: ybrBuffer must be defined'); } if (imageFrame.length % 3 !== 0) { throw new Error( `convertYBRFullByPlane: ybrBuffer length ${imageFrame.length} must be divisible by 3` ); } const numPixels = imageFrame.length / 3; let bufferIndex = 0; let yIndex = 0; let cbIndex = numPixels; let crIndex = numPixels * 2; if (useRGBA) { for (let i = 0; i < numPixels; i++) { const y = imageFrame[yIndex++]; const cb = imageFrame[cbIndex++]; const cr = imageFrame[crIndex++]; colorBuffer[bufferIndex++] = y + 1.402 * (cr - 128); // red colorBuffer[bufferIndex++] = y - 0.34414 * (cb - 128) - 0.71414 * (cr - 128); // green colorBuffer[bufferIndex++] = y + 1.772 * (cb - 128); // blue colorBuffer[bufferIndex++] = 255; // alpha } return; } for (let i = 0; i < numPixels; i++) { const y = imageFrame[yIndex++]; const cb = imageFrame[cbIndex++]; const cr = imageFrame[crIndex++]; colorBuffer[bufferIndex++] = y + 1.402 * (cr - 128); // red colorBuffer[bufferIndex++] = y - 0.34414 * (cb - 128) - 0.71414 * (cr - 128); // green colorBuffer[bufferIndex++] = y + 1.772 * (cb - 128); // blue } } |