Enhance decodeRect for 16bpp pixel format support
Modified decodeRect to handle 16bpp raw pixel format decoding with customizable parameters.
This commit is contained in:
parent
dc19a62112
commit
fd4c72eb92
|
|
@ -12,7 +12,7 @@ export default class RawDecoder {
|
|||
this._lines = 0;
|
||||
}
|
||||
|
||||
decodeRect(x, y, width, height, sock, display, depth) {
|
||||
decodeRect(x, y, width, height, sock, display, depth, pixelFormat) {
|
||||
if ((width === 0) || (height === 0)) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ export default class RawDecoder {
|
|||
this._lines = height;
|
||||
}
|
||||
|
||||
const pixelSize = depth == 8 ? 1 : 4;
|
||||
const pixelSize = depth == 8 ? 1 : (depth == 16 ? 2 : 4); // Modifications
|
||||
const bytesPerLine = width * pixelSize;
|
||||
|
||||
while (this._lines > 0) {
|
||||
|
|
@ -43,6 +43,36 @@ export default class RawDecoder {
|
|||
newdata[i * 4 + 3] = 255;
|
||||
}
|
||||
data = newdata;
|
||||
} else if (depth == 16) { // Modifications: decode 16bpp raw
|
||||
const fmt = pixelFormat || {};
|
||||
const redMax = fmt.redMax !== undefined ? fmt.redMax : 31;
|
||||
const greenMax = fmt.greenMax !== undefined ? fmt.greenMax : 63;
|
||||
const blueMax = fmt.blueMax !== undefined ? fmt.blueMax : 31;
|
||||
const redShift = fmt.redShift !== undefined ? fmt.redShift : 11;
|
||||
const greenShift = fmt.greenShift !== undefined ? fmt.greenShift : 5;
|
||||
const blueShift = fmt.blueShift !== undefined ? fmt.blueShift : 0;
|
||||
const bigEndian = !!fmt.bigEndian;
|
||||
|
||||
const newdata = new Uint8Array(width * 4);
|
||||
for (let i = 0; i < width; i++) {
|
||||
const idx = i * 2;
|
||||
let pixel;
|
||||
if (bigEndian) {
|
||||
pixel = (data[idx] << 8) | data[idx + 1];
|
||||
} else {
|
||||
pixel = data[idx] | (data[idx + 1] << 8);
|
||||
}
|
||||
|
||||
const r = (pixel >> redShift) & redMax;
|
||||
const g = (pixel >> greenShift) & greenMax;
|
||||
const b = (pixel >> blueShift) & blueMax;
|
||||
|
||||
newdata[i * 4 + 0] = redMax ? (r * 255 / redMax) : 0;
|
||||
newdata[i * 4 + 1] = greenMax ? (g * 255 / greenMax) : 0;
|
||||
newdata[i * 4 + 2] = blueMax ? (b * 255 / blueMax) : 0;
|
||||
newdata[i * 4 + 3] = 255;
|
||||
}
|
||||
data = newdata;
|
||||
}
|
||||
|
||||
// Max sure the image is fully opaque
|
||||
|
|
|
|||
Loading…
Reference in New Issue