• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <type_traits>
11 #include <utility>
12 
13 #include "build/build_config.h"
14 
15 #if BUILDFLAG(IS_WIN)
16 #include <windows.h>
17 #endif
18 
19 #if BUILDFLAG(IS_WIN)
20 static_assert(sizeof(FX_COLORREF) == sizeof(COLORREF),
21               "FX_COLORREF vs. COLORREF mismatch");
22 #endif
23 
24 // Assert that FX_*_STRUCTS are packed.
25 static_assert(sizeof(FX_RGB_STRUCT<uint8_t>) == 3u);
26 static_assert(sizeof(FX_BGR_STRUCT<uint8_t>) == 3u);
27 static_assert(sizeof(FX_ARGB_STRUCT<uint8_t>) == 4u);
28 static_assert(sizeof(FX_ABGR_STRUCT<uint8_t>) == 4u);
29 static_assert(sizeof(FX_RGBA_STRUCT<uint8_t>) == 4u);
30 static_assert(sizeof(FX_BGRA_STRUCT<uint8_t>) == 4u);
31 static_assert(sizeof(FX_CMYK_STRUCT<uint8_t>) == 4u);
32 
33 // Assert that FX_*_STRUCTS remain aggregates.
34 static_assert(std::is_aggregate_v<FX_RGB_STRUCT<float>>);
35 static_assert(std::is_aggregate_v<FX_BGR_STRUCT<float>>);
36 static_assert(std::is_aggregate_v<FX_ARGB_STRUCT<float>>);
37 static_assert(std::is_aggregate_v<FX_ABGR_STRUCT<float>>);
38 static_assert(std::is_aggregate_v<FX_RGBA_STRUCT<float>>);
39 static_assert(std::is_aggregate_v<FX_BGRA_STRUCT<float>>);
40 static_assert(std::is_aggregate_v<FX_CMYK_STRUCT<float>>);
41 
42 FXDIB_ResampleOptions::FXDIB_ResampleOptions() = default;
43 
HasAnyOptions() const44 bool FXDIB_ResampleOptions::HasAnyOptions() const {
45   return bInterpolateBilinear || bHalftone || bNoSmoothing || bLossy;
46 }
47 
ArgbToBGRAStruct(FX_ARGB argb)48 FX_BGRA_STRUCT<uint8_t> ArgbToBGRAStruct(FX_ARGB argb) {
49   return {FXARGB_B(argb), FXARGB_G(argb), FXARGB_R(argb), FXARGB_A(argb)};
50 }
51 
ArgbToBGRStruct(FX_ARGB argb)52 FX_BGR_STRUCT<uint8_t> ArgbToBGRStruct(FX_ARGB argb) {
53   return {FXARGB_B(argb), FXARGB_G(argb), FXARGB_R(argb)};
54 }
55 
ArgbToAlphaAndColorRef(FX_ARGB argb)56 std::pair<uint8_t, FX_COLORREF> ArgbToAlphaAndColorRef(FX_ARGB argb) {
57   return {FXARGB_A(argb), ArgbToColorRef(argb)};
58 }
59 
ArgbToColorRef(FX_ARGB argb)60 FX_COLORREF ArgbToColorRef(FX_ARGB argb) {
61   return FXSYS_BGR(FXARGB_B(argb), FXARGB_G(argb), FXARGB_R(argb));
62 }
63 
AlphaAndColorRefToArgb(int a,FX_COLORREF colorref)64 FX_ARGB AlphaAndColorRefToArgb(int a, FX_COLORREF colorref) {
65   return ArgbEncode(a, FXSYS_GetRValue(colorref), FXSYS_GetGValue(colorref),
66                     FXSYS_GetBValue(colorref));
67 }
68