Sunday, March 16, 2014

Binary decoding with AWK

http://awk.info/?doc/bitmaps.html


function Bytes2Number( String, x, y, z, Number ) {
x = split( String, Scratch, "" )
Number = 0
for( y = 1; y <= x; y++ ) {
z = index( CharString, Scratch[ y ] ) -1
Number = Number + z * (256^(x - y))
}
return Number
}

BEGIN{
for( x = 0; x <= 255; x++ ) {
CharString = CharString sprintf( "%c", x )
FS= ""
RS = /ABC/
}

{ Width = Bytes2Number( $22 $21 $20 $19 )
Height = Bytes2Number( $26 $25 $24 $23 )
Data = Bytes2Number( $14 $13 $12 $11 )
Size = Bytes2Number( $6 $5 $4 $3 )
Depth = Bytes2Number( $30 $29 ) / 8
ImgSize = Bytes2Number( $38 $37 $36 $35 )
....
}

No comments: