Home | History | Annotate | Download | only in images
      1 #ifndef SkScaledBitmapSampler_DEFINED
      2 #define SkScaledBitmapSampler_DEFINED
      3 
      4 #include "SkTypes.h"
      5 #include "SkColor.h"
      6 
      7 class SkBitmap;
      8 
      9 class SkScaledBitmapSampler {
     10 public:
     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.
     30     bool begin(SkBitmap* dst, SrcConfig sc, bool doDither,
     31                const SkPMColor* = NULL);
     32     // 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 
     36 private:
     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
     44 
     45     typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
     46                             const uint8_t* SK_RESTRICT src,
     47                             int width, int deltaSrc, int y,
     48                             const SkPMColor[]);
     49 
     50     // 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;
     56 
     57     // optional reference to the src colors if the src is a palette model
     58     const SkPMColor* fCTable;
     59 };
     60 
     61 #endif
     62