reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame^] | 1 | /* libs/graphics/sgl/SkBitmapSamplerTemplate.h |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | /* this guy is pulled in multiple times, with the following symbols defined each time: |
| 19 | |
| 20 | #define BITMAP_CLASSNAME_PREFIX(name) ARGB32##name |
| 21 | #defube BITMAP_PIXEL_TO_PMCOLOR(bitmap, x, y) *bitmap.getAddr32(x, y) |
| 22 | */ |
| 23 | |
| 24 | class BITMAP_CLASSNAME_PREFIX(_Point_Sampler) : public SkBitmapSampler { |
| 25 | public: |
| 26 | BITMAP_CLASSNAME_PREFIX(_Point_Sampler)(const SkBitmap& bm, SkShader::TileMode tmx, SkShader::TileMode tmy) |
| 27 | : SkBitmapSampler(bm, false, tmx, tmy) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | virtual SkPMColor sample(SkFixed x, SkFixed y) const |
| 32 | { |
| 33 | x = fTileProcX(SkFixedFloor(x), fMaxX); |
| 34 | y = fTileProcY(SkFixedFloor(y), fMaxY); |
| 35 | return BITMAP_PIXEL_TO_PMCOLOR(fBitmap, x, y); |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | |
| 40 | class BITMAP_CLASSNAME_PREFIX(_Point_Clamp_Sampler) : public SkBitmapSampler { |
| 41 | public: |
| 42 | BITMAP_CLASSNAME_PREFIX(_Point_Clamp_Sampler)(const SkBitmap& bm) |
| 43 | : SkBitmapSampler(bm, false, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode) |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | virtual SkPMColor sample(SkFixed x, SkFixed y) const |
| 48 | { |
| 49 | x = do_clamp(SkFixedFloor(x), fMaxX); |
| 50 | y = do_clamp(SkFixedFloor(y), fMaxY); |
| 51 | return BITMAP_PIXEL_TO_PMCOLOR(fBitmap, x, y); |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | class BITMAP_CLASSNAME_PREFIX(_Point_Repeat_Pow2_Sampler) : public SkBitmapSampler { |
| 56 | public: |
| 57 | BITMAP_CLASSNAME_PREFIX(_Point_Repeat_Pow2_Sampler)(const SkBitmap& bm) |
| 58 | : SkBitmapSampler(bm, false, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | virtual SkPMColor sample(SkFixed x, SkFixed y) const |
| 63 | { |
| 64 | x = do_repeat_pow2(SkFixedFloor(x), fMaxX); |
| 65 | y = do_repeat_pow2(SkFixedFloor(y), fMaxY); |
| 66 | return BITMAP_PIXEL_TO_PMCOLOR(fBitmap, x, y); |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | class BITMAP_CLASSNAME_PREFIX(_Point_Repeat_Mod_Sampler) : public SkBitmapSampler { |
| 71 | public: |
| 72 | BITMAP_CLASSNAME_PREFIX(_Point_Repeat_Mod_Sampler)(const SkBitmap& bm) |
| 73 | : SkBitmapSampler(bm, false, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | virtual SkPMColor sample(SkFixed x, SkFixed y) const |
| 78 | { |
| 79 | x = do_repeat_mod(SkFixedFloor(x), fMaxX); |
| 80 | y = do_repeat_mod(SkFixedFloor(y), fMaxY); |
| 81 | return BITMAP_PIXEL_TO_PMCOLOR(fBitmap, x, y); |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | class BITMAP_CLASSNAME_PREFIX(_Point_Mirror_Pow2_Sampler) : public SkBitmapSampler { |
| 86 | public: |
| 87 | BITMAP_CLASSNAME_PREFIX(_Point_Mirror_Pow2_Sampler)(const SkBitmap& bm) |
| 88 | : SkBitmapSampler(bm, false, SkShader::kMirror_TileMode, SkShader::kMirror_TileMode) |
| 89 | { |
| 90 | } |
| 91 | |
| 92 | virtual SkPMColor sample(SkFixed x, SkFixed y) const |
| 93 | { |
| 94 | x = do_mirror_pow2(SkFixedFloor(x), fMaxX); |
| 95 | y = do_mirror_pow2(SkFixedFloor(y), fMaxY); |
| 96 | return BITMAP_PIXEL_TO_PMCOLOR(fBitmap, x, y); |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | class BITMAP_CLASSNAME_PREFIX(_Point_Mirror_Mod_Sampler) : public SkBitmapSampler { |
| 101 | public: |
| 102 | BITMAP_CLASSNAME_PREFIX(_Point_Mirror_Mod_Sampler)(const SkBitmap& bm) |
| 103 | : SkBitmapSampler(bm, false, SkShader::kMirror_TileMode, SkShader::kMirror_TileMode) |
| 104 | { |
| 105 | } |
| 106 | |
| 107 | virtual SkPMColor sample(SkFixed x, SkFixed y) const |
| 108 | { |
| 109 | x = do_mirror_mod(SkFixedFloor(x), fMaxX); |
| 110 | y = do_mirror_mod(SkFixedFloor(y), fMaxY); |
| 111 | return BITMAP_PIXEL_TO_PMCOLOR(fBitmap, x, y); |
| 112 | } |
| 113 | }; |
| 114 | |
| 115 | #undef BITMAP_CLASSNAME_PREFIX |
| 116 | #undef BITMAP_PIXEL_TO_PMCOLOR |