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

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

Issue 137993012: use some helper Make functions to initialize SkImageInfo (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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 | « gm/srcmode.cpp ('k') | platform_tools/android/examples/hello_skia_app/jni/helloskia.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 2013 Google Inc. 2 * Copyright 2013 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 SkImageInfo_DEFINED 8 #ifndef SkImageInfo_DEFINED
9 #define SkImageInfo_DEFINED 9 #define SkImageInfo_DEFINED
10 10
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 #include "SkSize.h"
12 13
13 class SkFlattenableWriteBuffer; 14 class SkFlattenableWriteBuffer;
14 class SkFlattenableReadBuffer; 15 class SkFlattenableReadBuffer;
15 16
16 /** 17 /**
17 * Describes how to interpret the alpha compoent of a pixel. 18 * Describes how to interpret the alpha compoent of a pixel.
18 */ 19 */
19 enum SkAlphaType { 20 enum SkAlphaType {
20 /** 21 /**
21 * All pixels should be treated as opaque, regardless of the value stored 22 * All pixels should be treated as opaque, regardless of the value stored
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 103
103 /** 104 /**
104 * Describe an image's dimensions and pixel type. 105 * Describe an image's dimensions and pixel type.
105 */ 106 */
106 struct SkImageInfo { 107 struct SkImageInfo {
107 int fWidth; 108 int fWidth;
108 int fHeight; 109 int fHeight;
109 SkColorType fColorType; 110 SkColorType fColorType;
110 SkAlphaType fAlphaType; 111 SkAlphaType fAlphaType;
111 112
113 static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType a t) {
114 SkASSERT(width >= 0);
115 SkASSERT(height >= 0);
116 SkImageInfo info = {
117 width, height, ct, at
118 };
119 return info;
120 }
121
122 /**
123 * Sets colortype to the native ARGB32 type.
124 */
125 static SkImageInfo MakeN32(int width, int height, SkAlphaType at) {
126 SkASSERT(width >= 0);
127 SkASSERT(height >= 0);
128 SkImageInfo info = {
129 width, height, kPMColor_SkColorType, at
130 };
131 return info;
132 }
133
134 /**
135 * Sets colortype to the native ARGB32 type, and the alphatype to premul.
136 */
137 static SkImageInfo MakeN32Premul(int width, int height) {
138 SkASSERT(width >= 0);
139 SkASSERT(height >= 0);
140 SkImageInfo info = {
141 width, height, kPMColor_SkColorType, kPremul_SkAlphaType
142 };
143 return info;
144 }
145
146 /**
147 * Sets colortype to the native ARGB32 type, and the alphatype to premul.
148 */
149 static SkImageInfo MakeN32Premul(const SkISize& size) {
150 return MakeN32Premul(size.width(), size.height());
151 }
152
153 static SkImageInfo MakeA8(int width, int height) {
154 SkASSERT(width >= 0);
155 SkASSERT(height >= 0);
156 SkImageInfo info = {
157 width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType
158 };
159 return info;
160 }
161
112 bool isOpaque() const { 162 bool isOpaque() const {
113 return SkAlphaTypeIsOpaque(fAlphaType); 163 return SkAlphaTypeIsOpaque(fAlphaType);
114 } 164 }
115 165
116 int bytesPerPixel() const { 166 int bytesPerPixel() const {
117 return SkColorTypeBytesPerPixel(fColorType); 167 return SkColorTypeBytesPerPixel(fColorType);
118 } 168 }
119 169
120 size_t minRowBytes() const { 170 size_t minRowBytes() const {
121 return fWidth * this->bytesPerPixel(); 171 return fWidth * this->bytesPerPixel();
(...skipping 11 matching lines...) Expand all
133 183
134 size_t getSafeSize(size_t rowBytes) const { 184 size_t getSafeSize(size_t rowBytes) const {
135 if (0 == fHeight) { 185 if (0 == fHeight) {
136 return 0; 186 return 0;
137 } 187 }
138 return (fHeight - 1) * rowBytes + fWidth * this->bytesPerPixel(); 188 return (fHeight - 1) * rowBytes + fWidth * this->bytesPerPixel();
139 } 189 }
140 }; 190 };
141 191
142 #endif 192 #endif
OLDNEW
« no previous file with comments | « gm/srcmode.cpp ('k') | platform_tools/android/examples/hello_skia_app/jni/helloskia.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698