Final Fantasy 8 > Support

[Question]Texture formation of android version

<< < (2/2)

albert:

--- Quote from: rabsanek on 2024-11-06 15:54:24 ---can share your script please?

--- End quote ---


Here you are:



import sys, os, lz4.block

isDecompress=True
op='1'

astcenc=os.path.join(os.path.abspath(os.path.dirname(__file__)),'etcpack','astcenc-sse2.exe')

def get():
   print('input your choise:\n\t1.deachieve_Z\n\t2.achieve_Z\n\t3.png_trans_astc\n\t4.astc_trans_png')
   s=input()
   global op
   if s in ['1','2','3','4','']:
      
      if s=='':
         op='1'
      else:
         op=s
      #if s in ['1','']:
      #   isDecompress=False
      #else:
      #   isDecompress=True
   else:
      print('Inpurt error')
      get()

def get_path():   
   path=input('Please_input_the_path(don't_have_any_blankspace:')
   if os.path.isdir(path):
      pass
   else:
      print('Invalid_path'+path)
      get_path()
      return -1
   #print(os.getcwd())
   if op=='1':
      exts=['ddsz','pkmz','astcz']
   elif op=='2':
      exts=['dds','pkm','astc']
   elif op=='3':
      os.chdir(os.path.dirname(astcenc))
      exts=['png']
   elif op=='4':
      os.chdir(os.path.dirname(astcenc))
      exts=['astc']
   else:
      pass
   #input(os.getcwd())
   for root,dirs,files in os.walk(path):
      #for d in dirs:
      #   print(d)
      for fn in files:
         #print(os.path.join(root,fn),root,fn)
         ext=fn.split('.')[-1].lower()
         extLen=len(ext)
         #print(fn,exts,ext)
         if ext in exts:
            #print("1")
            p=os.path.join(root,fn)
            if op in ['1','2']:
               fi=open(p,'rb')
               data=fi.read()
               if op=='1':
                  print(p+'Deachieve...')
                  newData=lz4.block.decompress(data[4:])
                  fo=open(p[:-1],'wb')
                  fo.write(newData)
               else:
                  print(p+'Achieve...')
                  newData=lz4.block.compress(data)
                  newData0=(len(newData)+4).to_bytes(4, byteorder='little', signed=True)
                  fo=open(p+'z','wb')
                  fo.write(newData0)
                  fo.write(newData)
               fi.close()
               fo.close()
            elif op in ['3']:
               print('Transforming:'+p)
               os.system(' '.join([astcenc,'-cs',p,p[0:-3]+'astc','4x4','-exhaustive']))
            elif op in ['4']:
               print('Transforming:'+p)
               cmd=' '.join([astcenc,'-d',p,p[0:-4]+'png'])
               print(cmd)
               os.system(' '.join([astcenc,'-ds',p,p[0:-4]+'png']))

               
get()
get_path()

rabsanek:
Thanks, but it show error
input your choise:
        1.deachieve_Z
        2.achieve_Z
        3.png_trans_astc
        4.astc_trans_png
1
Please_input_the_path_dont_have_any_blankspace:/home/alex2/2
/home/alex2/2/logo.astczDeachieve...
Traceback (most recent call last):
  File "/home/alex2/albert.py", line 87, in <module>
    get_path()
  File "/home/alex2/albert.py", line 64, in get_path
    newData=lz4.block.decompress(data[4:])
_block.LZ4BlockError: Decompression failed: corrupt input or insufficient space in destination buffer. Error code: 12

albert:

--- Quote from: rabsanek on 2024-11-08 08:07:55 ---Thanks, but it show error
input your choise:
        1.deachieve_Z
        2.achieve_Z
        3.png_trans_astc
        4.astc_trans_png
1
Please_input_the_path_dont_have_any_blankspace:/home/alex2/2
/home/alex2/2/logo.astczDeachieve...
Traceback (most recent call last):
  File "/home/alex2/albert.py", line 87, in <module>
    get_path()
  File "/home/alex2/albert.py", line 64, in get_path
    newData=lz4.block.decompress(data[4:])
_block.LZ4BlockError: Decompression failed: corrupt input or insufficient space in destination buffer. Error code: 12

--- End quote ---

There are original code:



import sys, os, lz4.block

isDecompress=True
op='1'

astcenc=os.path.join(os.path.abspath(os.path.dirname(__file__)),'etcpack','astcenc-sse2.exe')

def get():
   print('请输入你的选择:\n\t1.解压z文件\n\t2.压缩成z文件\n\t3.png转astc\n\t4.astc转png')
   s=input()
   global op
   if s in ['1','2','3','4','']:
      
      if s=='':
         op='1'
      else:
         op=s
      #if s in ['1','']:
      #   isDecompress=False
      #else:
      #   isDecompress=True
   else:
      print('输入错误。')
      get()

def get_path():   
   path=input('请输入文件夹地址(不能有空格):')
   if os.path.isdir(path):
      pass
   else:
      print('无效的文件夹地址:'+path)
      get_path()
      return -1
   #print(os.getcwd())
   if op=='1':
      exts=['ddsz','pkmz','astcz']
   elif op=='2':
      exts=['dds','pkm','astc']
   elif op=='3':
      os.chdir(os.path.dirname(astcenc))
      exts=['png']
   elif op=='4':
      os.chdir(os.path.dirname(astcenc))
      exts=['astc']
   else:
      pass
   #input(os.getcwd())
   for root,dirs,files in os.walk(path):
      #for d in dirs:
      #   print(d)
      for fn in files:
         #print(os.path.join(root,fn),root,fn)
         ext=fn.split('.')[-1].lower()
         extLen=len(ext)
         #print(fn,exts,ext)
         if ext in exts:
            #print("1")
            p=os.path.join(root,fn)
            if op in ['1','2']:
               fi=open(p,'rb')
               data=fi.read()
               if op=='1':
                  print(p+'正在解压...')
                  newData=lz4.block.decompress(data[4:])
                  fo=open(p[:-1],'wb')
                  fo.write(newData)
               else:
                  print(p+'正在压缩...')
                  newData=lz4.block.compress(data)
                  newData0=(len(newData)+4).to_bytes(4, byteorder='little', signed=True)
                  fo=open(p+'z','wb')
                  fo.write(newData0)
                  fo.write(newData)
               fi.close()
               fo.close()
            elif op in ['3']:
               print('正在转换:'+p)
               os.system(' '.join([astcenc,'-cs',p,p[0:-3]+'astc','4x4','-exhaustive']))
            elif op in ['4']:
               print('正在转换:'+p)
               cmd=' '.join([astcenc,'-d',p,p[0:-4]+'png'])
               print(cmd)
               os.system(' '.join([astcenc,'-ds',p,p[0:-4]+'png']))

               
get()
get_path()

Navigation

[0] Message Index

[*] Previous page

Go to full version