View Single Post
Old 17th March 2014, 02:49   #8  |  Link
JanWillem32
Registered User
 
JanWillem32's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 1,083
Code:
used tools:
(construct the RGB to XYZ matrices first)
matrix math

BT.709 RGB to XYZ matrix
{{506752./1228815., 87881./245763., 12673./70218.},
{87098./409605., 175762./245763., 12673./175545.},
{7918./409605., 87881./737289., 1001167./1053270.}}
XYZ_w
{{3127/3290},{1},{3583/3290}}
iLMSCAT02_w
{{3903713/4112500},{34064741/32900000},{4472059/4112500}}
iLMSCAT02_wr
{{4112500/3903713},{32900000/34064741},{4112500/4472059}}
{{4112500/3903713,0,0},
{0,32900000/34064741,0},
{0,0,4112500/4472059}}
// white point adaptation and LMSCAT02 to XYZ to LMS
{{464053391886875/594479206165966,546172937177000/2593784454432131,25677829793875/681030107553338},
{89354738755625/297239603082983,1563686005000000/2593784454432131,28321738606875/340515053776669},
{-274069337500/27021782098453,-14274125600000/2593784454432131,317936256400000/340515053776669}}
// XYZ to LMSCAT02, white point adaptation and LMSCAT02 to XYZ to LMS
{{1535883035237967283712368316373/3622507351858025034877836622160,313936929155525071434095214423/452813418982253129359729577770,-320255941654937541603650371757/3622507351858025034877836622160},
{-73765545839823421271159289111/362250735185802503487783662216,52237841914778168455574637779/45281341898225312935972957777,13276522859463209890873256879/362250735185802503487783662216},
{-3125719934910748888276760/4116485627111392085088450707,-4119398094368106819832290/4116485627111392085088450707,3786370264907456584747946550/4116485627111392085088450707}}
// RGB to XYZ to LMSCAT02, white point adaptation and LMSCAT02 to XYZ to LMS
{{722868859153469683239595115393861/2255010826531620584211453297294600,2585192674261804536498018473512337/4059019487756917051580615935130280,431657167547167713128315634772483/10147548719392292628951539837825700},
{12180008436477856247752895389891/75167027551054019473715109909820,307102197566215335489903665465341/405901948775691705158061593513028,82569264131239864825730732355689/1014754871939229262895153983782570},
{53058419719444384066923671296/3075014763452209887561072678129,111365697442061984458791034130/1025004921150736629187024226043,2687859251406579550117775904443/3075014763452209887561072678129}}
// reverse
{{25377313278362757037750367/4668794666720483257968250,-214723657934986669707431539/46687946667204832579682500,7638471818563931909610369/46687946667204832579682500},
{-605343464019237999732424841/518184319406495060865758750,12063681187144308402184664197/5181843194064950608657587500,-828403352886977796202828287/5181843194064950608657587500},
{396581977151187822859327/10461567155328133121940425,-20775485687965286836237859/104615671553281331219404250,121425337469734739827048839/104615671553281331219404250}}


SMPTE 170M/SMPTE 240M/SMPTE C (NTSC) RGB to XYZ matrix
{{401584./932715., 2548549./7461720., 88721./497448.},
{276089./1243620., 87881./124362., 88721./1243620.},
{25099./1243620., 966691./7461720., 7008959./7461720.}}
XYZ_w
{{3127/3290},{1},{3583/3290}}
iLMSCAT02_w
{{3903713/4112500},{34064741/32900000},{4472059/4112500}}
iLMSCAT02_wr
{{4112500/3903713},{32900000/34064741},{4112500/4472059}}
{{4112500/3903713,0,0},
{0,32900000/34064741,0},
{0,0,4112500/4472059}}
// white point adaptation and LMSCAT02 to XYZ to LMS
{{464053391886875/594479206165966,546172937177000/2593784454432131,25677829793875/681030107553338},
{89354738755625/297239603082983,1563686005000000/2593784454432131,28321738606875/340515053776669},
{-274069337500/27021782098453,-14274125600000/2593784454432131,317936256400000/340515053776669}}
// XYZ to LMSCAT02, white point adaptation and LMSCAT02 to XYZ to LMS
{{1535883035237967283712368316373/3622507351858025034877836622160,313936929155525071434095214423/452813418982253129359729577770,-320255941654937541603650371757/3622507351858025034877836622160},
{-73765545839823421271159289111/362250735185802503487783662216,52237841914778168455574637779/45281341898225312935972957777,13276522859463209890873256879/362250735185802503487783662216},
{-3125719934910748888276760/4116485627111392085088450707,-4119398094368106819832290/4116485627111392085088450707,3786370264907456584747946550/4116485627111392085088450707}}
// RGB to XYZ to LMSCAT02, white point adaptation and LMSCAT02 to XYZ to LMS
{{4582795022958559125948622834369921/13693077790023334631838222431764800,465527727195754310063646435959647/746895152183090979918448496278080,431705826356959866042061203601013/10269808342517500973878666823823600},
{77217992358463681223124506539751/456435926334111154394607414392160,56048129428711216246386203396963/74689515218309097991844849627808,82578571800427591248026245959679/1026980834251750097387866682382360},
{42047021865948932675414158432/2334047350572159312245151550869,1103514589028385241176926280029/9336189402288637248980606203476,2688162241932152092367341096573/3112063134096212416326868734492}}
// reverse
{{763198626475360358257813253/147994540717374853866816250,-6373975142277374689886058001/1479945407173748538668162500,221934284697519645976087971/1479945407173748538668162500},
{-605343464019237999732424841/518184319406495060865758750,12063681187144308402184664197/5181843194064950608657587500,-828403352886977796202828287/5181843194064950608657587500},
{27361298410291889828212027/523137322083995952425108750,-1196635193693957989329923759/5231373220839959524251087500,6154395430430998615298890989/5231373220839959524251087500}}


