@@ -7,9 +7,9 @@ use bytes::{Bytes, BytesMut};
7
7
use crate :: { error:: AsyncTiffResult , reader:: Endianness , tile:: PredictorInfo } ;
8
8
9
9
/// Trait for reverse predictors to implement
10
- pub trait RevPredict : Debug + Send + Sync {
10
+ pub trait Unpredict : Debug + Send + Sync {
11
11
/// reverse predict the decompressed bytes and fix endianness on the output
12
- fn rev_predict_fix_endianness (
12
+ fn fix_endianness_and_unpredict (
13
13
& self ,
14
14
buffer : Bytes ,
15
15
predictor_info : & PredictorInfo ,
@@ -22,8 +22,8 @@ pub trait RevPredict: Debug + Send + Sync {
22
22
#[ derive( Debug ) ]
23
23
pub struct NoPredictor ;
24
24
25
- impl RevPredict for NoPredictor {
26
- fn rev_predict_fix_endianness (
25
+ impl Unpredict for NoPredictor {
26
+ fn fix_endianness_and_unpredict (
27
27
& self ,
28
28
buffer : Bytes ,
29
29
predictor_info : & PredictorInfo ,
@@ -44,8 +44,8 @@ impl RevPredict for NoPredictor {
44
44
#[ derive( Debug ) ]
45
45
pub struct HorizontalPredictor ;
46
46
47
- impl RevPredict for HorizontalPredictor {
48
- fn rev_predict_fix_endianness (
47
+ impl Unpredict for HorizontalPredictor {
48
+ fn fix_endianness_and_unpredict (
49
49
& self ,
50
50
buffer : Bytes ,
51
51
predictor_info : & PredictorInfo ,
@@ -140,8 +140,8 @@ pub fn fix_endianness(buf: &mut [u8], byte_order: Endianness, bit_depth: u16) {
140
140
#[ derive( Debug ) ]
141
141
pub struct FloatingPointPredictor ;
142
142
143
- impl RevPredict for FloatingPointPredictor {
144
- fn rev_predict_fix_endianness (
143
+ impl Unpredict for FloatingPointPredictor {
144
+ fn fix_endianness_and_unpredict (
145
145
& self ,
146
146
buffer : Bytes ,
147
147
predictor_info : & PredictorInfo ,
@@ -291,7 +291,7 @@ mod test {
291
291
tile:: PredictorInfo ,
292
292
} ;
293
293
294
- use super :: { HorizontalPredictor , NoPredictor , RevPredict } ;
294
+ use super :: { HorizontalPredictor , NoPredictor , Unpredict } ;
295
295
296
296
const PRED_INFO : PredictorInfo = PredictorInfo {
297
297
endianness : Endianness :: LittleEndian ,
@@ -346,7 +346,7 @@ mod test {
346
346
( 1 , 1 , Bytes :: from_static ( & RES_BOT_RIGHT [ ..] ) , Bytes :: from_static ( & RES_BOT_RIGHT [ ..] ) )
347
347
] ;
348
348
for ( x, y, input, expected) in cases {
349
- assert_eq ! ( p. rev_predict_fix_endianness ( input, & PRED_INFO , x, y) . unwrap( ) , expected) ;
349
+ assert_eq ! ( p. fix_endianness_and_unpredict ( input, & PRED_INFO , x, y) . unwrap( ) , expected) ;
350
350
}
351
351
}
352
352
@@ -388,25 +388,25 @@ mod test {
388
388
println ! ( "testing u8" ) ;
389
389
let buffer = Bytes :: from ( input. iter ( ) . map ( |v| * v as u8 ) . collect :: < Vec < _ > > ( ) ) ;
390
390
let res = Bytes :: from ( expected. clone ( ) ) ;
391
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
391
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
392
392
assert_eq ! ( -1i32 as u16 , u16 :: MAX ) ;
393
393
println ! ( "testing u16" ) ;
394
394
predictor_info. bits_per_sample = & [ 16 ] ;
395
395
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u16 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
396
396
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as u16 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
397
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
397
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
398
398
assert_eq ! ( -1i32 as u32 , u32 :: MAX ) ;
399
399
println ! ( "testing u32" ) ;
400
400
predictor_info. bits_per_sample = & [ 32 ] ;
401
401
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u32 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
402
402
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as u32 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
403
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
403
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
404
404
assert_eq ! ( -1i32 as u64 , u64 :: MAX ) ;
405
405
println ! ( "testing u64" ) ;
406
406
predictor_info. bits_per_sample = & [ 64 ] ;
407
407
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u64 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
408
408
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as u64 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
409
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
409
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
410
410
411
411
println ! ( "ints littleendian" ) ;
412
412
predictor_info. sample_format = & [ SampleFormat :: Int ] ;
@@ -415,22 +415,22 @@ mod test {
415
415
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i8 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
416
416
println ! ( "{:?}" , & buffer[ ..] ) ;
417
417
let res = Bytes :: from ( expected. clone ( ) ) ;
418
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) [ ..] , res[ ..] ) ;
418
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) [ ..] , res[ ..] ) ;
419
419
println ! ( "testing i16" ) ;
420
420
predictor_info. bits_per_sample = & [ 16 ] ;
421
421
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i16 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
422
422
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as i16 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
423
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
423
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
424
424
println ! ( "testing i32" ) ;
425
425
predictor_info. bits_per_sample = & [ 32 ] ;
426
426
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| v. to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
427
427
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as i32 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
428
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
428
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
429
429
println ! ( "testing i64" ) ;
430
430
predictor_info. bits_per_sample = & [ 64 ] ;
431
431
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i64 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
432
432
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as i64 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
433
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
433
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
434
434
435
435
println ! ( "uints bigendian" ) ;
436
436
predictor_info. endianness = Endianness :: BigEndian ;
@@ -440,53 +440,52 @@ mod test {
440
440
println ! ( "testing u8" ) ;
441
441
let buffer = Bytes :: from ( input. iter ( ) . map ( |v| * v as u8 ) . collect :: < Vec < _ > > ( ) ) ;
442
442
let res = Bytes :: from ( expected. clone ( ) ) ;
443
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
443
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
444
444
assert_eq ! ( -1i32 as u16 , u16 :: MAX ) ;
445
445
println ! ( "testing u16" ) ;
446
446
predictor_info. bits_per_sample = & [ 16 ] ;
447
447
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u16 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
448
448
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as u16 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
449
449
println ! ( "buffer: {:?}" , & buffer[ ..] ) ;
450
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) [ ..] , res[ ..] ) ;
450
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) [ ..] , res[ ..] ) ;
451
451
assert_eq ! ( -1i32 as u32 , u32 :: MAX ) ;
452
452
println ! ( "testing u32" ) ;
453
453
predictor_info. bits_per_sample = & [ 32 ] ;
454
454
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u32 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
455
455
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as u32 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
456
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
456
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
457
457
assert_eq ! ( -1i32 as u64 , u64 :: MAX ) ;
458
458
println ! ( "testing u64" ) ;
459
459
predictor_info. bits_per_sample = & [ 64 ] ;
460
460
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u64 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
461
461
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as u64 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
462
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
462
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
463
463
464
464
println ! ( "ints bigendian" ) ;
465
- predictor_info. sample_format = & [ SampleFormat :: Int ] ;
466
465
predictor_info. bits_per_sample = & [ 8 ] ;
467
466
assert_eq ! ( -1i32 as u8 , 255 ) ;
468
467
println ! ( "testing i8" ) ;
469
468
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i8 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
470
469
let res = Bytes :: from ( expected. clone ( ) ) ;
471
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
470
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
472
471
assert_eq ! ( -1i32 as u16 , u16 :: MAX ) ;
473
472
println ! ( "testing i16" ) ;
474
473
predictor_info. bits_per_sample = & [ 16 ] ;
475
474
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i16 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
476
475
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as i16 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
477
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
476
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
478
477
assert_eq ! ( -1i32 as u32 , u32 :: MAX ) ;
479
478
println ! ( "testing i32" ) ;
480
479
predictor_info. bits_per_sample = & [ 32 ] ;
481
480
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| v. to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
482
481
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as i32 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
483
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
482
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
484
483
assert_eq ! ( -1i32 as u64 , u64 :: MAX ) ;
485
484
println ! ( "testing i64" ) ;
486
485
predictor_info. bits_per_sample = & [ 64 ] ;
487
486
let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i64 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
488
487
let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as i64 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
489
- assert_eq ! ( p. rev_predict_fix_endianness ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
488
+ assert_eq ! ( p. fix_endianness_and_unpredict ( buffer, & predictor_info, x, y) . unwrap( ) , res) ;
490
489
}
491
490
}
492
491
@@ -515,7 +514,7 @@ mod test {
515
514
} ;
516
515
let input = Bytes :: from_owner ( diffed) ;
517
516
assert_eq ! (
518
- & FloatingPointPredictor . rev_predict_fix_endianness ( input, & info, 1 , 1 ) . unwrap( ) [ ..] ,
517
+ & FloatingPointPredictor . fix_endianness_and_unpredict ( input, & info, 1 , 1 ) . unwrap( ) [ ..] ,
519
518
& expect_le[ ..]
520
519
)
521
520
}
@@ -545,7 +544,7 @@ mod test {
545
544
} ;
546
545
let input = Bytes :: from_owner ( diffed) ;
547
546
assert_eq ! (
548
- & FloatingPointPredictor . rev_predict_fix_endianness ( input, & info, 1 , 1 ) . unwrap( ) [ ..] ,
547
+ & FloatingPointPredictor . fix_endianness_and_unpredict ( input, & info, 1 , 1 ) . unwrap( ) [ ..] ,
549
548
& expect_le[ ..]
550
549
)
551
550
}
@@ -575,12 +574,12 @@ mod test {
575
574
let input = Bytes :: from_owner ( diffed) ;
576
575
assert_eq ! (
577
576
& FloatingPointPredictor
578
- . rev_predict_fix_endianness ( input. clone( ) , & info, 0 , 1 ) . unwrap( ) [ ..] ,
577
+ . fix_endianness_and_unpredict ( input. clone( ) , & info, 0 , 1 ) . unwrap( ) [ ..] ,
579
578
& expect_le
580
579
) ;
581
580
info. endianness = Endianness :: BigEndian ;
582
581
assert_eq ! (
583
- & FloatingPointPredictor . rev_predict_fix_endianness ( input, & info, 0 , 1 ) . unwrap( ) [ ..] ,
582
+ & FloatingPointPredictor . fix_endianness_and_unpredict ( input, & info, 0 , 1 ) . unwrap( ) [ ..] ,
584
583
& expect_le
585
584
)
586
585
}
@@ -610,7 +609,7 @@ mod test {
610
609
let input = Bytes :: from_owner ( diffed) ;
611
610
assert_eq ! (
612
611
& FloatingPointPredictor
613
- . rev_predict_fix_endianness ( input, & info, 0 , 1 )
612
+ . fix_endianness_and_unpredict ( input, & info, 0 , 1 )
614
613
. unwrap( ) [ ..] ,
615
614
& expect_be[ ..]
616
615
) ;
0 commit comments