MCPcopy Create free account
hub / github.com/Snapchat/Valdi / preprocessFilter

Function preprocessFilter

valdi/src/valdi/runtime/Attributes/AssetAttributes.cpp:155–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153
154static Error invalidFilterError() {
155 return Error("Invalid filter");
156}
157
158static Result<Value> preprocessFilter(const Value& value) {
159 if (value.isNullOrUndefined()) {
160 return value;
161 }
162
163 const auto* array = value.getArray();
164 if (array == nullptr) {
165 return invalidFilterError();
166 }
167
168 if (array->empty()) {
169 return Value();
170 }
171
172 static constexpr int32_t kFilterTypeBlur = 1;
173 static constexpr int32_t kFilterTypeColorMatrix = 2;
174
175 Ref<ImageFilter> filter = makeShared<ImageFilter>();
176
177 size_t i = 0;
178 size_t end = array->size();
179
180 while (i < end) {
181 switch ((*array)[i++].toInt()) {
182 case kFilterTypeBlur:
183 if (i + 1 > end) {
184 return invalidFilterError();
185 }
186 if (filter->getBlurRadius() != 0.0f) {
187 return Error("Multiple blur filters are not supported");
188 }
189 filter->setBlurRadius((*array)[i++].toFloat());
190 break;
191 case kFilterTypeColorMatrix:
192 if (i + ImageFilter::kColorMatrixSize > end) {
193 return invalidFilterError();
194 }
195 float colorMatrix[ImageFilter::kColorMatrixSize];
196 for (float& j : colorMatrix) {
197 j = (*array)[i++].toFloat();
198 }
199
200 filter->concatColorMatrix(colorMatrix);
201 break;
202 default:
203 return invalidFilterError();
204 }
205 }
206
207 return Value(filter);
208}

Callers

nothing calls this directly

Calls 12

invalidFilterErrorFunction · 0.85
getBlurRadiusMethod · 0.80
setBlurRadiusMethod · 0.80
toFloatMethod · 0.80
concatColorMatrixMethod · 0.80
ValueClass · 0.50
ErrorInterface · 0.50
isNullOrUndefinedMethod · 0.45
getArrayMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
toIntMethod · 0.45

Tested by

no test coverage detected