| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
| 9 #include "SkSurface.h" | 9 #include "SkSurface.h" |
| 10 #include "Resources.h" | 10 #include "Resources.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 SK_ColorBLUE, | 117 SK_ColorBLUE, |
| 118 SK_ColorCYAN, | 118 SK_ColorCYAN, |
| 119 SK_ColorMAGENTA, | 119 SK_ColorMAGENTA, |
| 120 SK_ColorYELLOW, | 120 SK_ColorYELLOW, |
| 121 }; | 121 }; |
| 122 SkPMColor pmColors[SK_ARRAY_COUNT(colors)]; | 122 SkPMColor pmColors[SK_ARRAY_COUNT(colors)]; |
| 123 for (size_t i = 0; i < SK_ARRAY_COUNT(colors); ++i) { | 123 for (size_t i = 0; i < SK_ARRAY_COUNT(colors); ++i) { |
| 124 pmColors[i] = premultiply_color(colors[i]); | 124 pmColors[i] = premultiply_color(colors[i]); |
| 125 } | 125 } |
| 126 SkBitmap bm; | 126 SkBitmap bm; |
| 127 SkAutoTUnref<SkColorTable> ctable( | 127 SkAutoTUnref<SkColorTable> ctable(new SkColorTable(pmColors, SK_ARRAY_COUNT(
pmColors))); |
| 128 SkNEW_ARGS(SkColorTable, (pmColors, SK_ARRAY_COUNT(pmColors)))); | |
| 129 SkImageInfo info = SkImageInfo::Make(SCALE, SCALE, kIndex_8_SkColorType, | 128 SkImageInfo info = SkImageInfo::Make(SCALE, SCALE, kIndex_8_SkColorType, |
| 130 kPremul_SkAlphaType); | 129 kPremul_SkAlphaType); |
| 131 bm.allocPixels(info, NULL, ctable); | 130 bm.allocPixels(info, NULL, ctable); |
| 132 SkAutoLockPixels autoLockPixels1(n32bitmap); | 131 SkAutoLockPixels autoLockPixels1(n32bitmap); |
| 133 SkAutoLockPixels autoLockPixels2(bm); | 132 SkAutoLockPixels autoLockPixels2(bm); |
| 134 for (int y = 0; y < SCALE; ++y) { | 133 for (int y = 0; y < SCALE; ++y) { |
| 135 for (int x = 0; x < SCALE; ++x) { | 134 for (int x = 0; x < SCALE; ++x) { |
| 136 SkPMColor c = *n32bitmap.getAddr32(x, y); | 135 SkPMColor c = *n32bitmap.getAddr32(x, y); |
| 137 int idx = find(pmColors, SK_ARRAY_COUNT(pmColors), c); | 136 int idx = find(pmColors, SK_ARRAY_COUNT(pmColors), c); |
| 138 *bm.getAddr8(x, y) = SkClampMax(idx, SK_ARRAY_COUNT(pmColors) - 1); | 137 *bm.getAddr8(x, y) = SkClampMax(idx, SK_ARRAY_COUNT(pmColors) - 1); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 183 |
| 185 canvas->translate(0.0f, SkIntToScalar(SCALE)); | 184 canvas->translate(0.0f, SkIntToScalar(SCALE)); |
| 186 SkBitmap bitmapA8 = make_bitmap(kAlpha_8_SkColorType); | 185 SkBitmap bitmapA8 = make_bitmap(kAlpha_8_SkColorType); |
| 187 draw(canvas, p, bitmapA8, kAlpha_8_SkColorType, "Alpha 8"); | 186 draw(canvas, p, bitmapA8, kAlpha_8_SkColorType, "Alpha 8"); |
| 188 | 187 |
| 189 p.setColor(SK_ColorRED); | 188 p.setColor(SK_ColorRED); |
| 190 canvas->translate(0.0f, SkIntToScalar(SCALE)); | 189 canvas->translate(0.0f, SkIntToScalar(SCALE)); |
| 191 SkBitmap bitmapG8 = make_bitmap(kGray_8_SkColorType); | 190 SkBitmap bitmapG8 = make_bitmap(kGray_8_SkColorType); |
| 192 draw(canvas, p, bitmapG8, kGray_8_SkColorType, "Gray 8"); | 191 draw(canvas, p, bitmapG8, kGray_8_SkColorType, "Gray 8"); |
| 193 } | 192 } |
| OLD | NEW |