コード例 #1
0
ファイル: BNTX.py プロジェクト: Tyulis/3DSkit
	def pack_brti(self, out, texinfo):
		startpos = out.tell()
		images = []
		tilemode = texinfo['tilemode']
		swizzle = texinfo['swizzle_value']
		self.pack('4s12x6H', b'BRTI', texinfo['unk1'], tilemode, swizzle, texinfo['mipmap_number'], texinfo['multi_samples_num'], texinfo['unk2'], out)
		pixelformat = PIXEL_FORMATS[texinfo['pixel_format']]
		valueformat = VALUE_FORMATS[texinfo['value_format']]
		format = (pixelformat << 8) | valueformat
		try:
			for element in texinfo['output']:
				images.append(Image.open(element))
		except IOError:
			error.FileNotFoundError('The file given by the JSON meta-data file "%s" is not found')
		width = images[0].width
		height = images[0].height
		depth = texinfo['depth']
		arraylength = texinfo['array_length']
		blockheight_exponent = texinfo['block_height_exponent']
		self.pack('8I20s4x', format, texinfo['gpu_access_type'], width, height, depth, arraylength, blockheight_exponent, texinfo['unk3'], bytes.fromhex(texinfo['unk4']), out)
		redsource = CHANNEL_SOURCES[texinfo['red_source']]
		greensource = CHANNEL_SOURCES[texinfo['green_source']]
		bluesource = CHANNEL_SOURCES[texinfo['blue_source']]
		alphasource = CHANNEL_SOURCES[texinfo['alpha_source']]
		dimension = DIMENSIONS[texinfo['dimension']]
		self.pack('I5B3x', texinfo['texture_data_alignment'], redsource, greensource, bluesource, alphasource, dimension, out)
		self.pack('8q', self.string_offset(texinfo['texture_name']), 0x20, startpos + 672, 0, startpos + 160, startpos + 416, 0, 0, out)
		return startpos, images
コード例 #2
0
 def packTGLP_NX(self, out, meta):
     self.tglpoffset = out.tell()
     try:
         bntx = open(meta['output'][0], 'rb')
     except FileNotFoundError:
         error.FileNotFoundError(
             'The file %s could not be found. Check if it has the right name in the "textures > output" property in %s'
             % (meta['output'][0], self.inname))
     if bntx.read(4) != b'BNTX':
         error.InvalidInputError('%s is not a valid BNTX file' %
                                 meta['output'][0])
     bntx.seek(0, 2)
     bntxsize = bntx.tell()
     bntx.seek(0)
     format = FORMATS_NX[meta['format']]
     sheetsize = bntxsize // meta['num_sheets']
     self.pack('4s4x 4BI6H I', b'TGLP', meta['cell_width'],
               meta['cell_height'], meta['num_sheets'], meta['max_width'],
               sheetsize, meta['base_line_position'], format,
               meta['num_columns'], meta['num_lines'], meta['sheet_width'],
               meta['sheet_height'], TEXTURE_DATA_OFFSET, out)
     out.seek(TEXTURE_DATA_OFFSET)
     out.write(bntx.read())
     bntx.close()
     endpos = out.tell()
     out.seek(self.tglpoffset + 4)
     self.pack('I', endpos - self.tglpoffset, out)
     out.seek(endpos)
コード例 #3
0
ファイル: 3DSkit.py プロジェクト: cesarmiquel/3DSkit
def extract_files(filename, isbigendian, givenformat, verbose, opts):
    endian = '>' if isbigendian else '<'
    if os.path.isdir(filename):
        filenames = []
        for p, d, f in os.walk(filename):
            for name in f:
                filenames.append(os.path.join(p, name))
    else:
        filenames = [filename]
    for filename in filenames:
        print('\n--------%s--------' % filename)
        try:
            file = open(filename, 'rb')
        except FileNotFoundError:
            error.FileNotFoundError('File %s does not exist' % filename)
        format = unpack.recognize_file(file, givenformat)
        file.seek(0)
        if format is None:
            format = unpack.recognize_filename(filename, givenformat)
        if format not in unpack.SKIP_DECOMPRESSION:
            comp = compress.recognize(file)
            if comp == 0:
                if len(filenames) > 1:
                    err = error.InvalidInputWarning
                else:
                    err = error.InvalidInputError
                err("The given file is empty")
                continue
            if comp is not None:
                print('Compression: %s' % comp)
                print('Decompressing...')
                out = BytesIO()
                compress.decompress(file, out, comp, verbose)
                file.close()
                file = out
                print('Decompressed')
            else:
                print('No compression')
        else:
            print('No compression')
        format = unpack.recognize_file(file, givenformat)
        if format is None:
            format = unpack.recognize_filename(filename, givenformat)
        if format is None:  #still
            if len(filenames) > 1:
                err = error.UnrecognizedFormatWarning
            else:
                err = error.UnrecognizedFormatError
            err('Unrecognized format')
            continue
        print('%s file found' % format)
        print('Extracting...')
        unpack.extract(filename, file, format, endian, verbose, opts)
        print('Extracted')
