OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkEmbossMaskFilter.h" | 10 #include "SkEmbossMaskFilter.h" |
11 #include "SkBlurMaskFilter.h" | 11 #include "SkBlurMaskFilter.h" |
12 #include "SkBlurMask.h" | 12 #include "SkBlurMask.h" |
13 #include "SkEmbossMask.h" | 13 #include "SkEmbossMask.h" |
14 #include "SkFlattenableBuffers.h" | 14 #include "SkReadBuffer.h" |
| 15 #include "SkWriteBuffer.h" |
15 #include "SkString.h" | 16 #include "SkString.h" |
16 | 17 |
17 static inline int pin2byte(int n) { | 18 static inline int pin2byte(int n) { |
18 if (n < 0) { | 19 if (n < 0) { |
19 n = 0; | 20 n = 0; |
20 } else if (n > 0xFF) { | 21 } else if (n > 0xFF) { |
21 n = 0xFF; | 22 n = 0xFF; |
22 } | 23 } |
23 return n; | 24 return n; |
24 } | 25 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 SkPoint::Length(fLight.fDirection[0], fLight.fDirection[1])); | 123 SkPoint::Length(fLight.fDirection[0], fLight.fDirection[1])); |
123 | 124 |
124 SkEmbossMask::Emboss(dst, light); | 125 SkEmbossMask::Emboss(dst, light); |
125 | 126 |
126 // restore original alpha | 127 // restore original alpha |
127 memcpy(dst->fImage, src.fImage, src.computeImageSize()); | 128 memcpy(dst->fImage, src.fImage, src.computeImageSize()); |
128 | 129 |
129 return true; | 130 return true; |
130 } | 131 } |
131 | 132 |
132 SkEmbossMaskFilter::SkEmbossMaskFilter(SkFlattenableReadBuffer& buffer) | 133 SkEmbossMaskFilter::SkEmbossMaskFilter(SkReadBuffer& buffer) |
133 : SkMaskFilter(buffer) { | 134 : SkMaskFilter(buffer) { |
134 SkASSERT(buffer.getArrayCount() == sizeof(Light)); | 135 SkASSERT(buffer.getArrayCount() == sizeof(Light)); |
135 buffer.readByteArray(&fLight, sizeof(Light)); | 136 buffer.readByteArray(&fLight, sizeof(Light)); |
136 SkASSERT(fLight.fPad == 0); // for the font-cache lookup to be clean | 137 SkASSERT(fLight.fPad == 0); // for the font-cache lookup to be clean |
137 fBlurSigma = buffer.readScalar(); | 138 fBlurSigma = buffer.readScalar(); |
138 } | 139 } |
139 | 140 |
140 void SkEmbossMaskFilter::flatten(SkFlattenableWriteBuffer& buffer) const { | 141 void SkEmbossMaskFilter::flatten(SkWriteBuffer& buffer) const { |
141 this->INHERITED::flatten(buffer); | 142 this->INHERITED::flatten(buffer); |
142 | 143 |
143 Light tmpLight = fLight; | 144 Light tmpLight = fLight; |
144 tmpLight.fPad = 0; // for the font-cache lookup to be clean | 145 tmpLight.fPad = 0; // for the font-cache lookup to be clean |
145 buffer.writeByteArray(&tmpLight, sizeof(tmpLight)); | 146 buffer.writeByteArray(&tmpLight, sizeof(tmpLight)); |
146 buffer.writeScalar(fBlurSigma); | 147 buffer.writeScalar(fBlurSigma); |
147 } | 148 } |
148 | 149 |
149 #ifdef SK_DEVELOPER | 150 #ifdef SK_DEVELOPER |
150 void SkEmbossMaskFilter::toString(SkString* str) const { | 151 void SkEmbossMaskFilter::toString(SkString* str) const { |
151 str->append("SkEmbossMaskFilter: ("); | 152 str->append("SkEmbossMaskFilter: ("); |
152 | 153 |
153 str->append("direction: ("); | 154 str->append("direction: ("); |
154 str->appendScalar(fLight.fDirection[0]); | 155 str->appendScalar(fLight.fDirection[0]); |
155 str->append(", "); | 156 str->append(", "); |
156 str->appendScalar(fLight.fDirection[1]); | 157 str->appendScalar(fLight.fDirection[1]); |
157 str->append(", "); | 158 str->append(", "); |
158 str->appendScalar(fLight.fDirection[2]); | 159 str->appendScalar(fLight.fDirection[2]); |
159 str->append(") "); | 160 str->append(") "); |
160 | 161 |
161 str->appendf("ambient: %d specular: %d ", | 162 str->appendf("ambient: %d specular: %d ", |
162 fLight.fAmbient, fLight.fSpecular); | 163 fLight.fAmbient, fLight.fSpecular); |
163 | 164 |
164 str->append("blurSigma: "); | 165 str->append("blurSigma: "); |
165 str->appendScalar(fBlurSigma); | 166 str->appendScalar(fBlurSigma); |
166 str->append(")"); | 167 str->append(")"); |
167 } | 168 } |
168 #endif | 169 #endif |
OLD | NEW |