OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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); |
OLD | NEW |