SMIL  0.9.1
DColorConvert.h
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _D_COLOR_CONVERT_H
31 #define _D_COLOR_CONVERT_H
32 
33 #include "Core/include/private/DImage.hxx"
34 #include "Core/include/DColor.h"
35 
36 #include "NSTypes/RGB/include/DRGB.h"
37 
38 namespace smil
39 {
50  RES_T RGBToXYZ(const Image<RGB> &imRgbIn, Image<RGB> &imXyzOut);
51 
57  RES_T XYZToRGB(const Image<RGB> &imXyzIn, Image<RGB> &imRgbOut);
58 
64  RES_T XYZToLAB(const Image<RGB> &imXyzIn, Image<RGB> &imLabOut);
65 
71  RES_T LABToXYZ(const Image<RGB> &imLabIn, Image<RGB> &imXyzOut);
72 
78  RES_T RGBToHLS(const Image<RGB> &imRgbIn, Image<RGB> &imHlsOut);
79 
85  RES_T HLSToRGB(const Image<RGB> &imHlsIn, Image<RGB> &imRgbOut);
86 
92  RES_T RGBToHSV(const Image<RGB> &imRgbIn, Image<RGB> &imHlsOut);
93 
99  RES_T RGBToLAB(const Image<RGB> &imRgbIn, Image<RGB> &imLabOut);
100 
106  RES_T LABToRGB(const Image<RGB> &imLabIn, Image<RGB> &imRgbOut);
107 
113  template <class T>
114  RES_T RGBToLuminance(const Image<RGB> &imRgbIn, Image<T> &imLumOut)
115  {
116  ASSERT_ALLOCATED(&imRgbIn)
117  ASSERT_SAME_SIZE(&imRgbIn, &imLumOut)
118 
119  ImageFreezer freeze(imLumOut);
120 
121  ImDtTypes<UINT8>::lineType rArr = imRgbIn.getPixels().arrays[0];
122  ImDtTypes<UINT8>::lineType gArr = imRgbIn.getPixels().arrays[1];
123  ImDtTypes<UINT8>::lineType bArr = imRgbIn.getPixels().arrays[2];
124  typename ImDtTypes<T>::lineType outPixels = imLumOut.getPixels();
125 
126  size_t pixNbr = imRgbIn.getPixelCount();
127 
128  for (size_t i = 0; i < pixNbr; i++) {
129  outPixels[i] = T(0.2126 * rArr[i] + 0.7152 * gArr[i] + 0.0722 * bArr[i]);
130  }
131 
132  return RES_OK;
133  }
135 } // namespace smil
136 
137 #endif // _D_COLOR_CONVERT_H
RES_T RGBToXYZ(const Image< RGB > &imRgbIn, Image< RGB > &imXyzOut)
RGBToXYZ.
Definition: DColorConvert.cpp:36
Author Vincent Morard Date : 7 march 2011 See : Morard V. and Dokladal P. and Decenciere E...
Definition: DApplyThreshold.hpp:36
Definition: DBaseImage.h:235
RES_T LABToXYZ(const Image< RGB > &imLabIn, Image< RGB > &imXyzOut)
LABToXYZ.
Definition: DColorConvert.cpp:203
RES_T RGBToLAB(const Image< RGB > &imRgbIn, Image< RGB > &imLabOut)
RGBToLAB.
Definition: DColorConvert.cpp:561
RES_T RGBToLuminance(const Image< RGB > &imRgbIn, Image< T > &imLumOut)
RGBToLuminance.
Definition: DColorConvert.h:114
RES_T XYZToRGB(const Image< RGB > &imXyzIn, Image< RGB > &imRgbOut)
XYZToRGB.
Definition: DColorConvert.cpp:67
RES_T XYZToLAB(const Image< RGB > &imXyzIn, Image< RGB > &imLabOut)
XYZToLAB.
Definition: DColorConvert.cpp:156
RES_T RGBToHSV(const Image< RGB > &imRgbIn, Image< RGB > &imHlsOut)
RGBToHSV.
Definition: DColorConvert.cpp:399
RES_T HLSToRGB(const Image< RGB > &imHlsIn, Image< RGB > &imRgbOut)
HLSToRGB.
Definition: DColorConvert.cpp:434
RES_T LABToRGB(const Image< RGB > &imLabIn, Image< RGB > &imRgbOut)
LABToRGB.
Definition: DColorConvert.cpp:567
size_t getPixelCount() const
Get the number of pixels.
Definition: DBaseImage.h:150
Definition: DTypes.hpp:80
lineType getPixels() const
Get the pixels as a 1D array.
Definition: DImage.hpp:110
RES_T RGBToHLS(const Image< RGB > &imRgbIn, Image< RGB > &imHlsOut)
RGBToHLS.
Definition: DColorConvert.cpp:251