BT.470-2 System M RGB to XYZ matrix
{{43349./71416., 12387./71416., 3581./17854.},
{21351./71416., 293159./499912., 7162./62489.},
{0., 4129./62489., 139659./124978.}}
XYZ_w
{{155/158},{1},{187/158}}
iLMSCAT02_w
{{37773/39500},{1602877/1580000},{233137/197500}}
iLMSCAT02_wr
{{39500/37773},{1580000/1602877},{197500/233137}}
{{39500/37773,0,0},
{0,1580000/1602877,0},
{0,0,197500/233137}}
// white point adaptation and LMSCAT02 to XYZ to LMS
{{4457169356725/5752283288886,26229581785400/122047528409707,1233160215025/35503403730734},
{858240043975/2876141644443,75094951000000/122047528409707,1360132127625/17751701865367},
{-28956383500/2876141644443,-685505120000/122047528409707,15268671280000/17751701865367}}
// XYZ to LMSCAT02, white point adaptation and LMSCAT02 to XYZ to LMS
{{4841799350800837556394979/11619299292878301472724400,169003540689637258532741/242068735268297947348425,-1050013174810519557556547/11619299292878301472724400},
{-1243396960144830232381973/5809649646439150736362200,284114598684068163097666/242068735268297947348425,178013982619508170577989/5809649646439150736362200},
{-122785085978668174408/145241241160978768409055,-104660313950594725082/48413747053659589469685,123084260858684068852154/145241241160978768409055}}
// RGB to XYZ to LMSCAT02, white point adaptation and LMSCAT02 to XYZ to LMS
{{4849241781348846485632006241/10503846560761984531342857600,34978470582276588065997919961/73526925925333891719400003200,35966897450120142609203434/574429108791671029057812525},
{1160596510009705046375091833/5251923280380992265671428800,24013221393818167547899894193/36763462962666945859700001600,72282281230950671674601009/574429108791671029057812525},
{-76116568237764117836011/65649041004762403320892860,25082445529946839408599149/459543287033336823246250020,108748414370263583165625737/114885821758334205811562505}}
// reverse
{{6356039832931337684547833/1907495674013736213630625,-9291369607363479369136241/3814991348027472427261250,15771251581131057092073/152599653921098897090450},
{-13887055372386146338232481/12173183366310226933664375,57992533744044875121627737/24346366732620453867328750,-234882250666085143113361/973854669304818154693150},
{737565350893551523311808/10557561064363507544066875,-1481563549980151961947408/10557561064363507544066875,452062370538004319308099/422302442574540301762675}}


