@@ -10,13 +10,12 @@ use crate::buffer_::{
1010 ConvertBuffer , Gray16Image , GrayAlpha16Image , GrayAlphaImage , GrayImage , ImageBuffer ,
1111 Rgb16Image , RgbImage , Rgba16Image , RgbaImage ,
1212} ;
13- use crate :: color:: { self , IntoColor } ;
13+ use crate :: color:: { self } ;
1414use crate :: error:: { ImageError , ImageResult , ParameterError , ParameterErrorKind } ;
1515use crate :: flat:: FlatSamples ;
16- use crate :: image:: { GenericImage , GenericImageView , ImageDecoder , ImageEncoder , ImageFormat } ;
16+ use crate :: image:: { ImageDecoder , ImageEncoder , ImageFormat } ;
1717use crate :: image_reader:: free_functions;
1818use crate :: math:: resize_dimensions;
19- use crate :: traits:: Pixel ;
2019use crate :: { image, Luma , LumaA } ;
2120use crate :: { imageops, ExtendedColorType } ;
2221use crate :: { ImageReader , Orientation } ;
@@ -703,6 +702,11 @@ impl DynamicImage {
703702 dynamic_map ! ( * self , ref p, { p. height( ) } )
704703 }
705704
705+ /// Returns the dimensions of the underlying image
706+ pub fn dimensions ( & self ) -> ( u32 , u32 ) {
707+ ( self . width ( ) , self . height ( ) )
708+ }
709+
706710 /// Return a grayscale version of this image.
707711 /// Returns `Luma` images in most cases. However, for `f32` images,
708712 /// this will return a grayscale `Rgb/Rgba` image instead.
@@ -1120,66 +1124,6 @@ impl From<ImageBuffer<LumaA<f32>, Vec<f32>>> for DynamicImage {
11201124 DynamicImage :: ImageRgba32F ( image. convert ( ) )
11211125 }
11221126}
1123-
1124- #[ allow( deprecated) ]
1125- impl GenericImageView for DynamicImage {
1126- type Pixel = color:: Rgba < u8 > ; // TODO use f32 as default for best precision and unbounded color?
1127-
1128- fn dimensions ( & self ) -> ( u32 , u32 ) {
1129- dynamic_map ! ( * self , ref p, p. dimensions( ) )
1130- }
1131-
1132- fn get_pixel ( & self , x : u32 , y : u32 ) -> color:: Rgba < u8 > {
1133- dynamic_map ! ( * self , ref p, p. get_pixel( x, y) . to_rgba( ) . into_color( ) )
1134- }
1135- }
1136-
1137- #[ allow( deprecated) ]
1138- impl GenericImage for DynamicImage {
1139- fn put_pixel ( & mut self , x : u32 , y : u32 , pixel : color:: Rgba < u8 > ) {
1140- match * self {
1141- DynamicImage :: ImageLuma8 ( ref mut p) => p. put_pixel ( x, y, pixel. to_luma ( ) ) ,
1142- DynamicImage :: ImageLumaA8 ( ref mut p) => p. put_pixel ( x, y, pixel. to_luma_alpha ( ) ) ,
1143- DynamicImage :: ImageRgb8 ( ref mut p) => p. put_pixel ( x, y, pixel. to_rgb ( ) ) ,
1144- DynamicImage :: ImageRgba8 ( ref mut p) => p. put_pixel ( x, y, pixel) ,
1145- DynamicImage :: ImageLuma16 ( ref mut p) => p. put_pixel ( x, y, pixel. to_luma ( ) . into_color ( ) ) ,
1146- DynamicImage :: ImageLumaA16 ( ref mut p) => {
1147- p. put_pixel ( x, y, pixel. to_luma_alpha ( ) . into_color ( ) ) ;
1148- }
1149- DynamicImage :: ImageRgb16 ( ref mut p) => p. put_pixel ( x, y, pixel. to_rgb ( ) . into_color ( ) ) ,
1150- DynamicImage :: ImageRgba16 ( ref mut p) => p. put_pixel ( x, y, pixel. into_color ( ) ) ,
1151- DynamicImage :: ImageRgb32F ( ref mut p) => p. put_pixel ( x, y, pixel. to_rgb ( ) . into_color ( ) ) ,
1152- DynamicImage :: ImageRgba32F ( ref mut p) => p. put_pixel ( x, y, pixel. into_color ( ) ) ,
1153- }
1154- }
1155-
1156- fn blend_pixel ( & mut self , x : u32 , y : u32 , pixel : color:: Rgba < u8 > ) {
1157- match * self {
1158- DynamicImage :: ImageLuma8 ( ref mut p) => p. blend_pixel ( x, y, pixel. to_luma ( ) ) ,
1159- DynamicImage :: ImageLumaA8 ( ref mut p) => p. blend_pixel ( x, y, pixel. to_luma_alpha ( ) ) ,
1160- DynamicImage :: ImageRgb8 ( ref mut p) => p. blend_pixel ( x, y, pixel. to_rgb ( ) ) ,
1161- DynamicImage :: ImageRgba8 ( ref mut p) => p. blend_pixel ( x, y, pixel) ,
1162- DynamicImage :: ImageLuma16 ( ref mut p) => {
1163- p. blend_pixel ( x, y, pixel. to_luma ( ) . into_color ( ) ) ;
1164- }
1165- DynamicImage :: ImageLumaA16 ( ref mut p) => {
1166- p. blend_pixel ( x, y, pixel. to_luma_alpha ( ) . into_color ( ) ) ;
1167- }
1168- DynamicImage :: ImageRgb16 ( ref mut p) => p. blend_pixel ( x, y, pixel. to_rgb ( ) . into_color ( ) ) ,
1169- DynamicImage :: ImageRgba16 ( ref mut p) => p. blend_pixel ( x, y, pixel. into_color ( ) ) ,
1170- DynamicImage :: ImageRgb32F ( ref mut p) => {
1171- p. blend_pixel ( x, y, pixel. to_rgb ( ) . into_color ( ) ) ;
1172- }
1173- DynamicImage :: ImageRgba32F ( ref mut p) => p. blend_pixel ( x, y, pixel. into_color ( ) ) ,
1174- }
1175- }
1176-
1177- /// Do not use is function: It is unimplemented!
1178- fn get_pixel_mut ( & mut self , _: u32 , _: u32 ) -> & mut color:: Rgba < u8 > {
1179- unimplemented ! ( )
1180- }
1181- }
1182-
11831127impl Default for DynamicImage {
11841128 fn default ( ) -> Self {
11851129 Self :: ImageRgba8 ( Default :: default ( ) )
@@ -1400,84 +1344,6 @@ mod test {
14001344 assert_eq ! ( image. color( ) , ColorType :: Rgba16 ) ;
14011345 }
14021346
1403- fn test_grayscale ( mut img : super :: DynamicImage , alpha_discarded : bool ) {
1404- use crate :: image:: { GenericImage , GenericImageView } ;
1405- img. put_pixel ( 0 , 0 , crate :: color:: Rgba ( [ 255 , 0 , 0 , 100 ] ) ) ;
1406- let expected_alpha = if alpha_discarded { 255 } else { 100 } ;
1407- assert_eq ! (
1408- img. grayscale( ) . get_pixel( 0 , 0 ) ,
1409- crate :: color:: Rgba ( [ 54 , 54 , 54 , expected_alpha] )
1410- ) ;
1411- }
1412-
1413- fn test_grayscale_alpha_discarded ( img : super :: DynamicImage ) {
1414- test_grayscale ( img, true ) ;
1415- }
1416-
1417- fn test_grayscale_alpha_preserved ( img : super :: DynamicImage ) {
1418- test_grayscale ( img, false ) ;
1419- }
1420-
1421- #[ test]
1422- fn test_grayscale_luma8 ( ) {
1423- test_grayscale_alpha_discarded ( super :: DynamicImage :: new_luma8 ( 1 , 1 ) ) ;
1424- test_grayscale_alpha_discarded ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: L8 ) ) ;
1425- }
1426-
1427- #[ test]
1428- fn test_grayscale_luma_a8 ( ) {
1429- test_grayscale_alpha_preserved ( super :: DynamicImage :: new_luma_a8 ( 1 , 1 ) ) ;
1430- test_grayscale_alpha_preserved ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: La8 ) ) ;
1431- }
1432-
1433- #[ test]
1434- fn test_grayscale_rgb8 ( ) {
1435- test_grayscale_alpha_discarded ( super :: DynamicImage :: new_rgb8 ( 1 , 1 ) ) ;
1436- test_grayscale_alpha_discarded ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgb8 ) ) ;
1437- }
1438-
1439- #[ test]
1440- fn test_grayscale_rgba8 ( ) {
1441- test_grayscale_alpha_preserved ( super :: DynamicImage :: new_rgba8 ( 1 , 1 ) ) ;
1442- test_grayscale_alpha_preserved ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgba8 ) ) ;
1443- }
1444-
1445- #[ test]
1446- fn test_grayscale_luma16 ( ) {
1447- test_grayscale_alpha_discarded ( super :: DynamicImage :: new_luma16 ( 1 , 1 ) ) ;
1448- test_grayscale_alpha_discarded ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: L16 ) ) ;
1449- }
1450-
1451- #[ test]
1452- fn test_grayscale_luma_a16 ( ) {
1453- test_grayscale_alpha_preserved ( super :: DynamicImage :: new_luma_a16 ( 1 , 1 ) ) ;
1454- test_grayscale_alpha_preserved ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: La16 ) ) ;
1455- }
1456-
1457- #[ test]
1458- fn test_grayscale_rgb16 ( ) {
1459- test_grayscale_alpha_discarded ( super :: DynamicImage :: new_rgb16 ( 1 , 1 ) ) ;
1460- test_grayscale_alpha_discarded ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgb16 ) ) ;
1461- }
1462-
1463- #[ test]
1464- fn test_grayscale_rgba16 ( ) {
1465- test_grayscale_alpha_preserved ( super :: DynamicImage :: new_rgba16 ( 1 , 1 ) ) ;
1466- test_grayscale_alpha_preserved ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgba16 ) ) ;
1467- }
1468-
1469- #[ test]
1470- fn test_grayscale_rgb32f ( ) {
1471- test_grayscale_alpha_discarded ( super :: DynamicImage :: new_rgb32f ( 1 , 1 ) ) ;
1472- test_grayscale_alpha_discarded ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgb32F ) ) ;
1473- }
1474-
1475- #[ test]
1476- fn test_grayscale_rgba32f ( ) {
1477- test_grayscale_alpha_preserved ( super :: DynamicImage :: new_rgba32f ( 1 , 1 ) ) ;
1478- test_grayscale_alpha_preserved ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgba32F ) ) ;
1479- }
1480-
14811347 #[ test]
14821348 fn test_dynamic_image_default_implementation ( ) {
14831349 // Test that structs wrapping a DynamicImage are able to auto-derive the Default trait
0 commit comments