【php开源代码栏目提醒】:网学会员鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“Compression.php”一文,供大家参考学习
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to version 1.0 of the Zend Framework
* license, that is bundled with this package in the file LICENSE, and
* is available through the world-wide-web at the following URL:
* http://www.zend.com/license/framework/1_0.txt. If you did not receive
* a copy of the Zend Framework license and are unable to obtain it
* through the world-wide-
web, please send a note to license@zend.com
* so we can mail you a copy immediately.
*
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2006 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://www.zend.com/license/framework/1_0.txt Zend Framework License version 1.0
*/
/** Zend_Pdf_Filter */
require_once 'Zend/Pdf/Filter.php';
/**
* ASCII85 stream filter
*
* @package Zend_Pdf
* @copyright Copyright (c) 2005-2006 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://www.zend.com/license/framework/1_0.txt Zend Framework License version 1.0
*/
abstract class Zend_Pdf_Filter_Compression extends Zend_Pdf_Filter
{
/**
* Paeth prediction function
*
* @param integer $a
* @param integer $b
* @param integer $c
* @return integer
*/
static private function _paeth($a, $b, $c)
{
// $a - left, $b - above, $c - upper left
$p = $a + $b - $c; // initial estimate
$pa = abs($p - $a); // distances to a, b, c
$pb = abs($p - $b);
$pc = abs($p - $c);
// return nearest of a,b,c,
// breaking ties in order a,b,c.
if ($pa <= $pb && $pa <= $pc) {
return $a;
} else if ($pb <= $pc) {
return $b;
} else {
return $c;
}
}
/**
* Get Predictor decode param value
*
* @param array $params
* @return integer
* @throws Zend_Pdf_Exception
*/
private static function _getPredictorValue(&$params)
{
if (isset($params['Predictor'])) {
$predictor = $params['Predictor'];
if ($predictor != 1 && $predictor != 2 &&
$predictor != 10 && $predictor != 11 && $predictor != 12 &&
$predictor != 13 && $predictor != 14 && $predictor != 15) {
throw new Zend_Pdf_Exception('Invalid value of \'Predictor\' decode param - ' . $predictor . '.' );
}
return $predictor;
} else {
return 1;
}
}
/**
* Get Colors decode param value
*
* @param array $params
* @return integer
* @throws Zend_Pdf_Exception
*/
private static function _getColorsValue(&$params)
{
if (isset($params['Colors'])) {
$colors = $params['Colors'];
if ($colors != 1 && $colors != 2 && $colors != 3 && $colors != 4) {
throw new Zend_Pdf_Exception('Invalid value of \'Color\' decode param - ' . $colors . '.' );
}
return $colors;
} else {
return 1;
}
}
/**
* Get BitsPerComponent decode param value
*
* @param array $params
* @return integer
* @throws Zend_Pdf_Exception
*/
private static function _getBitsPerComponentValue(&$params)
{
if (isset($params['BitsPerComponent'])) {
$bitsPerComponent = $params['BitsPerComponent'];
if ($bitsPerComponent != 1 && $bitsPerComponent != 2 &&
$bitsPerComponent != 4 && $bitsPerComponent != 8 &&
$bitsPerComponent != 16 ) {
throw new Zend_Pdf_Exception('Invalid value of \'BitsPerComponent\' decode param - ' . $bitsPerComponent . '.' );
}
return $bitsPerComponent;
} else {
return 8;
}
}
/**
* Get Columns decode param value
*
* @param array $params
* @return integer
*/
private static function _getColumnsValue(&$params)
{
if (isset($params['Columns'])) {
return $params['Columns'];
} else {
return 1;
}
}
/**
* Convert stream data according to the filter params set before encoding.
*
* @param string $data
* @param array $params
* @return string
* @throws Zend_Pdf_Exception
*/
protected static function _applyEncodeParams(&$data, $params) {
$predictor = self::_getPredictorValue($params);
$colors = self::_getColorsValue($params);
$bitsPerComponent = self::_getBitsPerComponentValue($params);
$columns = self::_getColumnsValue($params);
if ($predictor == 1) {
return $data;
}
throw new Zend_Pdf_Exception('Unknown prediction algorithm - ' . $predictor . '.' );
}
/**
* Convert stream data according to the filter params set after decoding.
*
* @param string $data
* @param array $params
* @return string
*/
protected function _applyDecodeParams(&$data, $params) {
$predictor = self::_getPredictorValue($params);
$colors = self::_getColorsValue($params);
$bitsPerComponent = self::_getBitsPerComponentValue($params);
$columns = self::_getColumnsValue