@@ -11,13 +11,9 @@ use dwrote;
11
11
#[ cfg( any( target_os = "linux" , target_os = "macos" ) ) ]
12
12
use font_loader:: system_fonts;
13
13
use glutin:: WindowProxy ;
14
- use image;
15
- use image:: GenericImage ;
16
14
use json_frame_writer:: JsonFrameWriter ;
17
- use parse_function:: parse_function;
18
- use premultiply:: premultiply;
19
15
use std:: collections:: HashMap ;
20
- use std:: path:: { Path , PathBuf } ;
16
+ use std:: path:: PathBuf ;
21
17
use time;
22
18
use webrender;
23
19
use webrender:: api:: * ;
@@ -119,8 +115,6 @@ pub struct Wrench {
119
115
120
116
window_title_to_set : Option < String > ,
121
117
122
- image_map : HashMap < ( PathBuf , Option < i64 > ) , ( ImageKey , LayoutSize ) > ,
123
-
124
118
graphics_api : webrender:: GraphicsApiInfo ,
125
119
126
120
pub rebuild_display_lists : bool ,
@@ -198,8 +192,6 @@ impl Wrench {
198
192
verbose,
199
193
device_pixel_ratio : dp_ratio,
200
194
201
- image_map : HashMap :: new ( ) ,
202
-
203
195
root_pipeline_id : PipelineId ( 0 , 0 ) ,
204
196
205
197
graphics_api,
@@ -385,76 +377,6 @@ impl Wrench {
385
377
key
386
378
}
387
379
388
- pub fn add_or_get_image ( & mut self , file : & Path , tiling : Option < i64 > ) -> ( ImageKey , LayoutSize ) {
389
- let key = ( file. to_owned ( ) , tiling) ;
390
- if let Some ( k) = self . image_map . get ( & key) {
391
- return * k;
392
- }
393
-
394
- let ( descriptor, image_data) = match image:: open ( file) {
395
- Ok ( image) => {
396
- let image_dims = image. dimensions ( ) ;
397
- let format = match image {
398
- image:: ImageLuma8 ( _) => ImageFormat :: A8 ,
399
- image:: ImageRgb8 ( _) => ImageFormat :: RGB8 ,
400
- image:: ImageRgba8 ( _) => ImageFormat :: BGRA8 ,
401
- _ => panic ! ( "We don't support whatever your crazy image type is, come on" ) ,
402
- } ;
403
- let mut bytes = image. raw_pixels ( ) ;
404
- if format == ImageFormat :: BGRA8 {
405
- premultiply ( bytes. as_mut_slice ( ) ) ;
406
- }
407
- let descriptor = ImageDescriptor :: new (
408
- image_dims. 0 ,
409
- image_dims. 1 ,
410
- format,
411
- is_image_opaque ( format, & bytes[ ..] ) ,
412
- ) ;
413
- let data = ImageData :: new ( bytes) ;
414
- ( descriptor, data)
415
- }
416
- _ => {
417
- // This is a hack but it is convenient when generating test cases and avoids
418
- // bloating the repository.
419
- match parse_function (
420
- file. components ( )
421
- . last ( )
422
- . unwrap ( )
423
- . as_os_str ( )
424
- . to_str ( )
425
- . unwrap ( ) ,
426
- ) {
427
- ( "xy-gradient" , args, _) => generate_xy_gradient_image (
428
- args. get ( 0 ) . unwrap_or ( & "1000" ) . parse :: < u32 > ( ) . unwrap ( ) ,
429
- args. get ( 1 ) . unwrap_or ( & "1000" ) . parse :: < u32 > ( ) . unwrap ( ) ,
430
- ) ,
431
- ( "solid-color" , args, _) => generate_solid_color_image (
432
- args. get ( 0 ) . unwrap_or ( & "255" ) . parse :: < u8 > ( ) . unwrap ( ) ,
433
- args. get ( 1 ) . unwrap_or ( & "255" ) . parse :: < u8 > ( ) . unwrap ( ) ,
434
- args. get ( 2 ) . unwrap_or ( & "255" ) . parse :: < u8 > ( ) . unwrap ( ) ,
435
- args. get ( 3 ) . unwrap_or ( & "255" ) . parse :: < u8 > ( ) . unwrap ( ) ,
436
- args. get ( 4 ) . unwrap_or ( & "1000" ) . parse :: < u32 > ( ) . unwrap ( ) ,
437
- args. get ( 5 ) . unwrap_or ( & "1000" ) . parse :: < u32 > ( ) . unwrap ( ) ,
438
- ) ,
439
- _ => {
440
- panic ! ( "Failed to load image {:?}" , file. to_str( ) ) ;
441
- }
442
- }
443
- }
444
- } ;
445
- let tiling = tiling. map ( |tile_size| tile_size as u16 ) ;
446
- let image_key = self . api . generate_image_key ( ) ;
447
- let mut resources = ResourceUpdates :: new ( ) ;
448
- resources. add_image ( image_key, descriptor, image_data, tiling) ;
449
- self . api . update_resources ( resources) ;
450
- let val = (
451
- image_key,
452
- LayoutSize :: new ( descriptor. width as f32 , descriptor. height as f32 ) ,
453
- ) ;
454
- self . image_map . insert ( key, val) ;
455
- val
456
- }
457
-
458
380
pub fn update ( & mut self , dim : DeviceUintSize ) {
459
381
if dim != self . window_size {
460
382
self . window_size = dim;
@@ -538,70 +460,3 @@ impl Wrench {
538
460
}
539
461
}
540
462
}
541
-
542
- fn is_image_opaque ( format : ImageFormat , bytes : & [ u8 ] ) -> bool {
543
- match format {
544
- ImageFormat :: BGRA8 => {
545
- let mut is_opaque = true ;
546
- for i in 0 .. ( bytes. len ( ) / 4 ) {
547
- if bytes[ i * 4 + 3 ] != 255 {
548
- is_opaque = false ;
549
- break ;
550
- }
551
- }
552
- is_opaque
553
- }
554
- ImageFormat :: RGB8 => true ,
555
- ImageFormat :: RG8 => true ,
556
- ImageFormat :: A8 => false ,
557
- ImageFormat :: Invalid | ImageFormat :: RGBAF32 => unreachable ! ( ) ,
558
- }
559
- }
560
-
561
- fn generate_xy_gradient_image ( w : u32 , h : u32 ) -> ( ImageDescriptor , ImageData ) {
562
- let mut pixels = Vec :: with_capacity ( ( w * h * 4 ) as usize ) ;
563
- for y in 0 .. h {
564
- for x in 0 .. w {
565
- let grid = if x % 100 < 3 || y % 100 < 3 { 0.9 } else { 1.0 } ;
566
- pixels. push ( ( y as f32 / h as f32 * 255.0 * grid) as u8 ) ;
567
- pixels. push ( 0 ) ;
568
- pixels. push ( ( x as f32 / w as f32 * 255.0 * grid) as u8 ) ;
569
- pixels. push ( 255 ) ;
570
- }
571
- }
572
-
573
- (
574
- ImageDescriptor :: new ( w, h, ImageFormat :: BGRA8 , true ) ,
575
- ImageData :: new ( pixels) ,
576
- )
577
- }
578
-
579
- fn generate_solid_color_image (
580
- r : u8 ,
581
- g : u8 ,
582
- b : u8 ,
583
- a : u8 ,
584
- w : u32 ,
585
- h : u32 ,
586
- ) -> ( ImageDescriptor , ImageData ) {
587
- let buf_size = ( w * h * 4 ) as usize ;
588
- let mut pixels = Vec :: with_capacity ( buf_size) ;
589
- // Unsafely filling the buffer is horrible. Unfortunately doing this idiomatically
590
- // is terribly slow in debug builds to the point that reftests/image/very-big.yaml
591
- // takes more than 20 seconds to run on a recent laptop.
592
- unsafe {
593
- pixels. set_len ( buf_size) ;
594
- let color: u32 = :: std:: mem:: transmute ( [ b, g, r, a] ) ;
595
- let mut ptr: * mut u32 = :: std:: mem:: transmute ( & mut pixels[ 0 ] ) ;
596
- let end = ptr. offset ( ( w * h) as isize ) ;
597
- while ptr < end {
598
- * ptr = color;
599
- ptr = ptr. offset ( 1 ) ;
600
- }
601
- }
602
-
603
- (
604
- ImageDescriptor :: new ( w, h, ImageFormat :: BGRA8 , a == 255 ) ,
605
- ImageData :: new ( pixels) ,
606
- )
607
- }
0 commit comments