digiKam
dcolorpixelaccess.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2005-03-02
7  * Description : methods to access on pixels color
8  *
9  * Copyright (C) 2005-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_DCOLOR_PIXEL_ACCESS_H
26 #define DIGIKAM_DCOLOR_PIXEL_ACCESS_H
27 
28 namespace Digikam
29 {
30 
37 inline void DColor::setColor(uchar* const data, bool sixteenBit)
38 {
39  m_sixteenBit = sixteenBit;
40 
41  if (!sixteenBit) // 8 bits image
42  {
43  setBlue (data[0]);
44  setGreen(data[1]);
45  setRed (data[2]);
46  setAlpha(data[3]);
47  }
48  else // 16 bits image
49  {
50  unsigned short* data16 = reinterpret_cast<unsigned short*>(data);
51  setBlue (data16[0]);
52  setGreen(data16[1]);
53  setRed (data16[2]);
54  setAlpha(data16[3]);
55  }
56 }
57 
58 inline void DColor::setPixel(uchar* const data) const
59 {
60  if (sixteenBit()) // 16 bits image.
61  {
62  unsigned short* data16 = reinterpret_cast<unsigned short*>(data);
63  data16[0] = (unsigned short)blue();
64  data16[1] = (unsigned short)green();
65  data16[2] = (unsigned short)red();
66  data16[3] = (unsigned short)alpha();
67  }
68  else // 8 bits image.
69  {
70  data[0] = (uchar)blue();
71  data[1] = (uchar)green();
72  data[2] = (uchar)red();
73  data[3] = (uchar)alpha();
74  }
75 }
76 
77 } // namespace Digikam
78 
79 #endif // DIGIKAM_DCOLOR_PIXEL_ACCESS_H
int green() const
Definition: dcolor.h:106
void setGreen(int green)
Definition: dcolor.h:131
void setAlpha(int alpha)
Definition: dcolor.h:141
void setRed(int red)
Definition: dcolor.h:126
bool sixteenBit() const
Definition: dcolor.h:121
void setBlue(int blue)
Definition: dcolor.h:136
int alpha() const
Definition: dcolor.h:116
void setPixel(uchar *const data) const
Definition: dcolorpixelaccess.h:58
int blue() const
Definition: dcolor.h:111
void setColor(uchar *const data, bool sixteenBit=false)
Definition: dcolorpixelaccess.h:37
int red() const
Definition: dcolor.h:101
Definition: datefolderview.cpp:43