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

Side by Side Diff: samplecode/SampleDitherBitmap.cpp

Issue 169063002: use SkColorType instead of SkBitmap::Config in samplecode (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 | « samplecode/SampleDither.cpp ('k') | samplecode/SampleEncode.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 static SkBitmap make_bitmap() { 55 static SkBitmap make_bitmap() {
56 SkPMColor c[256]; 56 SkPMColor c[256];
57 for (int i = 0; i < 256; i++) { 57 for (int i = 0; i < 256; i++) {
58 c[i] = SkPackARGB32(0xFF, i, 0, 0); 58 c[i] = SkPackARGB32(0xFF, i, 0, 0);
59 } 59 }
60 SkColorTable* ctable = new SkColorTable(c, 256, kOpaque_SkAlphaType); 60 SkColorTable* ctable = new SkColorTable(c, 256, kOpaque_SkAlphaType);
61 61
62 SkBitmap bm; 62 SkBitmap bm;
63 bm.setConfig(SkBitmap::kIndex8_Config, 256, 32); 63 bm.allocPixels(SkImageInfo::Make(256, 32, kIndex_8_SkColorType,
64 bm.allocPixels(ctable); 64 kPremul_SkAlphaType),
65 NULL, ctable);
65 ctable->unref(); 66 ctable->unref();
66 67
67 bm.lockPixels(); 68 bm.lockPixels();
68 for (int y = 0; y < bm.height(); y++) { 69 for (int y = 0; y < bm.height(); y++) {
69 uint8_t* p = bm.getAddr8(0, y); 70 uint8_t* p = bm.getAddr8(0, y);
70 for (int x = 0; x < 256; x++) { 71 for (int x = 0; x < 256; x++) {
71 p[x] = x; 72 p[x] = x;
72 } 73 }
73 } 74 }
74 bm.unlockPixels(); 75 bm.unlockPixels();
(...skipping 19 matching lines...) Expand all
94 if (SampleCode::TitleQ(*evt)) { 95 if (SampleCode::TitleQ(*evt)) {
95 SampleCode::TitleR(evt, "DitherBitmap"); 96 SampleCode::TitleR(evt, "DitherBitmap");
96 return true; 97 return true;
97 } 98 }
98 return this->INHERITED::onQuery(evt); 99 return this->INHERITED::onQuery(evt);
99 } 100 }
100 101
101 static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) { 102 static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
102 SkAutoLockPixels alp(*bm); // needed for ctable 103 SkAutoLockPixels alp(*bm); // needed for ctable
103 bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); 104 bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
104 #if 0
105 SkColorTable* ctable = bm->getColorTable();
106 if (ctable) {
107 if (ctable->isOpaque() != isOpaque) {
108 // how do we change a colortable? don't want to
109 }
110 }
111 #endif
112 } 105 }
113 106
114 static void draw2(SkCanvas* canvas, const SkBitmap& bm) { 107 static void draw2(SkCanvas* canvas, const SkBitmap& bm) {
115 SkPaint paint; 108 SkPaint paint;
116 SkBitmap bitmap(bm); 109 SkBitmap bitmap(bm);
117 110
118 setBitmapOpaque(&bitmap, false); 111 setBitmapOpaque(&bitmap, false);
119 paint.setDither(false); 112 paint.setDither(false);
120 canvas->drawBitmap(bitmap, 0, 0, &paint); 113 canvas->drawBitmap(bitmap, 0, 0, &paint);
121 paint.setDither(true); 114 paint.setDither(true);
(...skipping 27 matching lines...) Expand all
149 } 142 }
150 143
151 private: 144 private:
152 typedef SampleView INHERITED; 145 typedef SampleView INHERITED;
153 }; 146 };
154 147
155 ////////////////////////////////////////////////////////////////////////////// 148 //////////////////////////////////////////////////////////////////////////////
156 149
157 static SkView* MyFactory() { return new DitherBitmapView; } 150 static SkView* MyFactory() { return new DitherBitmapView; }
158 static SkViewRegister reg(MyFactory); 151 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleDither.cpp ('k') | samplecode/SampleEncode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698