7#include "core/fpdfapi/page/cpdf_devicecs.h"
11#include "core/fpdfapi/parser/cpdf_array.h"
12#include "core/fpdfapi/parser/cpdf_dictionary.h"
13#include "core/fpdfapi/parser/cpdf_document.h"
14#include "core/fpdfapi/parser/cpdf_stream_acc.h"
15#include "core/fpdfapi/parser/cpdf_string.h"
16#include "core/fxcodec/fx_codec.h"
17#include "core/fxge/dib/cfx_cmyk_to_srgb.h"
18#include "third_party/base/check.h"
19#include "third_party/base/notreached.h"
23float NormalizeChannel(
float fVal) {
24 return std::clamp(fVal, 0.0f, 1.0f);
30 DCHECK(family == Family::kDeviceGray || family == Family::kDeviceRGB ||
31 family == Family::kDeviceCMYK);
38 const CPDF_Array* pArray,
39 std::set<
const CPDF_Object*>* pVisited) {
42 NOTREACHED_NORETURN();
45bool CPDF_DeviceCS::
GetRGB(pdfium::span<
const float> pBuf,
51 *R = NormalizeChannel(pBuf[0]);
56 *R = NormalizeChannel(pBuf[0]);
57 *G = NormalizeChannel(pBuf[1]);
58 *B = NormalizeChannel(pBuf[2]);
63 *R = 1.0f -
std::min(1.0f, pBuf[0] + k);
64 *G = 1.0f -
std::min(1.0f, pBuf[1] + k);
65 *B = 1.0f -
std::min(1.0f, pBuf[2] + k);
67 std::tie(*R, *G, *B) = AdobeCMYK_to_sRGB(
68 NormalizeChannel(pBuf[0]), NormalizeChannel(pBuf[1]),
69 NormalizeChannel(pBuf[2]), NormalizeChannel(pBuf[3]));
73 NOTREACHED_NORETURN();
78 pdfium::span<
const uint8_t> src_span,
82 bool bTransMask)
const {
83 uint8_t* pDestBuf = dest_span.data();
84 const uint8_t* pSrcBuf = src_span.data();
87 for (
int i = 0; i < pixels; i++) {
90 const uint8_t pix = pSrcBuf[i];
101 for (
int i = 0; i < pixels; i++) {
104 const uint8_t s0 = pSrcBuf[0];
105 const uint8_t s1 = pSrcBuf[1];
106 const uint8_t s2 = pSrcBuf[2];
107 const int k = 255 - pSrcBuf[3];
108 pDestBuf[0] = ((255 - s0) * k) / 255;
109 pDestBuf[1] = ((255 - s1) * k) / 255;
110 pDestBuf[2] = ((255 - s2) * k) / 255;
116 for (
int i = 0; i < pixels; i++) {
119 const uint8_t s0 = pSrcBuf[0];
120 const uint8_t s1 = pSrcBuf[1];
121 const uint8_t s2 = pSrcBuf[2];
122 const uint8_t k = pSrcBuf[3];
123 pDestBuf[2] = 255 -
std::min(255, s0 + k);
124 pDestBuf[1] = 255 -
std::min(255, s1 + k);
125 pDestBuf[0] = 255 -
std::min(255, s2 + k);
130 for (
int i = 0; i < pixels; i++) {
131 std::tie(pDestBuf[2], pDestBuf[1], pDestBuf[0]) =
132 AdobeCMYK_to_sRGB1(pSrcBuf[0], pSrcBuf[1], pSrcBuf[2],
141 NOTREACHED_NORETURN();
CPDF_ColorSpace(Family family)
static uint32_t ComponentsForFamily(Family family)
bool IsStdConversionEnabled() const
void SetComponentsForStockCS(uint32_t nComponents)
~CPDF_DeviceCS() override
void TranslateImageLine(pdfium::span< uint8_t > dest_span, pdfium::span< const uint8_t > src_span, int pixels, int image_width, int image_height, bool bTransMask) const override
uint32_t v_Load(CPDF_Document *pDoc, const CPDF_Array *pArray, std::set< const CPDF_Object * > *pVisited) override
bool GetRGB(pdfium::span< const float > pBuf, float *R, float *G, float *B) const override
void ReverseRGB(uint8_t *pDestBuf, const uint8_t *pSrcBuf, int pixels)