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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 unsigned r, unsigned g, unsigned b, unsigned a, | 130 unsigned r, unsigned g, unsigned b, unsigned a, |
131 int32_t* SK_RESTRICT result) { | 131 int32_t* SK_RESTRICT result) { |
132 const int32_t* SK_RESTRICT array = state.fArray; | 132 const int32_t* SK_RESTRICT array = state.fArray; |
133 | 133 |
134 result[0] = r + (array[SkColorMatrix::kR_Trans] >> 16); | 134 result[0] = r + (array[SkColorMatrix::kR_Trans] >> 16); |
135 result[1] = g + (array[SkColorMatrix::kG_Trans] >> 16); | 135 result[1] = g + (array[SkColorMatrix::kG_Trans] >> 16); |
136 result[2] = b + (array[SkColorMatrix::kB_Trans] >> 16); | 136 result[2] = b + (array[SkColorMatrix::kB_Trans] >> 16); |
137 result[3] = a; | 137 result[3] = a; |
138 } | 138 } |
139 | 139 |
| 140 #define kNO_ALPHA_FLAGS (SkColorFilter::kAlphaUnchanged_Flag | \ |
| 141 SkColorFilter::kHasFilter16_Flag) |
| 142 |
140 // src is [20] but some compilers won't accept __restrict__ on anything | 143 // src is [20] but some compilers won't accept __restrict__ on anything |
141 // but an raw pointer or reference | 144 // but an raw pointer or reference |
142 void SkColorMatrixFilter::initState(const SkScalar* SK_RESTRICT src) { | 145 void SkColorMatrixFilter::initState(const SkScalar* SK_RESTRICT src) { |
143 transpose_to_pmorder(fTranspose, src); | 146 transpose_to_pmorder(fTranspose, src); |
144 | 147 |
145 int32_t* array = fState.fArray; | 148 int32_t* array = fState.fArray; |
146 SkFixed max = 0; | 149 SkFixed max = 0; |
147 for (int i = 0; i < 20; i++) { | 150 for (int i = 0; i < 20; i++) { |
148 SkFixed value = SkScalarToFixed(src[i]); | 151 SkFixed value = SkScalarToFixed(src[i]); |
149 array[i] = value; | 152 array[i] = value; |
(...skipping 21 matching lines...) Expand all Loading... |
171 // check if we have to munge Alpha | 174 // check if we have to munge Alpha |
172 int32_t changesAlpha = (array[15] | array[16] | array[17] | | 175 int32_t changesAlpha = (array[15] | array[16] | array[17] | |
173 (array[18] - one) | array[19]); | 176 (array[18] - one) | array[19]); |
174 int32_t usesAlpha = (array[3] | array[8] | array[13]); | 177 int32_t usesAlpha = (array[3] | array[8] | array[13]); |
175 bool shiftIs16 = (16 == fState.fShift); | 178 bool shiftIs16 = (16 == fState.fShift); |
176 | 179 |
177 if (changesAlpha | usesAlpha) { | 180 if (changesAlpha | usesAlpha) { |
178 fProc = shiftIs16 ? General16 : General; | 181 fProc = shiftIs16 ? General16 : General; |
179 fFlags = changesAlpha ? 0 : SkColorFilter::kAlphaUnchanged_Flag; | 182 fFlags = changesAlpha ? 0 : SkColorFilter::kAlphaUnchanged_Flag; |
180 } else { | 183 } else { |
181 fFlags = SkColorFilter::kAlphaUnchanged_Flag; | 184 fFlags = kNO_ALPHA_FLAGS; |
182 | 185 |
183 int32_t needsScale = (array[SkColorMatrix::kR_Scale] - one) | | 186 int32_t needsScale = (array[SkColorMatrix::kR_Scale] - one) | |
184 (array[SkColorMatrix::kG_Scale] - one) | | 187 (array[SkColorMatrix::kG_Scale] - one) | |
185 (array[SkColorMatrix::kB_Scale] - one); | 188 (array[SkColorMatrix::kB_Scale] - one); |
186 | 189 |
187 int32_t needs3x3 = array[1] | array[2] | // red off-axis | 190 int32_t needs3x3 = array[1] | array[2] | // red off-axis |
188 array[5] | array[7] | // green off-axis | 191 array[5] | array[7] | // green off-axis |
189 array[10] | array[11]; // blue off-axis | 192 array[10] | array[11]; // blue off-axis |
190 | 193 |
191 if (needs3x3) { | 194 if (needs3x3) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 r = pin(result[0], SK_R32_MASK); | 356 r = pin(result[0], SK_R32_MASK); |
354 g = pin(result[1], SK_G32_MASK); | 357 g = pin(result[1], SK_G32_MASK); |
355 b = pin(result[2], SK_B32_MASK); | 358 b = pin(result[2], SK_B32_MASK); |
356 a = pin(result[3], SK_A32_MASK); | 359 a = pin(result[3], SK_A32_MASK); |
357 // re-prepremultiply if needed | 360 // re-prepremultiply if needed |
358 dst[i] = SkPremultiplyARGBInline(a, r, g, b); | 361 dst[i] = SkPremultiplyARGBInline(a, r, g, b); |
359 } | 362 } |
360 } | 363 } |
361 } | 364 } |
362 | 365 |
| 366 void SkColorMatrixFilter::filterSpan16(const uint16_t src[], int count, |
| 367 uint16_t dst[]) const { |
| 368 SkASSERT(fFlags & SkColorFilter::kHasFilter16_Flag); |
| 369 |
| 370 Proc proc = fProc; |
| 371 const State& state = fState; |
| 372 int32_t result[4]; |
| 373 |
| 374 if (NULL == proc) { |
| 375 if (src != dst) { |
| 376 memcpy(dst, src, count * sizeof(uint16_t)); |
| 377 } |
| 378 return; |
| 379 } |
| 380 |
| 381 for (int i = 0; i < count; i++) { |
| 382 uint16_t c = src[i]; |
| 383 |
| 384 // expand to 8bit components (since our matrix translate is 8bit biased |
| 385 unsigned r = SkPacked16ToR32(c); |
| 386 unsigned g = SkPacked16ToG32(c); |
| 387 unsigned b = SkPacked16ToB32(c); |
| 388 |
| 389 proc(state, r, g, b, 0, result); |
| 390 |
| 391 r = pin(result[0], SK_R32_MASK); |
| 392 g = pin(result[1], SK_G32_MASK); |
| 393 b = pin(result[2], SK_B32_MASK); |
| 394 |
| 395 // now packed it back down to 16bits (hmmm, could dither...) |
| 396 dst[i] = SkPack888ToRGB16(r, g, b); |
| 397 } |
| 398 } |
| 399 |
363 /////////////////////////////////////////////////////////////////////////////// | 400 /////////////////////////////////////////////////////////////////////////////// |
364 | 401 |
365 void SkColorMatrixFilter::flatten(SkWriteBuffer& buffer) const { | 402 void SkColorMatrixFilter::flatten(SkWriteBuffer& buffer) const { |
366 SkASSERT(sizeof(fMatrix.fMat)/sizeof(SkScalar) == 20); | 403 SkASSERT(sizeof(fMatrix.fMat)/sizeof(SkScalar) == 20); |
367 buffer.writeScalarArray(fMatrix.fMat, 20); | 404 buffer.writeScalarArray(fMatrix.fMat, 20); |
368 } | 405 } |
369 | 406 |
370 SkFlattenable* SkColorMatrixFilter::CreateProc(SkReadBuffer& buffer) { | 407 SkFlattenable* SkColorMatrixFilter::CreateProc(SkReadBuffer& buffer) { |
371 SkColorMatrix matrix; | 408 SkColorMatrix matrix; |
372 if (buffer.readScalarArray(matrix.fMat, 20)) { | 409 if (buffer.readScalarArray(matrix.fMat, 20)) { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 str->append("matrix: ("); | 612 str->append("matrix: ("); |
576 for (int i = 0; i < 20; ++i) { | 613 for (int i = 0; i < 20; ++i) { |
577 str->appendScalar(fMatrix.fMat[i]); | 614 str->appendScalar(fMatrix.fMat[i]); |
578 if (i < 19) { | 615 if (i < 19) { |
579 str->append(", "); | 616 str->append(", "); |
580 } | 617 } |
581 } | 618 } |
582 str->append(")"); | 619 str->append(")"); |
583 } | 620 } |
584 #endif | 621 #endif |
OLD | NEW |