mirror of
https://github.com/lovell/sharp.git
synced 2025-07-10 19:10:14 +02:00
Add use of 'cc' to improve C++ code style linting
This commit is contained in:
parent
04f5c884a4
commit
81f5589411
18
package.json
18
package.json
@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "sharp",
|
"name": "sharp",
|
||||||
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images",
|
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images",
|
||||||
"version": "0.17.1",
|
"version": "0.17.2",
|
||||||
"author": "Lovell Fuller <npm@lovell.info>",
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
|
"homepage": "https://github.com/lovell/sharp",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Pierre Inglebert <pierre.inglebert@gmail.com>",
|
"Pierre Inglebert <pierre.inglebert@gmail.com>",
|
||||||
"Jonathan Ong <jonathanrichardong@gmail.com>",
|
"Jonathan Ong <jonathanrichardong@gmail.com>",
|
||||||
@ -35,7 +36,7 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rm -rf node_modules/ build/ vendor/ coverage/ test/fixtures/output.*",
|
"clean": "rm -rf node_modules/ build/ vendor/ coverage/ test/fixtures/output.*",
|
||||||
"test": "semistandard && cross-env VIPS_WARNING=0 nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
"test": "semistandard && cc && cross-env VIPS_WARNING=0 nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
||||||
"test-leak": "./test/leak/leak.sh",
|
"test-leak": "./test/leak/leak.sh",
|
||||||
"test-packaging": "./packaging/test-linux-x64.sh",
|
"test-packaging": "./packaging/test-linux-x64.sh",
|
||||||
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done"
|
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done"
|
||||||
@ -64,19 +65,19 @@
|
|||||||
"caw": "^2.0.0",
|
"caw": "^2.0.0",
|
||||||
"color": "^1.0.3",
|
"color": "^1.0.3",
|
||||||
"got": "^6.7.1",
|
"got": "^6.7.1",
|
||||||
"nan": "^2.5.0",
|
"nan": "^2.5.1",
|
||||||
"semver": "^5.3.0",
|
"semver": "^5.3.0",
|
||||||
"tar": "^2.2.1"
|
"tar": "^2.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^2.1.4",
|
"async": "^2.1.4",
|
||||||
"bufferutil": "^1.3.0",
|
"bufferutil": "^2.0.1",
|
||||||
|
"cc": "^1.0.0",
|
||||||
"cross-env": "^3.1.4",
|
"cross-env": "^3.1.4",
|
||||||
"documentation": "^4.0.0-beta.18",
|
"documentation": "^4.0.0-beta.18",
|
||||||
"exif-reader": "^1.0.2",
|
"exif-reader": "^1.0.2",
|
||||||
"icc": "^1.0.0",
|
"icc": "^1.0.0",
|
||||||
"mocha": "^3.2.0",
|
"mocha": "^3.2.0",
|
||||||
"node-cpplint": "^0.4.0",
|
|
||||||
"nyc": "^10.1.2",
|
"nyc": "^10.1.2",
|
||||||
"rimraf": "^2.5.4",
|
"rimraf": "^2.5.4",
|
||||||
"semistandard": "^9.2.1",
|
"semistandard": "^9.2.1",
|
||||||
@ -93,5 +94,12 @@
|
|||||||
"env": [
|
"env": [
|
||||||
"mocha"
|
"mocha"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"cc": {
|
||||||
|
"linelength": "120",
|
||||||
|
"filter": [
|
||||||
|
"build/include",
|
||||||
|
"runtime/indentation_namespace"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,27 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <node.h>
|
#include <node.h>
|
||||||
#include <node_buffer.h>
|
#include <node_buffer.h>
|
||||||
|
#include <nan.h>
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
|
|
||||||
#include "nan.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
using vips::VImage;
|
using vips::VImage;
|
||||||
@ -254,8 +269,7 @@ namespace sharp {
|
|||||||
return (
|
return (
|
||||||
(bands == 2 && interpretation == VIPS_INTERPRETATION_B_W) ||
|
(bands == 2 && interpretation == VIPS_INTERPRETATION_B_W) ||
|
||||||
(bands == 4 && interpretation != VIPS_INTERPRETATION_CMYK) ||
|
(bands == 4 && interpretation != VIPS_INTERPRETATION_CMYK) ||
|
||||||
(bands == 5 && interpretation == VIPS_INTERPRETATION_CMYK)
|
(bands == 5 && interpretation == VIPS_INTERPRETATION_CMYK));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -378,23 +392,23 @@ namespace sharp {
|
|||||||
int top = 0;
|
int top = 0;
|
||||||
|
|
||||||
// assign only if valid
|
// assign only if valid
|
||||||
if(x >= 0 && x < (inWidth - outWidth)) {
|
if (x >= 0 && x < (inWidth - outWidth)) {
|
||||||
left = x;
|
left = x;
|
||||||
} else if(x >= (inWidth - outWidth)) {
|
} else if (x >= (inWidth - outWidth)) {
|
||||||
left = inWidth - outWidth;
|
left = inWidth - outWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(y >= 0 && y < (inHeight - outHeight)) {
|
if (y >= 0 && y < (inHeight - outHeight)) {
|
||||||
top = y;
|
top = y;
|
||||||
} else if(y >= (inHeight - outHeight)) {
|
} else if (y >= (inHeight - outHeight)) {
|
||||||
top = inHeight - outHeight;
|
top = inHeight - outHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the resulting left and top could have been outside the image after calculation from bottom/right edges
|
// the resulting left and top could have been outside the image after calculation from bottom/right edges
|
||||||
if(left < 0) {
|
if (left < 0) {
|
||||||
left = 0;
|
left = 0;
|
||||||
}
|
}
|
||||||
if(top < 0) {
|
if (top < 0) {
|
||||||
top = 0;
|
top = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,8 +435,7 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VipsOperationBoolean GetBooleanOperation(std::string const opStr) {
|
VipsOperationBoolean GetBooleanOperation(std::string const opStr) {
|
||||||
return static_cast<VipsOperationBoolean>(
|
return static_cast<VipsOperationBoolean>(
|
||||||
vips_enum_from_nick(nullptr, VIPS_TYPE_OPERATION_BOOLEAN, opStr.data())
|
vips_enum_from_nick(nullptr, VIPS_TYPE_OPERATION_BOOLEAN, opStr.data()));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -430,8 +443,7 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VipsInterpretation GetInterpretation(std::string const typeStr) {
|
VipsInterpretation GetInterpretation(std::string const typeStr) {
|
||||||
return static_cast<VipsInterpretation>(
|
return static_cast<VipsInterpretation>(
|
||||||
vips_enum_from_nick(nullptr, VIPS_TYPE_INTERPRETATION, typeStr.data())
|
vips_enum_from_nick(nullptr, VIPS_TYPE_INTERPRETATION, typeStr.data()));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
21
src/common.h
21
src/common.h
@ -1,14 +1,28 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef SRC_COMMON_H_
|
#ifndef SRC_COMMON_H_
|
||||||
#define SRC_COMMON_H_
|
#define SRC_COMMON_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <node.h>
|
#include <node.h>
|
||||||
|
#include <nan.h>
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
|
|
||||||
#include "nan.h"
|
|
||||||
|
|
||||||
// Verify platform and compiler compatibility
|
// Verify platform and compiler compatibility
|
||||||
|
|
||||||
#if (VIPS_MAJOR_VERSION < 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 4))
|
#if (VIPS_MAJOR_VERSION < 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 4))
|
||||||
@ -63,8 +77,7 @@ namespace sharp {
|
|||||||
|
|
||||||
// Create an InputDescriptor instance from a v8::Object describing an input image
|
// Create an InputDescriptor instance from a v8::Object describing an input image
|
||||||
InputDescriptor* CreateInputDescriptor(
|
InputDescriptor* CreateInputDescriptor(
|
||||||
v8::Handle<v8::Object> input, std::vector<v8::Local<v8::Object>> buffersToPersist
|
v8::Handle<v8::Object> input, std::vector<v8::Local<v8::Object>> buffersToPersist);
|
||||||
);
|
|
||||||
|
|
||||||
enum class ImageType {
|
enum class ImageType {
|
||||||
JPEG,
|
JPEG,
|
||||||
|
@ -1,9 +1,24 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <node.h>
|
#include <node.h>
|
||||||
|
#include <nan.h>
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
|
|
||||||
#include "nan.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
|
||||||
@ -11,15 +26,14 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
public:
|
public:
|
||||||
MetadataWorker(
|
MetadataWorker(
|
||||||
Nan::Callback *callback, MetadataBaton *baton,
|
Nan::Callback *callback, MetadataBaton *baton,
|
||||||
std::vector<v8::Local<v8::Object>> const buffersToPersist
|
std::vector<v8::Local<v8::Object>> const buffersToPersist)
|
||||||
) : Nan::AsyncWorker(callback), baton(baton), buffersToPersist(buffersToPersist) {
|
: Nan::AsyncWorker(callback), baton(baton), buffersToPersist(buffersToPersist) {
|
||||||
// Protect Buffer objects from GC, keyed on index
|
// Protect Buffer objects from GC, keyed on index
|
||||||
std::accumulate(buffersToPersist.begin(), buffersToPersist.end(), 0,
|
std::accumulate(buffersToPersist.begin(), buffersToPersist.end(), 0,
|
||||||
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
|
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
|
||||||
SaveToPersistent(index, buffer);
|
SaveToPersistent(index, buffer);
|
||||||
return index + 1;
|
return index + 1;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
~MetadataWorker() {}
|
~MetadataWorker() {}
|
||||||
|
|
||||||
@ -72,7 +86,7 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
vips_thread_shutdown();
|
vips_thread_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleOKCallback () {
|
void HandleOKCallback() {
|
||||||
using Nan::New;
|
using Nan::New;
|
||||||
using Nan::Set;
|
using Nan::Set;
|
||||||
Nan::HandleScope();
|
Nan::HandleScope();
|
||||||
@ -99,14 +113,12 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
if (baton->exifLength > 0) {
|
if (baton->exifLength > 0) {
|
||||||
Set(info,
|
Set(info,
|
||||||
New("exif").ToLocalChecked(),
|
New("exif").ToLocalChecked(),
|
||||||
Nan::NewBuffer(baton->exif, baton->exifLength, sharp::FreeCallback, nullptr).ToLocalChecked()
|
Nan::NewBuffer(baton->exif, baton->exifLength, sharp::FreeCallback, nullptr).ToLocalChecked());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (baton->iccLength > 0) {
|
if (baton->iccLength > 0) {
|
||||||
Set(info,
|
Set(info,
|
||||||
New("icc").ToLocalChecked(),
|
New("icc").ToLocalChecked(),
|
||||||
Nan::NewBuffer(baton->icc, baton->iccLength, sharp::FreeCallback, nullptr).ToLocalChecked()
|
Nan::NewBuffer(baton->icc, baton->iccLength, sharp::FreeCallback, nullptr).ToLocalChecked());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
argv[1] = info;
|
argv[1] = info;
|
||||||
}
|
}
|
||||||
@ -116,8 +128,7 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
|
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
|
||||||
GetFromPersistent(index);
|
GetFromPersistent(index);
|
||||||
return index + 1;
|
return index + 1;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
delete baton->input;
|
delete baton->input;
|
||||||
delete baton;
|
delete baton;
|
||||||
|
|
||||||
|
@ -1,8 +1,24 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef SRC_METADATA_H_
|
#ifndef SRC_METADATA_H_
|
||||||
#define SRC_METADATA_H_
|
#define SRC_METADATA_H_
|
||||||
|
|
||||||
#include "nan.h"
|
#include <string>
|
||||||
#include "common.h"
|
#include <nan.h>
|
||||||
|
|
||||||
|
#include "./common.h"
|
||||||
|
|
||||||
struct MetadataBaton {
|
struct MetadataBaton {
|
||||||
// Input
|
// Input
|
||||||
|
@ -1,7 +1,23 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -17,7 +33,7 @@ namespace sharp {
|
|||||||
Assumes alpha channels are already premultiplied and will be unpremultiplied after.
|
Assumes alpha channels are already premultiplied and will be unpremultiplied after.
|
||||||
*/
|
*/
|
||||||
VImage Composite(VImage src, VImage dst, const int gravity) {
|
VImage Composite(VImage src, VImage dst, const int gravity) {
|
||||||
if(IsInputValidForComposition(src, dst)) {
|
if (IsInputValidForComposition(src, dst)) {
|
||||||
// Enlarge overlay src, if required
|
// Enlarge overlay src, if required
|
||||||
if (src.width() < dst.width() || src.height() < dst.height()) {
|
if (src.width() < dst.width() || src.height() < dst.height()) {
|
||||||
// Calculate the (left, top) coordinates of the output image within the input image, applying the given gravity.
|
// Calculate the (left, top) coordinates of the output image within the input image, applying the given gravity.
|
||||||
@ -28,8 +44,7 @@ namespace sharp {
|
|||||||
std::vector<double> background { 0.0, 0.0, 0.0, 0.0 };
|
std::vector<double> background { 0.0, 0.0, 0.0, 0.0 };
|
||||||
src = src.embed(left, top, dst.width(), dst.height(), VImage::option()
|
src = src.embed(left, top, dst.width(), dst.height(), VImage::option()
|
||||||
->set("extend", VIPS_EXTEND_BACKGROUND)
|
->set("extend", VIPS_EXTEND_BACKGROUND)
|
||||||
->set("background", background)
|
->set("background", background));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return CompositeImage(src, dst);
|
return CompositeImage(src, dst);
|
||||||
}
|
}
|
||||||
@ -38,7 +53,7 @@ namespace sharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VImage Composite(VImage src, VImage dst, const int x, const int y) {
|
VImage Composite(VImage src, VImage dst, const int x, const int y) {
|
||||||
if(IsInputValidForComposition(src, dst)) {
|
if (IsInputValidForComposition(src, dst)) {
|
||||||
// Enlarge overlay src, if required
|
// Enlarge overlay src, if required
|
||||||
if (src.width() < dst.width() || src.height() < dst.height()) {
|
if (src.width() < dst.width() || src.height() < dst.height()) {
|
||||||
// Calculate the (left, top) coordinates of the output image within the input image, applying the given gravity.
|
// Calculate the (left, top) coordinates of the output image within the input image, applying the given gravity.
|
||||||
@ -49,8 +64,7 @@ namespace sharp {
|
|||||||
std::vector<double> background { 0.0, 0.0, 0.0, 0.0 };
|
std::vector<double> background { 0.0, 0.0, 0.0, 0.0 };
|
||||||
src = src.embed(left, top, dst.width(), dst.height(), VImage::option()
|
src = src.embed(left, top, dst.width(), dst.height(), VImage::option()
|
||||||
->set("extend", VIPS_EXTEND_BACKGROUND)
|
->set("extend", VIPS_EXTEND_BACKGROUND)
|
||||||
->set("background", background)
|
->set("background", background));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return CompositeImage(src, dst);
|
return CompositeImage(src, dst);
|
||||||
}
|
}
|
||||||
@ -145,12 +159,11 @@ namespace sharp {
|
|||||||
std::vector<double> background { 0.0, 0.0, 0.0, 0.0 };
|
std::vector<double> background { 0.0, 0.0, 0.0, 0.0 };
|
||||||
mask = mask.embed(left, top, dst.width(), dst.height(), VImage::option()
|
mask = mask.embed(left, top, dst.width(), dst.height(), VImage::option()
|
||||||
->set("extend", VIPS_EXTEND_BACKGROUND)
|
->set("extend", VIPS_EXTEND_BACKGROUND)
|
||||||
->set("background", background)
|
->set("background", background));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we use the mask alpha if it has alpha
|
// we use the mask alpha if it has alpha
|
||||||
if(maskHasAlpha) {
|
if (maskHasAlpha) {
|
||||||
mask = mask.extract_band(mask.bands() - 1, VImage::option()->set("n", 1));;
|
mask = mask.extract_band(mask.bands() - 1, VImage::option()->set("n", 1));;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,8 +297,8 @@ namespace sharp {
|
|||||||
colourspaceBeforeSharpen = VIPS_INTERPRETATION_sRGB;
|
colourspaceBeforeSharpen = VIPS_INTERPRETATION_sRGB;
|
||||||
}
|
}
|
||||||
return image.sharpen(
|
return image.sharpen(
|
||||||
VImage::option()->set("sigma", sigma)->set("m1", flat)->set("m2", jagged)
|
VImage::option()->set("sigma", sigma)->set("m1", flat)->set("m2", jagged))
|
||||||
).colourspace(colourspaceBeforeSharpen);
|
.colourspace(colourspaceBeforeSharpen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,12 +428,11 @@ namespace sharp {
|
|||||||
->set("tile_height", 10)
|
->set("tile_height", 10)
|
||||||
->set("max_tiles", static_cast<int>(round(1.0 + need_lines / 10.0)))
|
->set("max_tiles", static_cast<int>(round(1.0 + need_lines / 10.0)))
|
||||||
->set("access", VIPS_ACCESS_SEQUENTIAL)
|
->set("access", VIPS_ACCESS_SEQUENTIAL)
|
||||||
->set("threaded", TRUE)
|
->set("threaded", TRUE));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VImage Threshold(VImage image, double const threshold, bool const thresholdGrayscale) {
|
VImage Threshold(VImage image, double const threshold, bool const thresholdGrayscale) {
|
||||||
if(!thresholdGrayscale) {
|
if (!thresholdGrayscale) {
|
||||||
return image >= threshold;
|
return image >= threshold;
|
||||||
}
|
}
|
||||||
return image.colourspace(VIPS_INTERPRETATION_B_W) >= threshold;
|
return image.colourspace(VIPS_INTERPRETATION_B_W) >= threshold;
|
||||||
@ -485,7 +497,7 @@ namespace sharp {
|
|||||||
int width = right - left;
|
int width = right - left;
|
||||||
int height = bottom - top;
|
int height = bottom - top;
|
||||||
|
|
||||||
if(width <= 0 || height <= 0) {
|
if (width <= 0 || height <= 0) {
|
||||||
throw VError("Unexpected error while trimming. Try to lower the tolerance");
|
throw VError("Unexpected error while trimming. Try to lower the tolerance");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef SRC_OPERATIONS_H_
|
#ifndef SRC_OPERATIONS_H_
|
||||||
#define SRC_OPERATIONS_H_
|
#define SRC_OPERATIONS_H_
|
||||||
|
|
||||||
@ -78,8 +92,7 @@ namespace sharp {
|
|||||||
Calculate crop area based on given strategy (Entropy, Attention)
|
Calculate crop area based on given strategy (Entropy, Attention)
|
||||||
*/
|
*/
|
||||||
std::tuple<int, int> Crop(
|
std::tuple<int, int> Crop(
|
||||||
VImage image, int const outWidth, int const outHeight, std::function<double(VImage)> strategy
|
VImage image, int const outWidth, int const outHeight, std::function<double(VImage)> strategy);
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Insert a tile cache to prevent over-computation of any previous operations in the pipeline
|
Insert a tile cache to prevent over-computation of any previous operations in the pipeline
|
||||||
|
169
src/pipeline.cc
169
src/pipeline.cc
@ -1,15 +1,31 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <tuple>
|
#include <map>
|
||||||
#include <utility>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <map>
|
#include <string>
|
||||||
|
#include <tuple>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
#include <node.h>
|
#include <node.h>
|
||||||
|
#include <nan.h>
|
||||||
|
|
||||||
#include "nan.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "operations.h"
|
#include "operations.h"
|
||||||
#include "pipeline.h"
|
#include "pipeline.h"
|
||||||
@ -18,15 +34,14 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
public:
|
public:
|
||||||
PipelineWorker(
|
PipelineWorker(
|
||||||
Nan::Callback *callback, PipelineBaton *baton, Nan::Callback *queueListener,
|
Nan::Callback *callback, PipelineBaton *baton, Nan::Callback *queueListener,
|
||||||
std::vector<v8::Local<v8::Object>> const buffersToPersist
|
std::vector<v8::Local<v8::Object>> const buffersToPersist)
|
||||||
) : Nan::AsyncWorker(callback), baton(baton), queueListener(queueListener), buffersToPersist(buffersToPersist) {
|
: Nan::AsyncWorker(callback), baton(baton), queueListener(queueListener), buffersToPersist(buffersToPersist) {
|
||||||
// Protect Buffer objects from GC, keyed on index
|
// Protect Buffer objects from GC, keyed on index
|
||||||
std::accumulate(buffersToPersist.begin(), buffersToPersist.end(), 0,
|
std::accumulate(buffersToPersist.begin(), buffersToPersist.end(), 0,
|
||||||
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
|
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
|
||||||
SaveToPersistent(index, buffer);
|
SaveToPersistent(index, buffer);
|
||||||
return index + 1;
|
return index + 1;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
~PipelineWorker() {}
|
~PipelineWorker() {}
|
||||||
|
|
||||||
@ -84,7 +99,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Trim
|
// Trim
|
||||||
if(baton->trimTolerance != 0) {
|
if (baton->trimTolerance != 0) {
|
||||||
image = sharp::Trim(image, baton->trimTolerance);
|
image = sharp::Trim(image, baton->trimTolerance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,8 +292,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = image.icc_transform(
|
image = image.icc_transform(
|
||||||
const_cast<char*>(profileMap[VIPS_INTERPRETATION_sRGB].data()), VImage::option()
|
const_cast<char*>(profileMap[VIPS_INTERPRETATION_sRGB].data()), VImage::option()
|
||||||
->set("embedded", TRUE)
|
->set("embedded", TRUE)
|
||||||
->set("intent", VIPS_INTENT_PERCEPTUAL)
|
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
||||||
);
|
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
// Ignore failure of embedded profile
|
// Ignore failure of embedded profile
|
||||||
}
|
}
|
||||||
@ -286,8 +300,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = image.icc_transform(
|
image = image.icc_transform(
|
||||||
const_cast<char*>(profileMap[VIPS_INTERPRETATION_sRGB].data()), VImage::option()
|
const_cast<char*>(profileMap[VIPS_INTERPRETATION_sRGB].data()), VImage::option()
|
||||||
->set("input_profile", profileMap[VIPS_INTERPRETATION_CMYK].data())
|
->set("input_profile", profileMap[VIPS_INTERPRETATION_CMYK].data())
|
||||||
->set("intent", VIPS_INTENT_PERCEPTUAL)
|
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flatten image to remove alpha channel
|
// Flatten image to remove alpha channel
|
||||||
@ -301,8 +314,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
baton->background[2] * multiplier
|
baton->background[2] * multiplier
|
||||||
};
|
};
|
||||||
image = image.flatten(VImage::option()
|
image = image.flatten(VImage::option()
|
||||||
->set("background", background)
|
->set("background", background));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Negate the colours in the image
|
// Negate the colours in the image
|
||||||
@ -325,8 +337,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
if (hasOverlay && !HasAlpha(image)) {
|
if (hasOverlay && !HasAlpha(image)) {
|
||||||
double const multiplier = sharp::Is16Bit(image.interpretation()) ? 256.0 : 1.0;
|
double const multiplier = sharp::Is16Bit(image.interpretation()) ? 256.0 : 1.0;
|
||||||
image = image.bandjoin(
|
image = image.bandjoin(
|
||||||
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier)
|
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool const shouldShrink = xshrink > 1 || yshrink > 1;
|
bool const shouldShrink = xshrink > 1 || yshrink > 1;
|
||||||
@ -380,22 +391,19 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// Perform kernel-based reduction
|
// Perform kernel-based reduction
|
||||||
if (yresidual < 1.0 || xresidual < 1.0) {
|
if (yresidual < 1.0 || xresidual < 1.0) {
|
||||||
VipsKernel kernel = static_cast<VipsKernel>(
|
VipsKernel kernel = static_cast<VipsKernel>(
|
||||||
vips_enum_from_nick(nullptr, VIPS_TYPE_KERNEL, baton->kernel.data())
|
vips_enum_from_nick(nullptr, VIPS_TYPE_KERNEL, baton->kernel.data()));
|
||||||
);
|
|
||||||
if (kernel != VIPS_KERNEL_CUBIC && kernel != VIPS_KERNEL_LANCZOS2 && kernel != VIPS_KERNEL_LANCZOS3) {
|
if (kernel != VIPS_KERNEL_CUBIC && kernel != VIPS_KERNEL_LANCZOS2 && kernel != VIPS_KERNEL_LANCZOS3) {
|
||||||
throw vips::VError("Unknown kernel");
|
throw vips::VError("Unknown kernel");
|
||||||
}
|
}
|
||||||
if (yresidual < 1.0) {
|
if (yresidual < 1.0) {
|
||||||
image = image.reducev(1.0 / yresidual, VImage::option()
|
image = image.reducev(1.0 / yresidual, VImage::option()
|
||||||
->set("kernel", kernel)
|
->set("kernel", kernel)
|
||||||
->set("centre", baton->centreSampling)
|
->set("centre", baton->centreSampling));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (xresidual < 1.0) {
|
if (xresidual < 1.0) {
|
||||||
image = image.reduceh(1.0 / xresidual, VImage::option()
|
image = image.reduceh(1.0 / xresidual, VImage::option()
|
||||||
->set("kernel", kernel)
|
->set("kernel", kernel)
|
||||||
->set("centre", baton->centreSampling)
|
->set("centre", baton->centreSampling));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Perform affine enlargement
|
// Perform affine enlargement
|
||||||
@ -403,13 +411,11 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
vips::VInterpolate interpolator = vips::VInterpolate::new_from_name(baton->interpolator.data());
|
vips::VInterpolate interpolator = vips::VInterpolate::new_from_name(baton->interpolator.data());
|
||||||
if (yresidual > 1.0) {
|
if (yresidual > 1.0) {
|
||||||
image = image.affine({1.0, 0.0, 0.0, yresidual}, VImage::option()
|
image = image.affine({1.0, 0.0, 0.0, yresidual}, VImage::option()
|
||||||
->set("interpolate", interpolator)
|
->set("interpolate", interpolator));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (xresidual > 1.0) {
|
if (xresidual > 1.0) {
|
||||||
image = image.affine({xresidual, 0.0, 0.0, 1.0}, VImage::option()
|
image = image.affine({xresidual, 0.0, 0.0, 1.0}, VImage::option()
|
||||||
->set("interpolate", interpolator)
|
->set("interpolate", interpolator));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -433,13 +439,12 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Join additional color channels to the image
|
// Join additional color channels to the image
|
||||||
if(baton->joinChannelIn.size() > 0) {
|
if (baton->joinChannelIn.size() > 0) {
|
||||||
VImage joinImage;
|
VImage joinImage;
|
||||||
ImageType joinImageType = ImageType::UNKNOWN;
|
ImageType joinImageType = ImageType::UNKNOWN;
|
||||||
|
|
||||||
for(unsigned int i = 0; i < baton->joinChannelIn.size(); i++) {
|
for (unsigned int i = 0; i < baton->joinChannelIn.size(); i++) {
|
||||||
std::tie(joinImage, joinImageType) = sharp::OpenInput(baton->joinChannelIn[i], baton->accessMethod);
|
std::tie(joinImage, joinImageType) = sharp::OpenInput(baton->joinChannelIn[i], baton->accessMethod);
|
||||||
|
|
||||||
image = image.bandjoin(joinImage);
|
image = image.bandjoin(joinImage);
|
||||||
}
|
}
|
||||||
image = image.copy(VImage::option()->set("interpretation", baton->colourspace));
|
image = image.copy(VImage::option()->set("interpretation", baton->colourspace));
|
||||||
@ -463,8 +468,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
background = { multiplier * (
|
background = { multiplier * (
|
||||||
0.2126 * baton->background[0] +
|
0.2126 * baton->background[0] +
|
||||||
0.7152 * baton->background[1] +
|
0.7152 * baton->background[1] +
|
||||||
0.0722 * baton->background[2]
|
0.0722 * baton->background[2])
|
||||||
)};
|
};
|
||||||
}
|
}
|
||||||
// Add alpha channel to background colour
|
// Add alpha channel to background colour
|
||||||
if (baton->background[3] < 255.0 || HasAlpha(image)) {
|
if (baton->background[3] < 255.0 || HasAlpha(image)) {
|
||||||
@ -475,16 +480,14 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// Add non-transparent alpha channel, if required
|
// Add non-transparent alpha channel, if required
|
||||||
if (baton->background[3] < 255.0 && !HasAlpha(image)) {
|
if (baton->background[3] < 255.0 && !HasAlpha(image)) {
|
||||||
image = image.bandjoin(
|
image = image.bandjoin(
|
||||||
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier)
|
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// Embed
|
// Embed
|
||||||
int left = static_cast<int>(round((baton->width - image.width()) / 2));
|
int left = static_cast<int>(round((baton->width - image.width()) / 2));
|
||||||
int top = static_cast<int>(round((baton->height - image.height()) / 2));
|
int top = static_cast<int>(round((baton->height - image.height()) / 2));
|
||||||
image = image.embed(left, top, baton->width, baton->height, VImage::option()
|
image = image.embed(left, top, baton->width, baton->height, VImage::option()
|
||||||
->set("extend", VIPS_EXTEND_BACKGROUND)
|
->set("extend", VIPS_EXTEND_BACKGROUND)
|
||||||
->set("background", background)
|
->set("background", background));
|
||||||
);
|
|
||||||
} else if (baton->canvas != Canvas::IGNORE_ASPECT) {
|
} else if (baton->canvas != Canvas::IGNORE_ASPECT) {
|
||||||
// Crop/max/min
|
// Crop/max/min
|
||||||
int left;
|
int left;
|
||||||
@ -492,8 +495,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
if (baton->crop < 9) {
|
if (baton->crop < 9) {
|
||||||
// Gravity-based crop
|
// Gravity-based crop
|
||||||
std::tie(left, top) = sharp::CalculateCrop(
|
std::tie(left, top) = sharp::CalculateCrop(
|
||||||
image.width(), image.height(), baton->width, baton->height, baton->crop
|
image.width(), image.height(), baton->width, baton->height, baton->crop);
|
||||||
);
|
|
||||||
} else if (baton->crop == 16) {
|
} else if (baton->crop == 16) {
|
||||||
// Entropy-based crop
|
// Entropy-based crop
|
||||||
std::tie(left, top) = sharp::Crop(image, baton->width, baton->height, sharp::EntropyStrategy());
|
std::tie(left, top) = sharp::Crop(image, baton->width, baton->height, sharp::EntropyStrategy());
|
||||||
@ -512,8 +514,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// Post extraction
|
// Post extraction
|
||||||
if (baton->topOffsetPost != -1) {
|
if (baton->topOffsetPost != -1) {
|
||||||
image = image.extract_area(
|
image = image.extract_area(
|
||||||
baton->leftOffsetPost, baton->topOffsetPost, baton->widthPost, baton->heightPost
|
baton->leftOffsetPost, baton->topOffsetPost, baton->widthPost, baton->heightPost);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extend edges
|
// Extend edges
|
||||||
@ -533,8 +534,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
background = { multiplier * (
|
background = { multiplier * (
|
||||||
0.2126 * baton->background[0] +
|
0.2126 * baton->background[0] +
|
||||||
0.7152 * baton->background[1] +
|
0.7152 * baton->background[1] +
|
||||||
0.0722 * baton->background[2]
|
0.0722 * baton->background[2])
|
||||||
)};
|
};
|
||||||
}
|
}
|
||||||
// Add alpha channel to background colour
|
// Add alpha channel to background colour
|
||||||
if (baton->background[3] < 255.0 || HasAlpha(image)) {
|
if (baton->background[3] < 255.0 || HasAlpha(image)) {
|
||||||
@ -545,8 +546,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// Add non-transparent alpha channel, if required
|
// Add non-transparent alpha channel, if required
|
||||||
if (baton->background[3] < 255.0 && !HasAlpha(image)) {
|
if (baton->background[3] < 255.0 && !HasAlpha(image)) {
|
||||||
image = image.bandjoin(
|
image = image.bandjoin(
|
||||||
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier)
|
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// Embed
|
// Embed
|
||||||
baton->width = image.width() + baton->extendLeft + baton->extendRight;
|
baton->width = image.width() + baton->extendLeft + baton->extendRight;
|
||||||
@ -571,8 +571,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = sharp::Convolve(image,
|
image = sharp::Convolve(image,
|
||||||
baton->convKernelWidth, baton->convKernelHeight,
|
baton->convKernelWidth, baton->convKernelHeight,
|
||||||
baton->convKernelScale, baton->convKernelOffset,
|
baton->convKernelScale, baton->convKernelOffset,
|
||||||
baton->convKernel
|
baton->convKernel);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sharpen
|
// Sharpen
|
||||||
@ -606,17 +605,13 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// the overlayX/YOffsets will now be used to CalculateCrop for extract_area
|
// the overlayX/YOffsets will now be used to CalculateCrop for extract_area
|
||||||
std::tie(left, top) = sharp::CalculateCrop(
|
std::tie(left, top) = sharp::CalculateCrop(
|
||||||
overlayImage.width(), overlayImage.height(), image.width(), image.height(),
|
overlayImage.width(), overlayImage.height(), image.width(), image.height(),
|
||||||
baton->overlayXOffset, baton->overlayYOffset
|
baton->overlayXOffset, baton->overlayYOffset);
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// the overlayGravity will now be used to CalculateCrop for extract_area
|
// the overlayGravity will now be used to CalculateCrop for extract_area
|
||||||
std::tie(left, top) = sharp::CalculateCrop(
|
std::tie(left, top) = sharp::CalculateCrop(
|
||||||
overlayImage.width(), overlayImage.height(), image.width(), image.height(), baton->overlayGravity
|
overlayImage.width(), overlayImage.height(), image.width(), image.height(), baton->overlayGravity);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
overlayImage = overlayImage.extract_area(
|
overlayImage = overlayImage.extract_area(left, top, image.width(), image.height());
|
||||||
left, top, image.width(), image.height()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// the overlayGravity was used for extract_area, therefore set it back to its default value of 0
|
// the overlayGravity was used for extract_area, therefore set it back to its default value of 0
|
||||||
baton->overlayGravity = 0;
|
baton->overlayGravity = 0;
|
||||||
@ -629,15 +624,13 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
if (!HasAlpha(overlayImage)) {
|
if (!HasAlpha(overlayImage)) {
|
||||||
double const multiplier = sharp::Is16Bit(overlayImage.interpretation()) ? 256.0 : 1.0;
|
double const multiplier = sharp::Is16Bit(overlayImage.interpretation()) ? 256.0 : 1.0;
|
||||||
overlayImage = overlayImage.bandjoin(
|
overlayImage = overlayImage.bandjoin(
|
||||||
VImage::new_matrix(overlayImage.width(), overlayImage.height()).new_from_image(255 * multiplier)
|
VImage::new_matrix(overlayImage.width(), overlayImage.height()).new_from_image(255 * multiplier));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// Ensure image has alpha channel
|
// Ensure image has alpha channel
|
||||||
if (!HasAlpha(image)) {
|
if (!HasAlpha(image)) {
|
||||||
double const multiplier = sharp::Is16Bit(image.interpretation()) ? 256.0 : 1.0;
|
double const multiplier = sharp::Is16Bit(image.interpretation()) ? 256.0 : 1.0;
|
||||||
image = image.bandjoin(
|
image = image.bandjoin(
|
||||||
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier)
|
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// Ensure overlay is premultiplied sRGB
|
// Ensure overlay is premultiplied sRGB
|
||||||
overlayImage = overlayImage.colourspace(VIPS_INTERPRETATION_sRGB).premultiply();
|
overlayImage = overlayImage.colourspace(VIPS_INTERPRETATION_sRGB).premultiply();
|
||||||
@ -686,8 +679,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract an image channel (aka vips band)
|
// Extract an image channel (aka vips band)
|
||||||
if(baton->extractChannel > -1) {
|
if (baton->extractChannel > -1) {
|
||||||
if(baton->extractChannel >= image.bands()) {
|
if (baton->extractChannel >= image.bands()) {
|
||||||
(baton->err).append("Cannot extract channel from image. Too few channels in image.");
|
(baton->err).append("Cannot extract channel from image. Too few channels in image.");
|
||||||
return Error();
|
return Error();
|
||||||
}
|
}
|
||||||
@ -701,12 +694,9 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// Convert colourspace, pass the current known interpretation so libvips doesn't have to guess
|
// Convert colourspace, pass the current known interpretation so libvips doesn't have to guess
|
||||||
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
|
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
|
||||||
// Transform colours from embedded profile to output profile
|
// Transform colours from embedded profile to output profile
|
||||||
if (baton->withMetadata &&
|
if (baton->withMetadata && sharp::HasProfile(image) && profileMap[baton->colourspace] != std::string()) {
|
||||||
sharp::HasProfile(image) &&
|
|
||||||
profileMap[baton->colourspace] != std::string()) {
|
|
||||||
image = image.icc_transform(const_cast<char*>(profileMap[baton->colourspace].data()),
|
image = image.icc_transform(const_cast<char*>(profileMap[baton->colourspace].data()),
|
||||||
VImage::option()->set("embedded", TRUE)
|
VImage::option()->set("embedded", TRUE));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -732,14 +722,13 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
||||||
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
||||||
->set("optimize_scans", baton->jpegOptimiseScans)
|
->set("optimize_scans", baton->jpegOptimiseScans)
|
||||||
->set("optimize_coding", TRUE)
|
->set("optimize_coding", TRUE)));
|
||||||
));
|
|
||||||
baton->bufferOut = static_cast<char*>(area->data);
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
baton->bufferOutLength = area->length;
|
baton->bufferOutLength = area->length;
|
||||||
area->free_fn = nullptr;
|
area->free_fn = nullptr;
|
||||||
vips_area_unref(area);
|
vips_area_unref(area);
|
||||||
baton->formatOut = "jpeg";
|
baton->formatOut = "jpeg";
|
||||||
if(baton->colourspace == VIPS_INTERPRETATION_CMYK) {
|
if (baton->colourspace == VIPS_INTERPRETATION_CMYK) {
|
||||||
baton->channels = std::min(baton->channels, 4);
|
baton->channels = std::min(baton->channels, 4);
|
||||||
} else {
|
} else {
|
||||||
baton->channels = std::min(baton->channels, 3);
|
baton->channels = std::min(baton->channels, 3);
|
||||||
@ -754,9 +743,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
VipsArea *area = VIPS_AREA(image.pngsave_buffer(VImage::option()
|
VipsArea *area = VIPS_AREA(image.pngsave_buffer(VImage::option()
|
||||||
->set("interlace", baton->pngProgressive)
|
->set("interlace", baton->pngProgressive)
|
||||||
->set("compression", baton->pngCompressionLevel)
|
->set("compression", baton->pngCompressionLevel)
|
||||||
->set("filter", baton->pngAdaptiveFiltering ?
|
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE)));
|
||||||
VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE )
|
|
||||||
));
|
|
||||||
baton->bufferOut = static_cast<char*>(area->data);
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
baton->bufferOutLength = area->length;
|
baton->bufferOutLength = area->length;
|
||||||
area->free_fn = nullptr;
|
area->free_fn = nullptr;
|
||||||
@ -769,8 +756,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("Q", baton->webpQuality)
|
->set("Q", baton->webpQuality)
|
||||||
->set("lossless", baton->webpLossless)
|
->set("lossless", baton->webpLossless)
|
||||||
->set("near_lossless", baton->webpNearLossless)
|
->set("near_lossless", baton->webpNearLossless)
|
||||||
->set("alpha_q", baton->webpAlphaQuality)
|
->set("alpha_q", baton->webpAlphaQuality)));
|
||||||
));
|
|
||||||
baton->bufferOut = static_cast<char*>(area->data);
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
baton->bufferOutLength = area->length;
|
baton->bufferOutLength = area->length;
|
||||||
area->free_fn = nullptr;
|
area->free_fn = nullptr;
|
||||||
@ -824,8 +810,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
||||||
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
||||||
->set("optimize_scans", baton->jpegOptimiseScans)
|
->set("optimize_scans", baton->jpegOptimiseScans)
|
||||||
->set("optimize_coding", TRUE)
|
->set("optimize_coding", TRUE));
|
||||||
);
|
|
||||||
baton->formatOut = "jpeg";
|
baton->formatOut = "jpeg";
|
||||||
baton->channels = std::min(baton->channels, 3);
|
baton->channels = std::min(baton->channels, 3);
|
||||||
} else if (baton->formatOut == "png" || isPng || (matchInput &&
|
} else if (baton->formatOut == "png" || isPng || (matchInput &&
|
||||||
@ -838,9 +823,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image.pngsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.pngsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("interlace", baton->pngProgressive)
|
->set("interlace", baton->pngProgressive)
|
||||||
->set("compression", baton->pngCompressionLevel)
|
->set("compression", baton->pngCompressionLevel)
|
||||||
->set("filter", baton->pngAdaptiveFiltering ?
|
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE));
|
||||||
VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE )
|
|
||||||
);
|
|
||||||
baton->formatOut = "png";
|
baton->formatOut = "png";
|
||||||
} else if (baton->formatOut == "webp" || isWebp || (matchInput && inputImageType == ImageType::WEBP)) {
|
} else if (baton->formatOut == "webp" || isWebp || (matchInput && inputImageType == ImageType::WEBP)) {
|
||||||
// Write WEBP to file
|
// Write WEBP to file
|
||||||
@ -849,16 +832,14 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("Q", baton->webpQuality)
|
->set("Q", baton->webpQuality)
|
||||||
->set("lossless", baton->webpLossless)
|
->set("lossless", baton->webpLossless)
|
||||||
->set("near_lossless", baton->webpNearLossless)
|
->set("near_lossless", baton->webpNearLossless)
|
||||||
->set("alpha_q", baton->webpAlphaQuality)
|
->set("alpha_q", baton->webpAlphaQuality));
|
||||||
);
|
|
||||||
baton->formatOut = "webp";
|
baton->formatOut = "webp";
|
||||||
} else if (baton->formatOut == "tiff" || isTiff || (matchInput && inputImageType == ImageType::TIFF)) {
|
} else if (baton->formatOut == "tiff" || isTiff || (matchInput && inputImageType == ImageType::TIFF)) {
|
||||||
// Write TIFF to file
|
// Write TIFF to file
|
||||||
image.tiffsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.tiffsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata)
|
||||||
->set("Q", baton->tiffQuality)
|
->set("Q", baton->tiffQuality)
|
||||||
->set("compression", VIPS_FOREIGN_TIFF_COMPRESSION_JPEG)
|
->set("compression", VIPS_FOREIGN_TIFF_COMPRESSION_JPEG));
|
||||||
);
|
|
||||||
baton->formatOut = "tiff";
|
baton->formatOut = "tiff";
|
||||||
baton->channels = std::min(baton->channels, 3);
|
baton->channels = std::min(baton->channels, 3);
|
||||||
} else if (baton->formatOut == "dz" || isDz || isDzZip) {
|
} else if (baton->formatOut == "dz" || isDz || isDzZip) {
|
||||||
@ -904,14 +885,12 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("overlap", baton->tileOverlap)
|
->set("overlap", baton->tileOverlap)
|
||||||
->set("container", baton->tileContainer)
|
->set("container", baton->tileContainer)
|
||||||
->set("layout", baton->tileLayout)
|
->set("layout", baton->tileLayout)
|
||||||
->set("suffix", const_cast<char*>(suffix.data()))
|
->set("suffix", const_cast<char*>(suffix.data())));
|
||||||
);
|
|
||||||
baton->formatOut = "dz";
|
baton->formatOut = "dz";
|
||||||
} else if (baton->formatOut == "v" || isV || (matchInput && inputImageType == ImageType::VIPS)) {
|
} else if (baton->formatOut == "v" || isV || (matchInput && inputImageType == ImageType::VIPS)) {
|
||||||
// Write V to file
|
// Write V to file
|
||||||
image.vipssave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.vipssave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata));
|
||||||
);
|
|
||||||
baton->formatOut = "v";
|
baton->formatOut = "v";
|
||||||
} else {
|
} else {
|
||||||
// Unsupported output format
|
// Unsupported output format
|
||||||
@ -927,7 +906,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
vips_thread_shutdown();
|
vips_thread_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleOKCallback () {
|
void HandleOKCallback() {
|
||||||
using Nan::New;
|
using Nan::New;
|
||||||
using Nan::Set;
|
using Nan::Set;
|
||||||
Nan::HandleScope();
|
Nan::HandleScope();
|
||||||
@ -961,8 +940,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
if (baton->bufferOutLength > 0) {
|
if (baton->bufferOutLength > 0) {
|
||||||
// Pass ownership of output data to Buffer instance
|
// Pass ownership of output data to Buffer instance
|
||||||
argv[1] = Nan::NewBuffer(
|
argv[1] = Nan::NewBuffer(
|
||||||
static_cast<char*>(baton->bufferOut), baton->bufferOutLength, sharp::FreeCallback, nullptr
|
static_cast<char*>(baton->bufferOut), baton->bufferOutLength, sharp::FreeCallback, nullptr)
|
||||||
).ToLocalChecked();
|
.ToLocalChecked();
|
||||||
// Add buffer size to info
|
// Add buffer size to info
|
||||||
Set(info, New("size").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(baton->bufferOutLength)));
|
Set(info, New("size").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(baton->bufferOutLength)));
|
||||||
argv[2] = info;
|
argv[2] = info;
|
||||||
@ -981,16 +960,14 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
|
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
|
||||||
GetFromPersistent(index);
|
GetFromPersistent(index);
|
||||||
return index + 1;
|
return index + 1;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
delete baton->input;
|
delete baton->input;
|
||||||
delete baton->overlay;
|
delete baton->overlay;
|
||||||
delete baton->boolean;
|
delete baton->boolean;
|
||||||
for_each(baton->joinChannelIn.begin(), baton->joinChannelIn.end(),
|
for_each(baton->joinChannelIn.begin(), baton->joinChannelIn.end(),
|
||||||
[this](sharp::InputDescriptor *joinChannelIn) {
|
[this](sharp::InputDescriptor *joinChannelIn) {
|
||||||
delete joinChannelIn;
|
delete joinChannelIn;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
delete baton;
|
delete baton;
|
||||||
|
|
||||||
// Decrement processing task counter
|
// Decrement processing task counter
|
||||||
@ -1021,7 +998,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
bool flip = FALSE;
|
bool flip = FALSE;
|
||||||
bool flop = FALSE;
|
bool flop = FALSE;
|
||||||
if (angle == -1) {
|
if (angle == -1) {
|
||||||
switch(sharp::ExifOrientation(image)) {
|
switch (sharp::ExifOrientation(image)) {
|
||||||
case 6: rotate = VIPS_ANGLE_D90; break;
|
case 6: rotate = VIPS_ANGLE_D90; break;
|
||||||
case 3: rotate = VIPS_ANGLE_D180; break;
|
case 3: rotate = VIPS_ANGLE_D180; break;
|
||||||
case 8: rotate = VIPS_ANGLE_D270; break;
|
case 8: rotate = VIPS_ANGLE_D270; break;
|
||||||
@ -1141,12 +1118,12 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->interpolator = AttrAsStr(options, "interpolator");
|
baton->interpolator = AttrAsStr(options, "interpolator");
|
||||||
baton->centreSampling = AttrTo<bool>(options, "centreSampling");
|
baton->centreSampling = AttrTo<bool>(options, "centreSampling");
|
||||||
// Join Channel Options
|
// Join Channel Options
|
||||||
if(HasAttr(options, "joinChannelIn")) {
|
if (HasAttr(options, "joinChannelIn")) {
|
||||||
v8::Local<v8::Object> joinChannelObject = Nan::Get(options, Nan::New("joinChannelIn").ToLocalChecked())
|
v8::Local<v8::Object> joinChannelObject = Nan::Get(options, Nan::New("joinChannelIn").ToLocalChecked())
|
||||||
.ToLocalChecked().As<v8::Object>();
|
.ToLocalChecked().As<v8::Object>();
|
||||||
v8::Local<v8::Array> joinChannelArray = joinChannelObject.As<v8::Array>();
|
v8::Local<v8::Array> joinChannelArray = joinChannelObject.As<v8::Array>();
|
||||||
int joinChannelArrayLength = AttrTo<int32_t>(joinChannelObject, "length");
|
int joinChannelArrayLength = AttrTo<int32_t>(joinChannelObject, "length");
|
||||||
for(int i = 0; i < joinChannelArrayLength; i++) {
|
for (int i = 0; i < joinChannelArrayLength; i++) {
|
||||||
baton->joinChannelIn.push_back(
|
baton->joinChannelIn.push_back(
|
||||||
CreateInputDescriptor(
|
CreateInputDescriptor(
|
||||||
Nan::Get(joinChannelArray, i).ToLocalChecked().As<v8::Object>(),
|
Nan::Get(joinChannelArray, i).ToLocalChecked().As<v8::Object>(),
|
||||||
@ -1163,7 +1140,7 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->threshold = AttrTo<int32_t>(options, "threshold");
|
baton->threshold = AttrTo<int32_t>(options, "threshold");
|
||||||
baton->thresholdGrayscale = AttrTo<bool>(options, "thresholdGrayscale");
|
baton->thresholdGrayscale = AttrTo<bool>(options, "thresholdGrayscale");
|
||||||
baton->trimTolerance = AttrTo<int32_t>(options, "trimTolerance");
|
baton->trimTolerance = AttrTo<int32_t>(options, "trimTolerance");
|
||||||
if(baton->accessMethod == VIPS_ACCESS_SEQUENTIAL && baton->trimTolerance != 0) {
|
if (baton->accessMethod == VIPS_ACCESS_SEQUENTIAL && baton->trimTolerance != 0) {
|
||||||
baton->accessMethod = VIPS_ACCESS_RANDOM;
|
baton->accessMethod = VIPS_ACCESS_RANDOM;
|
||||||
}
|
}
|
||||||
baton->gamma = AttrTo<double>(options, "gamma");
|
baton->gamma = AttrTo<double>(options, "gamma");
|
||||||
|
@ -1,12 +1,28 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef SRC_PIPELINE_H_
|
#ifndef SRC_PIPELINE_H_
|
||||||
#define SRC_PIPELINE_H_
|
#define SRC_PIPELINE_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <nan.h>
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
|
|
||||||
#include "nan.h"
|
#include "./common.h"
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
NAN_METHOD(pipeline);
|
NAN_METHOD(pipeline);
|
||||||
|
|
||||||
|
19
src/sharp.cc
19
src/sharp.cc
@ -1,7 +1,20 @@
|
|||||||
#include <node.h>
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
#include <vips/vips8>
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#include "nan.h"
|
#include <node.h>
|
||||||
|
#include <nan.h>
|
||||||
|
#include <vips/vips8>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
@ -1,10 +1,25 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <node.h>
|
#include <node.h>
|
||||||
|
#include <nan.h>
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
#include <vips/vector.h>
|
#include <vips/vector.h>
|
||||||
|
|
||||||
#include "nan.h"
|
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "operations.h"
|
#include "operations.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
@ -45,14 +60,11 @@ NAN_METHOD(cache) {
|
|||||||
// Get memory stats
|
// Get memory stats
|
||||||
Local<Object> memory = New<Object>();
|
Local<Object> memory = New<Object>();
|
||||||
Set(memory, New("current").ToLocalChecked(),
|
Set(memory, New("current").ToLocalChecked(),
|
||||||
New<Integer>(static_cast<int>(round(vips_tracked_get_mem() / 1048576)))
|
New<Integer>(static_cast<int>(round(vips_tracked_get_mem() / 1048576))));
|
||||||
);
|
|
||||||
Set(memory, New("high").ToLocalChecked(),
|
Set(memory, New("high").ToLocalChecked(),
|
||||||
New<Integer>(static_cast<int>(round(vips_tracked_get_mem_highwater() / 1048576)))
|
New<Integer>(static_cast<int>(round(vips_tracked_get_mem_highwater() / 1048576))));
|
||||||
);
|
|
||||||
Set(memory, New("max").ToLocalChecked(),
|
Set(memory, New("max").ToLocalChecked(),
|
||||||
New<Integer>(static_cast<int>(round(vips_cache_get_max_mem() / 1048576)))
|
New<Integer>(static_cast<int>(round(vips_cache_get_max_mem() / 1048576))));
|
||||||
);
|
|
||||||
// Get file stats
|
// Get file stats
|
||||||
Local<Object> files = New<Object>();
|
Local<Object> files = New<Object>();
|
||||||
Set(files, New("current").ToLocalChecked(), New<Integer>(vips_tracked_get_files()));
|
Set(files, New("current").ToLocalChecked(), New<Integer>(vips_tracked_get_files()));
|
||||||
|
@ -1,7 +1,21 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef SRC_UTILITIES_H_
|
#ifndef SRC_UTILITIES_H_
|
||||||
#define SRC_UTILITIES_H_
|
#define SRC_UTILITIES_H_
|
||||||
|
|
||||||
#include "nan.h"
|
#include <nan.h>
|
||||||
|
|
||||||
NAN_METHOD(cache);
|
NAN_METHOD(cache);
|
||||||
NAN_METHOD(concurrency);
|
NAN_METHOD(concurrency);
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const assert = require('assert');
|
|
||||||
|
|
||||||
const cpplint = require('node-cpplint/lib/');
|
|
||||||
|
|
||||||
describe('cpplint', function () {
|
|
||||||
// Ignore cpplint failures, possibly newline-related, on Windows
|
|
||||||
if (process.platform !== 'win32') {
|
|
||||||
// List C++ source files
|
|
||||||
fs.readdirSync(path.join(__dirname, '..', '..', 'src')).filter(function (source) {
|
|
||||||
return source !== 'libvips';
|
|
||||||
}).forEach(function (source) {
|
|
||||||
const file = path.join('src', source);
|
|
||||||
it(file, function (done) {
|
|
||||||
// Lint each source file
|
|
||||||
cpplint({
|
|
||||||
files: [file],
|
|
||||||
linelength: 120,
|
|
||||||
filters: {
|
|
||||||
legal: {
|
|
||||||
copyright: false
|
|
||||||
},
|
|
||||||
build: {
|
|
||||||
include: false
|
|
||||||
},
|
|
||||||
whitespace: {
|
|
||||||
parens: false
|
|
||||||
},
|
|
||||||
runtime: {
|
|
||||||
indentation_namespace: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, function (err, report) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
const expected = {};
|
|
||||||
expected[file] = [];
|
|
||||||
assert.deepEqual(expected, report);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
Loading…
x
Reference in New Issue
Block a user