Skip to content

Commit

Permalink
Compression bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
robgridley committed Apr 4, 2016
1 parent b562ef3 commit f71f01c
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/Zpl/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ protected function create($data)
protected function encode()
{
$bitmap = null;
$lastRow = null;

for ($y = 0; $y < $this->height; $y++) {
$bits = null;
Expand All @@ -131,7 +132,8 @@ protected function encode()
$row .= sprintf('%02X', bindec($byte));
}

$bitmap .= $this->compress($row);
$bitmap .= $this->compress($row, $lastRow);
$lastRow = $row;
}

return $bitmap;
Expand All @@ -141,11 +143,12 @@ protected function encode()
* Compress a row of ASCII hexadecimal data.
*
* @param string $row
* @param string $lastRow
* @return string
*/
protected function compress($row)
protected function compress($row, $lastRow)
{
if ($this->matchesLastRow($row)) {
if ($row === $lastRow) {
return ':';
}

Expand All @@ -155,25 +158,6 @@ protected function compress($row)
return $row;
}

/**
* Determine if the specified row is the same as the last row.
*
* @param string $row
* @return bool
*/
protected function matchesLastRow($row)
{
static $lastRow = null;

if ($row == $lastRow) {
return true;
}

$lastRow = $row;

return false;
}

/**
* Replace trailing zeros or ones with a comma (,) or exclamation (!) respectively.
*
Expand Down

0 comments on commit f71f01c

Please sign in to comment.