From 6c1e32de3067fd2ab29a351ca8d9ad6febadf81f Mon Sep 17 00:00:00 2001 From: meltingice Date: Thu, 19 Apr 2012 21:58:20 -0400 Subject: Added support for LAB 16-bit color --- examples/images/test-lab16.psd | Bin 0 -> 1971872 bytes lib/psd.js | 21 +++++++++++++++++++++ lib/psd.min.js | 2 ++ src/psdimage.coffee | 17 +++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 examples/images/test-lab16.psd diff --git a/examples/images/test-lab16.psd b/examples/images/test-lab16.psd new file mode 100644 index 0000000..53b5b12 Binary files /dev/null and b/examples/images/test-lab16.psd differ diff --git a/lib/psd.js b/lib/psd.js index b22353b..0fe2e01 100644 --- a/lib/psd.js +++ b/lib/psd.js @@ -1588,6 +1588,27 @@ var jspack = new JSPack(); ; return _results; }; + PSDImage.prototype.combineLAB16Channel = function() { + var a, alpha, b, i, l, rgb, _i, _ref, _results; + _results = []; + for (i = _i = 0, _ref = this.numPixels; _i < _ref; i = _i += 2) { + if (this.getImageChannels() === 4) { + alpha = this.channelData[i]; + l = this.channelData[i + this.channelLength]; + a = this.channelData[i + this.channelLength * 2]; + b = this.channelData[i + this.channelLength * 3]; + } else { + alpha = 255; + l = this.channelData[i]; + a = this.channelData[i + this.channelLength]; + b = this.channelData[i + this.channelLength * 2]; + } + rgb = PSDColor.labToRGB(l * 100 >> 8, a - 128, b - 128); + _results.push(this.pixelData.push(rgb.r, rgb.g, rgb.b, this.getAlphaValue(alpha))); + } + return _results; + }; + PSDImage.prototype.combineMultiChannel8 = function() { var c, i, k, m, rgb, y, _i, _ref, _results; _results = []; diff --git a/lib/psd.min.js b/lib/psd.min.js index 650c6a1..dd1d37e 100644 --- a/lib/psd.min.js +++ b/lib/psd.min.js @@ -176,6 +176,8 @@ return _results;};PSDImage.prototype.combineCMYK16Channel=function(){var a,c,i,k rgb=PSDColor.cmykToRGB(255-c,255-m,255-y,255-k);_results.push(this.pixelData.push(rgb.r,rgb.g,rgb.b,this.getAlphaValue(a)));} return _results;};PSDImage.prototype.combineLAB8Channel=function(){var a,alpha,b,i,l,rgb,_i,_ref,_results;_results=[];for(i=_i=0,_ref=this.numPixels;0<=_ref?_i<_ref:_i>_ref;i=0<=_ref?++_i:--_i){if(this.getImageChannels()===4){alpha=this.channelData[i];l=this.channelData[i+this.channelLength];a=this.channelData[i+this.channelLength*2];b=this.channelData[i+this.channelLength*3];}else{alpha=255;l=this.channelData[i];a=this.channelData[i+this.channelLength];b=this.channelData[i+this.channelLength*2];} rgb=PSDColor.labToRGB(l*100>>8,a-128,b-128);_results.push(this.pixelData.push(rgb.r,rgb.g,rgb.b,this.getAlphaValue(alpha)));} +return _results;};PSDImage.prototype.combineLAB16Channel=function(){var a,alpha,b,i,l,rgb,_i,_ref,_results;_results=[];for(i=_i=0,_ref=this.numPixels;_i<_ref;i=_i+=2){if(this.getImageChannels()===4){alpha=this.channelData[i];l=this.channelData[i+this.channelLength];a=this.channelData[i+this.channelLength*2];b=this.channelData[i+this.channelLength*3];}else{alpha=255;l=this.channelData[i];a=this.channelData[i+this.channelLength];b=this.channelData[i+this.channelLength*2];} +rgb=PSDColor.labToRGB(l*100>>8,a-128,b-128);_results.push(this.pixelData.push(rgb.r,rgb.g,rgb.b,this.getAlphaValue(alpha)));} return _results;};PSDImage.prototype.combineMultiChannel8=function(){var c,i,k,m,rgb,y,_i,_ref,_results;_results=[];for(i=_i=0,_ref=this.numPixels;0<=_ref?_i<_ref:_i>_ref;i=0<=_ref?++_i:--_i){c=this.channelData[i];m=this.channelData[i+this.channelLength];y=this.channelData[i+this.channelLength*2];if(this.getImageChannels()===4){k=this.channelData[i+this.channelLength*3];}else{k=255;} rgb=PSDColor.cmykToRGB(255-c,255-m,255-y,255-k);_results.push(this.pixelData.push(rgb.r,rgb.g,rgb.b,this.getAlphaValue(255)));} return _results;};PSDImage.prototype.toCanvasPixels=function(){return this.pixelData;};PSDImage.prototype.toFile=function(filename,cb){var png;if(this.toCanvasPixels().length===0){return cb();} diff --git a/src/psdimage.coffee b/src/psdimage.coffee index 03c1f57..35f8bbd 100755 --- a/src/psdimage.coffee +++ b/src/psdimage.coffee @@ -301,6 +301,23 @@ class PSDImage @pixelData.push rgb.r, rgb.g, rgb.b, @getAlphaValue(alpha) + combineLAB16Channel: -> + for i in [0...@numPixels] by 2 + if @getImageChannels() is 4 + alpha = @channelData[i] + l = @channelData[i + @channelLength] + a = @channelData[i + @channelLength * 2] + b = @channelData[i + @channelLength * 3] + else + alpha = 255 + l = @channelData[i] + a = @channelData[i + @channelLength] + b = @channelData[i + @channelLength * 2] + + rgb = PSDColor.labToRGB l * 100 >> 8, a - 128, b - 128 + + @pixelData.push rgb.r, rgb.g, rgb.b, @getAlphaValue(alpha) + combineMultiChannel8: -> for i in [0...@numPixels] c = @channelData[i] -- cgit v1.2.3-59-g8ed1b