forked from sorccu/node-jpeg-turbo
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
749 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
platform: | ||
- x86 | ||
- x64 | ||
environment: | ||
matrix: | ||
- nodejs_version: '4' | ||
- nodejs_version: '5' | ||
- nodejs_version: '6' | ||
- nodejs_version: '7' | ||
install: | ||
- ps: Install-Product node $env:nodejs_version $env:Platform | ||
- node --version && npm --version | ||
- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-http-proxy.ps1')) | ||
- IF DEFINED APPVEYOR_HTTP_PROXY_IP npm config set proxy http://%APPVEYOR_HTTP_PROXY_IP%:%APPVEYOR_HTTP_PROXY_PORT% | ||
- IF DEFINED APPVEYOR_HTTP_PROXY_IP npm config set https-proxy | ||
- npm config set -g msvs_version 2015 | ||
- mkdir c:\yasm | ||
- set PATH=%APPDATA%\npm;c:\yasm;%PATH% | ||
- set CI=true | ||
- if "%PLATFORM%" == "x64" curl -o "c:\yasm\yasm.exe" http://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win64.exe | ||
- if "%PLATFORM%" == "x86" curl -o "c:\yasm\yasm.exe" http://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win32.exe | ||
- yasm --version | ||
- git submodule update --init | ||
- if "%PLATFORM%" == "x64" npm config set python C:\Python27-x64\python.exe | ||
- if "%PLATFORM%" == "x86" npm config set python C:\Python27\python.exe | ||
- if "%PLATFORM%" == "x86" if "%NODEJS_VERSION%" == "4" npm config set -g cafile=package.json | ||
- if "%PLATFORM%" == "x86" if "%NODEJS_VERSION%" == "4" npm config set -g strict-ssl=false | ||
- npm install | ||
- npm run prebuilt-bindings -- clean build pack | ||
matrix: | ||
fast_finish: true | ||
build: off | ||
clone_depth: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef INLINE | ||
#if defined(__GNUC__) | ||
#define INLINE inline __attribute__((always_inline)) | ||
#elif defined(_MSC_VER) | ||
#define INLINE __forceinline | ||
#else | ||
#define INLINE | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,106 @@ | ||
#include "exports.h" | ||
using namespace Nan; | ||
using namespace v8; | ||
|
||
static char errStr[NJT_MSG_LENGTH_MAX] = "No error"; | ||
#define _throw(m) {snprintf(errStr, NJT_MSG_LENGTH_MAX, "%s", m); retval=-1; goto bailout;} | ||
|
||
NAN_METHOD(BufferSize) { | ||
if (info.Length() < 1) { | ||
return Nan::ThrowError(Nan::TypeError("Too few arguments")); | ||
int retval = 0; | ||
|
||
// Input | ||
Callback *callback = NULL; | ||
Local<Object> options; | ||
Local<Value> sampObject; | ||
uint32_t jpegSubsamp = NJT_DEFAULT_SUBSAMPLING; | ||
Local<Value> widthObject; | ||
uint32_t width = 0; | ||
Local<Value> heightObject; | ||
uint32_t height = 0; | ||
uint32_t dstLength = 0; | ||
|
||
// Try to find callback here, so if we want to throw something we can use callback's err | ||
if (info[info.Length() - 1]->IsFunction()) { | ||
callback = new Callback(info[info.Length() - 1].As<Function>()); | ||
} | ||
|
||
if ((NULL != callback && info.Length() < 2) || (NULL == callback && info.Length() < 1)) { | ||
_throw("Too few arguments"); | ||
} | ||
|
||
// Options | ||
v8::Local<v8::Object> options = info[0].As<v8::Object>(); | ||
options = info[0].As<Object>(); | ||
if (!options->IsObject()) { | ||
return Nan::ThrowError(Nan::TypeError("Options must be an Object")); | ||
_throw("Options must be an Object"); | ||
} | ||
|
||
// Subsampling | ||
v8::Local<v8::Value> sampObject = | ||
options->Get(Nan::New("subsampling").ToLocalChecked()); | ||
|
||
uint32_t jpegSubsamp = sampObject->IsUndefined() | ||
? DEFAULT_SUBSAMPLING | ||
: sampObject->Uint32Value(); | ||
sampObject = options->Get(New("subsampling").ToLocalChecked()); | ||
if (!sampObject->IsUndefined()) { | ||
if (!sampObject->IsUint32()) { | ||
_throw("Invalid subsampling method"); | ||
} | ||
jpegSubsamp = sampObject->Uint32Value(); | ||
} | ||
|
||
switch (jpegSubsamp) { | ||
case SAMP_444: | ||
case SAMP_422: | ||
case SAMP_420: | ||
case SAMP_GRAY: | ||
case SAMP_440: | ||
break; | ||
default: | ||
return Nan::ThrowError(Nan::TypeError("Invalid subsampling method")); | ||
case SAMP_444: | ||
case SAMP_422: | ||
case SAMP_420: | ||
case SAMP_GRAY: | ||
case SAMP_440: | ||
break; | ||
default: | ||
_throw("Invalid subsampling method"); | ||
} | ||
|
||
// Width | ||
v8::Local<v8::Value> widthObject = | ||
options->Get(Nan::New("width").ToLocalChecked()); | ||
|
||
widthObject = options->Get(New("width").ToLocalChecked()); | ||
if (widthObject->IsUndefined()) { | ||
return Nan::ThrowError(Nan::TypeError("Missing width")); | ||
_throw("Missing width"); | ||
} | ||
|
||
uint32_t width = widthObject->Uint32Value(); | ||
if (!widthObject->IsUint32()) { | ||
_throw("Invalid width value"); | ||
} | ||
width = widthObject->Uint32Value(); | ||
|
||
// Height | ||
v8::Local<v8::Value> heightObject = | ||
options->Get(Nan::New("height").ToLocalChecked()); | ||
|
||
heightObject = options->Get(New("height").ToLocalChecked()); | ||
if (heightObject->IsUndefined()) { | ||
return Nan::ThrowError(Nan::TypeError("Missing height")); | ||
_throw("Missing height"); | ||
} | ||
|
||
uint32_t height = heightObject->Uint32Value(); | ||
if (!heightObject->IsUint32()) { | ||
_throw("Invalid height value"); | ||
} | ||
height = heightObject->Uint32Value(); | ||
|
||
// Finally, calculate the buffer size | ||
uint32_t dstLength = tjBufSize(width, height, jpegSubsamp); | ||
dstLength = tjBufSize(width, height, jpegSubsamp); | ||
|
||
info.GetReturnValue().Set(Nan::New(dstLength)); | ||
// How to return length | ||
if (NULL != callback) { | ||
Local<Value> argv[] = { | ||
Null(), | ||
New(dstLength) | ||
}; | ||
callback->Call(2, argv); | ||
} | ||
else { | ||
info.GetReturnValue().Set(New(dstLength)); | ||
} | ||
|
||
|
||
bailout: | ||
if (retval != 0) { | ||
if (NULL == callback) { | ||
ThrowError(TypeError(errStr)); | ||
} | ||
else { | ||
Local<Value> argv[] = { | ||
New(errStr).ToLocalChecked() | ||
}; | ||
callback->Call(1, argv); | ||
} | ||
return; | ||
} | ||
} |
Oops, something went wrong.