Home | History | Annotate | Download | only in fxge
      1 // Copyright 2014 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_FX_DIB_H_
      8 #define CORE_FXGE_FX_DIB_H_
      9 
     10 #include <tuple>
     11 #include <utility>
     12 
     13 #include "core/fxcrt/fx_coordinates.h"
     14 #include "core/fxcrt/widestring.h"
     15 
     16 enum FXDIB_Format {
     17   FXDIB_Invalid = 0,
     18   FXDIB_1bppRgb = 0x001,
     19   FXDIB_8bppRgb = 0x008,
     20   FXDIB_Rgb = 0x018,
     21   FXDIB_Rgb32 = 0x020,
     22   FXDIB_1bppMask = 0x101,
     23   FXDIB_8bppMask = 0x108,
     24   FXDIB_8bppRgba = 0x208,
     25   FXDIB_Rgba = 0x218,
     26   FXDIB_Argb = 0x220,
     27   FXDIB_1bppCmyk = 0x401,
     28   FXDIB_8bppCmyk = 0x408,
     29   FXDIB_Cmyk = 0x420,
     30   FXDIB_8bppCmyka = 0x608,
     31   FXDIB_Cmyka = 0x620,
     32 };
     33 
     34 struct PixelWeight {
     35   int m_SrcStart;
     36   int m_SrcEnd;
     37   int m_Weights[1];
     38 };
     39 
     40 typedef uint32_t FX_ARGB;
     41 typedef uint32_t FX_COLORREF;
     42 typedef uint32_t FX_CMYK;
     43 class CFX_ClipRgn;
     44 class CFX_DIBSource;
     45 class CStretchEngine;
     46 
     47 extern const int16_t SDP_Table[513];
     48 
     49 #define FXDIB_DOWNSAMPLE 0x04
     50 #define FXDIB_INTERPOL 0x20
     51 #define FXDIB_BICUBIC_INTERPOL 0x80
     52 #define FXDIB_NOSMOOTH 0x100
     53 
     54 #define FXDIB_BLEND_NORMAL 0
     55 #define FXDIB_BLEND_MULTIPLY 1
     56 #define FXDIB_BLEND_SCREEN 2
     57 #define FXDIB_BLEND_OVERLAY 3
     58 #define FXDIB_BLEND_DARKEN 4
     59 #define FXDIB_BLEND_LIGHTEN 5
     60 #define FXDIB_BLEND_COLORDODGE 6
     61 #define FXDIB_BLEND_COLORBURN 7
     62 #define FXDIB_BLEND_HARDLIGHT 8
     63 #define FXDIB_BLEND_SOFTLIGHT 9
     64 #define FXDIB_BLEND_DIFFERENCE 10
     65 #define FXDIB_BLEND_EXCLUSION 11
     66 #define FXDIB_BLEND_NONSEPARABLE 21
     67 #define FXDIB_BLEND_HUE 21
     68 #define FXDIB_BLEND_SATURATION 22
     69 #define FXDIB_BLEND_COLOR 23
     70 #define FXDIB_BLEND_LUMINOSITY 24
     71 #define FXDIB_BLEND_UNSUPPORTED -1
     72 
     73 #define FXSYS_RGB(r, g, b) ((r) | ((g) << 8) | ((b) << 16))
     74 #define FXSYS_GetRValue(rgb) ((rgb)&0xff)
     75 #define FXSYS_GetGValue(rgb) (((rgb) >> 8) & 0xff)
     76 #define FXSYS_GetBValue(rgb) (((rgb) >> 16) & 0xff)
     77 
     78 #define FXSYS_GetCValue(cmyk) ((uint8_t)((cmyk) >> 24) & 0xff)
     79 #define FXSYS_GetMValue(cmyk) ((uint8_t)((cmyk) >> 16) & 0xff)
     80 #define FXSYS_GetYValue(cmyk) ((uint8_t)((cmyk) >> 8) & 0xff)
     81 #define FXSYS_GetKValue(cmyk) ((uint8_t)(cmyk)&0xff)
     82 
     83 inline FX_CMYK CmykEncode(int c, int m, int y, int k) {
     84   return (c << 24) | (m << 16) | (y << 8) | k;
     85 }
     86 
     87 // Returns tuple a, r, g, b
     88 std::tuple<int, int, int, int> ArgbDecode(FX_ARGB argb);
     89 
     90 // Returns pair a, rgb
     91 std::pair<int, FX_COLORREF> ArgbToColorRef(FX_ARGB argb);
     92 
     93 inline FX_ARGB ArgbEncode(int a, int r, int g, int b) {
     94   return (a << 24) | (r << 16) | (g << 8) | b;
     95 }
     96 FX_ARGB ArgbEncode(int a, FX_COLORREF rgb);
     97 
     98 FX_ARGB StringToFXARGB(const WideStringView& view);
     99 
    100 #define FXARGB_A(argb) ((uint8_t)((argb) >> 24))
    101 #define FXARGB_R(argb) ((uint8_t)((argb) >> 16))
    102 #define FXARGB_G(argb) ((uint8_t)((argb) >> 8))
    103 #define FXARGB_B(argb) ((uint8_t)(argb))
    104 #define FXARGB_MAKE(a, r, g, b) \
    105   (((uint32_t)(a) << 24) | ((r) << 16) | ((g) << 8) | (b))
    106 #define FXARGB_MUL_ALPHA(argb, alpha) \
    107   (((((argb) >> 24) * (alpha) / 255) << 24) | ((argb)&0xffffff))
    108 
    109 #define FXRGB2GRAY(r, g, b) (((b)*11 + (g)*59 + (r)*30) / 100)
    110 #define FXDIB_ALPHA_MERGE(backdrop, source, source_alpha) \
    111   (((backdrop) * (255 - (source_alpha)) + (source) * (source_alpha)) / 255)
    112 #define FXARGB_GETDIB(p)                              \
    113   ((((uint8_t*)(p))[0]) | (((uint8_t*)(p))[1] << 8) | \
    114    (((uint8_t*)(p))[2] << 16) | (((uint8_t*)(p))[3] << 24))
    115 #define FXARGB_SETDIB(p, argb)                  \
    116   ((uint8_t*)(p))[0] = (uint8_t)(argb),         \
    117   ((uint8_t*)(p))[1] = (uint8_t)((argb) >> 8),  \
    118   ((uint8_t*)(p))[2] = (uint8_t)((argb) >> 16), \
    119   ((uint8_t*)(p))[3] = (uint8_t)((argb) >> 24)
    120 #define FXARGB_SETRGBORDERDIB(p, argb)          \
    121   ((uint8_t*)(p))[3] = (uint8_t)(argb >> 24),   \
    122   ((uint8_t*)(p))[0] = (uint8_t)((argb) >> 16), \
    123   ((uint8_t*)(p))[1] = (uint8_t)((argb) >> 8),  \
    124   ((uint8_t*)(p))[2] = (uint8_t)(argb)
    125 #define FXARGB_TODIB(argb) (argb)
    126 #define FXCMYK_TODIB(cmyk)                                    \
    127   ((uint8_t)((cmyk) >> 24) | ((uint8_t)((cmyk) >> 16)) << 8 | \
    128    ((uint8_t)((cmyk) >> 8)) << 16 | ((uint8_t)(cmyk) << 24))
    129 #define FXARGB_TOBGRORDERDIB(argb)                       \
    130   ((uint8_t)(argb >> 16) | ((uint8_t)(argb >> 8)) << 8 | \
    131    ((uint8_t)(argb)) << 16 | ((uint8_t)(argb >> 24) << 24))
    132 
    133 FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
    134                           int width,
    135                           int height,
    136                           bool bFlipX,
    137                           bool bFlipY);
    138 
    139 #endif  // CORE_FXGE_FX_DIB_H_
    140