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