コード例 #4
0
ファイル: 3DSkit.py プロジェクト: Tyulis/3DSkit
def pack_files(filenames, output, compression, format, isbigendian, verbose, opts):
	endian = '>' if isbigendian else '<'
	for name in filenames:
		if not os.path.exists(name):
			error.FileNotFoundError('Input file %s is not found' % name)
	if format.upper() in pack.formats:
		print('Packing %s...' % output)
		pack.pack(filenames, output, format, endian, verbose, opts)
		print('Packed!')
	else:
		error.UnsupportedFormatError('3DSkit is currently unable to pack this format')
	if compression is not None:
		compress_file(output, compression, verbose, False)
コード例 #5
0
ファイル: 3DSkit.py プロジェクト: cesarmiquel/3DSkit
def main(args, opts):
    global basedir
    if args.ckit:
        error.SettingWarning(
            'Forcing usage of c3DSkit. Remember that if it is not used by default, there is probably a reason.'
        )
        import c3DSkit
        util.libkit = c3DSkit
    elif args.pykit:
        error.SettingWarning(
            'Forcing usage of py3DSkit. Remember that if it is not used by default, there is probably a reason.'
        )
        import py3DSkit
        util.libkit = py3DSkit
    if args.quiet:
        initial_stdout = sys.stdout
        sys.stdout = StringIO()
    if args.debug:
        error.SettingWarning(
            'Entering debugging mode. This will turn every error into Python exception. It is only useful with a debugger, you should not use it as an end user.'
        )
        args.verbose = True
        error.debug = True
    elif args.extract:
        for filename in args.files:
            extract_files(filename, args.big, args.format, args.verbose, opts)
    elif args.pack:
        files = []
        basedir = os.getcwd() + os.path.sep
        if args.format is None:
            error.ForgottenArgumentError(
                'You have to specify the output format')
        if args.out is None:
            args.out = '%s.%s' % (os.path.splitext(
                args.files[0])[0], args.format.lower())
        if args.dir:
            try:
                os.chdir(args.files[0])
            except FileNotFoundError:
                error.FileNotFoundError(
                    'The given directory %s does not exist' % args.files[0])
            for path, dirs, filenames in os.walk(os.path.curdir):
                for filename in filenames:
                    files.append(os.path.join(
                        path, filename)[2:])  #strip the ./ or :\
        else:
            for file in args.files:
                if os.path.isdir(file):
                    for path, dirs, filenames in os.walk(file):
                        for filename in filenames:
                            files.append(os.path.join(path, filename))
                else:
                    files.append(file)
        pack_files(files, args.out, args.compression, args.format, args.big,
                   args.verbose, opts)
        os.chdir(basedir)
    elif args.decompress:
        if len(args.files) > 1:
            for filename in args.files:
                decompress_file(filename, None, args.verbose)
        else:
            decompress_file(args.files[0], args.out, args.verbose)

    elif args.compress:
        if args.compression is None:
            error.ForgottenArgumentError(
                'You have to specify the compression type')
        if len(args.files) > 1:
            for filename in args.files:
                compress_file(filename, None, args.compression, args.verbose)
        else:
            compress_file(args.files[0], args.out, args.compression,
                          args.verbose)
    elif args.plugin is not None:
        plugins.run_plugin(args.plugin, args.files, args.verbose)
    else:
        if args.quiet:
            sys.stdout = initial_stdout
        return 1
    if args.quiet:
        sys.stdout = initial_stdout
    return 0