OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkImage_DEFINED | 8 #ifndef SkImage_DEFINED |
9 #define SkImage_DEFINED | 9 #define SkImage_DEFINED |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 /** | 85 /** |
86 * Encode the image's pixels and return the result as a new SkData, which | 86 * Encode the image's pixels and return the result as a new SkData, which |
87 * the caller must manage (i.e. call unref() when they are done). | 87 * the caller must manage (i.e. call unref() when they are done). |
88 * | 88 * |
89 * If the image type cannot be encoded, or the requested encoder type is | 89 * If the image type cannot be encoded, or the requested encoder type is |
90 * not supported, this will return NULL. | 90 * not supported, this will return NULL. |
91 */ | 91 */ |
92 SkData* encode(SkImageEncoder::Type t = SkImageEncoder::kPNG_Type, | 92 SkData* encode(SkImageEncoder::Type t = SkImageEncoder::kPNG_Type, |
93 int quality = 80) const; | 93 int quality = 80) const; |
94 | 94 |
95 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const; | |
96 | |
97 /** | |
98 * Draw the image, cropped to the src rect, to the dst rect of a canvas. | |
99 * If src is larger than the bounds of the image, the rest of the image is | |
100 * filled with transparent black pixels. | |
101 * | |
102 * See SkCanvas::drawBitmapRectToRect for similar behavior. | |
103 */ | |
104 void draw(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint*) c
onst; | |
105 | |
106 protected: | 95 protected: |
107 SkImage(int width, int height) : | 96 SkImage(int width, int height) : |
108 fWidth(width), | 97 fWidth(width), |
109 fHeight(height), | 98 fHeight(height), |
110 fUniqueID(NextUniqueID()) { | 99 fUniqueID(NextUniqueID()) { |
111 | 100 |
112 SkASSERT(width >= 0); | 101 SkASSERT(width >= 0); |
113 SkASSERT(height >= 0); | 102 SkASSERT(height >= 0); |
114 } | 103 } |
115 | 104 |
116 private: | 105 private: |
117 const int fWidth; | 106 const int fWidth; |
118 const int fHeight; | 107 const int fHeight; |
119 const uint32_t fUniqueID; | 108 const uint32_t fUniqueID; |
120 | 109 |
121 static uint32_t NextUniqueID(); | 110 static uint32_t NextUniqueID(); |
122 | 111 |
123 typedef SkRefCnt INHERITED; | 112 typedef SkRefCnt INHERITED; |
124 | 113 |
| 114 friend class SkCanvas; |
| 115 |
| 116 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const; |
| 117 |
| 118 /** |
| 119 * Draw the image, cropped to the src rect, to the dst rect of a canvas. |
| 120 * If src is larger than the bounds of the image, the rest of the image is |
| 121 * filled with transparent black pixels. |
| 122 * |
| 123 * See SkCanvas::drawBitmapRectToRect for similar behavior. |
| 124 */ |
| 125 void draw(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint*) c
onst; |
| 126 |
125 /** | 127 /** |
126 * Return a copy of the image's pixels, limiting them to the subset | 128 * Return a copy of the image's pixels, limiting them to the subset |
127 * rectangle's intersection wit the image bounds. If subset is NULL, then | 129 * rectangle's intersection wit the image bounds. If subset is NULL, then |
128 * the entire image will be considered. | 130 * the entire image will be considered. |
129 * | 131 * |
130 * If the bitmap's pixels have already been allocated, then readPixels() | 132 * If the bitmap's pixels have already been allocated, then readPixels() |
131 * will succeed only if it can support converting the image's pixels into | 133 * will succeed only if it can support converting the image's pixels into |
132 * the bitmap's ColorType/AlphaType. Any pixels in the bitmap that do not | 134 * the bitmap's ColorType/AlphaType. Any pixels in the bitmap that do not |
133 * intersect with the image's bounds and the subset (if not null) will be | 135 * intersect with the image's bounds and the subset (if not null) will be |
134 * left untouched. | 136 * left untouched. |
135 * | 137 * |
136 * If the bitmap is initially empty/unallocated, then it will be allocated | 138 * If the bitmap is initially empty/unallocated, then it will be allocated |
137 * using the default allocator, and the ColorType/AlphaType will be chosen | 139 * using the default allocator, and the ColorType/AlphaType will be chosen |
138 * to most closely fit the image's configuration. | 140 * to most closely fit the image's configuration. |
139 * | 141 * |
140 * On failure, false will be returned, and bitmap will unmodified. | 142 * On failure, false will be returned, and bitmap will unmodified. |
141 */ | 143 */ |
142 // On ice for now: | 144 // On ice for now: |
143 // - should it respect the particular colortype/alphatype of the src | 145 // - should it respect the particular colortype/alphatype of the src |
144 // - should it have separate entrypoints for preallocated and not bitmaps? | 146 // - should it have separate entrypoints for preallocated and not bitmaps? |
145 // - isn't it enough to allow the caller to draw() the image into a canvas? | 147 // - isn't it enough to allow the caller to draw() the image into a canvas? |
146 bool readPixels(SkBitmap* bitmap, const SkIRect* subset = NULL) const; | 148 bool readPixels(SkBitmap* bitmap, const SkIRect* subset = NULL) const; |
147 }; | 149 }; |
148 | 150 |
149 #endif | 151 #endif |
OLD | NEW |