OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkColorMatrixFilter.h" | 8 #include "SkColorMatrixFilter.h" |
9 #include "SkColorMatrix.h" | 9 #include "SkColorMatrix.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 #endif | 292 #endif |
293 | 293 |
294 if (use_floats) { | 294 if (use_floats) { |
295 const Sk4f c0 = Sk4f::Load(fTranspose + 0); | 295 const Sk4f c0 = Sk4f::Load(fTranspose + 0); |
296 const Sk4f c1 = Sk4f::Load(fTranspose + 4); | 296 const Sk4f c1 = Sk4f::Load(fTranspose + 4); |
297 const Sk4f c2 = Sk4f::Load(fTranspose + 8); | 297 const Sk4f c2 = Sk4f::Load(fTranspose + 8); |
298 const Sk4f c3 = Sk4f::Load(fTranspose + 12); | 298 const Sk4f c3 = Sk4f::Load(fTranspose + 12); |
299 const Sk4f c4 = Sk4f::Load(fTranspose + 16); // translates | 299 const Sk4f c4 = Sk4f::Load(fTranspose + 16); // translates |
300 | 300 |
301 // todo: we could cache this in the constructor... | 301 // todo: we could cache this in the constructor... |
302 SkPMColor matrix_translate_pmcolor = SkPMFloat(premul(clamp_0_255(c4))).
clamped(); | 302 SkPMColor matrix_translate_pmcolor = SkPMFloat(premul(clamp_0_255(c4))).
roundClamp(); |
303 | 303 |
304 for (int i = 0; i < count; i++) { | 304 for (int i = 0; i < count; i++) { |
305 const SkPMColor src_c = src[i]; | 305 const SkPMColor src_c = src[i]; |
306 if (0 == src_c) { | 306 if (0 == src_c) { |
307 dst[i] = matrix_translate_pmcolor; | 307 dst[i] = matrix_translate_pmcolor; |
308 continue; | 308 continue; |
309 } | 309 } |
310 | 310 |
311 SkPMFloat srcf(src_c); | 311 SkPMFloat srcf(src_c); |
312 | 312 |
313 if (0xFF != SkGetPackedA32(src_c)) { | 313 if (0xFF != SkGetPackedA32(src_c)) { |
314 srcf = unpremul(srcf); | 314 srcf = unpremul(srcf); |
315 } | 315 } |
316 | 316 |
317 Sk4f r4 = Sk4f(srcf.r()); | 317 Sk4f r4 = Sk4f(srcf.r()); |
318 Sk4f g4 = Sk4f(srcf.g()); | 318 Sk4f g4 = Sk4f(srcf.g()); |
319 Sk4f b4 = Sk4f(srcf.b()); | 319 Sk4f b4 = Sk4f(srcf.b()); |
320 Sk4f a4 = Sk4f(srcf.a()); | 320 Sk4f a4 = Sk4f(srcf.a()); |
321 | 321 |
322 // apply matrix | 322 // apply matrix |
323 Sk4f dst4 = c0 * r4 + c1 * g4 + c2 * b4 + c3 * a4 + c4; | 323 Sk4f dst4 = c0 * r4 + c1 * g4 + c2 * b4 + c3 * a4 + c4; |
324 | 324 |
325 // clamp, re-premul, and write | 325 // clamp, re-premul, and write |
326 dst[i] = SkPMFloat(premul(clamp_0_255(dst4))).get(); | 326 dst[i] = SkPMFloat(premul(clamp_0_255(dst4))).round(); |
327 } | 327 } |
328 } else { | 328 } else { |
329 const State& state = fState; | 329 const State& state = fState; |
330 int32_t result[4]; | 330 int32_t result[4]; |
331 const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable(); | 331 const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable(); |
332 | 332 |
333 for (int i = 0; i < count; i++) { | 333 for (int i = 0; i < count; i++) { |
334 SkPMColor c = src[i]; | 334 SkPMColor c = src[i]; |
335 | 335 |
336 unsigned r = SkGetPackedR32(c); | 336 unsigned r = SkGetPackedR32(c); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 str->append("matrix: ("); | 577 str->append("matrix: ("); |
578 for (int i = 0; i < 20; ++i) { | 578 for (int i = 0; i < 20; ++i) { |
579 str->appendScalar(fMatrix.fMat[i]); | 579 str->appendScalar(fMatrix.fMat[i]); |
580 if (i < 19) { | 580 if (i < 19) { |
581 str->append(", "); | 581 str->append(", "); |
582 } | 582 } |
583 } | 583 } |
584 str->append(")"); | 584 str->append(")"); |
585 } | 585 } |
586 #endif | 586 #endif |
OLD | NEW |