summaryrefslogtreecommitdiffstats
path: root/skia/ports/SkFontHost_gamma.cpp
diff options
context:
space:
mode:
authorinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-27 00:09:42 +0000
committerinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-27 00:09:42 +0000
commitae2c20f398933a9e86c387dcc465ec0f71065ffc (patch)
treede668b1411e2ee0b4e49b6d8f8b68183134ac990 /skia/ports/SkFontHost_gamma.cpp
parent09911bf300f1a419907a9412154760efd0b7abc3 (diff)
downloadchromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.zip
chromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.tar.gz
chromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.tar.bz2
Add skia to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ports/SkFontHost_gamma.cpp')
-rw-r--r--skia/ports/SkFontHost_gamma.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/skia/ports/SkFontHost_gamma.cpp b/skia/ports/SkFontHost_gamma.cpp
new file mode 100644
index 0000000..28c7051
--- /dev/null
+++ b/skia/ports/SkFontHost_gamma.cpp
@@ -0,0 +1,65 @@
+
+#include "SkFontHost.h"
+#include <math.h>
+
+static void build_power_table(uint8_t table[], float ee)
+{
+// printf("------ build_power_table %g\n", ee);
+ for (int i = 0; i < 256; i++)
+ {
+ float x = i / 255.f;
+ // printf(" %d %g", i, x);
+ x = powf(x, ee);
+ // printf(" %g", x);
+ int xx = SkScalarRound(SkFloatToScalar(x * 255));
+ // printf(" %d\n", xx);
+ table[i] = SkToU8(xx);
+ }
+}
+
+static bool gGammaIsBuilt;
+static uint8_t gBlackGamma[256], gWhiteGamma[256];
+
+#define ANDROID_BLACK_GAMMA (1.4f)
+#define ANDROID_WHITE_GAMMA (1/1.4f)
+
+void SkFontHost::GetGammaTables(const uint8_t* tables[2])
+{
+ // would be cleaner if these tables were precomputed and just linked in
+ if (!gGammaIsBuilt)
+ {
+ build_power_table(gBlackGamma, ANDROID_BLACK_GAMMA);
+ build_power_table(gWhiteGamma, ANDROID_WHITE_GAMMA);
+ gGammaIsBuilt = true;
+ }
+ tables[0] = gBlackGamma;
+ tables[1] = gWhiteGamma;
+}
+
+#define BLACK_GAMMA_THRESHOLD 0x40
+#define WHITE_GAMMA_THRESHOLD 0xC0
+
+int SkFontHost::ComputeGammaFlag(const SkPaint& paint)
+{
+ if (paint.getShader() == NULL)
+ {
+ SkColor c = paint.getColor();
+ int r = SkColorGetR(c);
+ int g = SkColorGetG(c);
+ int b = SkColorGetB(c);
+ int luminance = (r * 2 + g * 5 + b) >> 3;
+
+ if (luminance <= BLACK_GAMMA_THRESHOLD)
+ {
+ // printf("------ black gamma for [%d %d %d]\n", r, g, b);
+ return SkScalerContext::kGammaForBlack_Flag;
+ }
+ if (luminance >= WHITE_GAMMA_THRESHOLD)
+ {
+ // printf("------ white gamma for [%d %d %d]\n", r, g, b);
+ return SkScalerContext::kGammaForWhite_Flag;
+ }
+ }
+ return 0;
+}
+