/src/compiler/android/jni/ftk/SkScaledBitmapSampler.h

http://ftk.googlecode.com/ · C++ Header · 61 lines · 41 code · 13 blank · 7 comment · 0 complexity · 256f1124039c05a8acc31d141a762d12 MD5 · raw file

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