aboutsummaryrefslogtreecommitdiff
path: root/newtitle.pl
blob: 36e8baf21973b249a18d5c1c6fa25f02a165b0ab (plain)
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
64
#!/usr/bin/perl -w

use bytes;
use Image::Magick;
use Data::Dumper;
my $img = new Image::Magick;
$img->read("newtitle.png");
@pixels = $img->GetPixels(
		width     => 256,
		height    => 184,
		x         => 0,
		y         => 0,
		map       => 'G',
);
#print Dumper \@pixels;
#print "got " . @pixels . " pixels\n";

for $y (0..183) {
	for $b (0..31) {
		my $byte = 0;
		for($x = 0; $x < 8; $x++) {
			$byte <<= 1;
			$byte |= ($pixels[$y * 256 + $b * 8 + $x] > 0);
		}
		push @bytes, $byte;
	}
}

# turn off utf-8 encoding for stdout. without doing this, the build
# break if someone's set PERL_UNICODE in the environment. plus, I
# strongly suspect utf-8 will be enabled by default in perl 7.
binmode STDOUT, ':raw';

# just output the raw data, no xex header.
print chr($_) for @bytes;


#print scalar @bytes;

#for $y (0..183) {
#	for $b (0..31) {
#		my $data = sprintf "%08b", $bytes[$y * 32 + $b];
#		$data =~ s,0, ,g;
#		$data =~ s,1,X,g;
#		print $data;
#	}
#	print "\n";
#}

# we might try a crude form of RLE, but not right now
#$run = 0;
#for(@bytes) {
#	if($_ == 0) {
#		$run++;
#	} else {
#		if($run > 1) {
#			print "run of $run 0 bytes\n";
#			$total += $run;
#		}
#		$run = 0;
#	}
#}
#
#print "total $total\n";