1 | /*****************************************************************************/ |
2 | // Copyright 2006-2007 Adobe Systems Incorporated |
3 | // All Rights Reserved. |
4 | // |
5 | // NOTICE: Adobe permits you to use, modify, and distribute this file in |
6 | // accordance with the terms of the Adobe license agreement accompanying it. |
7 | /*****************************************************************************/ |
8 | |
9 | /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_xy_coord.cpp#1 $ */ |
10 | /* $DateTime: 2012/05/30 13:28:51 $ */ |
11 | /* $Change: 832332 $ */ |
12 | /* $Author: tknoll $ */ |
13 | |
14 | /*****************************************************************************/ |
15 | |
16 | #include "dng_xy_coord.h" |
17 | |
18 | #include "dng_matrix.h" |
19 | #include "dng_utils.h" |
20 | |
21 | /******************************************************************************/ |
22 | |
23 | dng_xy_coord XYZtoXY (const dng_vector_3 &coord) |
24 | { |
25 | |
26 | real64 X = coord [0]; |
27 | real64 Y = coord [1]; |
28 | real64 Z = coord [2]; |
29 | |
30 | real64 total = X + Y + Z; |
31 | |
32 | if (total > 0.0) |
33 | { |
34 | |
35 | return dng_xy_coord (X / total, |
36 | Y / total); |
37 | |
38 | } |
39 | |
40 | return D50_xy_coord (); |
41 | |
42 | } |
43 | |
44 | /*****************************************************************************/ |
45 | |
46 | dng_vector_3 XYtoXYZ (const dng_xy_coord &coord) |
47 | { |
48 | |
49 | dng_xy_coord temp = coord; |
50 | |
51 | // Restrict xy coord to someplace inside the range of real xy coordinates. |
52 | // This prevents math from doing strange things when users specify |
53 | // extreme temperature/tint coordinates. |
54 | |
55 | temp.x = Pin_real64 (0.000001, temp.x, 0.999999); |
56 | temp.y = Pin_real64 (0.000001, temp.y, 0.999999); |
57 | |
58 | if (temp.x + temp.y > 0.999999) |
59 | { |
60 | real64 scale = 0.999999 / (temp.x + temp.y); |
61 | temp.x *= scale; |
62 | temp.y *= scale; |
63 | } |
64 | |
65 | return dng_vector_3 (temp.x / temp.y, |
66 | 1.0, |
67 | (1.0 - temp.x - temp.y) / temp.y); |
68 | |
69 | } |
70 | |
71 | /*****************************************************************************/ |
72 | |
73 | dng_xy_coord PCStoXY () |
74 | { |
75 | |
76 | return D50_xy_coord (); |
77 | |
78 | } |
79 | |
80 | /*****************************************************************************/ |
81 | |
82 | dng_vector_3 PCStoXYZ () |
83 | { |
84 | |
85 | return XYtoXYZ (PCStoXY ()); |
86 | |
87 | } |
88 | |
89 | /*****************************************************************************/ |
90 | |