mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Ensure correct interp of 16-bit raw input #3808
This commit is contained in:
parent
ca95979ecc
commit
f8cf25ca56
@ -13,6 +13,9 @@ Requires libvips v8.14.5
|
|||||||
* Make `compression` option of `heif` mandatory to help reduce HEIF vs HEIC confusion.
|
* Make `compression` option of `heif` mandatory to help reduce HEIF vs HEIC confusion.
|
||||||
[#3740](https://github.com/lovell/sharp/issues/3740)
|
[#3740](https://github.com/lovell/sharp/issues/3740)
|
||||||
|
|
||||||
|
* Ensure correct interpretation of 16-bit raw input.
|
||||||
|
[#3808](https://github.com/lovell/sharp/issues/3808)
|
||||||
|
|
||||||
## v0.32 - *flow*
|
## v0.32 - *flow*
|
||||||
|
|
||||||
Requires libvips v8.14.5
|
Requires libvips v8.14.5
|
||||||
|
@ -363,12 +363,13 @@ namespace sharp {
|
|||||||
if (descriptor->isBuffer) {
|
if (descriptor->isBuffer) {
|
||||||
if (descriptor->rawChannels > 0) {
|
if (descriptor->rawChannels > 0) {
|
||||||
// Raw, uncompressed pixel data
|
// Raw, uncompressed pixel data
|
||||||
|
bool const is8bit = vips_band_format_is8bit(descriptor->rawDepth);
|
||||||
image = VImage::new_from_memory(descriptor->buffer, descriptor->bufferLength,
|
image = VImage::new_from_memory(descriptor->buffer, descriptor->bufferLength,
|
||||||
descriptor->rawWidth, descriptor->rawHeight, descriptor->rawChannels, descriptor->rawDepth);
|
descriptor->rawWidth, descriptor->rawHeight, descriptor->rawChannels, descriptor->rawDepth);
|
||||||
if (descriptor->rawChannels < 3) {
|
if (descriptor->rawChannels < 3) {
|
||||||
image.get_image()->Type = VIPS_INTERPRETATION_B_W;
|
image.get_image()->Type = is8bit ? VIPS_INTERPRETATION_B_W : VIPS_INTERPRETATION_GREY16;
|
||||||
} else {
|
} else {
|
||||||
image.get_image()->Type = VIPS_INTERPRETATION_sRGB;
|
image.get_image()->Type = is8bit ? VIPS_INTERPRETATION_sRGB : VIPS_INTERPRETATION_RGB16;
|
||||||
}
|
}
|
||||||
if (descriptor->rawPremultiplied) {
|
if (descriptor->rawPremultiplied) {
|
||||||
image = image.unpremultiply();
|
image = image.unpremultiply();
|
||||||
|
@ -284,4 +284,42 @@ describe('Raw pixel data', function () {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('16-bit roundtrip', () => {
|
||||||
|
it('grey', async () => {
|
||||||
|
const grey = 42000;
|
||||||
|
const png = await sharp(
|
||||||
|
Uint16Array.from([grey]),
|
||||||
|
{ raw: { width: 1, height: 1, channels: 1 } }
|
||||||
|
)
|
||||||
|
.toColourspace('grey16')
|
||||||
|
.png({ compressionLevel: 0 })
|
||||||
|
.toBuffer();
|
||||||
|
const raw = await sharp(png)
|
||||||
|
.toColourspace('grey16')
|
||||||
|
.raw({ depth: 'ushort' })
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
assert.strictEqual(raw.readUint16LE(0), grey);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('RGB', async () => {
|
||||||
|
const rgb = [10946, 28657, 46368];
|
||||||
|
const png = await sharp(
|
||||||
|
Uint16Array.from(rgb),
|
||||||
|
{ raw: { width: 1, height: 1, channels: 3 } }
|
||||||
|
)
|
||||||
|
.toColourspace('rgb16')
|
||||||
|
.png({ compressionLevel: 0 })
|
||||||
|
.toBuffer();
|
||||||
|
const raw = await sharp(png)
|
||||||
|
.toColourspace('rgb16')
|
||||||
|
.raw({ depth: 'ushort' })
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
assert.strictEqual(raw.readUint16LE(0), rgb[0]);
|
||||||
|
assert.strictEqual(raw.readUint16LE(2), rgb[1]);
|
||||||
|
assert.strictEqual(raw.readUint16LE(4), rgb[2]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user