reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | #ifndef SkScaledBitmapSampler_DEFINED |
| 2 | #define SkScaledBitmapSampler_DEFINED |
| 3 | |
| 4 | #include "SkTypes.h" |
reed@android.com | 1134426 | 2009-07-08 20:09:23 +0000 | [diff] [blame] | 5 | #include "SkColor.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | |
| 7 | class SkBitmap; |
| 8 | |
| 9 | class SkScaledBitmapSampler { |
| 10 | public: |
| 11 | SkScaledBitmapSampler(int origWidth, int origHeight, int cellSize); |
| 12 | |
| 13 | int scaledWidth() const { return fScaledWidth; } |
| 14 | int scaledHeight() const { return fScaledHeight; } |
| 15 | |
| 16 | int srcY0() const { return fY0; } |
| 17 | int srcDY() const { return fDY; } |
| 18 | |
| 19 | enum SrcConfig { |
| 20 | kGray, // 1 byte per pixel |
| 21 | kIndex, // 1 byte per pixel |
| 22 | kRGB, // 3 bytes per pixel |
| 23 | kRGBX, // 4 byes per pixel (ignore 4th) |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame^] | 24 | kRGBA, // 4 bytes per pixel |
| 25 | kRGB_565 // 2 bytes per pixel |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | // Given a dst bitmap (with pixels already allocated) and a src-config, |
| 29 | // prepares iterator to process the src colors and write them into dst. |
| 30 | // Returns false if the request cannot be fulfulled. |
reed@android.com | 1134426 | 2009-07-08 20:09:23 +0000 | [diff] [blame] | 31 | bool begin(SkBitmap* dst, SrcConfig sc, bool doDither, |
| 32 | const SkPMColor* = NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | // call with row of src pixels, for y = 0...scaledHeight-1. |
| 34 | // returns true if the row had non-opaque alpha in it |
| 35 | bool next(const uint8_t* SK_RESTRICT src); |
| 36 | |
| 37 | private: |
| 38 | int fScaledWidth; |
| 39 | int fScaledHeight; |
| 40 | |
| 41 | int fX0; // first X coord to sample |
| 42 | int fY0; // first Y coord (scanline) to sample |
| 43 | int fDX; // step between X samples |
| 44 | int fDY; // step between Y samples |
reed@android.com | 1134426 | 2009-07-08 20:09:23 +0000 | [diff] [blame] | 45 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | typedef bool (*RowProc)(void* SK_RESTRICT dstRow, |
| 47 | const uint8_t* SK_RESTRICT src, |
reed@android.com | 1134426 | 2009-07-08 20:09:23 +0000 | [diff] [blame] | 48 | int width, int deltaSrc, int y, |
| 49 | const SkPMColor[]); |
| 50 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | // setup state |
| 52 | char* fDstRow; // points into bitmap's pixels |
| 53 | int fDstRowBytes; |
| 54 | int fCurrY; // used for dithering |
| 55 | int fSrcPixelSize; // 1, 3, 4 |
| 56 | RowProc fRowProc; |
reed@android.com | 1134426 | 2009-07-08 20:09:23 +0000 | [diff] [blame] | 57 | |
| 58 | // optional reference to the src colors if the src is a palette model |
| 59 | const SkPMColor* fCTable; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | #endif |