Skip to content

Commit

Permalink
Merge branch 'empee-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
sorccu committed Nov 7, 2016
2 parents 18c0290 + 07d20d9 commit 254c158
Show file tree
Hide file tree
Showing 10 changed files with 749 additions and 285 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,36 @@ apt-get install yasm
apk add yasm
```

**On Windows**

Download Win32 or Win64 yasm from [here](http://yasm.tortall.net/Download.html) and make sure it's found in path as yasm.exe. Use the "for general use" version. If the .exe doesn't run, or complains about a missing `MSVCR100.dll`, go to [KB2977003](https://support.microsoft.com/en-us/kb/2977003) and find "Microsoft Visual C++ 2010 Service Pack 1 Redistributable Package MFC Security Update" under "Visual Studio 2010 (VC++ 10.0) SP1". The .exe should work fine after installing the redistributable.

To verify your yasm setup, run:

```sh
yasm
```

This should give the output:

> yasm: No input files specified
Next, you need to make sure that you have a build environment set up. An easy way to do that is to use [windows-build-tools](https://github.com/felixrieseberg/windows-build-tools).

Now, just to make sure things are set up properly, run:

```
npm config get msvs_version
```

If the output is `2015` or newer, you're good. If it's anything else, or not set, you must run:

```
npm config set -g msvs_version 2015
```

Alternatively, you can specify the option at install time with `--msvs_version=2015`.

**Others**

Search your package manager for `yasm`.
Expand Down
33 changes: 33 additions & 0 deletions appveyor.yml
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
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'src/exports.cc',
],
'include_dirs': [
'<!(node -e \'require("nan")\')'
'<!(node -e "require(\'nan\')")'
],
'conditions': [
['OS=="mac"', {
Expand Down
9 changes: 9 additions & 0 deletions deps/include/jconfigint.h
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
70 changes: 48 additions & 22 deletions deps/libjpeg-turbo.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@
'HAVE_UNISTD_H=1',
'HAVE_UNSIGNED_CHAR=1',
'HAVE_UNSIGNED_SHORT=1',
'INLINE=inline __attribute__((always_inline))',
'JPEG_LIB_VERSION=62',
'LIBJPEG_TURBO_VERSION="1.4.1"',
'LIBJPEG_TURBO_VERSION="1.4.2"',
'MEM_SRCDST_SUPPORTED=1',
'NEED_SYS_TYPES_H=1',
'STDC_HEADERS=1',
'WITH_SIMD=1',
'VERSION="0.4.0"',
'PACKAGE_NAME="jpeg-turbo"'
],
'variables': {
'yasm_path%': 'yasm',
Expand All @@ -140,21 +141,21 @@
],
'sources': [
'libjpeg-turbo/simd/jsimd_x86_64.c',
'libjpeg-turbo/simd/jfdctflt-sse-64.asm',
'libjpeg-turbo/simd/jccolor-sse2-64.asm',
'libjpeg-turbo/simd/jcgray-sse2-64.asm',
'libjpeg-turbo/simd/jcsample-sse2-64.asm',
'libjpeg-turbo/simd/jdcolor-sse2-64.asm',
'libjpeg-turbo/simd/jdmerge-sse2-64.asm',
'libjpeg-turbo/simd/jdsample-sse2-64.asm',
'libjpeg-turbo/simd/jfdctflt-sse-64.asm',
'libjpeg-turbo/simd/jfdctfst-sse2-64.asm',
'libjpeg-turbo/simd/jfdctint-sse2-64.asm',
'libjpeg-turbo/simd/jidctflt-sse2-64.asm',
'libjpeg-turbo/simd/jidctfst-sse2-64.asm',
'libjpeg-turbo/simd/jidctint-sse2-64.asm',
'libjpeg-turbo/simd/jidctred-sse2-64.asm',
'libjpeg-turbo/simd/jquantf-sse2-64.asm',
'libjpeg-turbo/simd/jquanti-sse2-64.asm',
'libjpeg-turbo/simd/jquanti-sse2-64.asm'
],
}],
[ 'target_arch == "ia32"', {
Expand All @@ -166,39 +167,39 @@
],
'sources': [
'libjpeg-turbo/simd/jsimd_i386.c',
'libjpeg-turbo/simd/jsimdcpu.asm',
'libjpeg-turbo/simd/jfdctflt-3dn.asm',
'libjpeg-turbo/simd/jidctflt-3dn.asm',
'libjpeg-turbo/simd/jquant-3dn.asm',
'libjpeg-turbo/simd/jccolor-mmx.asm',
'libjpeg-turbo/simd/jcgray-mmx.asm',
'libjpeg-turbo/simd/jcsample-mmx.asm',
'libjpeg-turbo/simd/jdcolor-mmx.asm',
'libjpeg-turbo/simd/jdmerge-mmx.asm',
'libjpeg-turbo/simd/jdsample-mmx.asm',
'libjpeg-turbo/simd/jfdctfst-mmx.asm',
'libjpeg-turbo/simd/jfdctint-mmx.asm',
'libjpeg-turbo/simd/jidctfst-mmx.asm',
'libjpeg-turbo/simd/jidctint-mmx.asm',
'libjpeg-turbo/simd/jidctred-mmx.asm',
'libjpeg-turbo/simd/jquant-mmx.asm',
'libjpeg-turbo/simd/jfdctflt-sse.asm',
'libjpeg-turbo/simd/jidctflt-sse.asm',
'libjpeg-turbo/simd/jquant-sse.asm',
'libjpeg-turbo/simd/jccolor-sse2.asm',
'libjpeg-turbo/simd/jcgray-mmx.asm',
'libjpeg-turbo/simd/jcgray-sse2.asm',
'libjpeg-turbo/simd/jcsample-mmx.asm',
'libjpeg-turbo/simd/jcsample-sse2.asm',
'libjpeg-turbo/simd/jdcolor-mmx.asm',
'libjpeg-turbo/simd/jdcolor-sse2.asm',
'libjpeg-turbo/simd/jdmerge-mmx.asm',
'libjpeg-turbo/simd/jdmerge-sse2.asm',
'libjpeg-turbo/simd/jdsample-mmx.asm',
'libjpeg-turbo/simd/jdsample-sse2.asm',
'libjpeg-turbo/simd/jfdctflt-3dn.asm',
'libjpeg-turbo/simd/jfdctflt-sse.asm',
'libjpeg-turbo/simd/jfdctfst-mmx.asm',
'libjpeg-turbo/simd/jfdctfst-sse2.asm',
'libjpeg-turbo/simd/jfdctint-mmx.asm',
'libjpeg-turbo/simd/jfdctint-sse2.asm',
'libjpeg-turbo/simd/jidctflt-3dn.asm',
'libjpeg-turbo/simd/jidctflt-sse.asm',
'libjpeg-turbo/simd/jidctflt-sse2.asm',
'libjpeg-turbo/simd/jidctfst-mmx.asm',
'libjpeg-turbo/simd/jidctfst-sse2.asm',
'libjpeg-turbo/simd/jidctint-mmx.asm',
'libjpeg-turbo/simd/jidctint-sse2.asm',
'libjpeg-turbo/simd/jidctred-mmx.asm',
'libjpeg-turbo/simd/jidctred-sse2.asm',
'libjpeg-turbo/simd/jquant-3dn.asm',
'libjpeg-turbo/simd/jquant-mmx.asm',
'libjpeg-turbo/simd/jquant-sse.asm',
'libjpeg-turbo/simd/jquantf-sse2.asm',
'libjpeg-turbo/simd/jquanti-sse2.asm',
'libjpeg-turbo/simd/jsimdcpu.asm',
]
}],
[ 'target_arch == "arm"', {
Expand Down Expand Up @@ -268,6 +269,31 @@
],
},
}],
[ 'OS == "win"', {
'variables': {
'yasm_path': 'yasm.exe',
'conditions': [
[ 'target_arch == "x64"', {
'yasm_format': '-fwin64',
'yasm_flags': [
'-D__x86_64__',
'-DWIN64',
'-DMSVC',
'-I..\..\deps\include'
]
},
{
'yasm_format': '-fwin32',
'yasm_flags': [
'-D__x86__',
'-DWIN32',
'-DMSVC',
'-I..\..\deps\include'
]
}]
]
}
}]
],
'rules': [
{
Expand Down
113 changes: 81 additions & 32 deletions src/buffersize.cc
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;
}
}
Loading

0 comments on commit 254c158

Please sign in to comment.