Skip to content

Commit

Permalink
fix: color shift in FeColorMatrix on android (#2365)
Browse files Browse the repository at this point in the history
# Summary

While debugging #2364 I've noticed that color shift in `FeColorMatrix`
on Android is wrong.
On web, elements 5, 10, 15, 20 is a color shift represented by number
where 1 mean full color shift, while on Android it's 255 for full color
shift.

## Test

```tsx
<svg width="180" height="180" viewBox="0 0 180 180">
  <rect width="180" height="180" fill="red" filter="url(#filter)"/>
  <filter id="filter">
    <feColorMatrix type="matrix" values="0 0 0 0 1
                                         0 1 0 0 0
                                         0 0 1 0 0
                                         0 0 0 1 0"/>
  </filter>
</svg>
```
  • Loading branch information
jakex7 authored Jul 24, 2024
1 parent 67620f5 commit 9a2cd3d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions android/src/main/java/com/horcrux/svg/FeColorMatrixView.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Bitmap applyFilter(HashMap<String, Bitmap> resultsMap, Bitmap prevResult)
float[] rawMatrix = new float[mValues.size()];

for (int i = 0; i < this.mValues.size(); i++) {
rawMatrix[i] = (float) this.mValues.getDouble(i);
rawMatrix[i] = (float) this.mValues.getDouble(i) * (i % 5 == 4 ? 255 : 1);
}

colorMatrix.set(rawMatrix);
Expand Down Expand Up @@ -88,8 +88,7 @@ public Bitmap applyFilter(HashMap<String, Bitmap> resultsMap, Bitmap prevResult)
case LUMINANCE_TO_ALPHA:
colorMatrix.set(
new float[] {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.2125f, 0.7154f, 0.0721f, 0, 0, 0, 0, 0,
0, 1
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.2125f, 0.7154f, 0.0721f, 0, 0,
});
break;
}
Expand Down

0 comments on commit 9a2cd3d

Please sign in to comment.