Index: src/core/SkBitmapFilter.cpp |
diff --git a/src/core/SkBitmapFilter.cpp b/src/core/SkBitmapFilter.cpp |
index 5128d9b5dc7a3843508db023dd0811b90ce1eea9..c607e6814b2fbb55b291b4f62c159d131cd38f48 100644 |
--- a/src/core/SkBitmapFilter.cpp |
+++ b/src/core/SkBitmapFilter.cpp |
@@ -22,9 +22,10 @@ |
// the image is rotated or has some other complex transformation applied. |
// Scaled images will usually be rescaled directly before rasterization. |
-void highQualityFilter(const SkBitmapProcState& s, int x, int y, |
- SkPMColor* SK_RESTRICT colors, int count) { |
+namespace { |
+template <typename Color, typename ColorPacker> |
+void highQualityFilter(ColorPacker pack, const SkBitmapProcState& s, int x, int y, Color* SK_RESTRICT colors, int count) { |
const int maxX = s.fBitmap->width() - 1; |
const int maxY = s.fBitmap->height() - 1; |
@@ -70,12 +71,27 @@ void highQualityFilter(const SkBitmapProcState& s, int x, int y, |
int g = SkClampMax(SkScalarRoundToInt(fg), a); |
int b = SkClampMax(SkScalarRoundToInt(fb), a); |
- *colors++ = SkPackARGB32(a, r, g, b); |
+ *colors++ = pack(a, r, g, b); |
x++; |
} |
} |
+uint16_t PackTo565(int /*a*/, int r, int g, int b) { |
+ return SkPack888ToRGB16(r, g, b); |
+} |
+ |
+} // namespace |
+ |
+void highQualityFilter32(const SkBitmapProcState& s, int x, int y, SkPMColor* SK_RESTRICT colors, int count) { |
+ highQualityFilter(&SkPackARGB32, s, x, y, colors, count); |
reed1
2013/08/26 13:51:27
Have we confirmed that SkPackARGB32 got inlined (s
|
+} |
+ |
+void highQualityFilter16(const SkBitmapProcState& s, int x, int y, uint16_t* SK_RESTRICT colors, int count) { |
+ highQualityFilter(&PackTo565, s, x, y, colors, count); |
+} |
+ |
+ |
SK_CONF_DECLARE(const char *, c_bitmapFilter, "bitmap.filter", "mitchell", "Which scanline bitmap filter to use [mitchell, lanczos, hamming, gaussian, triangle, box]"); |
SkBitmapFilter *SkBitmapFilter::Allocate() { |
@@ -98,34 +114,35 @@ SkBitmapFilter *SkBitmapFilter::Allocate() { |
return NULL; |
} |
-SkBitmapProcState::ShaderProc32 |
-SkBitmapProcState::chooseBitmapFilterProc() { |
- |
+bool SkBitmapProcState::setBitmapFilterProcs() { |
if (fFilterLevel != SkPaint::kHigh_FilterLevel) { |
- return NULL; |
+ return false; |
} |
if (fAlphaScale != 256) { |
- return NULL; |
+ return false; |
} |
// TODO: consider supporting other configs (e.g. 565, A8) |
if (fBitmap->config() != SkBitmap::kARGB_8888_Config) { |
- return NULL; |
+ return false; |
} |
// TODO: consider supporting repeat and mirror |
if (SkShader::kClamp_TileMode != fTileModeX || SkShader::kClamp_TileMode != fTileModeY) { |
- return NULL; |
+ return false; |
} |
+ // TODO: is this right? do we want fBitmapFilter allocated even if we can't set shader procs? |
if (fInvType & (SkMatrix::kAffine_Mask | SkMatrix::kScale_Mask)) { |
fBitmapFilter = SkBitmapFilter::Allocate(); |
} |
if (fInvType & SkMatrix::kScale_Mask) { |
- return highQualityFilter; |
+ fShaderProc32 = highQualityFilter32; |
+ fShaderProc16 = highQualityFilter16; |
+ return true; |
} else { |
- return NULL; |
+ return false; |
} |
} |