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

Side by Side Diff: samplecode/SampleDitherBitmap.cpp

Issue 26572006: Revert "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 SkBitmap bm; 57 SkPMColor c[256];
58 SkColorTable* ctable = new SkColorTable(256);
59
60 SkPMColor* c = ctable->lockColors();
61 for (int i = 0; i < 256; i++) { 58 for (int i = 0; i < 256; i++) {
62 c[i] = SkPackARGB32(0xFF, i, 0, 0); 59 c[i] = SkPackARGB32(0xFF, i, 0, 0);
63 } 60 }
64 ctable->unlockColors(true); 61 SkColorTable* ctable = new SkColorTable(c, 256, kOpaque_SkAlphaType);
62
63 SkBitmap bm;
65 bm.setConfig(SkBitmap::kIndex8_Config, 256, 32); 64 bm.setConfig(SkBitmap::kIndex8_Config, 256, 32);
66 bm.allocPixels(ctable); 65 bm.allocPixels(ctable);
67 ctable->unref(); 66 ctable->unref();
68 67
69 bm.lockPixels(); 68 bm.lockPixels();
70 for (int y = 0; y < bm.height(); y++) { 69 for (int y = 0; y < bm.height(); y++) {
71 uint8_t* p = bm.getAddr8(0, y); 70 uint8_t* p = bm.getAddr8(0, y);
72 for (int x = 0; x < 256; x++) { 71 for (int x = 0; x < 256; x++) {
73 p[x] = x; 72 p[x] = x;
74 } 73 }
(...skipping 20 matching lines...) Expand all
95 if (SampleCode::TitleQ(*evt)) { 94 if (SampleCode::TitleQ(*evt)) {
96 SampleCode::TitleR(evt, "DitherBitmap"); 95 SampleCode::TitleR(evt, "DitherBitmap");
97 return true; 96 return true;
98 } 97 }
99 return this->INHERITED::onQuery(evt); 98 return this->INHERITED::onQuery(evt);
100 } 99 }
101 100
102 static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) { 101 static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
103 SkAutoLockPixels alp(*bm); // needed for ctable 102 SkAutoLockPixels alp(*bm); // needed for ctable
104 bm->setIsOpaque(isOpaque); 103 bm->setIsOpaque(isOpaque);
104 #if 0
105 SkColorTable* ctable = bm->getColorTable(); 105 SkColorTable* ctable = bm->getColorTable();
106 if (ctable) { 106 if (ctable) {
107 ctable->setIsOpaque(isOpaque); 107 if (ctable->isOpaque() != isOpaque) {
108 // how do we change a colortable? don't want to
109 }
108 } 110 }
111 #endif
109 } 112 }
110 113
111 static void draw2(SkCanvas* canvas, const SkBitmap& bm) { 114 static void draw2(SkCanvas* canvas, const SkBitmap& bm) {
112 SkPaint paint; 115 SkPaint paint;
113 SkBitmap bitmap(bm); 116 SkBitmap bitmap(bm);
114 117
115 setBitmapOpaque(&bitmap, false); 118 setBitmapOpaque(&bitmap, false);
116 paint.setDither(false); 119 paint.setDither(false);
117 canvas->drawBitmap(bitmap, 0, 0, &paint); 120 canvas->drawBitmap(bitmap, 0, 0, &paint);
118 paint.setDither(true); 121 paint.setDither(true);
(...skipping 19 matching lines...) Expand all
138 } 141 }
139 142
140 private: 143 private:
141 typedef SampleView INHERITED; 144 typedef SampleView INHERITED;
142 }; 145 };
143 146
144 ////////////////////////////////////////////////////////////////////////////// 147 //////////////////////////////////////////////////////////////////////////////
145 148
146 static SkView* MyFactory() { return new DitherBitmapView; } 149 static SkView* MyFactory() { return new DitherBitmapView; }
147 static SkViewRegister reg(MyFactory); 150 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