blob: 43f166946af39fd86d61111305095b32a10c7fd2 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#ifndef SkScaledBitmapSampler_DEFINED
2#define SkScaledBitmapSampler_DEFINED
3
4#include "SkTypes.h"
reed@android.com11344262009-07-08 20:09:23 +00005#include "SkColor.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00006
7class SkBitmap;
8
9class SkScaledBitmapSampler {
10public:
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.com57f49692011-02-23 20:46:31 +000024 kRGBA, // 4 bytes per pixel
25 kRGB_565 // 2 bytes per pixel
reed@android.com8a1c16f2008-12-17 15:59:43 +000026 };
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.com11344262009-07-08 20:09:23 +000031 bool begin(SkBitmap* dst, SrcConfig sc, bool doDither,
32 const SkPMColor* = NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +000033 // 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
37private:
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.com11344262009-07-08 20:09:23 +000045
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
47 const uint8_t* SK_RESTRICT src,
reed@android.com11344262009-07-08 20:09:23 +000048 int width, int deltaSrc, int y,
49 const SkPMColor[]);
50
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 // 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.com11344262009-07-08 20:09:23 +000057
58 // optional reference to the src colors if the src is a palette model
59 const SkPMColor* fCTable;
reed@android.com8a1c16f2008-12-17 15:59:43 +000060};
61
62#endif