Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: include/core/SkSurface.h

Issue 793723002: add readPixels to SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add tests Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 SkSurface_DEFINED 8 #ifndef SkSurface_DEFINED
9 #define SkSurface_DEFINED 9 #define SkSurface_DEFINED
10 10
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 * the surface object is in scope, and no API call is made on the surface 207 * the surface object is in scope, and no API call is made on the surface
208 * or its canvas. 208 * or its canvas.
209 * 209 *
210 * On failure, returns NULL and the info and rowBytes parameters are 210 * On failure, returns NULL and the info and rowBytes parameters are
211 * ignored. 211 * ignored.
212 */ 212 */
213 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); 213 const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
214 214
215 /** 215 /**
216 * Copy the pixels from the surface into the specified buffer (pixels + row Bytes), 216 * Copy the pixels from the surface into the specified buffer (pixels + row Bytes),
217 * converting them into the requested format (dstInfo). The base-layer pixe ls are read 217 * converting them into the requested format (dstInfo). The surface pixels are read
218 * starting at the specified (srcX,srcY) location in the coordinate system of the base-layer. 218 * starting at the specified (srcX,srcY) location.
219 * 219 *
220 * The specified ImageInfo and (srcX,srcY) offset specifies a source rectan gle 220 * The specified ImageInfo and (srcX,srcY) offset specifies a source rectan gle
221 * 221 *
222 * srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height()); 222 * srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
223 * 223 *
224 * srcR is intersected with the bounds of the base-layer. If this intersect ion is not empty, 224 * srcR is intersected with the bounds of the base-layer. If this intersect ion is not empty,
225 * then we have two sets of pixels (of equal size). Replace the dst pixels with the 225 * then we have two sets of pixels (of equal size). Replace the dst pixels with the
226 * corresponding src pixels, performing any colortype/alphatype transformat ions needed 226 * corresponding src pixels, performing any colortype/alphatype transformat ions needed
227 * (in the case where the src and dst have different colortypes or alphatyp es). 227 * (in the case where the src and dst have different colortypes or alphatyp es).
228 * 228 *
229 * This call can fail, returning false, for several reasons: 229 * This call can fail, returning false, for several reasons:
230 * - If srcR does not intersect the surface bounds. 230 * - If srcR does not intersect the surface bounds.
231 * - If the requested colortype/alphatype cannot be converted from the base -layer's types. 231 * - If the requested colortype/alphatype cannot be converted from the surf ace's types.
232 */ 232 */
233 bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBy tes, 233 bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBy tes,
234 int srcX, int srcY); 234 int srcX, int srcY);
235 235
236 /**
237 * Helper for allocating pixels and then calling readPixels(info, ...). The bitmap is resized
238 * to the intersection of srcRect and the surface bounds (if srcRect is non -null).
239 * On success, pixels will be allocated in bitmap and true returned. On fai lure,
240 * false is returned and bitmap will be set to empty.
241 */
242 bool readPixels(SkBitmap* dst, const SkIRect* srcRect = NULL);
243
244 const SkSurfaceProps& props() const { return fProps; } 236 const SkSurfaceProps& props() const { return fProps; }
245 237
246 protected: 238 protected:
247 SkSurface(int width, int height, const SkSurfaceProps*); 239 SkSurface(int width, int height, const SkSurfaceProps*);
248 SkSurface(const SkImageInfo&, const SkSurfaceProps*); 240 SkSurface(const SkImageInfo&, const SkSurfaceProps*);
249 241
250 // called by subclass if their contents have changed 242 // called by subclass if their contents have changed
251 void dirtyGenerationID() { 243 void dirtyGenerationID() {
252 fGenerationID = 0; 244 fGenerationID = 0;
253 } 245 }
254 246
255 private: 247 private:
256 const SkSurfaceProps fProps; 248 const SkSurfaceProps fProps;
257 const int fWidth; 249 const int fWidth;
258 const int fHeight; 250 const int fHeight;
259 uint32_t fGenerationID; 251 uint32_t fGenerationID;
260 252
261 typedef SkRefCnt INHERITED; 253 typedef SkRefCnt INHERITED;
262 }; 254 };
263 255
264 #endif 256 #endif
OLDNEW
« no previous file with comments | « include/core/SkImage.h ('k') | src/core/SkCanvas.cpp » ('j') | tests/SurfaceTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698