7#include "core/fpdfapi/page/cpdf_transferfuncdib.h"
11#include "build/build_config.h"
12#include "core/fpdfapi/page/cpdf_transferfunc.h"
13#include "core/fpdfapi/parser/cpdf_dictionary.h"
14#include "core/fxge/calculate_pitch.h"
15#include "third_party/base/check.h"
17CPDF_TransferFuncDIB::CPDF_TransferFuncDIB(
19 RetainPtr<CPDF_TransferFunc> pTransferFunc)
20 : m_pSrc(std::move(pSrc)),
21 m_pTransferFunc(std::move(pTransferFunc)),
22 m_RampR(m_pTransferFunc->GetSamplesR()),
23 m_RampG(m_pTransferFunc->GetSamplesG()),
24 m_RampB(m_pTransferFunc->GetSamplesB()) {
25 m_Width = m_pSrc->GetWidth();
26 m_Height = m_pSrc->GetHeight();
29 m_Scanline.resize(m_Pitch);
30 DCHECK(m_palette.empty());
35FXDIB_Format CPDF_TransferFuncDIB::GetDestFormat()
const {
36 if (m_pSrc->IsMaskFormat())
39 if (m_pSrc->IsAlphaFormat())
45void CPDF_TransferFuncDIB::TranslateScanline(
46 pdfium::span<
const uint8_t> src_span)
const {
47 const uint8_t* src_buf = src_span.data();
49 switch (m_pSrc->GetFormat()) {
50 case FXDIB_Format::k1bppRgb: {
54 int r1 = m_RampR[255];
55 int g1 = m_RampG[255];
56 int b1 = m_RampB[255];
58 for (
int i = 0; i <
m_Width; i++) {
59 if (src_buf[i / 8] & (1 << (7 - i % 8))) {
60 m_Scanline[index++] = b1;
61 m_Scanline[index++] = g1;
62 m_Scanline[index++] = r1;
64 m_Scanline[index++] = b0;
65 m_Scanline[index++] = g0;
66 m_Scanline[index++] = r0;
68#if BUILDFLAG(IS_APPLE)
74 case FXDIB_Format::k1bppMask: {
76 int m1 = m_RampR[255];
78 for (
int i = 0; i <
m_Width; i++) {
79 if (src_buf[i / 8] & (1 << (7 - i % 8)))
80 m_Scanline[index++] = m1;
82 m_Scanline[index++] = m0;
86 case FXDIB_Format::k8bppRgb: {
87 pdfium::span<
const uint32_t> src_palette = m_pSrc->GetPaletteSpan();
89 for (
int i = 0; i <
m_Width; i++) {
90 if (m_pSrc->HasPalette()) {
91 FX_ARGB src_argb = src_palette[*src_buf];
92 m_Scanline[index++] = m_RampB[
FXARGB_R(src_argb)];
93 m_Scanline[index++] = m_RampG[
FXARGB_G(src_argb)];
94 m_Scanline[index++] = m_RampR[
FXARGB_B(src_argb)];
96 uint32_t src_byte = *src_buf;
97 m_Scanline[index++] = m_RampB[src_byte];
98 m_Scanline[index++] = m_RampG[src_byte];
99 m_Scanline[index++] = m_RampR[src_byte];
102#if BUILDFLAG(IS_APPLE)
108 case FXDIB_Format::k8bppMask: {
110 for (
int i = 0; i < m_Width; i++)
111 m_Scanline[index++] = m_RampR[*(src_buf++)];
114 case FXDIB_Format::kRgb: {
116 for (
int i = 0; i <
m_Width; i++) {
117 m_Scanline[index++] = m_RampB[*(src_buf++)];
118 m_Scanline[index++] = m_RampG[*(src_buf++)];
119 m_Scanline[index++] = m_RampR[*(src_buf++)];
120#if BUILDFLAG(IS_APPLE)
126 case FXDIB_Format::kRgb32:
129 case FXDIB_Format::kArgb: {
131 for (
int i = 0; i <
m_Width; i++) {
132 m_Scanline[index++] = m_RampB[*(src_buf++)];
133 m_Scanline[index++] = m_RampG[*(src_buf++)];
134 m_Scanline[index++] = m_RampR[*(src_buf++)];
136 m_Scanline[index++] = *src_buf;
137#if BUILDFLAG(IS_APPLE)
151pdfium::span<
const uint8_t> CPDF_TransferFuncDIB::
GetScanline(
int line)
const {
152 TranslateScanline(m_pSrc->GetScanline(line));
static constexpr FXDIB_Format kPlatformRGBFormat
pdfium::span< const uint8_t > GetScanline(int line) const override
~CPDF_TransferFuncDIB() override
int GetBppFromFormat(FXDIB_Format format)
uint32_t CalculatePitch32OrDie(int bpp, int width)