From 6ca2a4a9cdd3aeb675380ea3385f5dd9b7931a80 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Thu, 11 Feb 2016 18:12:51 +0000 Subject: [PATCH] Ensure sharp.format lists support for raw input #220 --- src/pipeline.cc | 2 +- src/utilities.cc | 12 +++++------- test/unit/util.js | 7 +++++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pipeline.cc b/src/pipeline.cc index a55fb791..336d0199 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -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 diff --git a/src/utilities.cc b/src/utilities.cc index 9f121ae5..de37e24b 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -172,19 +172,17 @@ NAN_METHOD(format) { Local rawId = New("raw").ToLocalChecked(); Set(raw, attrId, rawId); Set(format, rawId, raw); - // No support for raw input yet, so always false + Local supported = New(true); Local unsupported = New(false); Local rawInput = New(); 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 hasOutputBufferRaw = New(vips_version(0) >= 8 || (vips_version(0) == 7 && vips_version(1) >= 42)); Local rawOutput = New(); 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); diff --git a/test/unit/util.js b/test/unit/util.js index dde22caf..022adb9c 100644 --- a/test/unit/util.js +++ b/test/unit/util.js @@ -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() {