OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "gm.h" | 8 #include "gm.h" |
9 #include "SkColorCubeFilter.h" | 9 #include "SkColorCubeFilter.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
| 12 #include "SkTemplates.h" |
12 | 13 |
13 namespace skiagm { | 14 namespace skiagm { |
14 | 15 |
15 static SkShader* MakeLinear() { | 16 static SkShader* MakeLinear() { |
16 static const SkPoint pts[2] = { | 17 static const SkPoint pts[2] = { |
17 { 0, 0 }, | 18 { 0, 0 }, |
18 { SkIntToScalar(80), SkIntToScalar(80) } | 19 { SkIntToScalar(80), SkIntToScalar(80) } |
19 }; | 20 }; |
20 static const SkColor colors[] = { SK_ColorYELLOW, SK_ColorBLUE }; | 21 static const SkColor colors[] = { SK_ColorYELLOW, SK_ColorBLUE }; |
21 return SkGradientShader::CreateLinear( | 22 return SkGradientShader::CreateLinear( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 SkShader* shader = MakeLinear(); | 66 SkShader* shader = MakeLinear(); |
66 paint.setShader(shader); | 67 paint.setShader(shader); |
67 SkRect r = { 0, 0, SkIntToScalar(80), SkIntToScalar(80) }; | 68 SkRect r = { 0, 0, SkIntToScalar(80), SkIntToScalar(80) }; |
68 canvas.drawRect(r, paint); | 69 canvas.drawRect(r, paint); |
69 shader->unref(); | 70 shader->unref(); |
70 } | 71 } |
71 | 72 |
72 void make_3Dlut(SkData** data, int size, bool invR, bool invG, bool invB) { | 73 void make_3Dlut(SkData** data, int size, bool invR, bool invG, bool invB) { |
73 *data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size); | 74 *data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size); |
74 SkColor* pixels = (SkColor*)((*data)->writable_data()); | 75 SkColor* pixels = (SkColor*)((*data)->writable_data()); |
75 SkAutoMalloc lutMemory(size); | 76 SkAutoTMalloc<uint8_t> lutMemory(size); |
76 SkAutoMalloc invLutMemory(size); | 77 SkAutoTMalloc<uint8_t> invLutMemory(size); |
77 uint8_t* lut = (uint8_t*)lutMemory.get(); | 78 uint8_t* lut = lutMemory.get(); |
78 uint8_t* invLut = (uint8_t*)invLutMemory.get(); | 79 uint8_t* invLut = invLutMemory.get(); |
79 const int maxIndex = size - 1; | 80 const int maxIndex = size - 1; |
80 for (int i = 0; i < size; i++) { | 81 for (int i = 0; i < size; i++) { |
81 lut[i] = (i * 255) / maxIndex; | 82 lut[i] = (i * 255) / maxIndex; |
82 invLut[i] = ((maxIndex - i) * 255) / maxIndex; | 83 invLut[i] = ((maxIndex - i) * 255) / maxIndex; |
83 } | 84 } |
84 for (int r = 0; r < size; ++r) { | 85 for (int r = 0; r < size; ++r) { |
85 for (int g = 0; g < size; ++g) { | 86 for (int g = 0; g < size; ++g) { |
86 for (int b = 0; b < size; ++b) { | 87 for (int b = 0; b < size; ++b) { |
87 pixels[(size * ((size * b) + g)) + r] = sk_tool_utils::color
_to_565( | 88 pixels[(size * ((size * b) + g)) + r] = sk_tool_utils::color
_to_565( |
88 SkColorSetARGB(0xFF, | 89 SkColorSetARGB(0xFF, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 SkData* f3DLut32; | 133 SkData* f3DLut32; |
133 SkData* f3DLut64; | 134 SkData* f3DLut64; |
134 }; | 135 }; |
135 | 136 |
136 ////////////////////////////////////////////////////////////////////////////// | 137 ////////////////////////////////////////////////////////////////////////////// |
137 | 138 |
138 static GM* MyFactory(void*) { return new ColorCubeGM; } | 139 static GM* MyFactory(void*) { return new ColorCubeGM; } |
139 static GMRegistry reg(MyFactory); | 140 static GMRegistry reg(MyFactory); |
140 | 141 |
141 } | 142 } |
OLD | NEW |