mirror of
https://github.com/lovell/sharp.git
synced 2025-07-12 03:50:13 +02:00
Ensure sharp.format lists support for raw input #220
This commit is contained in:
parent
a9eb65c462
commit
6ca2a4a9cd
@ -752,7 +752,7 @@ class PipelineWorker : public AsyncWorker {
|
||||
area->free_fn = nullptr;
|
||||
vips_area_unref(area);
|
||||
baton->formatOut = "webp";
|
||||
} else if (baton->formatOut == "raw") {
|
||||
} else if (baton->formatOut == "raw" || (baton->formatOut == "input" && inputImageType == ImageType::RAW)) {
|
||||
// Write raw, uncompressed image data to buffer
|
||||
if (baton->greyscale || image.interpretation() == VIPS_INTERPRETATION_B_W) {
|
||||
// Extract first band for greyscale image
|
||||
|
@ -172,19 +172,17 @@ NAN_METHOD(format) {
|
||||
Local<String> rawId = New("raw").ToLocalChecked();
|
||||
Set(raw, attrId, rawId);
|
||||
Set(format, rawId, raw);
|
||||
// No support for raw input yet, so always false
|
||||
Local<Boolean> supported = New<Boolean>(true);
|
||||
Local<Boolean> unsupported = New<Boolean>(false);
|
||||
Local<Object> rawInput = New<Object>();
|
||||
Set(rawInput, attrFile, unsupported);
|
||||
Set(rawInput, attrBuffer, unsupported);
|
||||
Set(rawInput, attrStream, unsupported);
|
||||
Set(rawInput, attrBuffer, supported);
|
||||
Set(rawInput, attrStream, supported);
|
||||
Set(raw, attrInput, rawInput);
|
||||
// Raw output via Buffer/Stream is available in libvips >= 7.42.0
|
||||
Local<Boolean> hasOutputBufferRaw = New<Boolean>(vips_version(0) >= 8 || (vips_version(0) == 7 && vips_version(1) >= 42));
|
||||
Local<Object> rawOutput = New<Object>();
|
||||
Set(rawOutput, attrFile, unsupported);
|
||||
Set(rawOutput, attrBuffer, hasOutputBufferRaw);
|
||||
Set(rawOutput, attrStream, hasOutputBufferRaw);
|
||||
Set(rawOutput, attrBuffer, supported);
|
||||
Set(rawOutput, attrStream, supported);
|
||||
Set(raw, attrOutput, rawOutput);
|
||||
|
||||
info.GetReturnValue().Set(format);
|
||||
|
@ -113,6 +113,13 @@ describe('Utilities', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
it('Raw file=false, buffer=true, stream=true', function() {
|
||||
['input', 'output'].forEach(function(direction) {
|
||||
assert.strictEqual(false, sharp.format.raw[direction].file);
|
||||
assert.strictEqual(true, sharp.format.raw[direction].buffer);
|
||||
assert.strictEqual(true, sharp.format.raw[direction].stream);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Versions', function() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user