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

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

Issue 155763004: add ways to peer into an image to get its pixels (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/image/SkImage.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 SkImage_DEFINED 8 #ifndef SkImage_DEFINED
9 #define SkImage_DEFINED 9 #define SkImage_DEFINED
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 /** 69 /**
70 * Draw the image, cropped to the src rect, to the dst rect of a canvas. 70 * Draw the image, cropped to the src rect, to the dst rect of a canvas.
71 * If src is larger than the bounds of the image, the rest of the image is 71 * If src is larger than the bounds of the image, the rest of the image is
72 * filled with transparent black pixels. 72 * filled with transparent black pixels.
73 * 73 *
74 * See SkCanvas::drawBitmapRectToRect for similar behavior. 74 * See SkCanvas::drawBitmapRectToRect for similar behavior.
75 */ 75 */
76 void draw(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint*); 76 void draw(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint*);
77 77
78 /** 78 /**
79 * If the image has direct access to its pixels (i.e. they are in local
80 * RAM) return the (const) address of those pixels, and if not null, return
81 * the ImageInfo and rowBytes. The returned address is only valid while
82 * the image object is in scope.
83 *
84 * On failure, returns NULL and the info and rowBytes parameters are
85 * ignored.
86 */
87 const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const;
88
89 /**
79 * Encode the image's pixels and return the result as a new SkData, which 90 * Encode the image's pixels and return the result as a new SkData, which
80 * the caller must manage (i.e. call unref() when they are done). 91 * the caller must manage (i.e. call unref() when they are done).
81 * 92 *
82 * If the image type cannot be encoded, or the requested encoder type is 93 * If the image type cannot be encoded, or the requested encoder type is
83 * not supported, this will return NULL. 94 * not supported, this will return NULL.
84 */ 95 */
85 SkData* encode(SkImageEncoder::Type t = SkImageEncoder::kPNG_Type, 96 SkData* encode(SkImageEncoder::Type t = SkImageEncoder::kPNG_Type,
86 int quality = 80) const; 97 int quality = 80) const;
87 98
88 protected: 99 protected:
89 SkImage(int width, int height) : 100 SkImage(int width, int height) :
90 fWidth(width), 101 fWidth(width),
91 fHeight(height), 102 fHeight(height),
92 fUniqueID(NextUniqueID()) { 103 fUniqueID(NextUniqueID()) {
93 104
94 SkASSERT(width >= 0); 105 SkASSERT(width >= 0);
95 SkASSERT(height >= 0); 106 SkASSERT(height >= 0);
96 } 107 }
97 108
98 private: 109 private:
99 const int fWidth; 110 const int fWidth;
100 const int fHeight; 111 const int fHeight;
101 const uint32_t fUniqueID; 112 const uint32_t fUniqueID;
102 113
103 static uint32_t NextUniqueID(); 114 static uint32_t NextUniqueID();
104 115
105 typedef SkRefCnt INHERITED; 116 typedef SkRefCnt INHERITED;
117
118 /**
119 * Return a copy of the image's pixels, limiting them to the subset
120 * rectangle's intersection wit the image bounds. If subset is NULL, then
121 * the entire image will be considered.
122 *
123 * If the bitmap's pixels have already been allocated, then readPixels()
124 * will succeed only if it can support converting the image's pixels into
125 * the bitmap's ColorType/AlphaType. Any pixels in the bitmap that do not
126 * intersect with the image's bounds and the subset (if not null) will be
127 * left untouched.
128 *
129 * If the bitmap is initially empty/unallocated, then it will be allocated
130 * using the default allocator, and the ColorType/AlphaType will be chosen
131 * to most closely fit the image's configuration.
132 *
133 * On failure, false will be returned, and bitmap will unmodified.
134 */
135 // On ice for now:
136 // - should it respect the particular colortype/alphatype of the src
137 // - should it have separate entrypoints for preallocated and not bitmaps?
138 // - isn't it enough to allow the caller to draw() the image into a canvas?
139 bool readPixels(SkBitmap* bitmap, const SkIRect* subset = NULL) const;
106 }; 140 };
107 141
108 #endif 142 #endif
OLDNEW
« no previous file with comments | « no previous file | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698