Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Protected Member Functions
Zend_Pdf_Filter_Compression Class Reference
Inheritance diagram for Zend_Pdf_Filter_Compression:
Zend_Pdf_Filter_Interface Zend_Pdf_Filter_Compression_Flate Zend_Pdf_Filter_Compression_Lzw

Static Protected Member Functions

static _applyEncodeParams ($data, $params)
 
static _applyDecodeParams ($data, $params)
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Pdf_Filter_Interface
static encode ($data, $params=null)
 
static decode ($data, $params=null)
 

Detailed Description

Definition at line 33 of file Compression.php.

Member Function Documentation

◆ _applyDecodeParams()

static _applyDecodeParams (   $data,
  $params 
)
staticprotected

Convert stream data according to the filter params set after decoding.

Parameters
string$data
array$params
Returns
string

None of prediction

TIFF Predictor 2

PNG prediction Prediction code is duplicated on each row. Thus all cases can be brought to one

None of prediction

Sub prediction

Up prediction

Average prediction

Paeth prediction

Optimal prediction

Definition at line 292 of file Compression.php.

292  {
293  $predictor = self::_getPredictorValue($params);
294  $colors = self::_getColorsValue($params);
295  $bitsPerComponent = self::_getBitsPerComponentValue($params);
296  $columns = self::_getColumnsValue($params);
297 
299  if ($predictor == 1) {
300  return $data;
301  }
302 
304  if ($predictor == 2) {
305  #require_once 'Zend/Pdf/Exception.php';
306  throw new Zend_Pdf_Exception('Not implemented yet' );
307  }
308 
314  if ($predictor == 10 ||
315  $predictor == 11 ||
316  $predictor == 12 ||
317  $predictor == 13 ||
318  $predictor == 14 ||
319  $predictor == 15 ) {
320 
321  $bitsPerSample = $bitsPerComponent*$colors;
322  $bytesPerSample = ceil($bitsPerSample/8);
323  $bytesPerRow = ceil($bitsPerSample*$columns/8);
324  $rows = ceil(strlen($data)/($bytesPerRow + 1));
325  $output = '';
326  $offset = 0;
327 
328  $lastRow = array_fill(0, $bytesPerRow, 0);
329  for ($count = 0; $count < $rows; $count++) {
330  $lastSample = array_fill(0, $bytesPerSample, 0);
331  switch (ord($data[$offset++])) {
332  case 0: // None of prediction
333  $output .= substr($data, $offset, $bytesPerRow);
334  for ($count2 = 0; $count2 < $bytesPerRow && $offset < strlen($data); $count2++) {
335  $lastSample[$count2 % $bytesPerSample] = $lastRow[$count2] = ord($data[$offset++]);
336  }
337  break;
338 
339  case 1: // Sub prediction
340  for ($count2 = 0; $count2 < $bytesPerRow && $offset < strlen($data); $count2++) {
341  $decodedByte = (ord($data[$offset++]) + $lastSample[$count2 % $bytesPerSample]) & 0xFF;
342  $lastSample[$count2 % $bytesPerSample] = $lastRow[$count2] = $decodedByte;
343  $output .= chr($decodedByte);
344  }
345  break;
346 
347  case 2: // Up prediction
348  for ($count2 = 0; $count2 < $bytesPerRow && $offset < strlen($data); $count2++) {
349  $decodedByte = (ord($data[$offset++]) + $lastRow[$count2]) & 0xFF;
350  $lastSample[$count2 % $bytesPerSample] = $lastRow[$count2] = $decodedByte;
351  $output .= chr($decodedByte);
352  }
353  break;
354 
355  case 3: // Average prediction
356  for ($count2 = 0; $count2 < $bytesPerRow && $offset < strlen($data); $count2++) {
357  $decodedByte = (ord($data[$offset++]) +
358  floor(( $lastSample[$count2 % $bytesPerSample] + $lastRow[$count2])/2)
359  ) & 0xFF;
360  $lastSample[$count2 % $bytesPerSample] = $lastRow[$count2] = $decodedByte;
361  $output .= chr($decodedByte);
362  }
363  break;
364 
365  case 4: // Paeth prediction
366  $currentRow = array();
367  for ($count2 = 0; $count2 < $bytesPerRow && $offset < strlen($data); $count2++) {
368  $decodedByte = (ord($data[$offset++]) +
369  self::_paeth($lastSample[$count2 % $bytesPerSample],
370  $lastRow[$count2],
371  ($count2 - $bytesPerSample < 0)?
372  0 : $lastRow[$count2 - $bytesPerSample])
373  ) & 0xFF;
374  $lastSample[$count2 % $bytesPerSample] = $currentRow[$count2] = $decodedByte;
375  $output .= chr($decodedByte);
376  }
377  $lastRow = $currentRow;
378  break;
379 
380  default:
381  #require_once 'Zend/Pdf/Exception.php';
382  throw new Zend_Pdf_Exception('Unknown prediction tag.');
383  }
384  }
385  return $output;
386  }
387 
388  #require_once 'Zend/Pdf/Exception.php';
389  throw new Zend_Pdf_Exception('Unknown prediction algorithm - ' . $predictor . '.' );
390  }
$count
Definition: recent.phtml:13
$columns
Definition: default.phtml:15
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ _applyEncodeParams()

static _applyEncodeParams (   $data,
  $params 
)
staticprotected

Convert stream data according to the filter params set before encoding.

