• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FXGE_CFX_COLOR_H_
8 #define CORE_FXGE_CFX_COLOR_H_
9 
10 #include "core/fxge/fx_dib.h"
11 
12 struct CFX_Color {
13   // Ordered by increasing number of components.
14   enum Type { kTransparent = 0, kGray, kRGB, kCMYK };
15 
CFX_ColorCFX_Color16   explicit CFX_Color(FX_COLORREF ref)
17       : CFX_Color(FXARGB_R(ref), FXARGB_G(ref), FXARGB_B(ref)) {}
18 
19   CFX_Color(int32_t type = CFX_Color::kTransparent,
20             float color1 = 0.0f,
21             float color2 = 0.0f,
22             float color3 = 0.0f,
23             float color4 = 0.0f)
nColorTypeCFX_Color24       : nColorType(type),
25         fColor1(color1),
26         fColor2(color2),
27         fColor3(color3),
28         fColor4(color4) {}
29 
CFX_ColorCFX_Color30   CFX_Color(int32_t r, int32_t g, int32_t b)
31       : nColorType(CFX_Color::kRGB),
32         fColor1(r / 255.0f),
33         fColor2(g / 255.0f),
34         fColor3(b / 255.0f),
35         fColor4(0) {}
36 
37   CFX_Color(const CFX_Color&) = default;
38 
39   CFX_Color operator/(float fColorDivide) const;
40   CFX_Color operator-(float fColorSub) const;
41 
42   CFX_Color ConvertColorType(int32_t nConvertColorType) const;
43 
44   FX_COLORREF ToFXColor(int32_t nTransparency) const;
45 
ResetCFX_Color46   void Reset() {
47     nColorType = CFX_Color::kTransparent;
48     fColor1 = 0.0f;
49     fColor2 = 0.0f;
50     fColor3 = 0.0f;
51     fColor4 = 0.0f;
52   }
53 
54   int32_t nColorType;
55   float fColor1;
56   float fColor2;
57   float fColor3;
58   float fColor4;
59 };
60 
61 inline bool operator==(const CFX_Color& c1, const CFX_Color& c2) {
62   return c1.nColorType == c2.nColorType && c1.fColor1 - c2.fColor1 < 0.0001 &&
63          c1.fColor1 - c2.fColor1 > -0.0001 &&
64          c1.fColor2 - c2.fColor2 < 0.0001 &&
65          c1.fColor2 - c2.fColor2 > -0.0001 &&
66          c1.fColor3 - c2.fColor3 < 0.0001 &&
67          c1.fColor3 - c2.fColor3 > -0.0001 &&
68          c1.fColor4 - c2.fColor4 < 0.0001 && c1.fColor4 - c2.fColor4 > -0.0001;
69 }
70 
71 inline bool operator!=(const CFX_Color& c1, const CFX_Color& c2) {
72   return !(c1 == c2);
73 }
74 
75 #endif  // CORE_FXGE_CFX_COLOR_H_
76