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

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

Issue 656503003: Move SkImage::encode to SkImageEncoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « bench/nanobench.cpp ('k') | include/core/SkImageEncoder.h » ('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
11 #include "SkImageInfo.h" 11 #include "SkImageInfo.h"
12 #include "SkImageEncoder.h"
13 #include "SkRefCnt.h" 12 #include "SkRefCnt.h"
14 #include "SkScalar.h" 13 #include "SkScalar.h"
15 #include "SkShader.h" 14 #include "SkShader.h"
16 15
17 class SkData; 16 class SkData;
18 class SkCanvas; 17 class SkCanvas;
19 class SkImageGenerator; 18 class SkImageGenerator;
19 class SkImageEncoder;
20 class SkPaint; 20 class SkPaint;
21 class GrContext; 21 class GrContext;
22 class GrTexture; 22 class GrTexture;
23 23
24 /** 24 /**
25 * SkImage is an abstraction for drawing a rectagle of pixels, though the 25 * SkImage is an abstraction for drawing a rectagle of pixels, though the
26 * particular type of image could be actually storing its data on the GPU, or 26 * particular type of image could be actually storing its data on the GPU, or
27 * as drawing commands (picture or PDF or otherwise), ready to be played back 27 * as drawing commands (picture or PDF or otherwise), ready to be played back
28 * into another canvas. 28 * into another canvas.
29 * 29 *
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 * If the image has direct access to its pixels (i.e. they are in local 75 * If the image has direct access to its pixels (i.e. they are in local
76 * RAM) return the (const) address of those pixels, and if not null, return 76 * RAM) return the (const) address of those pixels, and if not null, return
77 * the ImageInfo and rowBytes. The returned address is only valid while 77 * the ImageInfo and rowBytes. The returned address is only valid while
78 * the image object is in scope. 78 * the image object is in scope.
79 * 79 *
80 * On failure, returns NULL and the info and rowBytes parameters are 80 * On failure, returns NULL and the info and rowBytes parameters are
81 * ignored. 81 * ignored.
82 */ 82 */
83 const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const; 83 const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const;
84 84
85 /**
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).
88 *
89 * If the image type cannot be encoded, or the requested encoder type is
90 * not supported, this will return NULL.
91 */
92 SkData* encode(SkImageEncoder::Type t = SkImageEncoder::kPNG_Type,
93 int quality = 80) const;
94
95 protected: 85 protected:
96 SkImage(int width, int height) : 86 SkImage(int width, int height) :
97 fWidth(width), 87 fWidth(width),
98 fHeight(height), 88 fHeight(height),
99 fUniqueID(NextUniqueID()) { 89 fUniqueID(NextUniqueID()) {
100 90
101 SkASSERT(width >= 0); 91 SkASSERT(width >= 0);
102 SkASSERT(height >= 0); 92 SkASSERT(height >= 0);
103 } 93 }
104 94
105 private: 95 private:
106 const int fWidth; 96 const int fWidth;
107 const int fHeight; 97 const int fHeight;
108 const uint32_t fUniqueID; 98 const uint32_t fUniqueID;
109 99
110 static uint32_t NextUniqueID(); 100 static uint32_t NextUniqueID();
111 101
112 typedef SkRefCnt INHERITED; 102 typedef SkRefCnt INHERITED;
113 103
114 friend class SkCanvas; 104 friend class SkCanvas;
105 friend class SkImageEncoder;
115 106
116 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const; 107 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const;
117 108
118 /** 109 /**
119 * Draw the image, cropped to the src rect, to the dst rect of a canvas. 110 * 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 111 * If src is larger than the bounds of the image, the rest of the image is
121 * filled with transparent black pixels. 112 * filled with transparent black pixels.
122 * 113 *
123 * See SkCanvas::drawBitmapRectToRect for similar behavior. 114 * See SkCanvas::drawBitmapRectToRect for similar behavior.
124 */ 115 */
(...skipping 14 matching lines...) Expand all
139 * using the default allocator, and the ColorType/AlphaType will be chosen 130 * using the default allocator, and the ColorType/AlphaType will be chosen
140 * to most closely fit the image's configuration. 131 * to most closely fit the image's configuration.
141 * 132 *
142 * On failure, false will be returned, and bitmap will unmodified. 133 * On failure, false will be returned, and bitmap will unmodified.
143 */ 134 */
144 // On ice for now: 135 // On ice for now:
145 // - should it respect the particular colortype/alphatype of the src 136 // - should it respect the particular colortype/alphatype of the src
146 // - should it have separate entrypoints for preallocated and not bitmaps? 137 // - should it have separate entrypoints for preallocated and not bitmaps?
147 // - isn't it enough to allow the caller to draw() the image into a canvas? 138 // - isn't it enough to allow the caller to draw() the image into a canvas?
148 bool readPixels(SkBitmap* bitmap, const SkIRect* subset = NULL) const; 139 bool readPixels(SkBitmap* bitmap, const SkIRect* subset = NULL) const;
140
141 /** Returns the image for encoding.
142 * Returns true if bm contains the image, false if the operation fails.
143 */
144 bool getBitmapForEncoding(SkBitmap* bm) const;
149 }; 145 };
150 146
151 #endif 147 #endif
OLDNEW
« no previous file with comments | « bench/nanobench.cpp ('k') | include/core/SkImageEncoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698