Skip to content

Instantly share code, notes, and snippets.

@mveinot
Last active May 25, 2017 10:47
Show Gist options
  • Save mveinot/ca6cb186f96e065bd78491aee61dcde9 to your computer and use it in GitHub Desktop.
Save mveinot/ca6cb186f96e065bd78491aee61dcde9 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use Roku::RCP;
use GD;
use Image::Resize;
# connect to Roku
my $rcp = new Roku::RCP('192.168.5.40');
# get a string representing the display contents
my $display = $rcp->GetDisplayData();
# strip the length header - it's always the same length
$display =~ s/^data bytes: (\d+)\n//;
# create a new GD image and specify the colors we'll use
my $im = new GD::Image(280,16);
my $bg = $im->colorAllocate(0,0,0); # black, first color defined becomes the background color
my $fg = $im->colorAllocate(0,255,255); # cyan to match the VFD on the Soundbridge
# traverse the width of the display
for (my $i = 1; $i <= 280; $i++)
{
# extract a pair of hex values
my $col = substr($display, 0, 4, '');
# use pack/unpack to convert the hex string to a binary string
my $bin = unpack ('B*', pack ('H*',$col));
# traverse the binary string
for (my $j = 1; $j <= 16; $j++)
{
# extract each pixel value
my $pixel = substr($bin, $j-1, 1);
# if it's a '1', set the corresponding pixel color, otherwise we leave it black
$im->setPixel($i,$j,$fg) if ($pixel eq '1');
}
}
# 280x16 is pretty small, use Image::Resize to scale it up
my $resizer = Image::Resize->new($im);
my $large = $resizer->resize(560,32);
# "print" the scaled up image as a PNG to STDOUT
binmode STDOUT;
print $large->png;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment