1 // Copyright 2014 The PDFium Authors
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 #include "core/fxge/dib/fx_dib.h"
8
9 #include <tuple>
10 #include <utility>
11
12 #include "build/build_config.h"
13
14 #if BUILDFLAG(IS_WIN)
15 #include <windows.h>
16 #endif
17
18 #if BUILDFLAG(IS_WIN)
19 static_assert(sizeof(FX_COLORREF) == sizeof(COLORREF),
20 "FX_COLORREF vs. COLORREF mismatch");
21 #endif
22
MakeRGBFormat(int bpp)23 FXDIB_Format MakeRGBFormat(int bpp) {
24 switch (bpp) {
25 case 1:
26 return FXDIB_Format::k1bppRgb;
27 case 8:
28 return FXDIB_Format::k8bppRgb;
29 case 24:
30 return FXDIB_Format::kRgb;
31 case 32:
32 return FXDIB_Format::kRgb32;
33 default:
34 return FXDIB_Format::kInvalid;
35 }
36 }
37
38 FXDIB_ResampleOptions::FXDIB_ResampleOptions() = default;
39
HasAnyOptions() const40 bool FXDIB_ResampleOptions::HasAnyOptions() const {
41 return bInterpolateBilinear || bHalftone || bNoSmoothing || bLossy;
42 }
43
ArgbDecode(FX_ARGB argb)44 std::tuple<int, int, int, int> ArgbDecode(FX_ARGB argb) {
45 return std::make_tuple(FXARGB_A(argb), FXARGB_R(argb), FXARGB_G(argb),
46 FXARGB_B(argb));
47 }
48
ArgbToAlphaAndColorRef(FX_ARGB argb)49 std::pair<int, FX_COLORREF> ArgbToAlphaAndColorRef(FX_ARGB argb) {
50 return {FXARGB_A(argb), ArgbToColorRef(argb)};
51 }
52
ArgbToColorRef(FX_ARGB argb)53 FX_COLORREF ArgbToColorRef(FX_ARGB argb) {
54 return FXSYS_BGR(FXARGB_B(argb), FXARGB_G(argb), FXARGB_R(argb));
55 }
56
AlphaAndColorRefToArgb(int a,FX_COLORREF colorref)57 FX_ARGB AlphaAndColorRefToArgb(int a, FX_COLORREF colorref) {
58 return ArgbEncode(a, FXSYS_GetRValue(colorref), FXSYS_GetGValue(colorref),
59 FXSYS_GetBValue(colorref));
60 }
61