blob: 84a75ba544e3b0f1e65d7c4fb9eff62bc0470fed [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)
24 kRGBA // 4 bytes per pixel
25 };
26
27 // Given a dst bitmap (with pixels already allocated) and a src-config,
28 // prepares iterator to process the src colors and write them into dst.
29 // Returns false if the request cannot be fulfulled.
reed@android.com11344262009-07-08 20:09:23 +000030 bool begin(SkBitmap* dst, SrcConfig sc, bool doDither,
31 const SkPMColor* = NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +000032 // call with row of src pixels, for y = 0...scaledHeight-1.
33 // returns true if the row had non-opaque alpha in it
34 bool next(const uint8_t* SK_RESTRICT src);
35
36private:
37 int fScaledWidth;
38 int fScaledHeight;
39
40 int fX0; // first X coord to sample
41 int fY0; // first Y coord (scanline) to sample
42 int fDX; // step between X samples
43 int fDY; // step between Y samples
reed@android.com11344262009-07-08 20:09:23 +000044
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
46 const uint8_t* SK_RESTRICT src,
reed@android.com11344262009-07-08 20:09:23 +000047 int width, int deltaSrc, int y,
48 const SkPMColor[]);
49
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 // setup state
51 char* fDstRow; // points into bitmap's pixels
52 int fDstRowBytes;
53 int fCurrY; // used for dithering
54 int fSrcPixelSize; // 1, 3, 4
55 RowProc fRowProc;
reed@android.com11344262009-07-08 20:09:23 +000056
57 // optional reference to the src colors if the src is a palette model
58 const SkPMColor* fCTable;
reed@android.com8a1c16f2008-12-17 15:59:43 +000059};
60
61#endif