• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
8 #ifndef SkScaledBitmapSampler_DEFINED
9 #define SkScaledBitmapSampler_DEFINED
10 
11 #include "SkTypes.h"
12 #include "SkColor.h"
13 
14 class SkBitmap;
15 
16 class SkScaledBitmapSampler {
17 public:
18     SkScaledBitmapSampler(int origWidth, int origHeight, int cellSize);
19 
scaledWidth()20     int scaledWidth() const { return fScaledWidth; }
scaledHeight()21     int scaledHeight() const { return fScaledHeight; }
22 
srcY0()23     int srcY0() const { return fY0; }
srcDY()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)
31         kRGBA,  // 4 bytes per pixel
32         kRGB_565 // 2 bytes per pixel
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.
38     bool begin(SkBitmap* dst, SrcConfig sc, bool doDither,
39                const SkPMColor* = NULL);
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
52 
53     typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
54                             const uint8_t* SK_RESTRICT src,
55                             int width, int deltaSrc, int y,
56                             const SkPMColor[]);
57 
58     // setup state
59     char*   fDstRow; // points into bitmap's pixels
60     int     fDstRowBytes;
61     int     fCurrY; // used for dithering
62     int     fSrcPixelSize;  // 1, 3, 4
63     RowProc fRowProc;
64 
65     // optional reference to the src colors if the src is a palette model
66     const SkPMColor* fCTable;
67 };
68 
69 #endif
70