OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
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 "SkColorFilterImageFilter.h" | 8 #include "SkColorFilterImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 bool matrix_needs_clamping(SkScalar matrix[20]) { | 50 bool matrix_needs_clamping(SkScalar matrix[20]) { |
51 return component_needs_clamping(matrix) | 51 return component_needs_clamping(matrix) |
52 || component_needs_clamping(matrix+5) | 52 || component_needs_clamping(matrix+5) |
53 || component_needs_clamping(matrix+10) | 53 || component_needs_clamping(matrix+10) |
54 || component_needs_clamping(matrix+15); | 54 || component_needs_clamping(matrix+15); |
55 } | 55 } |
56 | 56 |
57 }; | 57 }; |
58 | 58 |
59 SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, | 59 SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, |
60 SkImageFilter* input, const SkIRect* cropRect) { | 60 SkImageFilter* input, const CropRect* cropRect) { |
61 SkASSERT(cf); | 61 SkASSERT(cf); |
62 SkScalar colorMatrix[20], inputMatrix[20]; | 62 SkScalar colorMatrix[20], inputMatrix[20]; |
63 SkColorFilter* inputColorFilter; | 63 SkColorFilter* inputColorFilter; |
64 if (input && cf->asColorMatrix(colorMatrix) | 64 if (input && cf->asColorMatrix(colorMatrix) |
65 && input->asColorFilter(&inputColorFilter) | 65 && input->asColorFilter(&inputColorFilter) |
66 && (NULL != inputColorFilter)) { | 66 && (NULL != inputColorFilter)) { |
67 SkAutoUnref autoUnref(inputColorFilter); | 67 SkAutoUnref autoUnref(inputColorFilter); |
68 if (inputColorFilter->asColorMatrix(inputMatrix) && !matrix_needs_clampi
ng(inputMatrix)) { | 68 if (inputColorFilter->asColorMatrix(inputMatrix) && !matrix_needs_clampi
ng(inputMatrix)) { |
69 SkScalar combinedMatrix[20]; | 69 SkScalar combinedMatrix[20]; |
70 mult_color_matrix(inputMatrix, colorMatrix, combinedMatrix); | 70 mult_color_matrix(inputMatrix, colorMatrix, combinedMatrix); |
71 SkAutoTUnref<SkColorFilter> newCF(SkNEW_ARGS(SkColorMatrixFilter, (c
ombinedMatrix))); | 71 SkAutoTUnref<SkColorFilter> newCF(SkNEW_ARGS(SkColorMatrixFilter, (c
ombinedMatrix))); |
72 return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput(
0), cropRect)); | 72 return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput(
0), cropRect)); |
73 } | 73 } |
74 } | 74 } |
75 return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input, cropRect)); | 75 return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input, cropRect)); |
76 } | 76 } |
77 | 77 |
78 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, | 78 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, |
79 SkImageFilter* input, const SkIRect* cropRect) | 79 SkImageFilter* input, const CropRect* cropRect) |
80 : INHERITED(input, cropRect), fColorFilter(cf) { | 80 : INHERITED(input, cropRect), fColorFilter(cf) { |
81 SkASSERT(cf); | 81 SkASSERT(cf); |
82 SkSafeRef(cf); | 82 SkSafeRef(cf); |
83 } | 83 } |
84 | 84 |
85 SkColorFilterImageFilter::SkColorFilterImageFilter(SkFlattenableReadBuffer& buff
er) : INHERITED(buffer) { | 85 SkColorFilterImageFilter::SkColorFilterImageFilter(SkFlattenableReadBuffer& buff
er) : INHERITED(buffer) { |
86 fColorFilter = buffer.readFlattenableT<SkColorFilter>(); | 86 fColorFilter = buffer.readFlattenableT<SkColorFilter>(); |
87 } | 87 } |
88 | 88 |
89 void SkColorFilterImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { | 89 void SkColorFilterImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
(...skipping 29 matching lines...) Expand all Loading... |
119 paint.setColorFilter(fColorFilter); | 119 paint.setColorFilter(fColorFilter); |
120 canvas.drawSprite(src, -bounds.fLeft, -bounds.fTop, &paint); | 120 canvas.drawSprite(src, -bounds.fLeft, -bounds.fTop, &paint); |
121 | 121 |
122 *result = device.get()->accessBitmap(false); | 122 *result = device.get()->accessBitmap(false); |
123 loc->fX += bounds.fLeft; | 123 loc->fX += bounds.fLeft; |
124 loc->fY += bounds.fTop; | 124 loc->fY += bounds.fTop; |
125 return true; | 125 return true; |
126 } | 126 } |
127 | 127 |
128 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { | 128 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { |
129 if (cropRect().isLargest()) { | 129 if (!cropRectIsSet()) { |
130 if (filter) { | 130 if (filter) { |
131 *filter = fColorFilter; | 131 *filter = fColorFilter; |
132 fColorFilter->ref(); | 132 fColorFilter->ref(); |
133 } | 133 } |
134 return true; | 134 return true; |
135 } | 135 } |
136 return false; | 136 return false; |
137 } | 137 } |
OLD | NEW |