Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var f = new File('c:\yourpath\\file.psd');
- f.readonly = true;
- f.encoding = "BINARY";
- f.open ("r");
- var ln = 4; // 4 pro PSD - 8 pro PSB
- /*alert(layersCount ());
- alert(getLayerInfoLength ());
- alert(getLayerInfoLength2 ());
- alert(getLayerInfoLength2 ());*/
- f.close();
- function getDecimalValue(str){
- return (parseInt(convertDecimalToHex(stringToBytes (str)),16));
- }
- function stringToBytes ( str ) {
- var ch, st, re = [];
- for (var i = 0; i < str.length; i++ ) {
- ch = str.charCodeAt(i); // get char
- st = []; // set up "stack"
- do {
- st.push( ch & 0xFF ); // push byte to stack
- ch = ch >> 8; // shift value down by 1 byte
- }
- while ( ch );
- // add stack contents to result
- // done because chars have "wrong" endianness
- re = re.concat( st.reverse() );
- }
- // return an array of bytes
- return re;
- }
- function convertDecimalToHex (str){ //funguje mění decimální čísla na hex
- var re=0x00;
- for (var i =0;i<str.length;i++){
- re+=str[i].toString(16);
- }
- return re;
- }
- ////////////////////////////
- // Main sections
- ////////////////////////////
- function seekHeader(){
- f.seek(0);
- }
- function seekColorMode(){
- f.seek(26);
- }
- function seekImageResources(){
- seekColorMode();
- f.seek(getDecimalValue(f.read(ln)),1)
- }
- function seekLayerAndMask(){
- seekImageResources ();
- f.seek(getDecimalValue(f.read(ln)),1)
- }
- function seekImageData(){
- seekLayerAndMask ();
- f.seek(getDecimalValue(f.read(ln)),1)
- }
- //////////////////////////////////
- function getLayerInfoLength(){
- seekLayerAndMask ();
- f.seek(ln,1); //poskočí dovnitř, jinak by četl délku sekce LayerAndMask
- var re = getDecimalValue(f.read(ln))
- if(re % 2 == 1){
- return re+1;
- }
- return re;
- }
- function getLayerInfoLength2(){
- f.seek(ln,1);
- var re = getDecimalValue(f.read(ln))
- if(re % 2 == 1){
- return re+1;
- }
- return re;
- }
- ////////////////////////
- // Utility
- ////////////////////////
- function layersCount(){
- seekLayerAndMask ();
- f.seek(ln*2,1);
- return getDecimalValue(f.read(2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement