Skip to content

Commit

Permalink
checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
misch2 committed Jan 27, 2023
1 parent ec00690 commit d863afb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
20 changes: 14 additions & 6 deletions server/app
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use Text::Unidecode;
use Readonly;
use List::Util;
use Try::Tiny;
use Digest::SHA1 qw(sha1_hex);

use PortalCalendar::Integration::iCal;

Expand Down Expand Up @@ -203,17 +204,14 @@ sub generate_bitmap {
return $self->render(data => $out, format => 'png');
} elsif ($format =~ /^raw/) {

# output format:
# "MM"
# <sequence of raw values directly usable for uploading into eink display>
my $out = 'MM';
my $bitmap = '';
if ($format eq 'raw8bpp') {
foreach my $y (0 .. $img->getheight - 1) {
foreach my $x (0 .. $img->getwidth - 1) {
my $color = $img->getpixel(x => $x, y => $y);
my @rgb = $color->rgba;
my $grayscale = $rgb[0]; # 0 - 255
$out .= chr($grayscale);
$bitmap .= chr($grayscale);
}
}
} elsif ($format eq 'raw1bpp') {
Expand All @@ -229,7 +227,7 @@ sub generate_bitmap {
$byte = $byte << 1 | $bit;
$bitcnt++;
if ($bitcnt == 8) {
$out .= chr($byte);
$bitmap .= chr($byte);
$byte = 0;
$bitcnt = 0;
}
Expand All @@ -238,6 +236,16 @@ sub generate_bitmap {
} else {
die "Unknown format requested: " . $format;
}

# output format:
# "MM"
# checksum
# <sequence of raw values directly usable for uploading into eink display>

my $out = "MM\n";
$out .= sha1_hex($bitmap) . "\n";
$out .= $bitmap;

return $self->render(data => $out);
} else {
die "Unknown format requested: " . $format;
Expand Down
1 change: 1 addition & 0 deletions server/cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ requires 'Readonly';
requires 'Moo';
requires 'LWP::UserAgent::Cached';
requires 'Try::Tiny';
requires 'Digest::SHA1';
requires 'iCal::Parser';


8 changes: 8 additions & 0 deletions server/cpanfile.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,14 @@ DISTRIBUTIONS
perl 5.006
strict 0
warnings 0
Digest-SHA1-2.13
pathname: G/GA/GAAS/Digest-SHA1-2.13.tar.gz
provides:
Digest::SHA1 2.13
requirements:
Digest::base 1.00
ExtUtils::MakeMaker 0
perl 5.004
Dist-CheckConflicts-0.11
pathname: D/DO/DOY/Dist-CheckConflicts-0.11.tar.gz
provides:
Expand Down

0 comments on commit d863afb

Please sign in to comment.