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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 * RAM) return the (const) address of those pixels, and if not null, return | 78 * RAM) return the (const) address of those pixels, and if not null, return |
79 * the ImageInfo and rowBytes. The returned address is only valid while | 79 * the ImageInfo and rowBytes. The returned address is only valid while |
80 * the image object is in scope. | 80 * the image object is in scope. |
81 * | 81 * |
82 * On failure, returns NULL and the info and rowBytes parameters are | 82 * On failure, returns NULL and the info and rowBytes parameters are |
83 * ignored. | 83 * ignored. |
84 */ | 84 */ |
85 const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const; | 85 const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const; |
86 | 86 |
87 /** | 87 /** |
| 88 * Copy the pixels from the image into the specified buffer (pixels + rowBy
tes), |
| 89 * converting them into the requested format (dstInfo). The image pixels ar
e read |
| 90 * starting at the specified (srcX,srcY) location. |
| 91 * |
| 92 * The specified ImageInfo and (srcX,srcY) offset specifies a source rectan
gle |
| 93 * |
| 94 * srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height()); |
| 95 * |
| 96 * srcR is intersected with the bounds of the image. If this intersection i
s not empty, |
| 97 * then we have two sets of pixels (of equal size). Replace the dst pixels
with the |
| 98 * corresponding src pixels, performing any colortype/alphatype transformat
ions needed |
| 99 * (in the case where the src and dst have different colortypes or alphatyp
es). |
| 100 * |
| 101 * This call can fail, returning false, for several reasons: |
| 102 * - If srcR does not intersect the image bounds. |
| 103 * - If the requested colortype/alphatype cannot be converted from the imag
e's types. |
| 104 */ |
| 105 bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBy
tes, |
| 106 int srcX, int srcY) const; |
| 107 |
| 108 /** |
88 * Encode the image's pixels and return the result as a new SkData, which | 109 * Encode the image's pixels and return the result as a new SkData, which |
89 * the caller must manage (i.e. call unref() when they are done). | 110 * the caller must manage (i.e. call unref() when they are done). |
90 * | 111 * |
91 * If the image type cannot be encoded, or the requested encoder type is | 112 * If the image type cannot be encoded, or the requested encoder type is |
92 * not supported, this will return NULL. | 113 * not supported, this will return NULL. |
93 */ | 114 */ |
94 SkData* encode(SkImageEncoder::Type t = SkImageEncoder::kPNG_Type, | 115 SkData* encode(SkImageEncoder::Type t = SkImageEncoder::kPNG_Type, |
95 int quality = 80) const; | 116 int quality = 80) const; |
96 | 117 |
97 /** | 118 /** |
(...skipping 29 matching lines...) Expand all Loading... |
127 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const; | 148 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const; |
128 | 149 |
129 /** | 150 /** |
130 * Draw the image, cropped to the src rect, to the dst rect of a canvas. | 151 * Draw the image, cropped to the src rect, to the dst rect of a canvas. |
131 * If src is larger than the bounds of the image, the rest of the image is | 152 * If src is larger than the bounds of the image, the rest of the image is |
132 * filled with transparent black pixels. | 153 * filled with transparent black pixels. |
133 * | 154 * |
134 * See SkCanvas::drawBitmapRectToRect for similar behavior. | 155 * See SkCanvas::drawBitmapRectToRect for similar behavior. |
135 */ | 156 */ |
136 void drawRect(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint
*) const; | 157 void drawRect(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint
*) const; |
137 | |
138 /** | |
139 * Return a copy of the image's pixels, limiting them to the subset | |
140 * rectangle's intersection wit the image bounds. If subset is NULL, then | |
141 * the entire image will be considered. | |
142 * | |
143 * If the bitmap's pixels have already been allocated, then readPixels() | |
144 * will succeed only if it can support converting the image's pixels into | |
145 * the bitmap's ColorType/AlphaType. Any pixels in the bitmap that do not | |
146 * intersect with the image's bounds and the subset (if not null) will be | |
147 * left untouched. | |
148 * | |
149 * If the bitmap is initially empty/unallocated, then it will be allocated | |
150 * using the default allocator, and the ColorType/AlphaType will be chosen | |
151 * to most closely fit the image's configuration. | |
152 * | |
153 * On failure, false will be returned, and bitmap will unmodified. | |
154 */ | |
155 // On ice for now: | |
156 // - should it respect the particular colortype/alphatype of the src | |
157 // - should it have separate entrypoints for preallocated and not bitmaps? | |
158 // - isn't it enough to allow the caller to draw() the image into a canvas? | |
159 bool readPixels(SkBitmap* bitmap, const SkIRect* subset = NULL) const; | |
160 }; | 158 }; |
161 | 159 |
162 #endif | 160 #endif |
OLD | NEW |