aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormeltingice <meltingice8917@gmail.com>2012-07-17 23:30:12 -0400
committermeltingice <meltingice8917@gmail.com>2012-07-17 23:30:12 -0400
commit81e156923a5fb9618042a5c24d00fca4fe300b6a (patch)
tree302fa79f9c7d10670d611947cd41debb405a9319
parentUpdate docs and version bump (diff)
downloadpsd.js-81e156923a5fb9618042a5c24d00fca4fe300b6a.tar.xz
psd.js-81e156923a5fb9618042a5c24d00fca4fe300b6a.zip
Remove accidental console.log call and fix parsing RAW images
-rw-r--r--lib/psd.js5
-rw-r--r--lib/psd.min.js6
-rwxr-xr-xsrc/psdimage.coffee2
-rwxr-xr-xsrc/psdlayer.coffee1
4 files changed, 6 insertions, 8 deletions
diff --git a/lib/psd.js b/lib/psd.js
index 1713506..b26b954 100644
--- a/lib/psd.js
+++ b/lib/psd.js
@@ -337,7 +337,7 @@ var jspack = new JSPack(); ;
Root.PSD = PSD = (function() {
- PSD.VERSION = "0.4.4";
+ PSD.VERSION = "0.4.5";
PSD.DEBUG = false;
@@ -1562,7 +1562,7 @@ var jspack = new JSPack(); ;
}
Log.debug("Attempting to parse RAW encoded image...");
for (i = _i = 0; 0 <= length ? _i < length : _i > length; i = 0 <= length ? ++_i : --_i) {
- this.channelData.push(this.file.read(1)[0]);
+ this.channelData[i] = this.file.read(1)[0];
}
return true;
};
@@ -2375,7 +2375,6 @@ var jspack = new JSPack(); ;
switch (key) {
case "SoCo":
this.adjustments.solidColor = (new PSDSolidColor(this, length)).parse();
- console.log("SoCo:", this.adjustments.solidColor);
break;
case "GdFl":
this.adjustments.gradient = (new PSDGradient(this, length)).parse();
diff --git a/lib/psd.min.js b/lib/psd.min.js
index 071043a..6274749 100644
--- a/lib/psd.min.js
+++ b/lib/psd.min.js
@@ -71,7 +71,7 @@ return a;};m.Pack=function(fmt,values)
{sum+=(((m[1]==undefined)||(m[1]==''))?1:parseInt(m[1]))*this._lenLut[m[2]];}
return sum;};};var jspack=new JSPack();;var Log,PSD,PSDBlackWhite,PSDBrightnessContrast,PSDChannelImage,PSDColor,PSDColorBalance,PSDCurves,PSDDescriptor,PSDDropDownLayerEffect,PSDExposure,PSDFile,PSDGradient,PSDHeader,PSDHueSaturation,PSDImage,PSDInvert,PSDLayer,PSDLayerEffect,PSDLayerEffectCommonStateInfo,PSDLayerMask,PSDLevels,PSDPattern,PSDPhotoFilter,PSDPosterize,PSDResource,PSDSelectiveColor,PSDSolidColor,PSDThreshold,PSDTypeTool,PSDVibrance,Root,Util,assert,fs,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key];}function ctor(){this.constructor=child;}ctor.prototype=parent.prototype;child.prototype=new ctor();child.__super__=parent.prototype;return child;};assert=(function(assert){if(typeof exports!=="undefined"&&exports!==null){return require('assert');}
assert=function(test){if(test!==true){throw"Assertion error";}};assert.equal=function(actual,expected){if(actual!==expected){throw"Assertion error";}};return assert;})(assert);if(typeof exports!=="undefined"&&exports!==null){Root=exports;fs=require('fs');}else{Root=window;}
-Root.PSD=PSD=(function(){PSD.VERSION="0.4.4";PSD.DEBUG=false;PSD.fromFile=function(file,cb){var data,reader;if(cb==null){cb=function(){};}
+Root.PSD=PSD=(function(){PSD.VERSION="0.4.5";PSD.DEBUG=false;PSD.fromFile=function(file,cb){var data,reader;if(cb==null){cb=function(){};}
if(typeof exports!=="undefined"&&exports!==null){data=fs.readFileSync(file);return new PSD(data);}else{reader=new FileReader();reader.onload=function(f){var bytes,psd;bytes=new Uint8Array(f.target.result);psd=new PSD(bytes);return cb(psd);};return reader.readAsArrayBuffer(file);}};PSD.fromURL=function(url,cb){var xhr;if(cb==null){cb=function(){};}
xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=function(){var data,psd;data=new Uint8Array(xhr.response||xhr.mozResponseArrayBuffer);psd=new PSD(data);return cb(psd);};return xhr.send(null);};PSD.prototype.options={layerImages:false,onlyVisibleLayers:false};function PSD(data){this.file=new PSDFile(data);this.header=null;this.resources=null;this.layerMask=null;this.layers=null;this.images=null;this.image=null;}
PSD.prototype.setOptions=function(options){var key,val,_results;_results=[];for(key in options){if(!__hasProp.call(options,key))continue;val=options[key];_results.push(this.options[key]=val);}
@@ -149,7 +149,7 @@ this.calculateLength();this.channelData=new Uint8Array(this.length);this.startPo
PSDImage.prototype.calculateLength=function(){this.length=(function(){switch(this.getImageDepth()){case 1:return(this.getImageWidth()+7)/8*this.getImageHeight();case 16:return this.getImageWidth()*this.getImageHeight()*2;default:return this.getImageWidth()*this.getImageHeight();}}).call(this);this.channelLength=this.length;return this.length*=this.getImageChannels();};PSDImage.prototype.parse=function(){var _ref;this.compression=this.parseCompression();Log.debug("Image size: "+this.length+" ("+(this.getImageWidth())+"x"+(this.getImageHeight())+")");if((_ref=this.compression)===2||_ref===3){Log.debug("ZIP compression not implemented yet, skipping.");return this.file.seek(this.endPos,false);}
return this.parseImageData();};PSDImage.prototype.skip=function(){Log.debug("Skipping image data");return this.file.seek(this.length);};PSDImage.prototype.parseCompression=function(){return this.file.readShortInt();};PSDImage.prototype.parseImageData=function(){Log.debug("Image compression: id="+this.compression+", name="+COMPRESSIONS[this.compression]);switch(this.compression){case 0:this.parseRaw();break;case 1:this.parseRLE();break;case 2:case 3:this.parseZip();break;default:Log.debug("Unknown image compression. Attempting to skip.");return this.file.seek(this.endPos,false);}
return this.processImageData();};PSDImage.prototype.parseRaw=function(length){var i,_i;if(length==null){length=this.length;}
-Log.debug("Attempting to parse RAW encoded image...");for(i=_i=0;0<=length?_i<length:_i>length;i=0<=length?++_i:--_i){this.channelData.push(this.file.read(1)[0]);}
+Log.debug("Attempting to parse RAW encoded image...");for(i=_i=0;0<=length?_i<length:_i>length;i=0<=length?++_i:--_i){this.channelData[i]=this.file.read(1)[0];}
return true;};PSDImage.prototype.parseRLE=function(){Log.debug("Attempting to parse RLE encoded image...");this.byteCounts=this.getByteCounts();Log.debug("Read byte counts. Current pos = "+(this.file.tell())+", Pixels = "+this.length);return this.parseChannelData();};PSDImage.prototype.getImageHeight=function(){return this.header.rows;};PSDImage.prototype.getImageWidth=function(){return this.header.cols;};PSDImage.prototype.getImageChannels=function(){return this.header.channels;};PSDImage.prototype.getImageDepth=function(){return this.header.depth;};PSDImage.prototype.getByteCounts=function(){var byteCounts,i,j,_i,_j,_ref,_ref1;byteCounts=[];for(i=_i=0,_ref=this.getImageChannels();0<=_ref?_i<_ref:_i>_ref;i=0<=_ref?++_i:--_i){for(j=_j=0,_ref1=this.getImageHeight();0<=_ref1?_j<_ref1:_j>_ref1;j=0<=_ref1?++_j:--_j){byteCounts.push(this.file.readShortInt());}}
return byteCounts;};PSDImage.prototype.parseChannelData=function(){var chanPos,i,lineIndex,_i,_ref,_ref1;chanPos=0;lineIndex=0;for(i=_i=0,_ref=this.getImageChannels();0<=_ref?_i<_ref:_i>_ref;i=0<=_ref?++_i:--_i){Log.debug("Parsing channel #"+i+", Start = "+(this.file.tell()));_ref1=this.decodeRLEChannel(chanPos,lineIndex),chanPos=_ref1[0],lineIndex=_ref1[1];}
return true;};PSDImage.prototype.decodeRLEChannel=function(chanPos,lineIndex){var byteCount,data,dataIndex,j,k,len,start,val,z,_i,_j,_k,_l,_ref,_ref1,_ref2;for(j=_i=0,_ref=this.getImageHeight();0<=_ref?_i<_ref:_i>_ref;j=0<=_ref?++_i:--_i){byteCount=this.byteCounts[lineIndex++];start=this.file.tell();while(this.file.tell()<start+byteCount){len=this.file.read(1)[0];if(len<128){len++;data=this.file.read(len);dataIndex=0;for(k=_j=chanPos,_ref1=chanPos+len;chanPos<=_ref1?_j<_ref1:_j>_ref1;k=chanPos<=_ref1?++_j:--_j){this.channelData[k]=data[dataIndex++];}
@@ -217,7 +217,7 @@ return _results;};PSDLayer.prototype.parseBlendModes=function(){var filler,flags
this.blendingMode=this.blendMode.blender;this.opacity=this.blendMode.opacity;this.visible=this.blendMode.visible;return Log.debug("Blending mode:",this.blendMode);};PSDLayer.prototype.parseMaskData=function(){var flags,_ref,_ref1,_ref2,_ref3;this.mask.size=this.file.readInt();assert((_ref=this.mask.size)===36||_ref===20||_ref===0);if(this.mask.size===0){return true;}
_ref1=this.file.readf(">llllBB"),this.mask.top=_ref1[0],this.mask.left=_ref1[1],this.mask.bottom=_ref1[2],this.mask.right=_ref1[3],this.mask.defaultColor=_ref1[4],flags=_ref1[5];assert((_ref2=this.mask.defaultColor)===0||_ref2===255);this.mask.width=this.mask.right-this.mask.left;this.mask.height=this.mask.bottom-this.mask.top;this.mask.relative=flags&0x01;this.mask.disabled=(flags&(0x01<<1))>0;this.mask.invert=(flags&(0x01<<2))>0;if(this.mask.size===20){this.file.seek(2);}else{_ref3=this.file.readf(">BB"),flags=_ref3[0],this.mask.defaultColor=_ref3[1];this.mask.relative=flags&0x01;this.mask.disabled=(flags&(0x01<<1))>0;this.mask.invert=(flags&(0x01<<2))>0;this.file.seek(16);}
return true;};PSDLayer.prototype.parseBlendingRanges=function(){var i,length,pos,_i,_ref,_results;length=this.file.readInt();this.blendingRanges.grey={source:{black:this.file.readShortInt(),white:this.file.readShortInt()},dest:{black:this.file.readShortInt(),white:this.file.readShortInt()}};pos=this.file.tell();this.blendingRanges.numChannels=(length-8)/8;assert(this.blendingRanges.numChannels>0);this.blendingRanges.channels=[];_results=[];for(i=_i=0,_ref=this.blendingRanges.numChannels;0<=_ref?_i<_ref:_i>_ref;i=0<=_ref?++_i:--_i){_results.push(this.blendingRanges.channels.push({source:{black:this.file.readShortInt(),white:this.file.readShortInt()},dest:{black:this.file.readShortInt(),white:this.file.readShortInt()}}));}
-return _results;};PSDLayer.prototype.parseLegacyLayerName=function(){var namelen;namelen=Util.pad4(this.file.read(1)[0]);return this.legacyName=Util.decodeMacroman(this.file.read(namelen)).replace(/\u0000/g,'');};PSDLayer.prototype.parseExtraData=function(){var key,length,pos,signature,_ref,_results;_results=[];while(this.file.tell()<this.layerEnd){_ref=this.file.readf(">4s4s"),signature=_ref[0],key=_ref[1];assert.equal(signature,"8BIM");length=Util.pad2(this.file.readInt());pos=this.file.tell();Log.debug("Extra layer info: key = "+key+", length = "+length);switch(key){case"SoCo":this.adjustments.solidColor=(new PSDSolidColor(this,length)).parse();console.log("SoCo:",this.adjustments.solidColor);break;case"GdFl":this.adjustments.gradient=(new PSDGradient(this,length)).parse();break;case"PtFl":this.adjustments.pattern=(new PSDPattern(this,length)).parse();break;case"brit":this.adjustments.brightnessContrast=(new PSDBrightnessContrast(this,length)).parse();break;case"levl":this.adjustments.levels=(new PSDLevels(this,length)).parse();break;case"curv":this.adjustments.curves=(new PSDCurves(this,length)).parse();break;case"expA":this.adjustments.exposure=(new PSDExposure(this,length)).parse();break;case"vibA":this.adjustments.vibrance=(new PSDVibrance(this,length)).parse();break;case"hue2":this.adjustments.hueSaturation=(new PSDHueSaturation(this,length)).parse();break;case"blnc":this.adjustments.colorBalance=(new PSDColorBalance(this,length)).parse();break;case"blwh":this.adjustments.blackWhite=(new PSDBlackWhite(this,length)).parse();break;case"phfl":this.adjustments.photoFilter=(new PSDPhotoFilter(this,length)).parse();break;case"thrs":this.adjustments.threshold=(new PSDThreshold(this,length)).parse();break;case"nvrt":this.adjustments.invert=(new PSDInvert(this,length)).parse();break;case"post":this.adjustments.posterize=(new PSDPosterize(this,length)).parse();break;case"tySh":this.adjustments.typeTool=(new PSDTypeTool(this,length)).parse(true);break;case"TySh":this.adjustments.typeTool=(new PSDTypeTool(this,length)).parse();break;case"luni":this.name=this.file.readUnicodeString();this.file.seek(pos+length,false);break;case"lyid":this.layerId=this.file.readInt();break;case"lsct":this.readLayerSectionDivider();break;case"lrFX":this.parseEffectsLayer();this.file.read(2);break;case"selc":this.adjustments.selectiveColor=(new PSDSelectiveColor(this,length)).parse();break;default:this.file.seek(length);Log.debug("Skipping additional layer info with key "+key);}
+return _results;};PSDLayer.prototype.parseLegacyLayerName=function(){var namelen;namelen=Util.pad4(this.file.read(1)[0]);return this.legacyName=Util.decodeMacroman(this.file.read(namelen)).replace(/\u0000/g,'');};PSDLayer.prototype.parseExtraData=function(){var key,length,pos,signature,_ref,_results;_results=[];while(this.file.tell()<this.layerEnd){_ref=this.file.readf(">4s4s"),signature=_ref[0],key=_ref[1];assert.equal(signature,"8BIM");length=Util.pad2(this.file.readInt());pos=this.file.tell();Log.debug("Extra layer info: key = "+key+", length = "+length);switch(key){case"SoCo":this.adjustments.solidColor=(new PSDSolidColor(this,length)).parse();break;case"GdFl":this.adjustments.gradient=(new PSDGradient(this,length)).parse();break;case"PtFl":this.adjustments.pattern=(new PSDPattern(this,length)).parse();break;case"brit":this.adjustments.brightnessContrast=(new PSDBrightnessContrast(this,length)).parse();break;case"levl":this.adjustments.levels=(new PSDLevels(this,length)).parse();break;case"curv":this.adjustments.curves=(new PSDCurves(this,length)).parse();break;case"expA":this.adjustments.exposure=(new PSDExposure(this,length)).parse();break;case"vibA":this.adjustments.vibrance=(new PSDVibrance(this,length)).parse();break;case"hue2":this.adjustments.hueSaturation=(new PSDHueSaturation(this,length)).parse();break;case"blnc":this.adjustments.colorBalance=(new PSDColorBalance(this,length)).parse();break;case"blwh":this.adjustments.blackWhite=(new PSDBlackWhite(this,length)).parse();break;case"phfl":this.adjustments.photoFilter=(new PSDPhotoFilter(this,length)).parse();break;case"thrs":this.adjustments.threshold=(new PSDThreshold(this,length)).parse();break;case"nvrt":this.adjustments.invert=(new PSDInvert(this,length)).parse();break;case"post":this.adjustments.posterize=(new PSDPosterize(this,length)).parse();break;case"tySh":this.adjustments.typeTool=(new PSDTypeTool(this,length)).parse(true);break;case"TySh":this.adjustments.typeTool=(new PSDTypeTool(this,length)).parse();break;case"luni":this.name=this.file.readUnicodeString();this.file.seek(pos+length,false);break;case"lyid":this.layerId=this.file.readInt();break;case"lsct":this.readLayerSectionDivider();break;case"lrFX":this.parseEffectsLayer();this.file.read(2);break;case"selc":this.adjustments.selectiveColor=(new PSDSelectiveColor(this,length)).parse();break;default:this.file.seek(length);Log.debug("Skipping additional layer info with key "+key);}
if(this.file.tell()!==(pos+length)){Log.debug("Warning: additional layer info with key "+key+" - unexpected end");_results.push(this.file.seek(pos+length,false));}else{_results.push(void 0);}}
return _results;};PSDLayer.prototype.parseEffectsLayer=function(){var count,data,effect,effects,left,pos,signature,size,type,v,_ref,_ref1;effects=[];_ref=this.file.readf(">HH"),v=_ref[0],count=_ref[1];while(count-->0){_ref1=this.file.readf(">4s4s"),signature=_ref1[0],type=_ref1[1];size=this.file.readf(">i")[0];pos=this.file.tell();Log.debug("Parsing effect layer with type "+type+" and size "+size);effect=(function(){switch(type){case"cmnS":return new PSDLayerEffectCommonStateInfo(this.file);case"dsdw":return new PSDDropDownLayerEffect(this.file);case"isdw":return new PSDDropDownLayerEffect(this.file,true);}}).call(this);data=effect!=null?effect.parse():void 0;left=(pos+size)-this.file.tell();if(left!==0){Log.debug("Failed to parse effect layer with type "+type);this.file.seek(left);}else{if(type!=="cmnS"){effects.push(data);}}}
return this.adjustments.effects=effects;};PSDLayer.prototype.readLayerSectionDivider=function(){var code;code=this.file.readInt();this.layerType=SECTION_DIVIDER_TYPES[code];Log.debug("Layer type:",this.layerType);switch(code){case 1:case 2:return this.isFolder=true;case 3:return this.isHidden=true;}};PSDLayer.prototype.toJSON=function(){var data,section,sections,_i,_len;sections=['name','legacyName','top','left','bottom','right','channels','rows','cols','channelsInfo','mask','layerType','blendMode','adjustments','visible'];data={};for(_i=0,_len=sections.length;_i<_len;_i++){section=sections[_i];data[section]=this[section];}
diff --git a/src/psdimage.coffee b/src/psdimage.coffee
index 266cda0..18c4093 100755
--- a/src/psdimage.coffee
+++ b/src/psdimage.coffee
@@ -70,7 +70,7 @@ class PSDImage
# Parse the image data as raw pixel values. There is no compression used here.
parseRaw: (length = @length) ->
Log.debug "Attempting to parse RAW encoded image..."
- @channelData.push @file.read(1)[0] for i in [0...length]
+ @channelData[i] = @file.read(1)[0] for i in [0...length]
return true
diff --git a/src/psdlayer.coffee b/src/psdlayer.coffee
index fa54216..14c371d 100755
--- a/src/psdlayer.coffee
+++ b/src/psdlayer.coffee
@@ -282,7 +282,6 @@ class PSDLayer
switch key
when "SoCo"
@adjustments.solidColor = (new PSDSolidColor(@, length)).parse()
- console.log "SoCo:", @adjustments.solidColor
when "GdFl"
@adjustments.gradient = (new PSDGradient(@, length)).parse()
when "PtFl"