Created
April 8, 2012 00:36
-
-
Save pao/2333148 to your computer and use it in GitHub Desktop.
Sample of struct.jl usage
This file contains hidden or 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
# Sample of struct.jl: Reading a .png header | |
load("struct.jl") | |
fpng = open(ARGS[1]) | |
# check the signature | |
signature = unpack(s"BcccBBBB", fpng) | |
@assert isequal(signature, struct(s"BcccBBBB", 0x89, 'P', 'N', 'G', 0x0D, 0x0A, 0x1A, 0x0A)) | |
# read the header | |
header = unpack(s" | |
> # big endian | |
i # length of this chunk | |
cccc # IHDR in this case | |
[size]2I | |
bbbbb | |
", fpng) | |
close(fpng) | |
println("PNG File info for $(ARGS[1]):") | |
# check we got the header correctly | |
@assert isequal(header[1], 0x0D) | |
@assert isequal(header[2:5], ['I', 'H', 'D', 'R']) | |
println("Width: $(header.size[1]), Height: $(header.size[2])") | |
println("Bit depth: $(header[7])") | |
println("Color type: $(header[8])") | |
println("Compression method: $(header[9])") | |
println("Filter method: $(header[10])") | |
println("Interlace method: $(header[11])") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment