digiKam
Loading...
Searching...
No Matches
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 * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 * SPDX-FileCopyrightText: 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 *
14 * ============================================================ */
15
16#pragma once
17
18namespace Digikam
19{
20
27inline void DColor::setColor(uchar* const data, bool sixteenBit)
28{
29 m_sixteenBit = sixteenBit;
30
31 if (!sixteenBit) // 8 bits image
32 {
33 setBlue (data[0]);
34 setGreen(data[1]);
35 setRed (data[2]);
36 setAlpha(data[3]);
37 }
38 else // 16 bits image
39 {
40 unsigned short* data16 = reinterpret_cast<unsigned short*>(data);
41 setBlue (data16[0]);
42 setGreen(data16[1]);
43 setRed (data16[2]);
44 setAlpha(data16[3]);
45 }
46}
47
48inline void DColor::setPixel(uchar* const data) const
49{
50 if (sixteenBit()) // 16 bits image.
51 {
52 unsigned short* data16 = reinterpret_cast<unsigned short*>(data);
53 data16[0] = (unsigned short)blue();
54 data16[1] = (unsigned short)green();
55 data16[2] = (unsigned short)red();
56 data16[3] = (unsigned short)alpha();
57 }
58 else // 8 bits image.
59 {
60 data[0] = (uchar)blue();
61 data[1] = (uchar)green();
62 data[2] = (uchar)red();
63 data[3] = (uchar)alpha();
64 }
65}
66
67} // namespace Digikam
int green() const
Definition dcolor.h:89
void setGreen(int green)
Definition dcolor.h:114
void setAlpha(int alpha)
Definition dcolor.h:124
void setRed(int red)
Definition dcolor.h:109
bool sixteenBit() const
Definition dcolor.h:104
void setBlue(int blue)
Definition dcolor.h:119
int alpha() const
Definition dcolor.h:99
void setPixel(uchar *const data) const
Definition dcolorpixelaccess.h:48
int blue() const
Definition dcolor.h:94
void setColor(uchar *const data, bool sixteenBit=false)
Definition dcolorpixelaccess.h:27
int red() const
Definition dcolor.h:84
Definition datefolderview.cpp:34