summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fxge/ge/cfx_facecache.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/core/fxge/ge/cfx_facecache.cpp b/core/fxge/ge/cfx_facecache.cpp
index 6d5e3d4355..9c79444dd3 100644
--- a/core/fxge/ge/cfx_facecache.cpp
+++ b/core/fxge/ge/cfx_facecache.cpp
@@ -35,44 +35,48 @@ namespace {
constexpr uint32_t kInvalidGlyphIndex = static_cast<uint32_t>(-1);
+constexpr int kMinPixel = 0;
+constexpr int kMaxPixel = 255;
+
+constexpr int kMaxGlyphDimension = 2048;
+
void ContrastAdjust(uint8_t* pDataIn,
uint8_t* pDataOut,
int nWidth,
int nHeight,
int nSrcRowBytes,
int nDstRowBytes) {
- int col, row, temp;
- int max = 0, min = 255;
- float rate;
- for (row = 0; row < nHeight; row++) {
+ int max = kMinPixel;
+ int min = kMaxPixel;
+ for (int row = 0; row < nHeight; row++) {
uint8_t* pRow = pDataIn + row * nSrcRowBytes;
- for (col = 0; col < nWidth; col++) {
- temp = *pRow++;
- max = std::max(temp, max);
- min = std::min(temp, min);
+ for (int col = 0; col < nWidth; col++) {
+ int val = pRow[col];
+ max = std::max(val, max);
+ min = std::min(val, min);
}
}
- temp = max - min;
- if (temp == 0 || temp == 255) {
+ int diff = max - min;
+ if (diff == kMinPixel || diff == kMaxPixel) {
int rowbytes = std::min(abs(nSrcRowBytes), nDstRowBytes);
- for (row = 0; row < nHeight; row++) {
+ for (int row = 0; row < nHeight; row++) {
memcpy(pDataOut + row * nDstRowBytes, pDataIn + row * nSrcRowBytes,
rowbytes);
}
return;
}
- rate = 255.f / temp;
- for (row = 0; row < nHeight; row++) {
+ float rate = 255.f / diff;
+ for (int row = 0; row < nHeight; row++) {
uint8_t* pSrcRow = pDataIn + row * nSrcRowBytes;
uint8_t* pDstRow = pDataOut + row * nDstRowBytes;
- for (col = 0; col < nWidth; col++) {
- temp = static_cast<int>((*(pSrcRow++) - min) * rate + 0.5);
- temp = std::min(temp, 255);
- temp = std::max(temp, 0);
- *pDstRow++ = (uint8_t)temp;
+ for (int col = 0; col < nWidth; col++) {
+ int val = static_cast<int>((pSrcRow[col] - min) * rate + 0.5);
+ pDstRow[col] =
+ static_cast<uint8_t>(pdfium::clamp(val, kMinPixel, kMaxPixel));
}
}
}
+
} // namespace
CFX_FaceCache::CFX_FaceCache(FXFT_Face face)
@@ -179,7 +183,7 @@ std::unique_ptr<CFX_GlyphBitmap> CFX_FaceCache::RenderGlyph(
return nullptr;
int bmwidth = FXFT_Get_Bitmap_Width(FXFT_Get_Glyph_Bitmap(m_Face));
int bmheight = FXFT_Get_Bitmap_Rows(FXFT_Get_Glyph_Bitmap(m_Face));
- if (bmwidth > 2048 || bmheight > 2048)
+ if (bmwidth > kMaxGlyphDimension || bmheight > kMaxGlyphDimension)
return nullptr;
int dib_width = bmwidth;
auto pGlyphBitmap = pdfium::MakeUnique<CFX_GlyphBitmap>();