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

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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 gEmpty->ref(); 82 gEmpty->ref();
83 return gEmpty; 83 return gEmpty;
84 } 84 }
85 85
86 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes) 86 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes)
87 : INHERITED(info.fWidth, info.fHeight) { 87 : INHERITED(info.fWidth, info.fHeight) {
88 bool isOpaque; 88 bool isOpaque;
89 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); 89 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
90 90
91 fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes); 91 fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes, isOpaque ?
92 kOpaque_SkAlphaType : kPremul_SkAlphaType);
92 fBitmap.setPixelRef(SkNEW_ARGS(SkDataPixelRef, (data)))->unref(); 93 fBitmap.setPixelRef(SkNEW_ARGS(SkDataPixelRef, (data)))->unref();
93 fBitmap.setIsOpaque(isOpaque);
94 fBitmap.setImmutable(); 94 fBitmap.setImmutable();
95 } 95 }
96 96
97 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes ) 97 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes )
98 : INHERITED(info.fWidth, info.fHeight) { 98 : INHERITED(info.fWidth, info.fHeight) {
99 bool isOpaque; 99 bool isOpaque;
100 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); 100 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
101 101
102 fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes); 102 fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes, isOpaque ?
103 kOpaque_SkAlphaType : kPremul_SkAlphaType);
103 fBitmap.setPixelRef(pr); 104 fBitmap.setPixelRef(pr);
104 fBitmap.setIsOpaque(isOpaque);
105 } 105 }
106 106
107 SkImage_Raster::~SkImage_Raster() {} 107 SkImage_Raster::~SkImage_Raster() {}
108 108
109 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa int* paint) { 109 void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa int* paint) {
110 canvas->drawBitmap(fBitmap, x, y, paint); 110 canvas->drawBitmap(fBitmap, x, y, paint);
111 } 111 }
112 112
113 void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) { 113 void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) {
114 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); 114 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 162 }
163 163
164 SkImage* SkNewImageFromPixelRef(const SkImage::Info& info, SkPixelRef* pr, 164 SkImage* SkNewImageFromPixelRef(const SkImage::Info& info, SkPixelRef* pr,
165 size_t rowBytes) { 165 size_t rowBytes) {
166 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes)); 166 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes));
167 } 167 }
168 168
169 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) { 169 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) {
170 return ((SkImage_Raster*)image)->getPixelRef(); 170 return ((SkImage_Raster*)image)->getPixelRef();
171 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698