BT.470-2 System B,G/EBU 3213 (PAL/SECAM) RGB to XYZ matrix
{{51177./130049., 4987652./13655145., 5234753./27310290.},
{82858./390147., 1367582./1950735., 168863./1950735.},
{2437./130049., 1528474./13655145., 5234753./5462058.}}
XYZ_w
{{3127/3290},{1},{3583/3290}}
iLMSCAT02_w
{{3903713/4112500},{34064741/32900000},{4472059/4112500}}
iLMSCAT02_wr
{{4112500/3903713},{32900000/34064741},{4112500/4472059}}
{{4112500/3903713,0,0},
{0,32900000/34064741,0},
{0,0,4112500/4472059}}
// white point adaptation and LMSCAT02 to XYZ to LMS
{{464053391886875/594479206165966,546172937177000/2593784454432131,25677829793875/681030107553338},
{89354738755625/297239603082983,1563686005000000/2593784454432131,28321738606875/340515053776669},
{-274069337500/27021782098453,-14274125600000/2593784454432131,317936256400000/340515053776669}}
// XYZ to LMSCAT02, white point adaptation and LMSCAT02 to XYZ to LMS
{{1535883035237967283712368316373/3622507351858025034877836622160,313936929155525071434095214423/452813418982253129359729577770,-320255941654937541603650371757/3622507351858025034877836622160},
{-73765545839823421271159289111/362250735185802503487783662216,52237841914778168455574637779/45281341898225312935972957777,13276522859463209890873256879/362250735185802503487783662216},
{-3125719934910748888276760/4116485627111392085088450707,-4119398094368106819832290/4116485627111392085088450707,3786370264907456584747946550/4116485627111392085088450707}}
// RGB to XYZ to LMSCAT02, white point adaptation and LMSCAT02 to XYZ to LMS
{{782910914364235953227073443841197/2505869460647788817876743483379180,47437201892727083793508359035427793/75176083819433664536302304501375400,4251554495779502145981742150711697/75176083819433664536302304501375400},
{124459316400474051550350235432343/751760838194336645363023045013754,5551656166817314597571817932574949/7517608381943366453630230450137540,240453017040437113518303387746387/2505869460647788817876743483379180},
{190503071007861562472684780870/11390315730217221899439743106269,3484707111371743136520220253336/34170947190651665698319229318807,30114730866256337874380954722861/34170947190651665698319229318807}}
// reverse
{{5889610677243193337436144851/1005872293755806060844662500,-50563246336667155788637763367/10058722937558060608446625000,1725862501793283022722939857/10058722937558060608446625000},
{-156299752813513892312443129/118586087319713310233175625,2972168594434151167364839293/1185860873197133102331756250,-223310193101879141908651753/1185860873197133102331756250},
{41217384068187972753550441/995689156108134584983951250,-1937830199233462093713839397/9956891561081345849839512500,11482547919632928216017847487/9956891561081345849839512500}}




preccalc64.exe
construct the RGB to XYZ matrices

/*
// these are for SMPTE 170M/SMPTE 240M/SMPTE C (NTSC)
ix_r = .63;
iy_r = .34;
ix_g = .31;
iy_g = .595;
ix_b = .155;
iy_b = .07;
ix_w = .3127;
iy_w = .329;
*/
/*
// these are for BT.470-2 System M
ix_r = .67;
iy_r = .33;
ix_g = .21;
iy_g = .71;
ix_b = .14;
iy_b = .08;
ix_w = .31;
iy_w = .316;
*/
/*
// these are for BT.470-2 System B,G/EBU 3213 (PAL/SECAM)
ix_r = .64;
iy_r = .33;
ix_g = .29;
iy_g = .6;
ix_b = .15;
iy_b = .06;
ix_w = .3127;
iy_w = .329;
*/
// these are for BT.709
ix_r = .64;
iy_r = .33;
ix_g = .3;
iy_g = .6;
ix_b = .15;
iy_b = .06;
ix_w = .3127;
iy_w = .329;



X_r = ix_r / iy_r;
Z_r = (1. - ix_r - iy_r) / iy_r;
X_g = ix_g / iy_g;
Z_g = (1. - ix_g - iy_g) / iy_g;
X_b = ix_b / iy_b;
Z_b = (1. - ix_b - iy_b) / iy_b;
X_w = ix_w / iy_w;
Z_w = (1. - ix_w - iy_w) / iy_w;

Mdetr = 1. / (X_r * (Z_b - Z_g) - X_g * (Z_b - Z_r) + X_b * (Z_g - Z_r));
S_r = (X_w * (Z_b - Z_g) + X_b * Z_g - X_g * Z_b + Z_w * (X_g - X_b)) * Mdetr;
S_g = (X_w * (Z_r - Z_b) + X_r * Z_b - X_b * Z_r + Z_w * (X_b - X_r)) * Mdetr;
S_b = (X_w * (Z_g - Z_r) + X_g * Z_r - X_r * Z_g + Z_w * (X_r - X_g)) * Mdetr;

MX_r = S_r * X_r;
MX_g = S_g * X_g;
MX_b = S_b * X_b;
MY_r = S_r;
MY_g = S_g;
MY_b = S_b;
MZ_r = S_r * Z_r;
MZ_g = S_g * Z_g;
MZ_b = S_b * Z_b;

print MX_r, ",", MX_g, ",", MX_b, ",", MY_r, ",", MY_g, ",", MY_b, ",", MZ_r, ",", MZ_g, ",", MZ_b;
__________________
development folder, containing MPC-HC experimental tester builds, pixel shaders and more: http://www.mediafire.com/?xwsoo403c53hv
JanWillem32 is offline   Reply With Quote