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

Side by Side Diff: src/image/SkImage_Raster.cpp

Issue 25275004: store SkAlphaType inside SkBitmap, on road to support unpremul (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
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 #include "SkImage_Base.h" 8 #include "SkImage_Base.h"
9 #include "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 13 matching lines...) Expand all
24 if (info.fWidth > maxDimension || info.fHeight > maxDimension) { 24 if (info.fWidth > maxDimension || info.fHeight > maxDimension) {
25 return false; 25 return false;
26 } 26 }
27 if ((unsigned)info.fColorType > (unsigned)kLastEnum_ColorType) { 27 if ((unsigned)info.fColorType > (unsigned)kLastEnum_ColorType) {
28 return false; 28 return false;
29 } 29 }
30 if ((unsigned)info.fAlphaType > (unsigned)kLastEnum_SkAlphaType) { 30 if ((unsigned)info.fAlphaType > (unsigned)kLastEnum_SkAlphaType) {
31 return false; 31 return false;
32 } 32 }
33 33
34 bool isOpaque; 34 if (SkImageInfoToBitmapConfig(info) == SkBitmap::kNo_Config) {
35 if (SkImageInfoToBitmapConfig(info, &isOpaque) == SkBitmap::kNo_Config) {
36 return false; 35 return false;
37 } 36 }
38 37
39 // TODO: check colorspace 38 // TODO: check colorspace
40 39
41 if (rowBytes < SkImageMinRowBytes(info)) { 40 if (rowBytes < SkImageMinRowBytes(info)) {
42 return false; 41 return false;
43 } 42 }
44 43
45 int64_t size = (int64_t)info.fHeight * rowBytes; 44 int64_t size = (int64_t)info.fHeight * rowBytes;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 static SkImage* gEmpty; 77 static SkImage* gEmpty;
79 if (NULL == gEmpty) { 78 if (NULL == gEmpty) {
80 gEmpty = SkNEW(SkImage_Raster); 79 gEmpty = SkNEW(SkImage_Raster);
81 } 80 }
82 gEmpty->ref(); 81 gEmpty->ref();
83 return gEmpty; 82 return gEmpty;
84 } 83 }
85 84
86 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes) 85 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes)
87 : INHERITED(info.fWidth, info.fHeight) { 86 : INHERITED(info.fWidth, info.fHeight) {
88 bool isOpaque; 87 SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
89 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
90 88
91 fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes); 89 fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes, info.fAlphaTy pe);
92 fBitmap.setPixelRef(SkNEW_ARGS(SkDataPixelRef, (data)))->unref(); 90 fBitmap.setPixelRef(SkNEW_ARGS(SkDataPixelRef, (data)))->unref();
93 fBitmap.setIsOpaque(isOpaque);
94 fBitmap.setImmutable(); 91 fBitmap.setImmutable();
95 } 92 }
96 93
97 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes ) 94 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes )
98 : INHERITED(info.fWidth, info.fHeight) { 95 : INHERITED(info.fWidth, info.fHeight) {
99 bool isOpaque; 96 SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
100 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
101 97
102 fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes); 98 fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes, info.fAlphaTy pe);
103 fBitmap.setPixelRef(pr); 99 fBitmap.setPixelRef(pr);
104 fBitmap.setIsOpaque(isOpaque);
105 } 100 }
106 101
107 SkImage_Raster::~SkImage_Raster() {} 102 SkImage_Raster::~SkImage_Raster() {}
108 103
109 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa int* paint) { 104 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa int* paint) {
110 canvas->drawBitmap(fBitmap, x, y, paint); 105 canvas->drawBitmap(fBitmap, x, y, paint);
111 } 106 }
112 107
113 void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) { 108 void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) {
114 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); 109 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 157 }
163 158
164 SkImage* SkNewImageFromPixelRef(const SkImage::Info& info, SkPixelRef* pr, 159 SkImage* SkNewImageFromPixelRef(const SkImage::Info& info, SkPixelRef* pr,
165 size_t rowBytes) { 160 size_t rowBytes) {
166 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes)); 161 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes));
167 } 162 }
168 163
169 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) { 164 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) {
170 return ((SkImage_Raster*)image)->getPixelRef(); 165 return ((SkImage_Raster*)image)->getPixelRef();
171 } 166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698