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