chromium/third_party/pdfium/core/fxge/dib/fx_dib.h

// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_FXGE_DIB_FX_DIB_H_
#define CORE_FXGE_DIB_FX_DIB_H_

#include <stdint.h>

#include <utility>

#include "core/fxcrt/compiler_specific.h"

// Encoding:
// - Bits-per-pixel: value & 0xFF
// - Is mask: value & 0x100
// - Has alpha: value & 0x200
// - Is premultiplied-alpha: value & 0x400
enum class FXDIB_Format : uint16_t {};

// Endian-dependent (in theory).
FX_ARGB;  // A in high bits, ..., B in low bits.
FX_CMYK;  // C in high bits, ..., K in low bits.

// FX_COLORREF, like win32 COLORREF, is BGR. i.e. 0x00BBGGRR.
// Note that while the non-existent alpha component should be set to 0, some
// parts of the codebase use 0xFFFFFFFF as a sentinel value to indicate error.
FX_COLORREF;

// Endian-independent, name-ordered by increasing address.
template <typename T>
struct FX_RGB_STRUCT {};

template <typename T>
struct FX_BGR_STRUCT {};

template <typename T>
struct FX_ARGB_STRUCT {};

template <typename T>
struct FX_ABGR_STRUCT {};

template <typename T>
struct FX_RGBA_STRUCT {};

template <typename T>
struct FX_BGRA_STRUCT {};

template <typename T>
struct FX_CMYK_STRUCT {};

template <typename T>
struct FX_LAB_STRUCT {};

struct FXDIB_ResampleOptions {};

// See PDF 1.7 spec, table 7.2 and 7.3. The enum values need to be in the same
// order as listed in the spec.
enum class BlendMode {};

constexpr uint32_t FXSYS_BGR(uint8_t b, uint8_t g, uint8_t r) {}

constexpr uint8_t FXSYS_GetRValue(uint32_t bgr) {}

constexpr uint8_t FXSYS_GetGValue(uint32_t bgr) {}

constexpr uint8_t FXSYS_GetBValue(uint32_t bgr) {}

constexpr unsigned int FXSYS_GetUnsignedAlpha(float alpha) {}

// Bits per pixel, not bytes.
inline int GetBppFromFormat(FXDIB_Format format) {}

// AKA bytes per pixel, assuming 8-bits per component.
inline int GetCompsFromFormat(FXDIB_Format format) {}

inline bool GetIsMaskFromFormat(FXDIB_Format format) {}

inline bool GetIsAlphaFromFormat(FXDIB_Format format) {}

FX_BGRA_STRUCT<uint8_t> ArgbToBGRAStruct(FX_ARGB argb);

// Ignores alpha.
FX_BGR_STRUCT<uint8_t> ArgbToBGRStruct(FX_ARGB argb);

// Returns (a, FX_COLORREF)
std::pair<uint8_t, FX_COLORREF> ArgbToAlphaAndColorRef(FX_ARGB argb);

FX_COLORREF ArgbToColorRef(FX_ARGB argb);
FX_ARGB AlphaAndColorRefToArgb(int a, FX_COLORREF colorref);

constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b) {}

constexpr FX_CMYK CmykEncode(uint32_t c, uint32_t m, uint32_t y, uint32_t k) {}

#define FXARGB_A(argb)
#define FXARGB_R(argb)
#define FXARGB_G(argb)
#define FXARGB_B(argb)
#define FXARGB_MUL_ALPHA(argb, alpha)

#define FXRGB2GRAY(r, g, b)
#define FXDIB_ALPHA_MERGE(backdrop, source, source_alpha)

#define FXCMYK_TODIB(cmyk)
#define FXARGB_TOBGRORDERDIB(argb)

// SAFETY: Caller must ensure 4 valid bytes at `p`.
UNSAFE_BUFFER_USAGE inline FX_ARGB FXARGB_GetDIB(const uint8_t* p) {}

// SAFETY: Caller must ensure 4 valid bytes at `p`.
UNSAFE_BUFFER_USAGE inline void FXARGB_SetDIB(uint8_t* p, uint32_t argb) {}

// SAFETY: Caller must ensure 4 valid bytes at `p`.
UNSAFE_BUFFER_USAGE inline void FXARGB_SetRGBOrderDIB(uint8_t* p,
                                                      uint32_t argb) {}

// SAFETY: Caller must ensure 3 valid bytes at `dest` and `src`.
UNSAFE_BUFFER_USAGE inline void ReverseCopy3Bytes(uint8_t* dest,
                                                  const uint8_t* src) {}

#if defined(PDF_USE_SKIA)
template <typename T>
T PreMultiplyColor(const T& input) {}

template <typename T>
T UnPreMultiplyColor(const T& input) {}
#endif  // defined(PDF_USE_SKIA)

#endif  // CORE_FXGE_DIB_FX_DIB_H_