Transfer functions on abstract pixels.

This commit is contained in:
Michael Jumper
2012-02-27 13:23:07 -08:00
parent ceb94ba4c3
commit 5eb316a3ba
2 changed files with 183 additions and 36 deletions

View File

@@ -430,10 +430,32 @@ Guacamole.Layer = function(width, height) {
// Apply transfer for each pixel
for (var i=0; i<srcw*srch*4; i+=4) {
dst.data[i ] = transferFunction(src.data[i ], dst.data[i ]);
dst.data[i+1] = transferFunction(src.data[i+1], dst.data[i+1]);
dst.data[i+2] = transferFunction(src.data[i+2], dst.data[i+2]);
dst.data[i+3] = 0xFF; // Assume output opaque
// Get source pixel environment
var src_pixel = new Guacamole.Layer.Pixel(
src.data[i],
src.data[i+1],
src.data[i+2],
src.data[i+3]
);
// Get destination pixel environment
var dst_pixel = new Guacamole.Layer.Pixel(
dst.data[i],
dst.data[i+1],
dst.data[i+2],
dst.data[i+3]
);
// Apply transfer function
transferFunction(src_pixel, dst_pixel);
// Save pixel data
dst.data[i ] = dst_pixel.red;
dst.data[i+1] = dst_pixel.green;
dst.data[i+2] = dst_pixel.blue;
dst.data[i+3] = dst_pixel.alpha;
}
// Draw image data
@@ -723,3 +745,42 @@ Guacamole.Layer.RATOP = 0x9;
*/
Guacamole.Layer.SRC = 0xC;
/**
* Represents a single pixel of image data. All components have a minimum value
* of 0 and a maximum value of 255.
*
* @constructor
*
* @param {Number} r The red component of this pixel.
* @param {Number} g The green component of this pixel.
* @param {Number} b The blue component of this pixel.
* @param {Number} a The alpha component of this pixel.
*/
Guacamole.Layer.Pixel = function(r, g, b, a) {
/**
* The red component of this pixel, where 0 is the minimum value,
* and 255 is the maximum.
*/
this.red = r;
/**
* The green component of this pixel, where 0 is the minimum value,
* and 255 is the maximum.
*/
this.green = g;
/**
* The blue component of this pixel, where 0 is the minimum value,
* and 255 is the maximum.
*/
this.blue = b;
/**
* The alpha component of this pixel, where 0 is the minimum value,
* and 255 is the maximum.
*/
this.alpha = a;
};