Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vonderheide committed Sep 19, 2016
1 parent 0d27258 commit 9a8dbdc
Showing 1 changed file with 65 additions and 4 deletions.
69 changes: 65 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,74 @@ bitmap.drawText(font, "Hello World!", 10, 100);
let bitmapData = bitmap.data(); // Return a Node.js Buffer
```

## Image formats

With release 2.0.0, drawing and pixel storage are separated. This way,
different image formats (e.g. RGB with interleaved or planar storage) can be used
by providing a `Canvas` implementantion to the `Bitmap` constructor.

The following canvas implementations are included in the distribution:

|Class name |Description |
|-------------------------|------------------------------------------------------|
|canvas.Grayscale |Grayscale pixel values |
|canvas.RGB |RGB pixel values, interleaved storage (R-G-B-R-G-B) |
|canvas.PlanarRGB |RGB pixel values, planar storage (R-R-G-G-B-B) |
|canvas.InterleavedStorage|Interleaved storage of values with multiple components|
|canvas.PlanarStorage |Planar storage of values with multiple components |
|canvas.Base |Base class, use this for custom implementations |

Note that drawing gradients using `drawGradientRect()` only produces sensible results on a grayscale canvas.

### Example: RGB image with 8 bits per pixel per color channel

```javascript
const bitmapManipulation = require("bitmap-manipulation");

// Create a canvas that stores interleaved RGB pixels
let canvas = new bitmapManipulation.canvas.RGB(400, 300, 1);

// Create a bitmap that uses this canvas for pixel storage
let bitmap = new bitmapManipulation.Bitmap(canvas);

// Draw a rectangle filled with cyan and a purple border.
// Note that the RGB canvas requires pixel values to be RGB arrays
bitmap.drawFilledRect(10, 10, 100, 50, [255, 0, 255], [0, 255, 255]);

// Get bytes of the image
let imageData = bitmap.data();
```

### Example: RGBA image with 16 bits per pixel per color channel

```javascript
const bitmapManipulation = require("bitmap-manipulation");

// Create a canvas that stores interleaved RGBA pixels
let canvas = new bitmapManipulation.canvas.Interleaved(400, 300, 4, 2);

// Create a bitmap that uses this canvas for pixel storage
let bitmap = new bitmapManipulation.Bitmap(canvas);

// Draw a rectangle filled with half-opaque cyan and a solid purple border.
let halfOpaqueCyan = [0, 65535, 65535, 32767];
let solidPurple = [65535, 0, 65535, 65535];
bitmap.drawFilledRect(10, 10, 100, 50, halfOpaqueCyan, solidPurple);

// Get bytes of the image
let imageData = bitmap.data();
```

## BMP file support

Loading from and writing to BMP files is supported using the subclass `BMPBitmap`.
See `examples/Drawing` for details.

## Documentation

The documentation can be generated from the source code by:
The documentation can be [generated](http://usejsdoc.org/) from the source code by:

<pre>
[jsdoc](http://usejsdoc.org/) index.js
</pre>
jsdoc index.js

## License

Expand Down

0 comments on commit 9a8dbdc

Please sign in to comment.