1 
2 
3 #include "tpixel.h"
4 #include "tpixelgr.h"
5 
6 const int TPixelRGBM32::maxChannelValue = 0xff;
7 const int TPixelRGBM64::maxChannelValue = 0xffff;
8 const int TPixelGR8::maxChannelValue    = 0xff;
9 const int TPixelGR16::maxChannelValue   = 0xffff;
10 
11 const TPixelRGBM32 TPixelRGBM32::Red(maxChannelValue, 0, 0);
12 const TPixelRGBM32 TPixelRGBM32::Green(0, maxChannelValue, 0);
13 const TPixelRGBM32 TPixelRGBM32::Blue(0, 0, maxChannelValue);
14 const TPixelRGBM32 TPixelRGBM32::Yellow(maxChannelValue, maxChannelValue, 0);
15 const TPixelRGBM32 TPixelRGBM32::Cyan(0, maxChannelValue, maxChannelValue);
16 const TPixelRGBM32 TPixelRGBM32::Magenta(maxChannelValue, 0, maxChannelValue);
17 const TPixelRGBM32 TPixelRGBM32::White(maxChannelValue, maxChannelValue,
18                                        maxChannelValue);
19 const TPixelRGBM32 TPixelRGBM32::Black(0, 0, 0);
20 const TPixelRGBM32 TPixelRGBM32::Transparent(0, 0, 0, 0);
21 //---------------------------------------------------
22 
23 const TPixelRGBM64 TPixelRGBM64::Red(maxChannelValue, 0, 0);
24 const TPixelRGBM64 TPixelRGBM64::Green(0, maxChannelValue, 0);
25 const TPixelRGBM64 TPixelRGBM64::Blue(0, 0, maxChannelValue);
26 const TPixelRGBM64 TPixelRGBM64::Yellow(maxChannelValue, maxChannelValue, 0);
27 const TPixelRGBM64 TPixelRGBM64::Cyan(0, maxChannelValue, maxChannelValue);
28 const TPixelRGBM64 TPixelRGBM64::Magenta(maxChannelValue, 0, maxChannelValue);
29 const TPixelRGBM64 TPixelRGBM64::White(maxChannelValue, maxChannelValue,
30                                        maxChannelValue);
31 const TPixelRGBM64 TPixelRGBM64::Black(0, 0, 0);
32 const TPixelRGBM64 TPixelRGBM64::Transparent(0, 0, 0, 0);
33 //---------------------------------------------------
34 const TPixelD TPixelD::Red(1, 0, 0);
35 const TPixelD TPixelD::Green(0, 1, 0);
36 const TPixelD TPixelD::Blue(0, 0, 1);
37 const TPixelD TPixelD::Yellow(1, 1, 0);
38 const TPixelD TPixelD::Cyan(0, 1, 1);
39 const TPixelD TPixelD::Magenta(1, 0, 1);
40 const TPixelD TPixelD::White(1, 1, 1);
41 const TPixelD TPixelD::Black(0, 0, 0);
42 const TPixelD TPixelD::Transparent(0, 0, 0, 0);
43 //---------------------------------------------------
44 const TPixelGR8 TPixelGR8::White(maxChannelValue);
45 const TPixelGR8 TPixelGR8::Black(0);
46 
47 const TPixelGR16 TPixelGR16::White(maxChannelValue);
48 const TPixelGR16 TPixelGR16::Black(0);
49 
operator <<(std::ostream & out,const TPixel32 & pixel)50 static std::ostream &operator<<(std::ostream &out, const TPixel32 &pixel) {
51   return out << "PixRGBM32(" << (int)pixel.r << ", " << (int)pixel.g << ", "
52              << (int)pixel.b << ", " << (int)pixel.m << ")";
53 }
54 
operator <<(std::ostream & out,const TPixel64 & pixel)55 static std::ostream &operator<<(std::ostream &out, const TPixel64 &pixel) {
56   return out << "PixRGBM64(" << pixel.r << ", " << pixel.g << ", " << pixel.b
57              << ", " << pixel.m << ")";
58 }
59 
operator <<(std::ostream & out,const TPixelD & pixel)60 static std::ostream &operator<<(std::ostream &out, const TPixelD &pixel) {
61   return out << "PixD(" << pixel.r << ", " << pixel.g << ", " << pixel.b << ", "
62              << pixel.m << ")";
63 }
64 
65 //=============================================================================
66 
67 /*
68 TPixel32 DVAPI TPixel32::from(const TPixelGR8 &pix)
69 {
70    return TPixel32(pix.value, pix.value, pix.value, maxChannelValue);
71 }
72 
73 //-----------------------------------------------------------------------------
74 
75 TPixel32 DVAPI TPixel32::from(const TPixelGR16 &pix)
76 {
77    UCHAR value = byteFromUshort(pix.value);
78    return TPixel32(value, value, value, maxChannelValue);
79 }
80 
81 //-----------------------------------------------------------------------------
82 
83 TPixelD DVAPI TPixelD::from(const TPixelGR8 &pix)
84 {
85   double v = (double)pix.value * (1.0/255.0);
86   return TPixelD(v,v,v,v);
87 }
88 
89 //-----------------------------------------------------------------------------
90 
91 
92 
93 TPixelD DVAPI TPixelD::from(const TPixelGR16 &pix)
94 {
95   double v = (double)pix.value * (1.0/65535.0);
96   return TPixelD(v,v,v,v);
97 }
98 
99 */
100 //-----------------------------------------------------------------------------
101 
102 // TPixelGR8 TPixelGR8::from(const TPixelD &pix)
103 //{
104 //  return from(TPixel32::from(pix));
105 //}
106 
107 //-----------------------------------------------------------------------------
108 
from(const TPixel32 & pix)109 TPixelGR8 DVAPI TPixelGR8::from(const TPixel32 &pix) {
110   return TPixelGR8((((UINT)(pix.r) * 19594 + (UINT)(pix.g) * 38472 +
111                      (UINT)(pix.b) * 7470 + (UINT)(1 << 15)) >>
112                     16));
113 }
114 
115 //-----------------------------------------------------------------------------
from(const TPixel64 & pix)116 TPixelGR16 DVAPI TPixelGR16::from(const TPixel64 &pix) {
117   return TPixelGR16((((UINT)(pix.r) * 19594 + (UINT)(pix.g) * 38472 +
118                       (UINT)(pix.b) * 7470 + (UINT)(1 << 15)) >>
119                      16));
120 }
121 
122 //-----------------------------------------------------------------------------
123