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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 if ((kernelOffset.fX < 0) || (kernelOffset.fX >= kernelSize.fWidth) || | 70 if ((kernelOffset.fX < 0) || (kernelOffset.fX >= kernelSize.fWidth) || |
71 (kernelOffset.fY < 0) || (kernelOffset.fY >= kernelSize.fHeight)) { | 71 (kernelOffset.fY < 0) || (kernelOffset.fY >= kernelSize.fHeight)) { |
72 return NULL; | 72 return NULL; |
73 } | 73 } |
74 return SkNEW_ARGS(SkMatrixConvolutionImageFilter, (kernelSize, kernel, gain,
bias, | 74 return SkNEW_ARGS(SkMatrixConvolutionImageFilter, (kernelSize, kernel, gain,
bias, |
75 kernelOffset, tileMode, c
onvolveAlpha, | 75 kernelOffset, tileMode, c
onvolveAlpha, |
76 input, cropRect, uniqueID
)); | 76 input, cropRect, uniqueID
)); |
77 } | 77 } |
78 | 78 |
79 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | |
80 static bool tile_mode_is_valid(SkMatrixConvolutionImageFilter::TileMode tileMode
) { | |
81 switch (tileMode) { | |
82 case SkMatrixConvolutionImageFilter::kClamp_TileMode: | |
83 case SkMatrixConvolutionImageFilter::kRepeat_TileMode: | |
84 case SkMatrixConvolutionImageFilter::kClampToBlack_TileMode: | |
85 return true; | |
86 default: | |
87 break; | |
88 } | |
89 return false; | |
90 } | |
91 | |
92 SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(SkReadBuffer& buf
fer) | |
93 : INHERITED(1, buffer) { | |
94 fKernelSize.fWidth = buffer.readInt(); | |
95 fKernelSize.fHeight = buffer.readInt(); | |
96 if ((fKernelSize.fWidth >= 1) && (fKernelSize.fHeight >= 1) && | |
97 // Make sure size won't be larger than a signed int, | |
98 // which would still be extremely large for a kernel, | |
99 // but we don't impose a hard limit for kernel size | |
100 (gMaxKernelSize / fKernelSize.fWidth >= fKernelSize.fHeight)) { | |
101 size_t size = fKernelSize.fWidth * fKernelSize.fHeight; | |
102 fKernel = SkNEW_ARRAY(SkScalar, size); | |
103 SkDEBUGCODE(bool success =) buffer.readScalarArray(fKernel, size); | |
104 SkASSERT(success); | |
105 } else { | |
106 fKernel = 0; | |
107 } | |
108 fGain = buffer.readScalar(); | |
109 fBias = buffer.readScalar(); | |
110 fKernelOffset.fX = buffer.readInt(); | |
111 fKernelOffset.fY = buffer.readInt(); | |
112 fTileMode = (TileMode) buffer.readInt(); | |
113 fConvolveAlpha = buffer.readBool(); | |
114 buffer.validate((fKernel != 0) && | |
115 SkScalarIsFinite(fGain) && | |
116 SkScalarIsFinite(fBias) && | |
117 tile_mode_is_valid(fTileMode) && | |
118 (fKernelOffset.fX >= 0) && (fKernelOffset.fX < fKernelSize.f
Width) && | |
119 (fKernelOffset.fY >= 0) && (fKernelOffset.fY < fKernelSize.f
Height)); | |
120 } | |
121 #endif | |
122 | |
123 SkFlattenable* SkMatrixConvolutionImageFilter::CreateProc(SkReadBuffer& buffer)
{ | 79 SkFlattenable* SkMatrixConvolutionImageFilter::CreateProc(SkReadBuffer& buffer)
{ |
124 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 80 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
125 SkISize kernelSize; | 81 SkISize kernelSize; |
126 kernelSize.fWidth = buffer.readInt(); | 82 kernelSize.fWidth = buffer.readInt(); |
127 kernelSize.fHeight = buffer.readInt(); | 83 kernelSize.fHeight = buffer.readInt(); |
128 const int count = buffer.getArrayCount(); | 84 const int count = buffer.getArrayCount(); |
129 | 85 |
130 const int64_t kernelArea = sk_64_mul(kernelSize.width(), kernelSize.height()
); | 86 const int64_t kernelArea = sk_64_mul(kernelSize.width(), kernelSize.height()
); |
131 if (!buffer.validate(kernelArea == count)) { | 87 if (!buffer.validate(kernelArea == count)) { |
132 return NULL; | 88 return NULL; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 fKernelSize, | 362 fKernelSize, |
407 fKernel, | 363 fKernel, |
408 fGain, | 364 fGain, |
409 fBias, | 365 fBias, |
410 fKernelOffset, | 366 fKernelOffset, |
411 convert_tilemodes(fTileMode), | 367 convert_tilemodes(fTileMode), |
412 fConvolveAlpha); | 368 fConvolveAlpha); |
413 return true; | 369 return true; |
414 } | 370 } |
415 #endif | 371 #endif |
OLD | NEW |