<?php
/**************************************************
 Author:MS-K  http://till-daylight.org
 2008-05-30(金)
***************************************************/

require './ColorConversion.Class.php';
require 
'./header_inc.php';

/***********************************
 *           色を入力
 **********************************/
$c $m $y $k'';
$r $g $b '';
$hexline $errorline '';
$maxint 3;

if(!empty(
$_POST['color'])) {

    
// 入力値
    
$input = new PutData();

    
// print_r($input);
    
    
if(!empty($input->errors)) {
        
$errorline $input->errors[0];
    }

    switch(
$_POST['color']) {
    case 
'cmyk':
        
// 入力値
        
$colorlist $input->putCMYK();
        list(
$c$m$y$k) = explode(','$colorlist);

        
// RGB
        
$rgb = new CMYK2RGB();
        
$rgbline $rgb->showRGB();
        list(
$r$g$b) = explode(','$rgbline);

        
// HEX
        
$hex = new CMYK2Hex();
        
$hexline $hex->showHex();
    break;

    case 
'rgb':
        
// 入力値
        
$colorlist $input->putRGB();
        list(
$r$g$b) = explode(','$colorlist);

        
// CMYK
        
$cmyk = new RGB2CMYK();
        
$cmykline $cmyk->showCMYK();
        list(
$c$m$y$k) = explode(','$cmykline);

        
// HEX
        
$hex = new RGB2Hex();
        
$hexline $hex->showHex();
    break;

    case 
'hex':
        
// 入力値
        
$hexline $input->putHEX();

        
// RGB
        
$rgb = new Hex2RGB();
        
$rgbline $rgb->showHex();
        list(
$r$g$b) = explode(','$rgbline);

        
// CMYK
        
$cmyk = new Hex2CMYK();
        
$cmykline $cmyk->showCMYK();
        list(
$c$m$y$k) = explode(','$cmykline);
    break;

    case 
'light':
    case 
'dark':
        
// 入力値
        
$colorlist $input->putCMYK();
        list(
$c$m$y$k) = explode(','$colorlist);

        
// RGB
        
$rgb = new CMYK2RGB();
        
$rgbline $rgb->showRGB();
        list(
$r$g$b) = explode(','$rgbline);

        
// HEX
        
$hex = new CMYK2Hex();
        
$hexline $hex->showHex();
    break;
    }
}




/***********************************
 *          HTML:出力
 **********************************/
echo <<< EOD

<div id="mainbox">

<p id="greeting">
CMYKへの変換は正確ではありません。参考程度にしてください。<br />
未入力の箇所は「0」が代入されます。
</p>


<div class="colorbox cmyk">
<form method="post" action="">
<span style="color: #00ffff;">C</span>
<input type="text" size="3" id="c" name="c" value="
{$c}" maxlength="{$maxint}"
  onclick="this.select()" />
<span style="color: #ff00ff;">M</span>
<input type="text" size="3" name="m" value="
{$m}" maxlength="{$maxint}"
 onclick="this.select()" />
<span style="color: #ffff00;">Y</span>
<input type="text" size="3" name="y" value="
{$y}" maxlength="{$maxint}"
 onclick="this.select()" />
<span style="color: #000000;">K</span>
<input type="text" size="3" name="k" value="
{$k}" maxlength="{$maxint}"
 onclick="this.select()" />

<input type="submit" value="変換" name="submit" class="submit" />
<input type="hidden" value="cmyk" name="color" />
<small>[ 0-100 ]</small>
</form>
</div>


<div class="colorbox rgb">
<form method="post" action="">
<span style="color: #ff0000;">R</span>
<input type="text" size="3" name="r" value="
{$r}" maxlength="{$maxint}"
 onclick="this.select()" />
<span style="color: #00ff00;">G</span>
<input type="text" size="3" name="g" value="
{$g}" maxlength="{$maxint}"
 onclick="this.select()" />
<span style="color: #0000ff;">B</span>
<input type="text" size="3" name="b" value="
{$b}" maxlength="{$maxint}"
 onclick="this.select()" />

<input type="submit" value="変換" name="submit" class="submit" />
<input type="hidden" value="rgb" name="color" />
<small>[ 0-255 ]</small>
</form>
</div>


<div class="colorbox hex">
<form method="post" action="">
#
<input type="text" size="7" name="hex" value="
{$hexline}" maxlength="6"
 onclick="this.select()" class="text2" />

<input type="submit" value="変換" name="submit" class="submit" />
<input type="hidden" value="hex" name="color" />
<small>[ 0-9a-f ]</small>
</form>
</div>


<div class="colorbox contrast">
<form method="post" action="">
<input type="submit" value="10%薄く" name="submit" class="submit d1" />
<input type="hidden" value="
{$c}" name="dc" />
<input type="hidden" value="
{$m}" name="dm" />
<input type="hidden" value="
{$y}" name="dy" />
<input type="hidden" value="
{$k}" name="dk" />
<input type="hidden" value="10" name="rate" />
<input type="hidden" value="light" name="color" />
</form>

<form method="post" action="">
<input type="submit" value="5%薄く" name="submit" class="submit d2" />
<input type="hidden" value="
{$c}" name="dc" />
<input type="hidden" value="
{$m}" name="dm" />
<input type="hidden" value="
{$y}" name="dy" />
<input type="hidden" value="
{$k}" name="dk" />
<input type="hidden" value="5" name="rate" />
<input type="hidden" value="light" name="color" />
</form>

<form method="post" action="">
<input type="submit" value="5%濃く" name="submit" class="submit d3" />
<input type="hidden" value="
{$c}" name="dc" />
<input type="hidden" value="
{$m}" name="dm" />
<input type="hidden" value="
{$y}" name="dy" />
<input type="hidden" value="
{$k}" name="dk" />
<input type="hidden" value="5" name="rate" />
<input type="hidden" value="dark" name="color" />
</form>

<form method="post" action="">
<input type="submit" value="10%濃く" name="submit" class="submit d4" />
<input type="hidden" value="
{$c}" name="dc" />
<input type="hidden" value="
{$m}" name="dm" />
<input type="hidden" value="
{$y}" name="dy" />
<input type="hidden" value="
{$k}" name="dk" />
<input type="hidden" value="10" name="rate" />
<input type="hidden" value="dark" name="color" />
</form>
</div>


<p id="error">
$errorline
</p>


<h2>参考にしたサイト</h2>

<p>
<a href="http://image-d.isp.jp/">ISP imaging-developers - システム計画研究所 画像処理研究プロジェクト</a>の<a href="http://image-d.isp.jp/commentary/color_cformula/">色変換式集</a><br />
ただ、ここの計算はCMYK、RGB全て0.0から1.0の範囲のため、独自に以下の拡張をしています。<br />
CMYKは0から100、RGBは0から255
</p>


<h3>ソース</h3>

<p>
<a href="./index.phps">index.php</a><br />
<a href="./ColorConversion.Class.phps">ColorConversion.Class.php</a>
</p>


<h3>連絡先</h3>

<p>
<a href="http://blog.till-daylight.org/archives/209-CMYK-RGB-Hex.html">blog</a>
からお願いします。
</p>


<div id="colorsample" style="background-color:#
{$hexline};">
    <div style="text-align:center; padding-top:40px;">
    color sample
    </div>
</div>

</div>
EOD;

require 
'./footer_inc.php';
?>