RGB-XYZ 색상 변환 구현

RGB-XYZ 색상 변환 구현
rgb2xyz

1 소스 코드[ | ]

<?php
function xmp_print($arr) { echo '<xmp>'; print_r($arr); echo '</xmp>'; }
function rgb2xyz($rgb){
	list($r, $g, $b) = $rgb;

	$r = $r > 0.0001586274509803922 ? pow( $r/269.025 + 0.0521327014218009, 2.4)*100 : $r/32.946;
	$g = $g > 0.0001586274509803922 ? pow( $g/269.025 + 0.0521327014218009, 2.4)*100 : $g/32.946;
	$b = $b > 0.0001586274509803922 ? pow( $b/269.025 + 0.0521327014218009, 2.4)*100 : $b/32.946;
	
	// Observer = 2°, Illuminant = D65
	$x = $r*0.4124 + $g*0.3576 + $b*0.1805;
	$y = $r*0.2126 + $g*0.7152 + $b*0.0722;
	$z = $r*0.0193 + $g*0.1192 + $b*0.9505;
	return array($x, $y, $z);
}

$white = array(255,255,255);
$yellow = array(255,255,0);
$red = array(255,0,0);
$black = array(0,0,0);

xmp_print( rgb2xyz( $white ) );
xmp_print( rgb2xyz( $yellow ) );
xmp_print( rgb2xyz( $red ) );
xmp_print( rgb2xyz( $black ) );

2 실행 결과[ | ]

Array
(
    [0] => 95.05
    [1] => 100
    [2] => 108.9
)
Array
(
    [0] => 77
    [1] => 92.78
    [2] => 13.85
)
Array
(
    [0] => 41.24
    [1] => 21.26
    [2] => 1.93
)
Array
(
    [0] => 0
    [1] => 0
    [2] => 0
)

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}