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 "SkMatrixConvolutionImageFilter.h" | 8 #include "SkMatrixConvolutionImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 return nullptr; | 67 return nullptr; |
68 } | 68 } |
69 if ((kernelOffset.fX < 0) || (kernelOffset.fX >= kernelSize.fWidth) || | 69 if ((kernelOffset.fX < 0) || (kernelOffset.fX >= kernelSize.fWidth) || |
70 (kernelOffset.fY < 0) || (kernelOffset.fY >= kernelSize.fHeight)) { | 70 (kernelOffset.fY < 0) || (kernelOffset.fY >= kernelSize.fHeight)) { |
71 return nullptr; | 71 return nullptr; |
72 } | 72 } |
73 return new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, ke
rnelOffset, | 73 return new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, ke
rnelOffset, |
74 tileMode, convolveAlpha, input, cr
opRect); | 74 tileMode, convolveAlpha, input, cr
opRect); |
75 } | 75 } |
76 | 76 |
77 SkFlattenable* SkMatrixConvolutionImageFilter::CreateProc(SkReadBuffer& buffer)
{ | 77 sk_sp<SkFlattenable> SkMatrixConvolutionImageFilter::CreateProc(SkReadBuffer& bu
ffer) { |
78 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 78 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
79 SkISize kernelSize; | 79 SkISize kernelSize; |
80 kernelSize.fWidth = buffer.readInt(); | 80 kernelSize.fWidth = buffer.readInt(); |
81 kernelSize.fHeight = buffer.readInt(); | 81 kernelSize.fHeight = buffer.readInt(); |
82 const int count = buffer.getArrayCount(); | 82 const int count = buffer.getArrayCount(); |
83 | 83 |
84 const int64_t kernelArea = sk_64_mul(kernelSize.width(), kernelSize.height()
); | 84 const int64_t kernelArea = sk_64_mul(kernelSize.width(), kernelSize.height()
); |
85 if (!buffer.validate(kernelArea == count)) { | 85 if (!buffer.validate(kernelArea == count)) { |
86 return nullptr; | 86 return nullptr; |
87 } | 87 } |
88 SkAutoSTArray<16, SkScalar> kernel(count); | 88 SkAutoSTArray<16, SkScalar> kernel(count); |
89 if (!buffer.readScalarArray(kernel.get(), count)) { | 89 if (!buffer.readScalarArray(kernel.get(), count)) { |
90 return nullptr; | 90 return nullptr; |
91 } | 91 } |
92 SkScalar gain = buffer.readScalar(); | 92 SkScalar gain = buffer.readScalar(); |
93 SkScalar bias = buffer.readScalar(); | 93 SkScalar bias = buffer.readScalar(); |
94 SkIPoint kernelOffset; | 94 SkIPoint kernelOffset; |
95 kernelOffset.fX = buffer.readInt(); | 95 kernelOffset.fX = buffer.readInt(); |
96 kernelOffset.fY = buffer.readInt(); | 96 kernelOffset.fY = buffer.readInt(); |
97 TileMode tileMode = (TileMode)buffer.readInt(); | 97 TileMode tileMode = (TileMode)buffer.readInt(); |
98 bool convolveAlpha = buffer.readBool(); | 98 bool convolveAlpha = buffer.readBool(); |
99 return Create(kernelSize, kernel.get(), gain, bias, kernelOffset, tileMode,
convolveAlpha, | 99 return sk_sp<SkFlattenable>(Create(kernelSize, kernel.get(), gain, bias, ker
nelOffset, tileMode, |
100 common.getInput(0).get(), &common.cropRect()); | 100 convolveAlpha, common.getInput(0).get(), &com
mon.cropRect())); |
101 } | 101 } |
102 | 102 |
103 void SkMatrixConvolutionImageFilter::flatten(SkWriteBuffer& buffer) const { | 103 void SkMatrixConvolutionImageFilter::flatten(SkWriteBuffer& buffer) const { |
104 this->INHERITED::flatten(buffer); | 104 this->INHERITED::flatten(buffer); |
105 buffer.writeInt(fKernelSize.fWidth); | 105 buffer.writeInt(fKernelSize.fWidth); |
106 buffer.writeInt(fKernelSize.fHeight); | 106 buffer.writeInt(fKernelSize.fHeight); |
107 buffer.writeScalarArray(fKernel, fKernelSize.fWidth * fKernelSize.fHeight); | 107 buffer.writeScalarArray(fKernel, fKernelSize.fWidth * fKernelSize.fHeight); |
108 buffer.writeScalar(fGain); | 108 buffer.writeScalar(fGain); |
109 buffer.writeScalar(fBias); | 109 buffer.writeScalar(fBias); |
110 buffer.writeInt(fKernelOffset.fX); | 110 buffer.writeInt(fKernelOffset.fX); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 str->appendf("%f ", fKernel[y * fKernelSize.width() + x]); | 390 str->appendf("%f ", fKernel[y * fKernelSize.width() + x]); |
391 } | 391 } |
392 } | 392 } |
393 str->appendf(")"); | 393 str->appendf(")"); |
394 str->appendf("gain: %f bias: %f ", fGain, fBias); | 394 str->appendf("gain: %f bias: %f ", fGain, fBias); |
395 str->appendf("offset: (%d, %d) ", fKernelOffset.fX, fKernelOffset.fY); | 395 str->appendf("offset: (%d, %d) ", fKernelOffset.fX, fKernelOffset.fY); |
396 str->appendf("convolveAlpha: %s", fConvolveAlpha ? "true" : "false"); | 396 str->appendf("convolveAlpha: %s", fConvolveAlpha ? "true" : "false"); |
397 str->append(")"); | 397 str->append(")"); |
398 } | 398 } |
399 #endif | 399 #endif |
OLD | NEW |