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 #include "SkImageDecoder.h" |
14 | 14 |
15 class SkBitmap; | 15 class SkBitmap; |
16 | 16 |
17 class SkScaledBitmapSampler { | 17 class SkScaledBitmapSampler { |
18 public: | 18 public: |
19 SkScaledBitmapSampler(int origWidth, int origHeight, int cellSize); | 19 SkScaledBitmapSampler(int origWidth, int origHeight, int cellSize); |
20 | 20 |
21 int scaledWidth() const { return fScaledWidth; } | 21 int scaledWidth() const { return fScaledWidth; } |
22 int scaledHeight() const { return fScaledHeight; } | 22 int scaledHeight() const { return fScaledHeight; } |
23 | 23 |
24 int srcY0() const { return fY0; } | 24 int srcY0() const { return fY0; } |
| 25 int srcDX() const { return fDX; } |
25 int srcDY() const { return fDY; } | 26 int srcDY() const { return fDY; } |
26 | 27 |
27 enum SrcConfig { | 28 enum SrcConfig { |
28 kGray, // 1 byte per pixel | 29 kGray, // 1 byte per pixel |
29 kIndex, // 1 byte per pixel | 30 kIndex, // 1 byte per pixel |
30 kRGB, // 3 bytes per pixel | 31 kRGB, // 3 bytes per pixel |
31 kRGBX, // 4 byes per pixel (ignore 4th) | 32 kRGBX, // 4 byes per pixel (ignore 4th) |
32 kRGBA, // 4 bytes per pixel | 33 kRGBA, // 4 bytes per pixel |
33 kRGB_565 // 2 bytes per pixel | 34 kRGB_565 // 2 bytes per pixel |
34 }; | 35 }; |
35 | 36 |
36 // Given a dst bitmap (with pixels already allocated) and a src-config, | 37 // Given a dst bitmap (with pixels already allocated) and a src-config, |
37 // prepares iterator to process the src colors and write them into dst. | 38 // prepares iterator to process the src colors and write them into dst. |
38 // Returns false if the request cannot be fulfulled. | 39 // Returns false if the request cannot be fulfulled. |
39 bool begin(SkBitmap* dst, SrcConfig sc, const SkImageDecoder& decoder, | 40 bool begin(SkBitmap* dst, SrcConfig sc, const SkImageDecoder& decoder, |
40 const SkPMColor* = NULL); | 41 const SkPMColor* = NULL); |
41 // call with row of src pixels, for y = 0...scaledHeight-1. | 42 // call with row of src pixels, for y = 0...scaledHeight-1. |
42 // returns true if the row had non-opaque alpha in it | 43 // returns true if the row had non-opaque alpha in it |
43 bool next(const uint8_t* SK_RESTRICT src); | 44 bool next(const uint8_t* SK_RESTRICT src); |
44 | 45 |
| 46 // Like next(), but specifies the y value of the source row, so the |
| 47 // rows can come in any order. If the row is not part of the output |
| 48 // sample, it will be skipped. Only sampleInterlaced OR next should |
| 49 // be called for one SkScaledBitmapSampler. |
| 50 bool sampleInterlaced(const uint8_t* SK_RESTRICT src, int srcY); |
| 51 |
45 typedef bool (*RowProc)(void* SK_RESTRICT dstRow, | 52 typedef bool (*RowProc)(void* SK_RESTRICT dstRow, |
46 const uint8_t* SK_RESTRICT src, | 53 const uint8_t* SK_RESTRICT src, |
47 int width, int deltaSrc, int y, | 54 int width, int deltaSrc, int y, |
48 const SkPMColor[]); | 55 const SkPMColor[]); |
49 | 56 |
50 private: | 57 private: |
51 int fScaledWidth; | 58 int fScaledWidth; |
52 int fScaledHeight; | 59 int fScaledHeight; |
53 | 60 |
54 int fX0; // first X coord to sample | 61 int fX0; // first X coord to sample |
55 int fY0; // first Y coord (scanline) to sample | 62 int fY0; // first Y coord (scanline) to sample |
56 int fDX; // step between X samples | 63 int fDX; // step between X samples |
57 int fDY; // step between Y samples | 64 int fDY; // step between Y samples |
58 | 65 |
| 66 #ifdef SK_DEBUG |
| 67 // Keep track of whether the caller is using next or sampleInterlaced. |
| 68 // Only one can be used per sampler. |
| 69 enum SampleMode { |
| 70 kUninitialized_SampleMode, |
| 71 kConsecutive_SampleMode, |
| 72 kInterlaced_SampleMode, |
| 73 }; |
| 74 |
| 75 SampleMode fSampleMode; |
| 76 #endif |
| 77 |
59 // setup state | 78 // setup state |
60 char* fDstRow; // points into bitmap's pixels | 79 char* fDstRow; // points into bitmap's pixels |
61 size_t fDstRowBytes; | 80 size_t fDstRowBytes; |
62 int fCurrY; // used for dithering | 81 int fCurrY; // used for dithering |
63 int fSrcPixelSize; // 1, 3, 4 | 82 int fSrcPixelSize; // 1, 3, 4 |
64 RowProc fRowProc; | 83 RowProc fRowProc; |
65 | 84 |
66 // optional reference to the src colors if the src is a palette model | 85 // optional reference to the src colors if the src is a palette model |
67 const SkPMColor* fCTable; | 86 const SkPMColor* fCTable; |
68 | 87 |
69 #ifdef SK_DEBUG | 88 #ifdef SK_DEBUG |
70 // Helper class allowing a test to have access to fRowProc. | 89 // Helper class allowing a test to have access to fRowProc. |
71 friend class RowProcTester; | 90 friend class RowProcTester; |
72 #endif | 91 #endif |
73 }; | 92 }; |
74 | 93 |
75 #endif | 94 #endif |
OLD | NEW |