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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 Sk4f toSk4f(Element index) const { | 154 Sk4f toSk4f(Element index) const { |
155 return fColorTable[index]; | 155 return fColorTable[index]; |
156 } | 156 } |
157 | 157 |
158 private: | 158 private: |
159 static const size_t kColorTableSize = sizeof(Sk4f[256]) + 12; | 159 static const size_t kColorTableSize = sizeof(Sk4f[256]) + 12; |
160 Sk4f convertPixel(SkPMColor pmColor) { | 160 Sk4f convertPixel(SkPMColor pmColor) { |
161 Sk4f pixel = to_4f(pmColor); | 161 return swizzle_rb_if_bgra( |
162 float alpha = get_alpha(pixel); | 162 (gammaType == kSRGB_SkGammaType) ? Sk4f_fromS32(pmColor) |
163 if (alpha != 0.0f) { | 163 : Sk4f_fromL32(pmColor)); |
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 } | 164 } |
175 SkAutoMalloc fColorTableStorage{kColorTableSize}; | 165 SkAutoMalloc fColorTableStorage{kColorTableSize}; |
176 Sk4f* fColorTable; | 166 Sk4f* fColorTable; |
177 }; | 167 }; |
178 | 168 |
179 template <SkGammaType gammaType> | 169 template <SkGammaType gammaType> |
180 class PixelConverter<kGray_8_SkColorType, gammaType> { | 170 class PixelConverter<kGray_8_SkColorType, gammaType> { |
181 public: | 171 public: |
182 using Element = uint8_t; | 172 using Element = uint8_t; |
183 PixelConverter(const SkPixmap& srcPixmap) { } | 173 PixelConverter(const SkPixmap& srcPixmap) { } |
184 | 174 |
185 Sk4f toSk4f(Element pixel) const { | 175 Sk4f toSk4f(Element pixel) const { |
186 float gray = pixel * (1.0f/255.0f); | 176 float gray = (gammaType == kSRGB_SkGammaType) |
187 Sk4f result = Sk4f{gray, gray, gray, 1.0f}; | 177 ? sk_linear_from_srgb[pixel] |
188 return gammaType == kSRGB_SkGammaType | 178 : pixel * (1/255.0f); |
189 ? srgb_to_linear(result) | 179 return {gray, gray, gray, 1.0f}; |
190 : result; | |
191 } | 180 } |
192 }; | 181 }; |
193 | 182 |
194 template <> | 183 template <> |
195 class PixelConverter<kRGBA_F16_SkColorType, kLinear_SkGammaType> { | 184 class PixelConverter<kRGBA_F16_SkColorType, kLinear_SkGammaType> { |
196 public: | 185 public: |
197 using Element = uint64_t; | 186 using Element = uint64_t; |
198 PixelConverter(const SkPixmap& srcPixmap) { } | 187 PixelConverter(const SkPixmap& srcPixmap) { } |
199 | 188 |
200 Sk4f toSk4f(const Element pixel) const { | 189 Sk4f toSk4f(const Element pixel) const { |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 } | 827 } |
839 } | 828 } |
840 | 829 |
841 Next* const fNext; | 830 Next* const fNext; |
842 Accessor fAccessor; | 831 Accessor fAccessor; |
843 }; | 832 }; |
844 | 833 |
845 } // namespace | 834 } // namespace |
846 | 835 |
847 #endif // SkLinearBitmapPipeline_sampler_DEFINED | 836 #endif // SkLinearBitmapPipeline_sampler_DEFINED |
OLD | NEW |