@@ -45,6 +45,10 @@ async fn image_bitmap_import() {
45
45
enum TestCase {
46
46
// Import the image as normal
47
47
Normal ,
48
+ // Sets the FlipY flag. Deals with global state on GLES, so run before other tests to ensure it's reset.
49
+ FlipY ,
50
+ // Sets the premultiplied alpha flag. Deals with global state on GLES, so run before other tests to ensure it's reset.
51
+ Premultiplied ,
48
52
// Set both the input offset and output offset to 1 in x, so the first column is omitted.
49
53
TrimLeft ,
50
54
// Set the size to 2 in x, so the last column is omitted
@@ -62,6 +66,8 @@ async fn image_bitmap_import() {
62
66
}
63
67
let cases = [
64
68
TestCase :: Normal ,
69
+ TestCase :: FlipY ,
70
+ TestCase :: Premultiplied ,
65
71
TestCase :: TrimLeft ,
66
72
TestCase :: TrimRight ,
67
73
TestCase :: SlideRight ,
@@ -77,10 +83,14 @@ async fn image_bitmap_import() {
77
83
let mut raw_image = raw_image. clone ( ) ;
78
84
// The origin used for the external copy on the source side.
79
85
let mut src_origin = wgpu:: Origin2d :: ZERO ;
86
+ // If the source should be flipped in Y
87
+ let mut src_flip_y = false ;
80
88
// The origin used for the external copy on the destination side.
81
89
let mut dest_origin = wgpu:: Origin3d :: ZERO ;
82
90
// The layer the external image's data should end up in.
83
91
let mut dest_data_layer = 0 ;
92
+ // The layer the external image's data should end up in.
93
+ let mut dest_premultiplied = false ;
84
94
// Size of the external copy
85
95
let mut copy_size = wgpu:: Extent3d {
86
96
width : 3 ,
@@ -98,6 +108,25 @@ async fn image_bitmap_import() {
98
108
let mut correct = true ;
99
109
match case {
100
110
TestCase :: Normal => { }
111
+ TestCase :: FlipY => {
112
+ src_flip_y = true ;
113
+ for x in 0 ..3 {
114
+ let top = raw_image[ ( x, 0 ) ] ;
115
+ let bottom = raw_image[ ( x, 2 ) ] ;
116
+ raw_image[ ( x, 0 ) ] = bottom;
117
+ raw_image[ ( x, 2 ) ] = top;
118
+ }
119
+ }
120
+ TestCase :: Premultiplied => {
121
+ dest_premultiplied = true ;
122
+ for pixel in raw_image. pixels_mut ( ) {
123
+ let mut float_pix = pixel. 0 . map ( |v| v as f32 / 255.0 ) ;
124
+ float_pix[ 0 ] *= float_pix[ 3 ] ;
125
+ float_pix[ 1 ] *= float_pix[ 3 ] ;
126
+ float_pix[ 2 ] *= float_pix[ 3 ] ;
127
+ pixel. 0 = float_pix. map ( |v| ( v * 255.0 ) . round ( ) as u8 ) ;
128
+ }
129
+ }
101
130
TestCase :: TrimLeft => {
102
131
valid = ctx
103
132
. adapter_downlevel_capabilities
@@ -173,15 +202,15 @@ async fn image_bitmap_import() {
173
202
& wgpu:: ImageCopyExternalImage {
174
203
source : wgpu:: ExternalImageSource :: ImageBitmap ( image_bitmap. clone ( ) ) ,
175
204
origin : src_origin,
176
- flip_y : false ,
205
+ flip_y : src_flip_y ,
177
206
} ,
178
207
wgpu:: ImageCopyTextureTagged {
179
208
texture : & texture,
180
209
mip_level : 0 ,
181
210
origin : dest_origin,
182
211
aspect : wgpu:: TextureAspect :: All ,
183
212
color_space : wgpu:: PredefinedColorSpace :: Srgb ,
184
- premultiplied_alpha : false ,
213
+ premultiplied_alpha : dest_premultiplied ,
185
214
} ,
186
215
copy_size,
187
216
) ;
0 commit comments