# glad-stream-decoder

[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)

> Transform stream that decodes GLAD forest alerts

[Global Forest Watch](https://www.globalforestwatch.org/) publishes weekly deforestation alerts as PNG map tiles. The data of the alert, the confidence level and intensity is encoded to the tile. This module decodes that information and creates an image tile with the alerts colored with the alpha transparency representing their intensity.

The transform stream expects raw image data, as you would get from reading the image data from the canvas. To decode a PNG to raw image data, and to re-encode the output to PNG, use [`png-stream`](https://github.com/devongovett/png-stream)

## Table of Contents

-   [Install](#install)
-   [Usage](#usage)
-   [API](#api)
-   [Maintainers](#maintainers)
-   [Contribute](#contribute)
-   [License](#license)

## Install

```sh
npm i glad-stream-decoder
```

## Usage

```js
var fs = require('fs')
var path = require('path')
var GLADStreamDecoder = require('glad-stream-decoder')
var PNGDecoder = require('png-stream/decoder')
var PNGEncoder = require('png-stream/encoder')

// encoded.png is an PNG encoded with date, confidence + intensity from
// http://wri-tiles.s3.amazonaws.com/glad_prod/tiles/{z}/{x}/{y}.png
var rs = fs.createReadStream('encoded.png'))
var ws = fs.createWriteStream('decoded.png'))

rs
  .pipe(new PNGDecoder())
  .pipe(new DecodeGLADStream({
    // Only show alerts since this date
    since: new Date(2017, 0, 1),
    // Color alerts green
    color: '#00FF00'
  }))
  .pipe(new PNGEncoder())
  .pipe(ws)

```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

-   [GLADStreamDecoder](#gladstreamdecoder)

### GLADStreamDecoder

Transforms an encoded rgb image stream (a buffer of r,g,b values in order)
from GLAD alerts into an rgba image stream with alerts as colored pixels
`opts.color` and the intensity as the transparency of the pixel.

**Parameters**

-   `opts` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
    -   `opts.color` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** CSS color string or [red, green, blue] array for color of pixels
    -   `opts.since` **[date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)** Date object, filters alerts since this date

## Maintainers

[@gmaclennan](https://github.com/gmaclennan)

## Contribute

PRs accepted.

Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.

## License

MIT © 2018 Digital Democracy
