Skip to content

Commit

Permalink
Merge pull request #40 from EyalAr/ver0.0.3
Browse files Browse the repository at this point in the history
0. Refactors code to components: decoder, encoder, image (#34)
0. Compatibility with Node 0.11 (#28)
0. Decoding of Buffer objects (#35)
0. Sharpen image (#16)
0. Adjust saturation (#8)
0. Adjust lightness (#10)
0. Adjust hue (#9)
  • Loading branch information
EyalAr committed Sep 15, 2014
2 parents b6180af + 38b45b3 commit eb77a65
Show file tree
Hide file tree
Showing 45 changed files with 2,955 additions and 1,226 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language: node_js
node_js:
- "0.10"
- "0.11"
99 changes: 93 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
0. [Usage](#usage)
0. [Supported formats](#supported-formats)
0. [API](#api)
0. [Open an image](#open-an-image)
0. [Open an image from file or buffer](#open-an-image)
0. [Image operations](#image-operations)
0. [Resize](#resize)
0. [Scale](#scale)
0. [Rotate](#rotate)
0. [Crop](#crop)
0. [Blur](#blur)
0. [Sharpen](#sharpen)
0. [Mirror](#mirror)
0. [Flip](#flip)
0. [Border](#border)
0. [Pad](#pad)
0. [Adjust saturation](#saturate)
0. Adjust lightness: [lighten](#lighten) / [darken](#darken)
0. [Adjust hue](#hue)
0. [Getters](#getters)
0. [Width](#width)
0. [Height](#height)
Expand Down Expand Up @@ -136,14 +140,16 @@ the `open` method.

### Open an image

`open(path, type, callback)`
`open(source, type, callback)`

0. `path {String}`: The path to the image on disk.
0. `source {String/Buffer}`: The path to the image on disk or an image buffer.
0. `type {String}`: **Optional** type of the image. If omitted, the type will be
inferred from the file extension. Can usually be omitted. Useful to open
image files without extensions.
inferred from the file extension. If `source` is a buffer, `type` must be
specified.
0. `callback {Function(err, image)}`

#### Open file example

```Javascript
var lwip = require('lwip');
lwip.open('path/to/image.jpg', function(err, image){
Expand All @@ -152,6 +158,21 @@ lwip.open('path/to/image.jpg', function(err, image){
});
```

#### Open buffer example

```Javascript
var fs = require('fs'),
lwip = require('lwip');

fs.readFile('path/to/image.png', function(err, buffer){
// check err
lwip.open(buffer, 'png', function(err, image){
// check 'err'. use 'image'.
// image.resize(...), etc.
});
});
```

### Image operations

#### Resize
Expand Down Expand Up @@ -225,7 +246,16 @@ Gaussian blur.

`image.blur(sigma, callback)`

0. `sigma {Float}`: Standard deviation of the Gaussian filter.
0. `sigma {Float>=0}`: Standard deviation of the Gaussian filter.
0. `callback {Function(err, image)}`

#### Sharpen

Inverse diffusion shapren.

`image.sharpen(amplitude, callback)`

0. `amplitude {Float}`: Sharpening amplitude.
0. `callback {Function(err, image)}`

#### Mirror
Expand Down Expand Up @@ -273,6 +303,63 @@ Pad image edges with colored pixels.
between 0 and 255.
0. `callback {Function(err, image)}`

#### Saturate

Adjust image saturation.

`image.saturate(delta, callback)`

0. `delta {Float}`: By how much to increase / decrease the saturation.
0. `callback {Function(err, image)}`

**Examples**:

0. `image.saturate(0, ...)` will have no effect on the image.
0. `image.saturate(0.5, ...)` will increase the saturation by 50%.
0. `image.saturate(-1, ...)` will decrease the saturation by 100%, effectively
desaturating the image.

#### Lighten

Adjust image lightness.

`image.lighten(delta, callback)`

0. `delta {Float}`: By how much to increase / decrease the lightness.
0. `callback {Function(err, image)}`

**Examples**:

0. `image.lighten(0, ...)` will have no effect on the image.
0. `image.lighten(0.5, ...)` will increase the lightness by 50%.
0. `image.lighten(-1, ...)` will decrease the lightness by 100%, effectively
making the image black.

#### Darken

Adjust image lightness.

`image.darken(delta, callback)`

Equivalent to `image.lighten(-delta, callback)`.

#### Hue

Adjust image hue.

`image.hue(shift, callback)`

0. `shift {Float}`: By how many degrees to shift each pixel's hue.
0. `callback {Function(err, image)}`

**Examples**:

0. `image.lighten(0, ...)` will have no effect on the image.
0. `image.lighten(100, ...)` will shift pixels' hue by 100 degrees.

**Note:** The hue is shifted in a circular manner in the range [0,360] for each
pixel individually.

### Getters

#### Width
Expand Down
184 changes: 154 additions & 30 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
{
"targets": [{
"target_name": "lwip",
"target_name": "lwip_decoder",
"sources": [
# LWIP:
#######
"src/lwip.cpp",
"src/LwipImage.cpp",
"src/decoder/init.cpp",
"src/decoder/util.cpp",
"src/decoder/buffer_worker.cpp",
"src/decoder/jpeg_decoder.cpp",
"src/decoder/png_decoder.cpp",
# LIB JPEG:
###########
"lib/jpeg/jmemnobs.c",
"lib/jpeg/jcapimin.c",
"lib/jpeg/jcapistd.c",
"lib/jpeg/jccoefct.c",
"lib/jpeg/jccolor.c",
"lib/jpeg/jcdctmgr.c",
"lib/jpeg/jchuff.c",
"lib/jpeg/jcinit.c",
"lib/jpeg/jcmainct.c",
"lib/jpeg/jcmarker.c",
"lib/jpeg/jcmaster.c",
"lib/jpeg/jcomapi.c",
"lib/jpeg/jcparam.c",
"lib/jpeg/jcprepct.c",
"lib/jpeg/jcsample.c",
"lib/jpeg/jdapimin.c",
"lib/jpeg/jdapistd.c",
"lib/jpeg/jdatadst.c",
Expand All @@ -46,48 +36,182 @@
"lib/jpeg/jidctint.c",
"lib/jpeg/jutils.c",
"lib/jpeg/jmemmgr.c",
"lib/jpeg/jcarith.c",
"lib/jpeg/jdarith.c",
"lib/jpeg/jquant1.c",
"lib/jpeg/jquant2.c",
"lib/jpeg/jdmerge.c",
"lib/jpeg/jaricom.c",
"lib/jpeg/jquant1.c",
"lib/jpeg/jquant2.c",
# LIB PNG:
##########
"lib/png/png.c",
"lib/png/pngset.c",
"lib/png/pngget.c",
"lib/png/pngrutil.c",
"lib/png/pngtrans.c",
"lib/png/pngwutil.c",
"lib/png/pngread.c",
"lib/png/pngrio.c",
"lib/png/pngwio.c",
"lib/png/pngwrite.c",
"lib/png/pngrtran.c",
"lib/png/pngwtran.c",
"lib/png/pngmem.c",
"lib/png/pngerror.c",
"lib/png/pngpread.c",
# ZLIB:
#######
"lib/zlib/adler32.c",
"lib/zlib/compress.c",
"lib/zlib/crc32.c",
"lib/zlib/deflate.c",
"lib/zlib/gzclose.c",
"lib/zlib/gzlib.c",
"lib/zlib/gzread.c",
"lib/zlib/gzwrite.c",
"lib/zlib/infback.c",
"lib/zlib/inflate.c",
"lib/zlib/inftrees.c",
"lib/zlib/inffast.c",
"lib/zlib/trees.c",
"lib/zlib/uncompr.c",
"lib/zlib/zutil.c"
"lib/zlib/zutil.c",
"lib/zlib/trees.c"
],
'include_dirs': [
'<!(node -e "require(\'nan\')")',
'src/decoder',
'lib/zlib',
'lib/jpeg',
'lib/cimg',
'lib/png'
],
'conditions': [
['OS=="linux"', {
'cflags!': ['-fno-exceptions'],
'cflags_cc!': ['-fno-exceptions'],
}],
['OS=="mac"', {
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
},
'include_dirs': ['/usr/include/malloc']
}],
['OS=="win"', {
'configurations': {
'Release': {
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': 1
}
}
}
}
}]
]
},{
"target_name": "lwip_encoder",
"sources": [
# LWIP:
#######
"src/encoder/init.cpp",
"src/encoder/jpeg_worker.cpp",
"src/encoder/png_worker.cpp",
# LIB JPEG:
###########
"lib/jpeg/jdatadst.c",
"lib/jpeg/jmemnobs.c",
"lib/jpeg/jcomapi.c",
"lib/jpeg/jerror.c",
"lib/jpeg/jfdctflt.c",
"lib/jpeg/jfdctfst.c",
"lib/jpeg/jfdctint.c",
"lib/jpeg/jidctflt.c",
"lib/jpeg/jidctfst.c",
"lib/jpeg/jidctint.c",
"lib/jpeg/jutils.c",
"lib/jpeg/jmemmgr.c",
"lib/jpeg/jaricom.c",
"lib/jpeg/jquant1.c",
"lib/jpeg/jquant2.c",
"lib/jpeg/jcapimin.c",
"lib/jpeg/jcapistd.c",
"lib/jpeg/jccoefct.c",
"lib/jpeg/jccolor.c",
"lib/jpeg/jcdctmgr.c",
"lib/jpeg/jchuff.c",
"lib/jpeg/jcinit.c",
"lib/jpeg/jcmainct.c",
"lib/jpeg/jcmarker.c",
"lib/jpeg/jcmaster.c",
"lib/jpeg/jcparam.c",
"lib/jpeg/jcprepct.c",
"lib/jpeg/jcsample.c",
"lib/jpeg/jcarith.c",
# LIB PNG:
##########
"lib/png/png.c",
"lib/png/pngset.c",
"lib/png/pngget.c",
"lib/png/pngtrans.c",
"lib/png/pngmem.c",
"lib/png/pngerror.c",
"lib/png/pngwrite.c",
"lib/png/pngwutil.c",
"lib/png/pngwio.c",
"lib/png/pngwtran.c",
# ZLIB:
#######
"lib/zlib/adler32.c",
"lib/zlib/crc32.c",
"lib/zlib/gzlib.c",
"lib/zlib/zutil.c",
"lib/zlib/gzwrite.c",
"lib/zlib/compress.c",
"lib/zlib/deflate.c",
"lib/zlib/trees.c"
],
'include_dirs': [
'<!(node -e "require(\'nan\')")',
'src/encoder',
'lib/zlib',
'lib/jpeg',
'lib/cimg',
'lib/png'
],
'conditions': [
['OS=="linux"', {
'cflags!': ['-fno-exceptions'],
'cflags_cc!': ['-fno-exceptions'],
}],
['OS=="mac"', {
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
},
'include_dirs': ['/usr/include/malloc']
}],
['OS=="win"', {
'configurations': {
'Release': {
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': 1
}
}
}
}
}]
]
},{
"target_name": "lwip_image",
"sources": [
# LWIP:
#######
"src/image/init.cpp",
"src/image/image.cpp",
"src/image/resize_worker.cpp",
"src/image/rotate_worker.cpp",
"src/image/blur_worker.cpp",
"src/image/crop_worker.cpp",
"src/image/mirror_worker.cpp",
"src/image/pad_worker.cpp",
"src/image/sharpen_worker.cpp",
"src/image/hsl_worker.cpp",
],
'include_dirs': [
'<!(node -e "require(\'nan\')")',
'lib/cimg',
],
'include_dirs': ['lib/zlib', 'lib/jpeg', 'lib/cimg', 'lib/png'],
'conditions': [
['OS=="linux"', {
'cflags!': ['-fno-exceptions'],
Expand Down
Loading

0 comments on commit eb77a65

Please sign in to comment.