summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/page/cpdf_colorspace.cpp91
-rw-r--r--core/fxcrt/fx_basic.h61
-rw-r--r--core/fxcrt/fx_basic_util.cpp26
3 files changed, 83 insertions, 95 deletions
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index cc4afa55c9..3244319cc2 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -7,6 +7,7 @@
#include "core/fpdfapi/page/cpdf_colorspace.h"
#include <algorithm>
+#include <limits>
#include <memory>
#include <utility>
@@ -227,6 +228,76 @@ class CPDF_DeviceNCS : public CPDF_ColorSpace {
std::unique_ptr<CPDF_Function> m_pFunc;
};
+class Vector_3by1 {
+ public:
+ Vector_3by1() : a(0.0f), b(0.0f), c(0.0f) {}
+
+ Vector_3by1(float a1, float b1, float c1) : a(a1), b(b1), c(c1) {}
+
+ float a;
+ float b;
+ float c;
+};
+
+class Matrix_3by3 {
+ public:
+ Matrix_3by3()
+ : a(0.0f),
+ b(0.0f),
+ c(0.0f),
+ d(0.0f),
+ e(0.0f),
+ f(0.0f),
+ g(0.0f),
+ h(0.0f),
+ i(0.0f) {}
+
+ Matrix_3by3(float a1,
+ float b1,
+ float c1,
+ float d1,
+ float e1,
+ float f1,
+ float g1,
+ float h1,
+ float i1)
+ : a(a1), b(b1), c(c1), d(d1), e(e1), f(f1), g(g1), h(h1), i(i1) {}
+
+ Matrix_3by3 Inverse() {
+ float det = a * (e * i - f * h) - b * (i * d - f * g) + c * (d * h - e * g);
+ if (FXSYS_fabs(det) < std::numeric_limits<float>::epsilon())
+ return Matrix_3by3();
+
+ return Matrix_3by3(
+ (e * i - f * h) / det, -(b * i - c * h) / det, (b * f - c * e) / det,
+ -(d * i - f * g) / det, (a * i - c * g) / det, -(a * f - c * d) / det,
+ (d * h - e * g) / det, -(a * h - b * g) / det, (a * e - b * d) / det);
+ }
+
+ Matrix_3by3 Multiply(const Matrix_3by3& m) {
+ return Matrix_3by3(a * m.a + b * m.d + c * m.g, a * m.b + b * m.e + c * m.h,
+ a * m.c + b * m.f + c * m.i, d * m.a + e * m.d + f * m.g,
+ d * m.b + e * m.e + f * m.h, d * m.c + e * m.f + f * m.i,
+ g * m.a + h * m.d + i * m.g, g * m.b + h * m.e + i * m.h,
+ g * m.c + h * m.f + i * m.i);
+ }
+
+ Vector_3by1 TransformVector(const Vector_3by1& v) {
+ return Vector_3by1(a * v.a + b * v.b + c * v.c, d * v.a + e * v.b + f * v.c,
+ g * v.a + h * v.b + i * v.c);
+ }
+
+ float a;
+ float b;
+ float c;
+ float d;
+ float e;
+ float f;
+ float g;
+ float h;
+ float i;
+};
+
float RGB_Conversion(float colorComponent) {
colorComponent = pdfium::clamp(colorComponent, 0.0f, 1.0f);
int scale = std::max(static_cast<int>(colorComponent * 1023), 0);
@@ -260,16 +331,16 @@ void XYZ_to_sRGB_WhitePoint(float X,
float Rx = 0.64f, Ry = 0.33f;
float Gx = 0.30f, Gy = 0.60f;
float Bx = 0.15f, By = 0.06f;
- CFX_Matrix_3by3 RGB_xyz(Rx, Gx, Bx, Ry, Gy, By, 1 - Rx - Ry, 1 - Gx - Gy,
- 1 - Bx - By);
- CFX_Vector_3by1 whitePoint(Xw, Yw, Zw);
- CFX_Vector_3by1 XYZ(X, Y, Z);
-
- CFX_Vector_3by1 RGB_Sum_XYZ = RGB_xyz.Inverse().TransformVector(whitePoint);
- CFX_Matrix_3by3 RGB_SUM_XYZ_DIAG(RGB_Sum_XYZ.a, 0, 0, 0, RGB_Sum_XYZ.b, 0, 0,
- 0, RGB_Sum_XYZ.c);
- CFX_Matrix_3by3 M = RGB_xyz.Multiply(RGB_SUM_XYZ_DIAG);
- CFX_Vector_3by1 RGB = M.Inverse().TransformVector(XYZ);
+ Matrix_3by3 RGB_xyz(Rx, Gx, Bx, Ry, Gy, By, 1 - Rx - Ry, 1 - Gx - Gy,
+ 1 - Bx - By);
+ Vector_3by1 whitePoint(Xw, Yw, Zw);
+ Vector_3by1 XYZ(X, Y, Z);
+
+ Vector_3by1 RGB_Sum_XYZ = RGB_xyz.Inverse().TransformVector(whitePoint);
+ Matrix_3by3 RGB_SUM_XYZ_DIAG(RGB_Sum_XYZ.a, 0, 0, 0, RGB_Sum_XYZ.b, 0, 0, 0,
+ RGB_Sum_XYZ.c);
+ Matrix_3by3 M = RGB_xyz.Multiply(RGB_SUM_XYZ_DIAG);
+ Vector_3by1 RGB = M.Inverse().TransformVector(XYZ);
*R = RGB_Conversion(RGB.a);
*G = RGB_Conversion(RGB.b);
diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h
index ee630e100d..076766a0a2 100644
--- a/core/fxcrt/fx_basic.h
+++ b/core/fxcrt/fx_basic.h
@@ -338,18 +338,12 @@ class CFX_BitStream {
public:
void Init(const uint8_t* pData, uint32_t dwSize);
- uint32_t GetBits(uint32_t nBits);
-
void ByteAlign();
-
- bool IsEOF() { return m_BitPos >= m_BitSize; }
-
+ bool IsEOF() const { return m_BitPos >= m_BitSize; }
+ uint32_t GetBits(uint32_t nBits);
void SkipBits(uint32_t nBits) { m_BitPos += nBits; }
-
void Rewind() { m_BitPos = 0; }
-
uint32_t GetPos() const { return m_BitPos; }
-
uint32_t BitsRemaining() const {
return m_BitSize >= m_BitPos ? m_BitSize - m_BitPos : 0;
}
@@ -378,57 +372,6 @@ class CFX_AutoRestorer {
const T m_OldValue;
};
-class CFX_Vector_3by1 {
- public:
- CFX_Vector_3by1() : a(0.0f), b(0.0f), c(0.0f) {}
-
- CFX_Vector_3by1(float a1, float b1, float c1) : a(a1), b(b1), c(c1) {}
-
- float a;
- float b;
- float c;
-};
-class CFX_Matrix_3by3 {
- public:
- CFX_Matrix_3by3()
- : a(0.0f),
- b(0.0f),
- c(0.0f),
- d(0.0f),
- e(0.0f),
- f(0.0f),
- g(0.0f),
- h(0.0f),
- i(0.0f) {}
-
- CFX_Matrix_3by3(float a1,
- float b1,
- float c1,
- float d1,
- float e1,
- float f1,
- float g1,
- float h1,
- float i1)
- : a(a1), b(b1), c(c1), d(d1), e(e1), f(f1), g(g1), h(h1), i(i1) {}
-
- CFX_Matrix_3by3 Inverse();
-
- CFX_Matrix_3by3 Multiply(const CFX_Matrix_3by3& m);
-
- CFX_Vector_3by1 TransformVector(const CFX_Vector_3by1& v);
-
- float a;
- float b;
- float c;
- float d;
- float e;
- float f;
- float g;
- float h;
- float i;
-};
-
uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits);
#endif // CORE_FXCRT_FX_BASIC_H_
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
index b3c5829fc9..19e5696c86 100644
--- a/core/fxcrt/fx_basic_util.cpp
+++ b/core/fxcrt/fx_basic_util.cpp
@@ -205,32 +205,6 @@ wchar_t FX_GetFolderSeparator() {
#endif
}
-CFX_Matrix_3by3 CFX_Matrix_3by3::Inverse() {
- float det = a * (e * i - f * h) - b * (i * d - f * g) + c * (d * h - e * g);
- if (FXSYS_fabs(det) < 0.0000001)
- return CFX_Matrix_3by3();
-
- return CFX_Matrix_3by3(
- (e * i - f * h) / det, -(b * i - c * h) / det, (b * f - c * e) / det,
- -(d * i - f * g) / det, (a * i - c * g) / det, -(a * f - c * d) / det,
- (d * h - e * g) / det, -(a * h - b * g) / det, (a * e - b * d) / det);
-}
-
-CFX_Matrix_3by3 CFX_Matrix_3by3::Multiply(const CFX_Matrix_3by3& m) {
- return CFX_Matrix_3by3(
- a * m.a + b * m.d + c * m.g, a * m.b + b * m.e + c * m.h,
- a * m.c + b * m.f + c * m.i, d * m.a + e * m.d + f * m.g,
- d * m.b + e * m.e + f * m.h, d * m.c + e * m.f + f * m.i,
- g * m.a + h * m.d + i * m.g, g * m.b + h * m.e + i * m.h,
- g * m.c + h * m.f + i * m.i);
-}
-
-CFX_Vector_3by1 CFX_Matrix_3by3::TransformVector(const CFX_Vector_3by1& v) {
- return CFX_Vector_3by1(a * v.a + b * v.b + c * v.c,
- d * v.a + e * v.b + f * v.c,
- g * v.a + h * v.b + i * v.c);
-}
-
uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) {
ASSERT(0 < nbits && nbits <= 32);
const uint8_t* dataPtr = &pData[bitpos / 8];