File tree 1 file changed +11
-0
lines changed
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 1
1
import 'dart:typed_data' ;
2
2
3
+ import '../../image.dart' ;
3
4
import '../color/color.dart' ;
4
5
import '../color/format.dart' ;
5
6
import '../exif/exif_data.dart' ;
@@ -122,6 +123,8 @@ class JpegEncoder extends Encoder {
122
123
return fp.getBytes ();
123
124
}
124
125
126
+ static const _black = const ConstColorRgb8 (0 , 0 , 0 );
127
+
125
128
void _calculateYUV (
126
129
Image image,
127
130
int x,
@@ -153,6 +156,14 @@ class JpegEncoder extends Encoder {
153
156
if (p.format != Format .uint8) {
154
157
p = p.convert (format: Format .uint8);
155
158
}
159
+ if (p.length > 3 ) {
160
+ final backgroundColor = image.backgroundColor ?? _black;
161
+ final a = p.aNormalized;
162
+ final invA = 1.0 - a;
163
+ p..r = (p.r * a + backgroundColor.r * invA).round ()
164
+ ..g = (p.g * a + backgroundColor.r * invA).round ()
165
+ ..b = (p.b * a + backgroundColor.r * invA).round ();
166
+ }
156
167
final r = p.r.toInt ();
157
168
final g = p.g.toInt ();
158
169
final b = p.b.toInt ();
You can’t perform that action at this time.
0 commit comments