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 55 56 57 58 59 60 61 62 63 | import type { ByteArray } from 'dicom-parser'; export default function ( imageFrame: ByteArray, colorBuffer: ByteArray, useRGBA: boolean ): void { if (imageFrame === undefined) { throw new Error('convertYBRFull422ByPixel: ybrBuffer must be defined'); } if (imageFrame.length % 2 !== 0) { throw new Error( `convertYBRFull422ByPixel: ybrBuffer length ${imageFrame.length} must be divisible by 2` ); } const numPixels = imageFrame.length / 2; let ybrIndex = 0; let bufferIndex = 0; if (useRGBA) { for (let i = 0; i < numPixels; i += 2) { const y1 = imageFrame[ybrIndex++]; const y2 = imageFrame[ybrIndex++]; const cb = imageFrame[ybrIndex++]; const cr = imageFrame[ybrIndex++]; colorBuffer[bufferIndex++] = y1 + 1.402 * (cr - 128); // red colorBuffer[bufferIndex++] = y1 - 0.34414 * (cb - 128) - 0.71414 * (cr - 128); // green colorBuffer[bufferIndex++] = y1 + 1.772 * (cb - 128); // blue colorBuffer[bufferIndex++] = 255; // alpha colorBuffer[bufferIndex++] = y2 + 1.402 * (cr - 128); // red colorBuffer[bufferIndex++] = y2 - 0.34414 * (cb - 128) - 0.71414 * (cr - 128); // green colorBuffer[bufferIndex++] = y2 + 1.772 * (cb - 128); // blue colorBuffer[bufferIndex++] = 255; // alpha } return; } for (let i = 0; i < numPixels; i += 2) { const y1 = imageFrame[ybrIndex++]; const y2 = imageFrame[ybrIndex++]; const cb = imageFrame[ybrIndex++]; const cr = imageFrame[ybrIndex++]; colorBuffer[bufferIndex++] = y1 + 1.402 * (cr - 128); // red colorBuffer[bufferIndex++] = y1 - 0.34414 * (cb - 128) - 0.71414 * (cr - 128); // green colorBuffer[bufferIndex++] = y1 + 1.772 * (cb - 128); // blue colorBuffer[bufferIndex++] = y2 + 1.402 * (cr - 128); // red colorBuffer[bufferIndex++] = y2 - 0.34414 * (cb - 128) - 0.71414 * (cr - 128); // green colorBuffer[bufferIndex++] = y2 + 1.772 * (cb - 128); // blue } } |