blob: f6de4ccc105f1692014ce7e48a699419ab5d44a8 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com8a1c16f2008-12-17 15:59:43 +00008#ifndef SkScaledBitmapSampler_DEFINED
9#define SkScaledBitmapSampler_DEFINED
10
11#include "SkTypes.h"
reed@android.com11344262009-07-08 20:09:23 +000012#include "SkColor.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013
14class SkBitmap;
15
16class SkScaledBitmapSampler {
17public:
18 SkScaledBitmapSampler(int origWidth, int origHeight, int cellSize);
rmistry@google.comd6176b02012-08-23 18:14:13 +000019
reed@android.com8a1c16f2008-12-17 15:59:43 +000020 int scaledWidth() const { return fScaledWidth; }
21 int scaledHeight() const { return fScaledHeight; }
rmistry@google.comd6176b02012-08-23 18:14:13 +000022
reed@android.com8a1c16f2008-12-17 15:59:43 +000023 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.com57f49692011-02-23 20:46:31 +000031 kRGBA, // 4 bytes per pixel
32 kRGB_565 // 2 bytes per pixel
reed@android.com8a1c16f2008-12-17 15:59:43 +000033 };
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.com11344262009-07-08 20:09:23 +000038 bool begin(SkBitmap* dst, SrcConfig sc, bool doDither,
39 const SkPMColor* = NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +000040 // 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
44private:
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.com11344262009-07-08 20:09:23 +000052
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
54 const uint8_t* SK_RESTRICT src,
reed@android.com11344262009-07-08 20:09:23 +000055 int width, int deltaSrc, int y,
56 const SkPMColor[]);
57
reed@android.com8a1c16f2008-12-17 15:59:43 +000058 // setup state
59 char* fDstRow; // points into bitmap's pixels
60 int fDstRowBytes;
61 int fCurrY; // used for dithering
rmistry@google.comd6176b02012-08-23 18:14:13 +000062 int fSrcPixelSize; // 1, 3, 4
reed@android.com8a1c16f2008-12-17 15:59:43 +000063 RowProc fRowProc;
reed@android.com11344262009-07-08 20:09:23 +000064
65 // optional reference to the src colors if the src is a palette model
66 const SkPMColor* fCTable;
reed@android.com8a1c16f2008-12-17 15:59:43 +000067};
68
69#endif