-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpix_to_coe.pl
63 lines (49 loc) · 1.15 KB
/
pix_to_coe.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl
use strict;
use warnings;
undef $/;
my $file = shift || die("No input file specified");
my $fh;
open($fh, "<", $file) or die($!);
binmode($fh);
my @data = map unpack('H2', $_), split //, <$fh>;
my $width = hex($data[0].$data[1]);
my $height = hex($data[2].$data[3]);
my $dummy = hex($data[4].$data[5]);
$dummy = hex($data[6].$data[7]);
my $bitsPerPixel = hex($data[8].$data[9]);
print "; depth=$height\n";
print "; width=$width\n";
print "memory_initialization_radix=2;\n";
print "memory_initialization_vector=\n";
my $offset = 10;
my $bitPos = 0;
my $row = "";
while($offset <= $#data && $bitPos < ($width * $height)){
my $length = hex($data[$offset++]);
my $color = 0;
for(my $b = 0; $b < $bitsPerPixel/8; $b++){
if(hex($data[$offset]) > 128){
$color = 1;
}
$offset++;
}
if($color == 1){
for($a = 0; $a < $length; $a++){
if(length($row) == $width){
print "$row,\n";
$row = "";
}
$row .= "0";
}
}else{
for($a = 0; $a < $length; $a++){
if(length($row) == $width){
print "$row,\n";
$row = "";
}
$row .= "1";
}
}
}
print "$row;";