Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsLeenheer committed Nov 23, 2017
0 parents commit 9cd24d1
Show file tree
Hide file tree
Showing 8 changed files with 2,483 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"node": true,
"es6": true
},
"extends": [
"eslint:recommended",
"google"
],
"rules": {
"max-len": [
1,
120
]
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.DS_Store
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2017 Niels Leenheer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# canvas-dither

Black and White dithering for the canvas element

## Usage

First, install the package using npm:

npm install canvas-dither --save

Then, require the package and use it like so:

let Dither = require('canvas-dither');

// Assume we have an existing canvas element with a 2D context
// Retrieve the image data of the canvas
let image = context.getImageData(0, 0, canvas.width, canvas.height);

// Dither the data using the Atkinson algoritm
image = Dither.atkinson(image);

// Place the image data back on the canvas
context.putImageData(image, 0, 0);

This package contains the following algorithms:

### Threshold
A simple threshold which will make all pixels with a luminance over the threshold white and under the threshold black.

Dither.threshold(imageData, threshold);

### Bayer
Using a Bayer matrix the image is converted to black and white with a cross-hatch pattern.

Dither.bayer(imageData, threshold);

### Floyd-Steinberg
Altough there is nothing random about this algorithm, the results looks like a random scattering of dots, making especially photos seem very natural.

Dither.floydsteinberg(imageData);

### Bill Atikinson
An improved version of the Floyd-Steinberg algorithm created by Bill Atkinson of MacPaint fame. This algorithm creates less noise in almost white backgrounds compared to Floyd-Steinberg, but has more contrast as a result.

Dither.atkinson(imageData);


## License

MIT
1 change: 1 addition & 0 deletions dist/canvas-dither.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9cd24d1

Please sign in to comment.