private function getRasterFormat()
{
/* Loop through and convert format */
$widthPixels = $this->getWidth();
$heightPixels = $this->getHeight();
$widthBytes = $this->getWidthBytes();
$heightBytes = $this->getHeightBytes();
$x = $y = $bit = $byte = $byteVal = 0;
$data = str_repeat("", $widthBytes * $heightPixels);
if (strlen($data) == 0) {
return $data;
}
do {
$byteVal |= (int) $this->imgData[$y * $widthPixels + $x] << 7 - $bit;
$x++;
$bit++;
if ($x >= $widthPixels) {
$x = 0;
$y++;
$bit = 8;
if ($y >= $heightPixels) {
$data[$byte] = chr($byteVal);
break;
}
}
if ($bit >= 8) {
$data[$byte] = chr($byteVal);
$byteVal = 0;
$bit = 0;
$byte++;
}
} while (true);
if (strlen($data) != $this->getWidthBytes() * $this->getHeight()) {
throw new Exception("Bug in " . __FUNCTION__ . ", wrong number of bytes.");
}
return $data;
}