forked from firka/flutter
colormatrix is now 0...1 (flutter/engine#8772)
* colormatrix is now 0...1 * reformat
This commit is contained in:
@@ -52,7 +52,7 @@ constexpr double kStrokeMiterLimitDefault = 4.0;
|
||||
|
||||
// A color matrix which inverts colors.
|
||||
// clang-format off
|
||||
constexpr SkScalar invert_colors[20] = {
|
||||
constexpr float invert_colors[20] = {
|
||||
-1.0, 0, 0, 1.0, 0,
|
||||
0, -1.0, 0, 1.0, 0,
|
||||
0, 0, -1.0, 1.0, 0,
|
||||
@@ -72,6 +72,19 @@ enum ColorFilterType {
|
||||
SRGBToLinearGamma
|
||||
};
|
||||
|
||||
// Flutter still defines the matrix to be biased by 255 in the last column
|
||||
// (translate). skia is normalized, treating the last column as 0...1, so we
|
||||
// post-scale here before calling the skia factory.
|
||||
static sk_sp<SkColorFilter> MakeColorMatrixFilter255(const float array[20]) {
|
||||
float tmp[20];
|
||||
memcpy(tmp, array, sizeof(tmp));
|
||||
tmp[4] *= 1.0f / 255;
|
||||
tmp[9] *= 1.0f / 255;
|
||||
tmp[14] *= 1.0f / 255;
|
||||
tmp[19] *= 1.0f / 255;
|
||||
return SkColorFilters::Matrix(tmp);
|
||||
}
|
||||
|
||||
sk_sp<SkColorFilter> ExtractColorFilter(const uint32_t* uint_data,
|
||||
Dart_Handle* values) {
|
||||
switch (uint_data[kColorFilterIndex]) {
|
||||
@@ -92,7 +105,7 @@ sk_sp<SkColorFilter> ExtractColorFilter(const uint32_t* uint_data,
|
||||
FML_CHECK(length == 20);
|
||||
|
||||
tonic::Float32List decoded(matrixHandle);
|
||||
return SkColorFilters::MatrixRowMajor255(decoded.data());
|
||||
return MakeColorMatrixFilter255(decoded.data());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -178,11 +191,11 @@ Paint::Paint(Dart_Handle paint_objects, Dart_Handle paint_data) {
|
||||
sk_sp<SkColorFilter> color_filter = ExtractColorFilter(uint_data, values);
|
||||
if (color_filter) {
|
||||
sk_sp<SkColorFilter> invert_filter =
|
||||
SkColorFilters::MatrixRowMajor255(invert_colors);
|
||||
MakeColorMatrixFilter255(invert_colors);
|
||||
paint_.setColorFilter(invert_filter->makeComposed(color_filter));
|
||||
}
|
||||
} else if (uint_data[kInvertColorIndex]) {
|
||||
paint_.setColorFilter(SkColorFilters::MatrixRowMajor255(invert_colors));
|
||||
paint_.setColorFilter(MakeColorMatrixFilter255(invert_colors));
|
||||
} else if (uint_data[kColorFilterIndex]) {
|
||||
sk_sp<SkColorFilter> color_filter = ExtractColorFilter(uint_data, values);
|
||||
if (color_filter) {
|
||||
|
||||
Reference in New Issue
Block a user