diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-08-26 18:09:58 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-08-26 18:09:58 +0000 |
commit | 2a4d1ff189ef8df14ec40499125b01f406cb442b (patch) | |
tree | 53ca454944be9399be54cdd64c8a7a265cea0a13 /src | |
parent | ff3e92d2f83521fd9be32f66c4bbff2e30bd7a00 (diff) |
allow the gamma to be changed at runtime
git-svn-id: http://skia.googlecode.com/svn/trunk@338 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/ports/SkFontHost_gamma.cpp | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/ports/SkFontHost_gamma.cpp b/src/ports/SkFontHost_gamma.cpp index 0b95bce1d6..3aecc43126 100644 --- a/src/ports/SkFontHost_gamma.cpp +++ b/src/ports/SkFontHost_gamma.cpp @@ -4,7 +4,7 @@ // define this to use pre-compiled tables for gamma. This is slightly faster, // and doesn't create any RW global memory, but means we cannot change the // gamma at runtime. -#define USE_PREDEFINED_GAMMA_TABLES +//#define USE_PREDEFINED_GAMMA_TABLES #ifndef USE_PREDEFINED_GAMMA_TABLES // define this if you want to spew out the "C" code for the tables, given @@ -14,21 +14,22 @@ /////////////////////////////////////////////////////////////////////////////// +#include "SkGraphics.h" + +// declared here, so we can link against it elsewhere +void skia_set_text_gamma(float blackGamma, float whiteGamma); + #ifdef USE_PREDEFINED_GAMMA_TABLES #include "sk_predefined_gamma.h" -#else // use writable globals for gamma tables +void skia_set_text_gamma(float blackGamma, float whiteGamma) {} -static bool gGammaIsBuilt; -static uint8_t gBlackGamma[256], gWhiteGamma[256]; - -#define SK_BLACK_GAMMA (1.4f) -#define SK_WHITE_GAMMA (1/1.4f) +#else // use writable globals for gamma tables static void build_power_table(uint8_t table[], float ee) { - // printf("------ build_power_table %g\n", ee); + SkDebugf("------ build_power_table %g\n", ee); for (int i = 0; i < 256; i++) { float x = i / 255.f; @@ -41,6 +42,21 @@ static void build_power_table(uint8_t table[], float ee) } } +static bool gGammaIsBuilt; +static uint8_t gBlackGamma[256], gWhiteGamma[256]; + +static float gBlackGammaCoeff = 1.4f; +static float gWhiteGammaCoeff = 1/1.4f; + +void skia_set_text_gamma(float blackGamma, float whiteGamma) { + gBlackGammaCoeff = blackGamma; + gWhiteGammaCoeff = whiteGamma; + gGammaIsBuilt = false; + SkGraphics::SetFontCacheUsed(0); + build_power_table(gBlackGamma, gBlackGammaCoeff); + build_power_table(gWhiteGamma, gWhiteGammaCoeff); +} + #ifdef DUMP_GAMMA_TABLES #include "SkString.h" @@ -72,13 +88,13 @@ void SkFontHost::GetGammaTables(const uint8_t* tables[2]) #ifndef USE_PREDEFINED_GAMMA_TABLES if (!gGammaIsBuilt) { - build_power_table(gBlackGamma, SK_BLACK_GAMMA); - build_power_table(gWhiteGamma, SK_WHITE_GAMMA); + build_power_table(gBlackGamma, gBlackGammaCoeff); + build_power_table(gWhiteGamma, gWhiteGammaCoeff); gGammaIsBuilt = true; #ifdef DUMP_GAMMA_TABLES - dump_a_table("gBlackGamma", gBlackGamma, SK_BLACK_GAMMA); - dump_a_table("gWhiteGamma", gWhiteGamma, SK_WHITE_GAMMA); + dump_a_table("gBlackGamma", gBlackGamma, gBlackGammaCoeff); + dump_a_table("gWhiteGamma", gWhiteGamma, gWhiteGammaCoeff); #endif } #endif |