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         kRGB_565 // 2 bytes per pixel
     26     };
     27 
     28     // Given a dst bitmap (with pixels already allocated) and a src-config,
     29     // prepares iterator to process the src colors and write them into dst.
     30     // Returns false if the request cannot be fulfulled.
     31     bool begin(SkBitmap* dst, SrcConfig sc, bool doDither,
     32                const SkPMColor* = NULL);
     33     // call with row of src pixels, for y = 0...scaledHeight-1.
     34     // returns true if the row had non-opaque alpha in it
     35     bool next(const uint8_t* SK_RESTRICT src);
     36 
     37 private:
     38     int fScaledWidth;
     39     int fScaledHeight;
     40 
     41     int fX0;    // first X coord to sample
     42     int fY0;    // first Y coord (scanline) to sample
     43     int fDX;    // step between X samples
     44     int fDY;    // step between Y samples
     45 
     46     typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
     47                             const uint8_t* SK_RESTRICT src,
     48                             int width, int deltaSrc, int y,
     49                             const SkPMColor[]);
     50 
     51     // setup state
     52     char*   fDstRow; // points into bitmap's pixels
     53     int     fDstRowBytes;
     54     int     fCurrY; // used for dithering
     55     int     fSrcPixelSize;  // 1, 3, 4
     56     RowProc fRowProc;
     57 
     58     // optional reference to the src colors if the src is a palette model
     59     const SkPMColor* fCTable;
     60 };
     61 
     62 #endif
     63