summaryrefslogtreecommitdiff
path: root/core/fxge/ge/cfx_facecache.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-05-15 17:38:19 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-05-16 02:02:56 +0000
commit58854942e06d96972bf4722ab0a90249650d07e0 (patch)
treebb6a6697bbf59104e80e7e5b6d4914387e269819 /core/fxge/ge/cfx_facecache.cpp
parent0c7f94f7f36d0bd8b0bbd0d3d440a8953499d47a (diff)
downloadpdfium-58854942e06d96972bf4722ab0a90249650d07e0.tar.xz
Simplify ContrastAdjust().chromium/3102
Add a few constants in the process. Change-Id: Id69b939e4ea6a3de879e0a1f29d1453e95c838db Reviewed-on: https://pdfium-review.googlesource.com/5552 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxge/ge/cfx_facecache.cpp')
-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>();