Parameters
string$data
array$params
Returns
string
Exceptions
Zend_Pdf_Exception

None of prediction

TIFF Predictor 2

Optimal PNG prediction

Use Paeth prediction as optimal

PNG prediction

None of prediction

Sub prediction

Up prediction

Average prediction

Paeth prediction

Definition at line 157 of file Compression.php.

157  {
158  $predictor = self::_getPredictorValue($params);
159  $colors = self::_getColorsValue($params);
160  $bitsPerComponent = self::_getBitsPerComponentValue($params);
161  $columns = self::_getColumnsValue($params);
162 
164  if ($predictor == 1) {
165  return $data;
166  }
167 
169  if ($predictor == 2) {
170  #require_once 'Zend/Pdf/Exception.php';
171  throw new Zend_Pdf_Exception('Not implemented yet' );
172  }
173 
175  if ($predictor == 15) {
177  $predictor = 14;
178  }
179 
181  if ($predictor == 10 ||
182  $predictor == 11 ||
183  $predictor == 12 ||
184  $predictor == 13 ||
185  $predictor == 14
186  ) {
187  $predictor -= 10;
188 
189  if($bitsPerComponent == 16) {
190  #require_once 'Zend/Pdf/Exception.php';
191  throw new Zend_Pdf_Exception("PNG Prediction with bit depth greater than 8 not yet supported.");
192  }
193 
194  $bitsPerSample = $bitsPerComponent*$colors;
195  $bytesPerSample = (int)(($bitsPerSample + 7)/8); // (int)ceil(...) emulation
196  $bytesPerRow = (int)(($bitsPerSample*$columns + 7)/8); // (int)ceil(...) emulation
197  $rows = strlen($data)/$bytesPerRow;
198  $output = '';
199  $offset = 0;
200 
201  if (!is_integer($rows)) {
202  #require_once 'Zend/Pdf/Exception.php';
203  throw new Zend_Pdf_Exception('Wrong data length.');
204  }
205 
206  switch ($predictor) {
207  case 0: // None of prediction
208  for ($count = 0; $count < $rows; $count++) {
209  $output .= chr($predictor);
210  $output .= substr($data, $offset, $bytesPerRow);
211  $offset += $bytesPerRow;
212  }
213  break;
214 
215  case 1: // Sub prediction
216  for ($count = 0; $count < $rows; $count++) {
217  $output .= chr($predictor);
218 
219  $lastSample = array_fill(0, $bytesPerSample, 0);
220  for ($count2 = 0; $count2 < $bytesPerRow; $count2++) {
221  $newByte = ord($data[$offset++]);
222  // Note. chr() automatically cuts input to 8 bit
223  $output .= chr($newByte - $lastSample[$count2 % $bytesPerSample]);
224  $lastSample[$count2 % $bytesPerSample] = $newByte;
225  }
226  }
227  break;
228 
229  case 2: // Up prediction
230  $lastRow = array_fill(0, $bytesPerRow, 0);
231  for ($count = 0; $count < $rows; $count++) {
232  $output .= chr($predictor);
233 
234  for ($count2 = 0; $count2 < $bytesPerRow; $count2++) {
235  $newByte = ord($data[$offset++]);
236  // Note. chr() automatically cuts input to 8 bit
237  $output .= chr($newByte - $lastRow[$count2]);
238  $lastRow[$count2] = $newByte;
239  }
240  }
241  break;
242 
243  case 3: // Average prediction
244  $lastRow = array_fill(0, $bytesPerRow, 0);
245  for ($count = 0; $count < $rows; $count++) {
246  $output .= chr($predictor);
247 
248  $lastSample = array_fill(0, $bytesPerSample, 0);
249  for ($count2 = 0; $count2 < $bytesPerRow; $count2++) {
250  $newByte = ord($data[$offset++]);
251  // Note. chr() automatically cuts input to 8 bit
252  $output .= chr($newByte - floor(( $lastSample[$count2 % $bytesPerSample] + $lastRow[$count2])/2));
253  $lastSample[$count2 % $bytesPerSample] = $lastRow[$count2] = $newByte;
254  }
255  }
256  break;
257 
258  case 4: // Paeth prediction
259  $lastRow = array_fill(0, $bytesPerRow, 0);
260  $currentRow = array();
261  for ($count = 0; $count < $rows; $count++) {
262  $output .= chr($predictor);
263 
264  $lastSample = array_fill(0, $bytesPerSample, 0);
265  for ($count2 = 0; $count2 < $bytesPerRow; $count2++) {
266  $newByte = ord($data[$offset++]);
267  // Note. chr() automatically cuts input to 8 bit
268  $output .= chr($newByte - self::_paeth( $lastSample[$count2 % $bytesPerSample],
269  $lastRow[$count2],
270  ($count2 - $bytesPerSample < 0)?
271  0 : $lastRow[$count2 - $bytesPerSample] ));
272  $lastSample[$count2 % $bytesPerSample] = $currentRow[$count2] = $newByte;
273  }
274  $lastRow = $currentRow;
275  }
276  break;
277  }
278  return $output;
279  }
280 
281  #require_once 'Zend/Pdf/Exception.php';
282  throw new Zend_Pdf_Exception('Unknown prediction algorithm - ' . $predictor . '.' );
283  }
$count
Definition: recent.phtml:13
$columns
Definition: default.phtml:15
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

The documentation for this class was generated from the following file: