@@ -21,12 +21,15 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function FileReader($filename) |
| 23 | 23 | { |
| 24 | - if(!file_exists($filename)) |
|
| 25 | - throw new Exception("File does not exist: ".$filename); |
|
| 26 | - if(!is_file($filename)) |
|
| 27 | - throw new Exception("Target is not a file."); |
|
| 28 | - if(!is_readable($filename)) |
|
| 29 | - throw new Exception("File exists, but is not readable."); |
|
| 24 | + if(!file_exists($filename)) { |
|
| 25 | + throw new Exception("File does not exist: ".$filename); |
|
| 26 | + } |
|
| 27 | + if(!is_file($filename)) { |
|
| 28 | + throw new Exception("Target is not a file."); |
|
| 29 | + } |
|
| 30 | + if(!is_readable($filename)) { |
|
| 31 | + throw new Exception("File exists, but is not readable."); |
|
| 32 | + } |
|
| 30 | 33 | |
| 31 | 34 | $this->fp = fopen($filename, 'rb'); |
| 32 | 35 | } |
@@ -45,8 +48,9 @@ discard block |
||
| 45 | 48 | for($x = 0; $x < $count; $x++) |
| 46 | 49 | { |
| 47 | 50 | $buffer = (ord(fgetc($this->fp)) << ($x * 8)); |
| 48 | - if($buffer === false) |
|
| 49 | - throw new Exception("Read failure"); |
|
| 51 | + if($buffer === false) { |
|
| 52 | + throw new Exception("Read failure"); |
|
| 53 | + } |
|
| 50 | 54 | $int += $buffer; |
| 51 | 55 | } |
| 52 | 56 | return $int; |
@@ -34,8 +34,9 @@ |
||
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $buffer = $reader->ReadInt(2); |
| 37 | - if($buffer < 1) |
|
| 38 | - throw new Exception('Sprite file appears to contain less than 1 frame.'); |
|
| 37 | + if($buffer < 1) { |
|
| 38 | + throw new Exception('Sprite file appears to contain less than 1 frame.'); |
|
| 39 | + } |
|
| 39 | 40 | $frameCount = $buffer; |
| 40 | 41 | for($x=0; $x < $frameCount; $x++) |
| 41 | 42 | { |
@@ -89,8 +89,7 @@ |
||
| 89 | 89 | $red = ($pixel & 0xF800) >> 8; |
| 90 | 90 | $green = ($pixel & 0x07E0) >> 3; |
| 91 | 91 | $blue = ($pixel & 0x001F) << 3; |
| 92 | - } |
|
| 93 | - else if($this->encoding == "555") |
|
| 92 | + } else if($this->encoding == "555") |
|
| 94 | 93 | { |
| 95 | 94 | $red = ($pixel & 0x7C00) >> 7; |
| 96 | 95 | $green = ($pixel & 0x03E0) >> 2; |
@@ -75,10 +75,11 @@ discard block |
||
| 75 | 75 | for($x = 0; $x < $this->GetWidth();) |
| 76 | 76 | { |
| 77 | 77 | $run = $this->reader->ReadInt(2); |
| 78 | - if(($run & 0x0001) > 0) |
|
| 79 | - $run_type = "colour"; |
|
| 80 | - else |
|
| 81 | - $run_type = "black"; |
|
| 78 | + if(($run & 0x0001) > 0) { |
|
| 79 | + $run_type = "colour"; |
|
| 80 | + } else { |
|
| 81 | + $run_type = "black"; |
|
| 82 | + } |
|
| 82 | 83 | $run_length = ($run & 0x7FFF) >> 1; |
| 83 | 84 | if($run_type == "black") |
| 84 | 85 | { |
@@ -87,8 +88,7 @@ discard block |
||
| 87 | 88 | { |
| 88 | 89 | imagesetpixel($image, $x, $y, imagecolorallocate($image, 0, 0, 0)); |
| 89 | 90 | } |
| 90 | - } |
|
| 91 | - else //colour run |
|
| 91 | + } else //colour run |
|
| 92 | 92 | { |
| 93 | 93 | $z = $x + $run_length; |
| 94 | 94 | for(;$x < $z; $x++) |
@@ -99,8 +99,7 @@ discard block |
||
| 99 | 99 | $red = ($pixel & 0xF800) >> 8; |
| 100 | 100 | $green = ($pixel & 0x07E0) >> 3; |
| 101 | 101 | $blue = ($pixel & 0x001F) << 3; |
| 102 | - } |
|
| 103 | - else if($this->encoding == "555") |
|
| 102 | + } else if($this->encoding == "555") |
|
| 104 | 103 | { |
| 105 | 104 | $red = ($pixel & 0x7C00) >> 7; |
| 106 | 105 | $green = ($pixel & 0x03E0) >> 2; |
@@ -110,8 +109,9 @@ discard block |
||
| 110 | 109 | imagesetpixel($image, $x, $y, $colour); |
| 111 | 110 | } |
| 112 | 111 | } |
| 113 | - if($x == $this->GetWidth()) |
|
| 114 | - $this->reader->Skip(2); |
|
| 112 | + if($x == $this->GetWidth()) { |
|
| 113 | + $this->reader->Skip(2); |
|
| 114 | + } |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | $this->gdImage = $image; |
@@ -101,8 +101,9 @@ |
||
| 101 | 101 | * if it does't already. |
| 102 | 102 | */ |
| 103 | 103 | protected function EnsureDecoded() { |
| 104 | - if(!$this->decoded) |
|
| 105 | - $this->Decode(); |
|
| 104 | + if(!$this->decoded) { |
|
| 105 | + $this->Decode(); |
|
| 106 | + } |
|
| 106 | 107 | |
| 107 | 108 | $this->decoded = true; |
| 108 | 109 | } |