<?php
/* AUTOR / AUTHOR : LUIS QUIJADA SERRANO
/* FECHA / DATE : 7/03/2002.
/* VERSION : 1.0
/* COMMENTS : SEE THE DOCUMENTATION AT rgb_esp.class.txt
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* ORIGINAL CLASS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
class RGB_Esp
{
function RGB_Esp()
{
}
function ExtraerComponenteRGB($rgb, $componente, $cseparador="") {
if (is_array($rgb)) $_RGB = $rgb;
else $_RGB = explode($cseparador,$rgb);
if (($componente & RGB_R) === RGB_R) $indice = 0;
elseif (($componente & RGB_G) === RGB_G) $indice = 1;
elseif (($componente & RGB_B) === RGB_B) $indice = 2;
for ($i=0;$i<3;$i++) {
if ($i==$indice) return $_RGB[$i];
}
}
function ExtraerComponenteCSS($colorcss, $componente) {
$_RGB = $this->ConvertirAColorRGB($colorcss);
return DecHex($this->ExtraerComponenteRGB($_RGB, $componente));
}
function SubstituirComponenteRGB($rgb, $nuevovalor, $componente, $cseparador="") {
if (is_array($rgb)) $_RGB = $rgb;
else $_RGB = explode($cseparador,$rgb);
if (($componente & RGB_R) === RGB_R) $indice = 0;
elseif (($componente & RGB_G) === RGB_G) $indice = 1;
elseif (($componente & RGB_B) === RGB_B) $indice = 2;
for ($i=0;$i<3;$i++) {
if ($i==$indice) {
$_RGB[$i] = $nuevovalor;
if ($cseparador!="") return join($cseparador, $_RGB);
return $_RGB;
}
}
}
function SubstituirComponenteCSS($colorcss, $nuevovalor, $componente)
{
$_RGB = $this->ConvertirAColorRGB($colorcss);
if (($componente & RGB_R) === RGB_R) $indice = 0;
elseif (($componente & RGB_G) === RGB_G) $indice = 1;
elseif (($componente & RGB_B) === RGB_B) $indice = 2;
$_RGB = $this->SubstituirComponenteRGB($_RGB, HexDec($nuevovalor), $componente);
return $this->ConvertirAColorCSS($_RGB);
}
function IncrementarComponenteRGB($cantidad, $rgb, $componente, $cseparador="")
{
if (is_array($rgb)) $_RGB = $rgb;
else $_RGB = explode($cseparador,$rgb);
if (($componente & RGB_R) === RGB_R) $indice = 0;
elseif (($componente & RGB_G) === RGB_G) $indice = 1;
elseif (($componente & RGB_B) === RGB_B) $indice = 2;
for ($i=0;$i<3;$i++) {
if ($i==$indice) {
if (($ibuff = ((int)$_RGB[$i])+ $cantidad)>255) {
$ibuff = 255;
}
$_RGB[$i] = $ibuff;
break;
}
}
if ($cseparador!="") return join($cseparador, $_RGB);
return $_RGB;
}
function IncrementarComponenteCSS($cantidad, $colorcss, $componente) {
$_RGB = $this->ConvertirAColorRGB($colorcss);
$_RGB = $this->IncrementarComponenteRGB($cantidad, $_RGB, $componente);
return $this->ConvertirAColorCSS($_RGB);
}
function DecrementarComponenteRGB($cantidad, $rgb, $componente, $cseparador="")
{
if (is_array($rgb)) $_RGB = $rgb;
else $_RGB = explode($cseparador,$rgb);
if (($componente & RGB_R) === RGB_R) $indice = 0;
elseif (($componente & RGB_G) === RGB_G) $indice = 1;
elseif (($componente & RGB_B) === RGB_B) $indice = 2;
for ($i=0;$i<3;$i++) {
if ($i==$indice) {
if (($ibuff = ((int)$_RGB[$i])-$cantidad)<0) {
$ibuff = 0;
}
$_RGB[$i] = $ibuff;
break;
}
}
if ($cseparador!="") return join($cseparador, $_RGB);
return $_RGB;
}
function DecrementarComponenteCSS($cantidad, $colorcss, $componente) {
$_RGB = $this->ConvertirAColorRGB($colorcss);
$_RGB = $this->DecrementarComponenteRGB($cantidad, $_RGB, $componente);
return $this->ConvertirAColorCSS($_RGB);
}
function SaturarRGB($cantidad, $rgb, $componente="", $cseparador="") {
if ($componente === "") $componente = RGB_MAYOR;
if (is_array($rgb)) $_RGB = $rgb;
else $_RGB = explode($cseparador,$rgb);
if (($componente & RGB_R) === RGB_R) $indice = 0;
elseif (($componente & RGB_G) === RGB_G) $indice = 1;
elseif (($componente & RGB_B) === RGB_B) $indice = 2;
elseif (($componente & RGB_MAYOR) === RGB_MAYOR) {
$indice = $r;
$r = (int)$_RGB[0];
$g = (int)$_RGB[1];
$b = (int)$_RGB[2];
if (($r==$g)==$b) {
$indice = -1;
}
if (($r>$g)&&($r>$b)) $indice = 0;
else {
if ($g>$b) $indice = 1;
else $indice = 2;
}
}
for ($i=0;$i<3;$i++) {
if ($i==$indice) {
if (($ibuff = ((int)$_RGB[$i])+ $cantidad)>255) {
$ibuff = 255;
}
}
elseif (($ibuff = ((int)$_RGB[$i])-$cantidad) > 255) {
$ibuff = 255;
}
$_RGB[$i] = $ibuff;
}
if ($cseparador!="") return join($cseparador, $_RGB);
return $_RGB;
}
function SaturarCSS($cantidad, $colorcss, $componente="")
{
if ($componente === "") $componente = RGB_MAYOR;
return $this->ConvertirAColorCSS(
$this->SaturarRGB($cantidad, $this->ConvertirAColorRGB($colorcss),
$componente));
}
function LuminizarRGB($cantidad, $rgb, $cseparador="")
{
if (is_array($rgb)) $_RGB = $rgb;
else $_RGB = explode($cseparador,$rgb);
for ($i=0;$i<3;$i++) {
if (($ibuff = ((int)$_RGB[$i])+$cantidad) > 255) {
$ibuff = 255;
}
$_RGB[$i] = $ibuff;
}
if ($cseparador!="") return join($cseparador, $_RGB);
return $_RGB;
}
function LuminizarCSS($cantidad, $colorcss)
{
return $this->ConvertirAColorCSS(
$this->LuminizarRGB($cantidad, $this->ConvertirAColorRGB($colorcss)));
}
function OscurecerRGB($cantidad, $rgb, $cseparador="")
{
if (is_array($rgb)) $_RGB = $rgb;
else $_RGB = explode($cseparador,$rgb);
for ($i=0;$i<3;$i++) {
if (($ibuff = ((int)$_RGB[$i])-$cantidad) < 0) {
$ibuff = 0;
}
$_RGB[$i] = $ibuff;
}
if ($cseparador!="") return join($cseparador, $_RGB);
return $_RGB;
}
function OscurecerCSS($cantidad, $colorcss)
{
return $this->ConvertirAColorCSS($this->OscurecerRGB($cantidad,
$this->ConvertirAColorRGB($colorcss)));
}
function ConvertirAColorCSS($rgb, $cseparador=",")
{
$szCSS = "#";
if (is_array($rgb)) $_RGB = $rgb;
else $_RGB = explode($cseparador,$rgb);
for ($i=0;$i<3;$i++) {
if (((int)$_RGB[$i]) < 16) $szCSS .= "0";
$szCSS .= sprintf("%X", $_RGB[$i]);
}
return $szCSS;
}
function ConvertirAColorRGB($colorcss, $cseparador="") {
$_RGB = array();
for ($i=0;$i<3;$i++) {
$_RGB[] = HexDec(substr($colorcss, ($i*2)+1,2));
}
if ($cseparador!="") return join($cseparador, $_RGB);
return $_RGB;
}
function _RGB_Esp()
{
}
}
?>