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

Side by Side Diff: samplecode/SampleDitherBitmap.cpp

Issue 26709002: Revert "change SkColorTable to be immutable" (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
« no previous file with comments | « samplecode/SampleBlur.cpp ('k') | samplecode/SampleTinyBitmap.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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 path.close(); 47 path.close();
48 48
49 SkIRect bounds; 49 SkIRect bounds;
50 path.getBounds().round(&bounds); 50 path.getBounds().round(&bounds);
51 SkRegion clip(bounds); 51 SkRegion clip(bounds);
52 bool result = region.setPath(path, clip); // <-- !! DOWN !! 52 bool result = region.setPath(path, clip); // <-- !! DOWN !!
53 SkDebugf("----- result %d\n", result); 53 SkDebugf("----- result %d\n", result);
54 } 54 }
55 55
56 static SkBitmap make_bitmap() { 56 static SkBitmap make_bitmap() {
57 SkPMColor c[256]; 57 SkBitmap bm;
58 SkColorTable* ctable = new SkColorTable(256);
59
60 SkPMColor* c = ctable->lockColors();
58 for (int i = 0; i < 256; i++) { 61 for (int i = 0; i < 256; i++) {
59 c[i] = SkPackARGB32(0xFF, i, 0, 0); 62 c[i] = SkPackARGB32(0xFF, i, 0, 0);
60 } 63 }
61 SkColorTable* ctable = new SkColorTable(c, 256, kOpaque_SkAlphaType); 64 ctable->unlockColors(true);
62
63 SkBitmap bm;
64 bm.setConfig(SkBitmap::kIndex8_Config, 256, 32); 65 bm.setConfig(SkBitmap::kIndex8_Config, 256, 32);
65 bm.allocPixels(ctable); 66 bm.allocPixels(ctable);
66 ctable->unref(); 67 ctable->unref();
67 68
68 bm.lockPixels(); 69 bm.lockPixels();
69 for (int y = 0; y < bm.height(); y++) { 70 for (int y = 0; y < bm.height(); y++) {
70 uint8_t* p = bm.getAddr8(0, y); 71 uint8_t* p = bm.getAddr8(0, y);
71 for (int x = 0; x < 256; x++) { 72 for (int x = 0; x < 256; x++) {
72 p[x] = x; 73 p[x] = x;
73 } 74 }
(...skipping 20 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->setIsOpaque(isOpaque); 104 bm->setIsOpaque(isOpaque);
104 #if 0
105 SkColorTable* ctable = bm->getColorTable(); 105 SkColorTable* ctable = bm->getColorTable();
106 if (ctable) { 106 if (ctable) {
107 if (ctable->isOpaque() != isOpaque) { 107 ctable->setIsOpaque(isOpaque);
108 // how do we change a colortable? don't want to
109 }
110 } 108 }
111 #endif
112 } 109 }
113 110
114 static void draw2(SkCanvas* canvas, const SkBitmap& bm) { 111 static void draw2(SkCanvas* canvas, const SkBitmap& bm) {
115 SkPaint paint; 112 SkPaint paint;
116 SkBitmap bitmap(bm); 113 SkBitmap bitmap(bm);
117 114
118 setBitmapOpaque(&bitmap, false); 115 setBitmapOpaque(&bitmap, false);
119 paint.setDither(false); 116 paint.setDither(false);
120 canvas->drawBitmap(bitmap, 0, 0, &paint); 117 canvas->drawBitmap(bitmap, 0, 0, &paint);
121 paint.setDither(true); 118 paint.setDither(true);
(...skipping 19 matching lines...) Expand all
141 } 138 }
142 139
143 private: 140 private:
144 typedef SampleView INHERITED; 141 typedef SampleView INHERITED;
145 }; 142 };
146 143
147 ////////////////////////////////////////////////////////////////////////////// 144 //////////////////////////////////////////////////////////////////////////////
148 145
149 static SkView* MyFactory() { return new DitherBitmapView; } 146 static SkView* MyFactory() { return new DitherBitmapView; }
150 static SkViewRegister reg(MyFactory); 147 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleBlur.cpp ('k') | samplecode/SampleTinyBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698