| 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 "SkColorMatrixFilterRowMajor255.h" | 8 #include "SkColorMatrixFilterRowMajor255.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkNx.h" | 10 #include "SkNx.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 const float* srcA = src + 15; | 25 const float* srcA = src + 15; |
| 26 | 26 |
| 27 for (int i = 0; i < 20; i += 4) { | 27 for (int i = 0; i < 20; i += 4) { |
| 28 dst[i + SK_PMORDER_INDEX_A] = *srcA++; | 28 dst[i + SK_PMORDER_INDEX_A] = *srcA++; |
| 29 dst[i + SK_PMORDER_INDEX_R] = *srcR++; | 29 dst[i + SK_PMORDER_INDEX_R] = *srcR++; |
| 30 dst[i + SK_PMORDER_INDEX_G] = *srcG++; | 30 dst[i + SK_PMORDER_INDEX_G] = *srcG++; |
| 31 dst[i + SK_PMORDER_INDEX_B] = *srcB++; | 31 dst[i + SK_PMORDER_INDEX_B] = *srcB++; |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 // src is [20] but some compilers won't accept __restrict__ on anything | 35 void SkColorMatrixFilterRowMajor255::initState() { |
| 36 // but an raw pointer or reference | 36 transpose_to_pmorder(fTranspose, fMatrix); |
| 37 void SkColorMatrixFilterRowMajor255::initState(const SkScalar* SK_RESTRICT src)
{ | |
| 38 transpose_to_pmorder(fTranspose, src); | |
| 39 | 37 |
| 40 const float* array = fMatrix; | 38 const float* array = fMatrix; |
| 41 | 39 |
| 42 // check if we have to munge Alpha | 40 // check if we have to munge Alpha |
| 43 bool changesAlpha = (array[15] || array[16] || array[17] || (array[18] - 1)
|| array[19]); | 41 bool changesAlpha = (array[15] || array[16] || array[17] || (array[18] - 1)
|| array[19]); |
| 44 bool usesAlpha = (array[3] || array[8] || array[13]); | 42 bool usesAlpha = (array[3] || array[8] || array[13]); |
| 45 | 43 |
| 46 if (changesAlpha || usesAlpha) { | 44 if (changesAlpha || usesAlpha) { |
| 47 fFlags = changesAlpha ? 0 : kAlphaUnchanged_Flag; | 45 fFlags = changesAlpha ? 0 : kAlphaUnchanged_Flag; |
| 48 } else { | 46 } else { |
| 49 fFlags = kAlphaUnchanged_Flag; | 47 fFlags = kAlphaUnchanged_Flag; |
| 50 } | 48 } |
| 51 fFlags |= kSupports4f_Flag; | 49 fFlags |= kSupports4f_Flag; |
| 52 } | 50 } |
| 53 | 51 |
| 54 /////////////////////////////////////////////////////////////////////////////// | 52 /////////////////////////////////////////////////////////////////////////////// |
| 55 | 53 |
| 56 SkColorMatrixFilterRowMajor255::SkColorMatrixFilterRowMajor255(const SkScalar ar
ray[20]) { | 54 SkColorMatrixFilterRowMajor255::SkColorMatrixFilterRowMajor255(const SkScalar ar
ray[20]) { |
| 57 memcpy(fMatrix, array, 20 * sizeof(SkScalar)); | 55 memcpy(fMatrix, array, 20 * sizeof(SkScalar)); |
| 58 this->initState(array); | 56 this->initState(); |
| 59 } | 57 } |
| 60 | 58 |
| 61 uint32_t SkColorMatrixFilterRowMajor255::getFlags() const { | 59 uint32_t SkColorMatrixFilterRowMajor255::getFlags() const { |
| 62 return this->INHERITED::getFlags() | fFlags; | 60 return this->INHERITED::getFlags() | fFlags; |
| 63 } | 61 } |
| 64 | 62 |
| 65 static Sk4f scale_rgb(float scale) { | 63 static Sk4f scale_rgb(float scale) { |
| 66 static_assert(SkPM4f::A == 3, "Alpha is lane 3"); | 64 static_assert(SkPM4f::A == 3, "Alpha is lane 3"); |
| 67 return Sk4f(scale, scale, scale, 1); | 65 return Sk4f(scale, scale, scale, 1); |
| 68 } | 66 } |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 411 } |
| 414 str->append(")"); | 412 str->append(")"); |
| 415 } | 413 } |
| 416 #endif | 414 #endif |
| 417 | 415 |
| 418 /////////////////////////////////////////////////////////////////////////////// | 416 /////////////////////////////////////////////////////////////////////////////// |
| 419 | 417 |
| 420 SkColorFilter* SkColorFilter::CreateMatrixFilterRowMajor255(const SkScalar array
[20]) { | 418 SkColorFilter* SkColorFilter::CreateMatrixFilterRowMajor255(const SkScalar array
[20]) { |
| 421 return new SkColorMatrixFilterRowMajor255(array); | 419 return new SkColorMatrixFilterRowMajor255(array); |
| 422 } | 420 } |
| 421 |
| 422 /////////////////////////////////////////////////////////////////////////////// |
| 423 |
| 424 SkColorFilter* SkColorMatrixFilterRowMajor255::CreateSingleChannelOutput(const S
kScalar row[5]) { |
| 425 SkASSERT(row); |
| 426 SkColorMatrixFilterRowMajor255* cf = new SkColorMatrixFilterRowMajor255(); |
| 427 static_assert(sizeof(SkScalar) * 5 * 4 == sizeof(cf->fMatrix), "sizes don't
match"); |
| 428 for (int i = 0; i < 4; ++i) { |
| 429 memcpy(cf->fMatrix + 5 * i, row, sizeof(SkScalar) * 5); |
| 430 } |
| 431 cf->initState(); |
| 432 return cf; |
| 433 } |
| OLD | NEW |