@@ -7,9 +7,9 @@ use bytes::{Bytes, BytesMut};
77use crate :: { error:: AsyncTiffResult , reader:: Endianness , tile:: PredictorInfo } ;
88
99/// Trait for reverse predictors to implement
10- pub trait RevPredict : Debug + Send + Sync {
10+ pub trait Unpredict : Debug + Send + Sync {
1111 /// reverse predict the decompressed bytes and fix endianness on the output
12- fn rev_predict_fix_endianness (
12+ fn fix_endianness_and_unpredict (
1313 & self ,
1414 buffer : Bytes ,
1515 predictor_info : & PredictorInfo ,
@@ -22,8 +22,8 @@ pub trait RevPredict: Debug + Send + Sync {
2222#[ derive( Debug ) ]
2323pub struct NoPredictor ;
2424
25- impl RevPredict for NoPredictor {
26- fn rev_predict_fix_endianness (
25+ impl Unpredict for NoPredictor {
26+ fn fix_endianness_and_unpredict (
2727 & self ,
2828 buffer : Bytes ,
2929 predictor_info : & PredictorInfo ,
@@ -44,8 +44,8 @@ impl RevPredict for NoPredictor {
4444#[ derive( Debug ) ]
4545pub struct HorizontalPredictor ;
4646
47- impl RevPredict for HorizontalPredictor {
48- fn rev_predict_fix_endianness (
47+ impl Unpredict for HorizontalPredictor {
48+ fn fix_endianness_and_unpredict (
4949 & self ,
5050 buffer : Bytes ,
5151 predictor_info : & PredictorInfo ,
@@ -140,8 +140,8 @@ pub fn fix_endianness(buf: &mut [u8], byte_order: Endianness, bit_depth: u16) {
140140#[ derive( Debug ) ]
141141pub struct FloatingPointPredictor ;
142142
143- impl RevPredict for FloatingPointPredictor {
144- fn rev_predict_fix_endianness (
143+ impl Unpredict for FloatingPointPredictor {
144+ fn fix_endianness_and_unpredict (
145145 & self ,
146146 buffer : Bytes ,
147147 predictor_info : & PredictorInfo ,
@@ -291,7 +291,7 @@ mod test {
291291 tile:: PredictorInfo ,
292292 } ;
293293
294- use super :: { HorizontalPredictor , NoPredictor , RevPredict } ;
294+ use super :: { HorizontalPredictor , NoPredictor , Unpredict } ;
295295
296296 const PRED_INFO : PredictorInfo = PredictorInfo {
297297 endianness : Endianness :: LittleEndian ,
@@ -346,7 +346,7 @@ mod test {
346346 ( 1 , 1 , Bytes :: from_static ( & RES_BOT_RIGHT [ ..] ) , Bytes :: from_static ( & RES_BOT_RIGHT [ ..] ) )
347347 ] ;
348348 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) ;
350350 }
351351 }
352352
@@ -388,25 +388,25 @@ mod test {
388388 println ! ( "testing u8" ) ;
389389 let buffer = Bytes :: from ( input. iter ( ) . map ( |v| * v as u8 ) . collect :: < Vec < _ > > ( ) ) ;
390390 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) ;
392392 assert_eq ! ( -1i32 as u16 , u16 :: MAX ) ;
393393 println ! ( "testing u16" ) ;
394394 predictor_info. bits_per_sample = & [ 16 ] ;
395395 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u16 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
396396 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) ;
398398 assert_eq ! ( -1i32 as u32 , u32 :: MAX ) ;
399399 println ! ( "testing u32" ) ;
400400 predictor_info. bits_per_sample = & [ 32 ] ;
401401 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u32 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
402402 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) ;
404404 assert_eq ! ( -1i32 as u64 , u64 :: MAX ) ;
405405 println ! ( "testing u64" ) ;
406406 predictor_info. bits_per_sample = & [ 64 ] ;
407407 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u64 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
408408 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) ;
410410
411411 println ! ( "ints littleendian" ) ;
412412 predictor_info. sample_format = & [ SampleFormat :: Int ] ;
@@ -415,22 +415,22 @@ mod test {
415415 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i8 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
416416 println ! ( "{:?}" , & buffer[ ..] ) ;
417417 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[ ..] ) ;
419419 println ! ( "testing i16" ) ;
420420 predictor_info. bits_per_sample = & [ 16 ] ;
421421 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i16 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
422422 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) ;
424424 println ! ( "testing i32" ) ;
425425 predictor_info. bits_per_sample = & [ 32 ] ;
426426 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| v. to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
427427 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) ;
429429 println ! ( "testing i64" ) ;
430430 predictor_info. bits_per_sample = & [ 64 ] ;
431431 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i64 ) . to_le_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
432432 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) ;
434434
435435 println ! ( "uints bigendian" ) ;
436436 predictor_info. endianness = Endianness :: BigEndian ;
@@ -440,53 +440,52 @@ mod test {
440440 println ! ( "testing u8" ) ;
441441 let buffer = Bytes :: from ( input. iter ( ) . map ( |v| * v as u8 ) . collect :: < Vec < _ > > ( ) ) ;
442442 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) ;
444444 assert_eq ! ( -1i32 as u16 , u16 :: MAX ) ;
445445 println ! ( "testing u16" ) ;
446446 predictor_info. bits_per_sample = & [ 16 ] ;
447447 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u16 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
448448 let res = Bytes :: from ( expected. iter ( ) . flat_map ( |v| ( * v as u16 ) . to_ne_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
449449 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[ ..] ) ;
451451 assert_eq ! ( -1i32 as u32 , u32 :: MAX ) ;
452452 println ! ( "testing u32" ) ;
453453 predictor_info. bits_per_sample = & [ 32 ] ;
454454 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u32 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
455455 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) ;
457457 assert_eq ! ( -1i32 as u64 , u64 :: MAX ) ;
458458 println ! ( "testing u64" ) ;
459459 predictor_info. bits_per_sample = & [ 64 ] ;
460460 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as u64 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
461461 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) ;
463463
464464 println ! ( "ints bigendian" ) ;
465- predictor_info. sample_format = & [ SampleFormat :: Int ] ;
466465 predictor_info. bits_per_sample = & [ 8 ] ;
467466 assert_eq ! ( -1i32 as u8 , 255 ) ;
468467 println ! ( "testing i8" ) ;
469468 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i8 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
470469 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) ;
472471 assert_eq ! ( -1i32 as u16 , u16 :: MAX ) ;
473472 println ! ( "testing i16" ) ;
474473 predictor_info. bits_per_sample = & [ 16 ] ;
475474 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i16 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
476475 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) ;
478477 assert_eq ! ( -1i32 as u32 , u32 :: MAX ) ;
479478 println ! ( "testing i32" ) ;
480479 predictor_info. bits_per_sample = & [ 32 ] ;
481480 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| v. to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
482481 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) ;
484483 assert_eq ! ( -1i32 as u64 , u64 :: MAX ) ;
485484 println ! ( "testing i64" ) ;
486485 predictor_info. bits_per_sample = & [ 64 ] ;
487486 let buffer = Bytes :: from ( input. iter ( ) . flat_map ( |v| ( * v as i64 ) . to_be_bytes ( ) ) . collect :: < Vec < _ > > ( ) ) ;
488487 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) ;
490489 }
491490 }
492491
@@ -515,7 +514,7 @@ mod test {
515514 } ;
516515 let input = Bytes :: from_owner ( diffed) ;
517516 assert_eq ! (
518- & FloatingPointPredictor . rev_predict_fix_endianness ( input, & info, 1 , 1 ) . unwrap( ) [ ..] ,
517+ & FloatingPointPredictor . fix_endianness_and_unpredict ( input, & info, 1 , 1 ) . unwrap( ) [ ..] ,
519518 & expect_le[ ..]
520519 )
521520 }
@@ -545,7 +544,7 @@ mod test {
545544 } ;
546545 let input = Bytes :: from_owner ( diffed) ;
547546 assert_eq ! (
548- & FloatingPointPredictor . rev_predict_fix_endianness ( input, & info, 1 , 1 ) . unwrap( ) [ ..] ,
547+ & FloatingPointPredictor . fix_endianness_and_unpredict ( input, & info, 1 , 1 ) . unwrap( ) [ ..] ,
549548 & expect_le[ ..]
550549 )
551550 }
@@ -575,12 +574,12 @@ mod test {
575574 let input = Bytes :: from_owner ( diffed) ;
576575 assert_eq ! (
577576 & FloatingPointPredictor
578- . rev_predict_fix_endianness ( input. clone( ) , & info, 0 , 1 ) . unwrap( ) [ ..] ,
577+ . fix_endianness_and_unpredict ( input. clone( ) , & info, 0 , 1 ) . unwrap( ) [ ..] ,
579578 & expect_le
580579 ) ;
581580 info. endianness = Endianness :: BigEndian ;
582581 assert_eq ! (
583- & FloatingPointPredictor . rev_predict_fix_endianness ( input, & info, 0 , 1 ) . unwrap( ) [ ..] ,
582+ & FloatingPointPredictor . fix_endianness_and_unpredict ( input, & info, 0 , 1 ) . unwrap( ) [ ..] ,
584583 & expect_le
585584 )
586585 }
@@ -610,7 +609,7 @@ mod test {
610609 let input = Bytes :: from_owner ( diffed) ;
611610 assert_eq ! (
612611 & FloatingPointPredictor
613- . rev_predict_fix_endianness ( input, & info, 0 , 1 )
612+ . fix_endianness_and_unpredict ( input, & info, 0 , 1 )
614613 . unwrap( ) [ ..] ,
615614 & expect_be[ ..]
616615 ) ;
0 commit comments