OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 #ifndef SkLinearBitmapPipeline_sampler_DEFINED | 8 #ifndef SkLinearBitmapPipeline_sampler_DEFINED |
9 #define SkLinearBitmapPipeline_sampler_DEFINED | 9 #define SkLinearBitmapPipeline_sampler_DEFINED |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 Sk4f toSk4f(const Element pixel) const { | 71 Sk4f toSk4f(const Element pixel) const { |
72 return fTintColor * (pixel * (1.0f/255.0f)); | 72 return fTintColor * (pixel * (1.0f/255.0f)); |
73 } | 73 } |
74 | 74 |
75 private: | 75 private: |
76 const Sk4f fTintColor; | 76 const Sk4f fTintColor; |
77 }; | 77 }; |
78 | 78 |
79 template <SkGammaType gammaType> | 79 template <SkGammaType gammaType> |
| 80 static inline Sk4f pmcolor_to_rgba(SkPMColor pixel) { |
| 81 return swizzle_rb_if_bgra( |
| 82 (gammaType == kSRGB_SkGammaType) ? Sk4f_fromS32(pixel) |
| 83 : Sk4f_fromL32(pixel)); |
| 84 } |
| 85 |
| 86 template <SkGammaType gammaType> |
80 class PixelConverter<kRGB_565_SkColorType, gammaType> { | 87 class PixelConverter<kRGB_565_SkColorType, gammaType> { |
81 public: | 88 public: |
82 using Element = uint16_t; | 89 using Element = uint16_t; |
83 PixelConverter(const SkPixmap& srcPixmap) { } | 90 PixelConverter(const SkPixmap& srcPixmap) { } |
84 | 91 |
85 Sk4f toSk4f(Element pixel) const { | 92 Sk4f toSk4f(Element pixel) const { |
86 SkPMColor pixel32 = SkPixel16ToPixel32(pixel); | 93 return pmcolor_to_rgba<gammaType>(SkPixel16ToPixel32(pixel)); |
87 return gammaType == kSRGB_SkGammaType | |
88 ? Sk4f_fromS32(pixel32) | |
89 : Sk4f_fromL32(pixel32); | |
90 } | 94 } |
91 }; | 95 }; |
92 | 96 |
93 template <SkGammaType gammaType> | 97 template <SkGammaType gammaType> |
94 class PixelConverter<kARGB_4444_SkColorType, gammaType> { | 98 class PixelConverter<kARGB_4444_SkColorType, gammaType> { |
95 public: | 99 public: |
96 using Element = uint16_t; | 100 using Element = uint16_t; |
97 PixelConverter(const SkPixmap& srcPixmap) { } | 101 PixelConverter(const SkPixmap& srcPixmap) { } |
98 | 102 |
99 Sk4f toSk4f(Element pixel) const { | 103 Sk4f toSk4f(Element pixel) const { |
100 SkPMColor pixel32 = SkPixel4444ToPixel32(pixel); | 104 return pmcolor_to_rgba<gammaType>(SkPixel4444ToPixel32(pixel)); |
101 return gammaType == kSRGB_SkGammaType | |
102 ? Sk4f_fromS32(pixel32) | |
103 : Sk4f_fromL32(pixel32); | |
104 } | 105 } |
105 }; | 106 }; |
106 | 107 |
107 template <SkGammaType gammaType> | 108 template <SkGammaType gammaType> |
108 class PixelConverter<kRGBA_8888_SkColorType, gammaType> { | 109 class PixelConverter<kRGBA_8888_SkColorType, gammaType> { |
109 public: | 110 public: |
110 using Element = uint32_t; | 111 using Element = uint32_t; |
111 PixelConverter(const SkPixmap& srcPixmap) { } | 112 PixelConverter(const SkPixmap& srcPixmap) { } |
112 | 113 |
113 Sk4f toSk4f(Element pixel) const { | 114 Sk4f toSk4f(Element pixel) const { |
(...skipping 18 matching lines...) Expand all Loading... |
132 template <SkGammaType gammaType> | 133 template <SkGammaType gammaType> |
133 class PixelConverter<kIndex_8_SkColorType, gammaType> { | 134 class PixelConverter<kIndex_8_SkColorType, gammaType> { |
134 public: | 135 public: |
135 using Element = uint8_t; | 136 using Element = uint8_t; |
136 PixelConverter(const SkPixmap& srcPixmap) { | 137 PixelConverter(const SkPixmap& srcPixmap) { |
137 SkColorTable* skColorTable = srcPixmap.ctable(); | 138 SkColorTable* skColorTable = srcPixmap.ctable(); |
138 SkASSERT(skColorTable != nullptr); | 139 SkASSERT(skColorTable != nullptr); |
139 | 140 |
140 fColorTable = (Sk4f*)SkAlign16((intptr_t)fColorTableStorage.get()); | 141 fColorTable = (Sk4f*)SkAlign16((intptr_t)fColorTableStorage.get()); |
141 for (int i = 0; i < skColorTable->count(); i++) { | 142 for (int i = 0; i < skColorTable->count(); i++) { |
142 fColorTable[i] = this->convertPixel((*skColorTable)[i]); | 143 fColorTable[i] = pmcolor_to_rgba<gammaType>((*skColorTable)[i]); |
143 } | 144 } |
144 } | 145 } |
145 | 146 |
146 PixelConverter(const PixelConverter& strategy) { | 147 PixelConverter(const PixelConverter& strategy) { |
147 fColorTable = (Sk4f*)SkAlign16((intptr_t)fColorTableStorage.get()); | 148 fColorTable = (Sk4f*)SkAlign16((intptr_t)fColorTableStorage.get()); |
148 // TODO: figure out the count. | 149 // TODO: figure out the count. |
149 for (int i = 0; i < 256; i++) { | 150 for (int i = 0; i < 256; i++) { |
150 fColorTable[i] = strategy.fColorTable[i]; | 151 fColorTable[i] = strategy.fColorTable[i]; |
151 } | 152 } |
152 } | 153 } |
153 | 154 |
154 Sk4f toSk4f(Element index) const { | 155 Sk4f toSk4f(Element index) const { |
155 return fColorTable[index]; | 156 return fColorTable[index]; |
156 } | 157 } |
157 | 158 |
158 private: | 159 private: |
159 static const size_t kColorTableSize = sizeof(Sk4f[256]) + 12; | 160 static const size_t kColorTableSize = sizeof(Sk4f[256]) + 12; |
160 Sk4f convertPixel(SkPMColor pmColor) { | 161 |
161 Sk4f pixel = to_4f(pmColor); | |
162 float alpha = get_alpha(pixel); | |
163 if (alpha != 0.0f) { | |
164 float invAlpha = 1.0f / alpha; | |
165 Sk4f normalize = {invAlpha, invAlpha, invAlpha, 1.0f / 255.0f}; | |
166 pixel = pixel * normalize; | |
167 if (gammaType == kSRGB_SkGammaType) { | |
168 pixel = linear_to_srgb(pixel); | |
169 } | |
170 return pixel; | |
171 } else { | |
172 return Sk4f{0.0f}; | |
173 } | |
174 } | |
175 SkAutoMalloc fColorTableStorage{kColorTableSize}; | 162 SkAutoMalloc fColorTableStorage{kColorTableSize}; |
176 Sk4f* fColorTable; | 163 Sk4f* fColorTable; |
177 }; | 164 }; |
178 | 165 |
179 template <SkGammaType gammaType> | 166 template <SkGammaType gammaType> |
180 class PixelConverter<kGray_8_SkColorType, gammaType> { | 167 class PixelConverter<kGray_8_SkColorType, gammaType> { |
181 public: | 168 public: |
182 using Element = uint8_t; | 169 using Element = uint8_t; |
183 PixelConverter(const SkPixmap& srcPixmap) { } | 170 PixelConverter(const SkPixmap& srcPixmap) { } |
184 | 171 |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 } | 825 } |
839 } | 826 } |
840 | 827 |
841 Next* const fNext; | 828 Next* const fNext; |
842 Accessor fAccessor; | 829 Accessor fAccessor; |
843 }; | 830 }; |
844 | 831 |
845 } // namespace | 832 } // namespace |
846 | 833 |
847 #endif // SkLinearBitmapPipeline_sampler_DEFINED | 834 #endif // SkLinearBitmapPipeline_sampler_DEFINED |
OLD | NEW |