-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpgm2fb.pl
More file actions
executable file
·49 lines (33 loc) · 748 Bytes
/
pgm2fb.pl
File metadata and controls
executable file
·49 lines (33 loc) · 748 Bytes
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
#!/usr/bin/perl
use warnings;
use strict;
my $path = shift @ARGV || die "usage: $0 image.pgm";
my $o_x = $ENV{O_X} || 0;
my $o_y = $ENV{O_Y} || 0;
open(my $in, '<', $path) || die "$path: $!";
my $magic = <$in>;
die "wrong magic $magic" unless $magic =~ m/^P5/;
my $size = <$in>;
chomp $size;
my ( $w, $h ) = split(/ /,$size);
<$in>;
my $fb;
my $y = 0;
seek($in, $w * $o_y, 1) if $o_y;
while(my $size = read($in, my $px, $w)) {
foreach my $x ( 0 .. $w / 2 - 1 ) {
my ($a,$b);
if ( length($px) < $x * 2 + $o_x + 2 ) {
print "\x00";
} else {
my ($a,$b) = unpack('CC', substr($px,$x * 2 + $o_x,2));
print pack( 'C', (
( $a & 0xf0 )
|
( ( $b & 0xf0 ) >> 4 )
) ^ 0xff );
}
}
$y++;
last if $y == $h;
}