Web Worker that can map imageData to a new palette given R, G, B or Alpha arrays
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README
gui-example.html
palette-map.js
world.png

README

palette-map.js

Allows you to map one set of colors to an existing Canvas, based on the pixel data contained.

This is similar to Actionscript's BitmapData.paletteMap method

An example is here:
http://shashashasha.github.com/palette-map-js/

Usage:
// create the web worker
var paletteMapper = new Worker('palette-map.js');
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);

// pass it the arrays of colors to be mapped
paletteMapper.postMessage({
	// possible modes include scaled-rgb, scaled-rgba, 
	mode: 'scaled-rgb',
	r: [an Array of values to be mapped to the Red channel],
	g: [an Array of values to be mapped to the Green channel],
	b: [an Array of values to be mapped to the Blue channel],
	imageData: imageData
});

// place the pixels back
paletteMapper.addEventListener('message', function(e) {
    if (e.data.imageData) {
        ctx.putImageData(e.data.imageData, 0, 0);
    }
}, false);