Created
July 7, 2012 23:49
-
-
Save killingmichael/3068617 to your computer and use it in GitHub Desktop.
Convert a .pvr.ccz texture to an decompressed / inflated .pvr texture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# InflatePVRCCZTexture.rb - By Michael J. Sikorsky @robotsNpencils | |
# Converts .pvr.ccz textures to .pvr | |
# | |
# Usage: ruby InflatePVRCCZTexture.rb {INPUT FILE.pvr.ccz} {OUTPUT FILE.pvr} | |
# Example: | |
# ruby InflatePVRCCZTexture.rb agametexture.pvr.ccv agametexture.pvr | |
# | |
# README: | |
# | |
# A .pvr.ccz file looks like this: | |
# | |
# +--------------+------------------------------------+ | |
# | CCZHEADER | ZLIB COMPRESSED PVR TEXTURE (.pvr) | | |
# +--------------+------------------------------------+ | |
# <-- 16 Bytes -> | |
# | |
# This script, chops off the CCZHeader Chunk, and Zlib Inflates the rest. | |
# | |
# TODO - make this better, like this :) http://rubylearning.com/blog/2011/01/03/how-do-i-make-a-command-line-tool-in-ruby/ | |
# | |
require 'zlib' | |
# | |
# COMPUTING THE SIZEOF THE CCZHEADER: | |
# | |
# From Andreas Loew: the creator of texturepacker (http://www.codeandweb.com/texturepacker): | |
# | |
# struct CCZHeader { | |
# uint8_t sig[4]; // signature. Should be 'CCZ!' 4 bytes | |
# uint16_t compression_type; // should 0 | |
# uint16_t version; // should be 2 (although version type==1 is also supported) | |
# uint32_t reserved; // Reserverd for users. | |
# uint32_t len; // size of the uncompressed file | |
# }; | |
# | |
# enum { | |
# CCZ_COMPRESSION_ZLIB, // zlib format. | |
# CCZ_COMPRESSION_BZIP2, // bzip2 format (not supported yet) | |
# CCZ_COMPRESSION_GZIP, // gzip format (not supported yet) | |
# CCZ_COMPRESSION_NONE, // plain (not supported yet) | |
# }; | |
# | |
SIZE_OF_CCZHEADER_IN_BYTES = 16 # see above | |
if ARGV.length != 2 then | |
puts """ | |
Usage: ruby InflatePVRCCZTexture.rb {INPUT FILE.pvr.ccz} {OUTPUT FILE.pvr} | |
Example: | |
ruby InflatePVRCCZTexture.rb agametexture.pvr.ccv agametexture.pvr | |
""" | |
fail "You need to pass an input file .pvr.ccz and output file .pvr." | |
end | |
input_file_name = ARGV[0] | |
output_file_name = ARGV[1] | |
def inflatePVRCCZ(input_file_name,output_file_name) | |
input_file = File.new(input_file_name,'rb') | |
input_binary_string = input_file.read | |
input_binary_string_without_cczheader = input_binary_string[SIZE_OF_CCZHEADER_IN_BYTES,input_binary_string.length] | |
input_binary_string = '' | |
input_file.close() | |
output_string = Zlib::Inflate.inflate(input_binary_string_without_cczheader) | |
output_file = File.new(output_file_name,'wb') | |
output_file.write(output_string) | |
output_file.close() | |
puts ".pvr.ccz file Inflated: "+output_file_name | |
end | |
begin | |
inflatePVRCCZ(input_file_name,output_file_name) | |
rescue Exception => e | |
fail "Something went wrong in inflatePVRCCZ - likely a file problem - check your input file exists and ends in .pvr.ccz; details = "+e.message | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the pvr.ccz has been Encryption