| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #ifndef SkScaledBitmapSampler_DEFINED | 8 #ifndef SkScaledBitmapSampler_DEFINED |
| 9 #define SkScaledBitmapSampler_DEFINED | 9 #define SkScaledBitmapSampler_DEFINED |
| 10 | 10 |
| 11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
| 12 #include "SkColor.h" | 12 #include "SkColor.h" |
| 13 #include "SkImageDecoder.h" |
| 13 | 14 |
| 14 class SkBitmap; | 15 class SkBitmap; |
| 15 | 16 |
| 16 class SkScaledBitmapSampler { | 17 class SkScaledBitmapSampler { |
| 17 public: | 18 public: |
| 18 SkScaledBitmapSampler(int origWidth, int origHeight, int cellSize); | 19 SkScaledBitmapSampler(int origWidth, int origHeight, int cellSize); |
| 19 | 20 |
| 20 int scaledWidth() const { return fScaledWidth; } | 21 int scaledWidth() const { return fScaledWidth; } |
| 21 int scaledHeight() const { return fScaledHeight; } | 22 int scaledHeight() const { return fScaledHeight; } |
| 22 | 23 |
| 23 int srcY0() const { return fY0; } | 24 int srcY0() const { return fY0; } |
| 24 int srcDY() const { return fDY; } | 25 int srcDY() const { return fDY; } |
| 25 | 26 |
| 26 enum SrcConfig { | 27 enum SrcConfig { |
| 27 kGray, // 1 byte per pixel | 28 kGray, // 1 byte per pixel |
| 28 kIndex, // 1 byte per pixel | 29 kIndex, // 1 byte per pixel |
| 29 kRGB, // 3 bytes per pixel | 30 kRGB, // 3 bytes per pixel |
| 30 kRGBX, // 4 byes per pixel (ignore 4th) | 31 kRGBX, // 4 byes per pixel (ignore 4th) |
| 31 kRGBA, // 4 bytes per pixel | 32 kRGBA, // 4 bytes per pixel |
| 32 kRGB_565 // 2 bytes per pixel | 33 kRGB_565 // 2 bytes per pixel |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 // Given a dst bitmap (with pixels already allocated) and a src-config, | 36 // 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 // prepares iterator to process the src colors and write them into dst. |
| 37 // Returns false if the request cannot be fulfulled. | 38 // Returns false if the request cannot be fulfulled. |
| 38 bool begin(SkBitmap* dst, SrcConfig sc, bool doDither, | 39 bool begin(SkBitmap* dst, SrcConfig sc, const SkImageDecoder& decoder, |
| 39 const SkPMColor* = NULL, bool requireUnPremul = false); | 40 const SkPMColor* = NULL); |
| 40 // call with row of src pixels, for y = 0...scaledHeight-1. | 41 // call with row of src pixels, for y = 0...scaledHeight-1. |
| 41 // returns true if the row had non-opaque alpha in it | 42 // returns true if the row had non-opaque alpha in it |
| 42 bool next(const uint8_t* SK_RESTRICT src); | 43 bool next(const uint8_t* SK_RESTRICT src); |
| 43 | 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 |
| 44 private: | 50 private: |
| 45 int fScaledWidth; | 51 int fScaledWidth; |
| 46 int fScaledHeight; | 52 int fScaledHeight; |
| 47 | 53 |
| 48 int fX0; // first X coord to sample | 54 int fX0; // first X coord to sample |
| 49 int fY0; // first Y coord (scanline) to sample | 55 int fY0; // first Y coord (scanline) to sample |
| 50 int fDX; // step between X samples | 56 int fDX; // step between X samples |
| 51 int fDY; // step between Y samples | 57 int fDY; // step between Y samples |
| 52 | 58 |
| 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 // setup state |
| 59 char* fDstRow; // points into bitmap's pixels | 60 char* fDstRow; // points into bitmap's pixels |
| 60 size_t fDstRowBytes; | 61 size_t fDstRowBytes; |
| 61 int fCurrY; // used for dithering | 62 int fCurrY; // used for dithering |
| 62 int fSrcPixelSize; // 1, 3, 4 | 63 int fSrcPixelSize; // 1, 3, 4 |
| 63 RowProc fRowProc; | 64 RowProc fRowProc; |
| 64 | 65 |
| 65 // optional reference to the src colors if the src is a palette model | 66 // optional reference to the src colors if the src is a palette model |
| 66 const SkPMColor* fCTable; | 67 const SkPMColor* fCTable; |
| 68 |
| 69 #ifdef SK_DEBUG |
| 70 // Helper class allowing a test to have access to fRowProc. |
| 71 friend class RowProcTester; |
| 72 #endif |
| 67 }; | 73 }; |
| 68 | 74 |
| 69 #endif | 75 #endif |
| OLD | NEW |