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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 const SkISize& kernelSize, | 50 const SkISize& kernelSize, |
51 const SkScalar* kernel, | 51 const SkScalar* kernel, |
52 SkScalar gain, | 52 SkScalar gain, |
53 SkScalar bias, | 53 SkScalar bias, |
54 const SkIPoint& kernelOffset, | 54 const SkIPoint& kernelOffset, |
55 TileMode tileMode, | 55 TileMode tileMode, |
56 bool convolveAlpha, | 56 bool convolveAlpha, |
57 SkImageFilter* input, | 57 SkImageFilter* input, |
58 const CropRect* cropRect) { | 58 const CropRect* cropRect) { |
59 if (kernelSize.width() < 1 || kernelSize.height() < 1) { | 59 if (kernelSize.width() < 1 || kernelSize.height() < 1) { |
60 return NULL; | 60 return nullptr; |
61 } | 61 } |
62 if (gMaxKernelSize / kernelSize.fWidth < kernelSize.fHeight) { | 62 if (gMaxKernelSize / kernelSize.fWidth < kernelSize.fHeight) { |
63 return NULL; | 63 return nullptr; |
64 } | 64 } |
65 if (!kernel) { | 65 if (!kernel) { |
66 return NULL; | 66 return nullptr; |
67 } | 67 } |
68 if ((kernelOffset.fX < 0) || (kernelOffset.fX >= kernelSize.fWidth) || | 68 if ((kernelOffset.fX < 0) || (kernelOffset.fX >= kernelSize.fWidth) || |
69 (kernelOffset.fY < 0) || (kernelOffset.fY >= kernelSize.fHeight)) { | 69 (kernelOffset.fY < 0) || (kernelOffset.fY >= kernelSize.fHeight)) { |
70 return NULL; | 70 return nullptr; |
71 } | 71 } |
72 return new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, ke
rnelOffset, | 72 return new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, ke
rnelOffset, |
73 tileMode, convolveAlpha, input, cr
opRect); | 73 tileMode, convolveAlpha, input, cr
opRect); |
74 } | 74 } |
75 | 75 |
76 SkFlattenable* SkMatrixConvolutionImageFilter::CreateProc(SkReadBuffer& buffer)
{ | 76 SkFlattenable* SkMatrixConvolutionImageFilter::CreateProc(SkReadBuffer& buffer)
{ |
77 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 77 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
78 SkISize kernelSize; | 78 SkISize kernelSize; |
79 kernelSize.fWidth = buffer.readInt(); | 79 kernelSize.fWidth = buffer.readInt(); |
80 kernelSize.fHeight = buffer.readInt(); | 80 kernelSize.fHeight = buffer.readInt(); |
81 const int count = buffer.getArrayCount(); | 81 const int count = buffer.getArrayCount(); |
82 | 82 |
83 const int64_t kernelArea = sk_64_mul(kernelSize.width(), kernelSize.height()
); | 83 const int64_t kernelArea = sk_64_mul(kernelSize.width(), kernelSize.height()
); |
84 if (!buffer.validate(kernelArea == count)) { | 84 if (!buffer.validate(kernelArea == count)) { |
85 return NULL; | 85 return nullptr; |
86 } | 86 } |
87 SkAutoSTArray<16, SkScalar> kernel(count); | 87 SkAutoSTArray<16, SkScalar> kernel(count); |
88 if (!buffer.readScalarArray(kernel.get(), count)) { | 88 if (!buffer.readScalarArray(kernel.get(), count)) { |
89 return NULL; | 89 return nullptr; |
90 } | 90 } |
91 SkScalar gain = buffer.readScalar(); | 91 SkScalar gain = buffer.readScalar(); |
92 SkScalar bias = buffer.readScalar(); | 92 SkScalar bias = buffer.readScalar(); |
93 SkIPoint kernelOffset; | 93 SkIPoint kernelOffset; |
94 kernelOffset.fX = buffer.readInt(); | 94 kernelOffset.fX = buffer.readInt(); |
95 kernelOffset.fY = buffer.readInt(); | 95 kernelOffset.fY = buffer.readInt(); |
96 TileMode tileMode = (TileMode)buffer.readInt(); | 96 TileMode tileMode = (TileMode)buffer.readInt(); |
97 bool convolveAlpha = buffer.readBool(); | 97 bool convolveAlpha = buffer.readBool(); |
98 return Create(kernelSize, kernel.get(), gain, bias, kernelOffset, tileMode,
convolveAlpha, | 98 return Create(kernelSize, kernel.get(), gain, bias, kernelOffset, tileMode,
convolveAlpha, |
99 common.getInput(0), &common.cropRect()); | 99 common.getInput(0), &common.cropRect()); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 str->appendf("%f ", fKernel[y * fKernelSize.width() + x]); | 378 str->appendf("%f ", fKernel[y * fKernelSize.width() + x]); |
379 } | 379 } |
380 } | 380 } |
381 str->appendf(")"); | 381 str->appendf(")"); |
382 str->appendf("gain: %f bias: %f ", fGain, fBias); | 382 str->appendf("gain: %f bias: %f ", fGain, fBias); |
383 str->appendf("offset: (%d, %d) ", fKernelOffset.fX, fKernelOffset.fY); | 383 str->appendf("offset: (%d, %d) ", fKernelOffset.fX, fKernelOffset.fY); |
384 str->appendf("convolveAlpha: %s", fConvolveAlpha ? "true" : "false"); | 384 str->appendf("convolveAlpha: %s", fConvolveAlpha ? "true" : "false"); |
385 str->append(")"); | 385 str->append(")"); |
386 } | 386 } |
387 #endif | 387 #endif |
OLD | NEW |