Skip to content

Commit

Permalink
Merge branch '2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
szymach committed Aug 21, 2017
2 parents 417b2c7 + 12cd5ab commit 3e04e49
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace CpChart;

use Exception;
use RuntimeException;

/**
* Data - class to manipulate data arrays
Expand Down Expand Up @@ -900,12 +901,28 @@ public function loadPalette($FileName, $Overwrite = false)
}

while (!feof($fileHandle)) {
$buffer = fgets($fileHandle, 4096);
if (preg_match("/,/", $buffer)) {
list($R, $G, $B, $Alpha) = preg_split("/,/", $buffer);
$ID = count($this->Palette);
$this->Palette[$ID] = ["R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha];
$line = fgets($fileHandle, 4096);
if (false === $line) {
continue;
}
$row = explode(',', $line);
if (empty($row)) {
continue;
}
if (count($row) !== 4) {
throw new RuntimeException(sprintf(
'A palette row must supply R, G, B and Alpha components, %s given!',
var_export($row, true)
));
}
list($R, $G, $B, $Alpha) = $row;
$ID = count($this->Palette);
$this->Palette[$ID] = [
"R" => trim($R),
"G" => trim($G),
"B" => trim($B),
"Alpha" => trim($Alpha)
];
}
fclose($fileHandle);

Expand Down

0 comments on commit 3e04e49

Please sign in to comment.