Advertisement
Guest User

Untitled

a guest
May 15th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var f = new File('c:\yourpath\\file.psd');
  3.  
  4. f.readonly = true;
  5. f.encoding = "BINARY";
  6. f.open ("r");
  7. var ln = 4; // 4 pro PSD - 8 pro PSB
  8.  
  9.  
  10. /*alert(layersCount ());
  11. alert(getLayerInfoLength ());
  12. alert(getLayerInfoLength2 ());
  13. alert(getLayerInfoLength2 ());*/
  14.  
  15. f.close();
  16.  
  17. function getDecimalValue(str){
  18.     return (parseInt(convertDecimalToHex(stringToBytes (str)),16));
  19. }
  20.  
  21. function stringToBytes ( str ) {
  22.   var ch, st, re = [];
  23.   for (var i = 0; i < str.length; i++ ) {
  24.     ch = str.charCodeAt(i);  // get char
  25.     st = [];                 // set up "stack"
  26.     do {
  27.       st.push( ch & 0xFF );  // push byte to stack
  28.       ch = ch >> 8;          // shift value down by 1 byte
  29.     }  
  30.     while ( ch );
  31.     // add stack contents to result
  32.     // done because chars have "wrong" endianness
  33.     re = re.concat( st.reverse() );
  34.   }
  35.   // return an array of bytes
  36.   return re;
  37. }
  38.  
  39. function convertDecimalToHex (str){ //funguje mění decimální čísla na hex
  40.     var re=0x00;
  41.     for (var i =0;i<str.length;i++){
  42.         re+=str[i].toString(16);
  43.        
  44.     }    
  45.     return re;
  46. }
  47.  
  48.  
  49. ////////////////////////////
  50. // Main sections
  51. ////////////////////////////
  52.  
  53. function seekHeader(){
  54.      f.seek(0);
  55. }
  56.  
  57. function seekColorMode(){
  58.     f.seek(26);
  59. }
  60.  
  61. function seekImageResources(){
  62.     seekColorMode();
  63.     f.seek(getDecimalValue(f.read(ln)),1)
  64. }
  65.  
  66. function seekLayerAndMask(){
  67.     seekImageResources ();
  68.     f.seek(getDecimalValue(f.read(ln)),1)
  69. }
  70.  
  71. function seekImageData(){
  72.     seekLayerAndMask ();
  73.     f.seek(getDecimalValue(f.read(ln)),1)
  74. }
  75.  
  76. //////////////////////////////////
  77.  
  78. function getLayerInfoLength(){
  79.     seekLayerAndMask ();
  80.     f.seek(ln,1); //poskočí dovnitř, jinak by četl délku sekce LayerAndMask
  81.     var re = getDecimalValue(f.read(ln))
  82.     if(re % 2 == 1){
  83.         return re+1;
  84.     }
  85.     return re;
  86. }
  87.  
  88. function getLayerInfoLength2(){
  89.     f.seek(ln,1);
  90.     var re = getDecimalValue(f.read(ln))
  91.     if(re % 2 == 1){
  92.         return re+1;
  93.     }
  94.     return re;
  95. }
  96.  
  97.  
  98. ////////////////////////
  99. // Utility
  100. ////////////////////////
  101.  
  102. function layersCount(){
  103.     seekLayerAndMask ();
  104.     f.seek(ln*2,1);
  105.     return getDecimalValue(f.read(2));
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement