@@ -10,14 +10,13 @@ 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;
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;
1919use crate :: metadata:: Orientation ;
20- use crate :: traits:: Pixel ;
2120use crate :: ImageReader ;
2221use crate :: { image, Luma , LumaA } ;
2322use crate :: { imageops, ExtendedColorType } ;
@@ -704,6 +703,11 @@ impl DynamicImage {
704703 dynamic_map ! ( * self , ref p, { p. height( ) } )
705704 }
706705
706+ /// Returns the dimensions of the underlying image
707+ pub fn dimensions ( & self ) -> ( u32 , u32 ) {
708+ ( self . width ( ) , self . height ( ) )
709+ }
710+
707711 /// Return a grayscale version of this image.
708712 /// Returns `Luma` images in most cases. However, for `f32` images,
709713 /// this will return a grayscale `Rgb/Rgba` image instead.
@@ -1108,66 +1112,6 @@ impl From<ImageBuffer<LumaA<f32>, Vec<f32>>> for DynamicImage {
11081112 DynamicImage :: ImageRgba32F ( image. convert ( ) )
11091113 }
11101114}
1111-
1112- #[ allow( deprecated) ]
1113- impl GenericImageView for DynamicImage {
1114- type Pixel = color:: Rgba < u8 > ; // TODO use f32 as default for best precision and unbounded color?
1115-
1116- fn dimensions ( & self ) -> ( u32 , u32 ) {
1117- dynamic_map ! ( * self , ref p, p. dimensions( ) )
1118- }
1119-
1120- fn get_pixel ( & self , x : u32 , y : u32 ) -> color:: Rgba < u8 > {
1121- dynamic_map ! ( * self , ref p, p. get_pixel( x, y) . to_rgba( ) . into_color( ) )
1122- }
1123- }
1124-
1125- #[ allow( deprecated) ]
1126- impl GenericImage for DynamicImage {
1127- fn put_pixel ( & mut self , x : u32 , y : u32 , pixel : color:: Rgba < u8 > ) {
1128- match * self {
1129- DynamicImage :: ImageLuma8 ( ref mut p) => p. put_pixel ( x, y, pixel. to_luma ( ) ) ,
1130- DynamicImage :: ImageLumaA8 ( ref mut p) => p. put_pixel ( x, y, pixel. to_luma_alpha ( ) ) ,
1131- DynamicImage :: ImageRgb8 ( ref mut p) => p. put_pixel ( x, y, pixel. to_rgb ( ) ) ,
1132- DynamicImage :: ImageRgba8 ( ref mut p) => p. put_pixel ( x, y, pixel) ,
1133- DynamicImage :: ImageLuma16 ( ref mut p) => p. put_pixel ( x, y, pixel. to_luma ( ) . into_color ( ) ) ,
1134- DynamicImage :: ImageLumaA16 ( ref mut p) => {
1135- p. put_pixel ( x, y, pixel. to_luma_alpha ( ) . into_color ( ) ) ;
1136- }
1137- DynamicImage :: ImageRgb16 ( ref mut p) => p. put_pixel ( x, y, pixel. to_rgb ( ) . into_color ( ) ) ,
1138- DynamicImage :: ImageRgba16 ( ref mut p) => p. put_pixel ( x, y, pixel. into_color ( ) ) ,
1139- DynamicImage :: ImageRgb32F ( ref mut p) => p. put_pixel ( x, y, pixel. to_rgb ( ) . into_color ( ) ) ,
1140- DynamicImage :: ImageRgba32F ( ref mut p) => p. put_pixel ( x, y, pixel. into_color ( ) ) ,
1141- }
1142- }
1143-
1144- fn blend_pixel ( & mut self , x : u32 , y : u32 , pixel : color:: Rgba < u8 > ) {
1145- match * self {
1146- DynamicImage :: ImageLuma8 ( ref mut p) => p. blend_pixel ( x, y, pixel. to_luma ( ) ) ,
1147- DynamicImage :: ImageLumaA8 ( ref mut p) => p. blend_pixel ( x, y, pixel. to_luma_alpha ( ) ) ,
1148- DynamicImage :: ImageRgb8 ( ref mut p) => p. blend_pixel ( x, y, pixel. to_rgb ( ) ) ,
1149- DynamicImage :: ImageRgba8 ( ref mut p) => p. blend_pixel ( x, y, pixel) ,
1150- DynamicImage :: ImageLuma16 ( ref mut p) => {
1151- p. blend_pixel ( x, y, pixel. to_luma ( ) . into_color ( ) ) ;
1152- }
1153- DynamicImage :: ImageLumaA16 ( ref mut p) => {
1154- p. blend_pixel ( x, y, pixel. to_luma_alpha ( ) . into_color ( ) ) ;
1155- }
1156- DynamicImage :: ImageRgb16 ( ref mut p) => p. blend_pixel ( x, y, pixel. to_rgb ( ) . into_color ( ) ) ,
1157- DynamicImage :: ImageRgba16 ( ref mut p) => p. blend_pixel ( x, y, pixel. into_color ( ) ) ,
1158- DynamicImage :: ImageRgb32F ( ref mut p) => {
1159- p. blend_pixel ( x, y, pixel. to_rgb ( ) . into_color ( ) ) ;
1160- }
1161- DynamicImage :: ImageRgba32F ( ref mut p) => p. blend_pixel ( x, y, pixel. into_color ( ) ) ,
1162- }
1163- }
1164-
1165- /// Do not use is function: It is unimplemented!
1166- fn get_pixel_mut ( & mut self , _: u32 , _: u32 ) -> & mut color:: Rgba < u8 > {
1167- unimplemented ! ( )
1168- }
1169- }
1170-
11711115impl Default for DynamicImage {
11721116 fn default ( ) -> Self {
11731117 Self :: ImageRgba8 ( Default :: default ( ) )
@@ -1388,84 +1332,6 @@ mod test {
13881332 assert_eq ! ( image. color( ) , ColorType :: Rgba16 ) ;
13891333 }
13901334
1391- fn test_grayscale ( mut img : super :: DynamicImage , alpha_discarded : bool ) {
1392- use crate :: image:: { GenericImage , GenericImageView } ;
1393- img. put_pixel ( 0 , 0 , crate :: color:: Rgba ( [ 255 , 0 , 0 , 100 ] ) ) ;
1394- let expected_alpha = if alpha_discarded { 255 } else { 100 } ;
1395- assert_eq ! (
1396- img. grayscale( ) . get_pixel( 0 , 0 ) ,
1397- crate :: color:: Rgba ( [ 54 , 54 , 54 , expected_alpha] )
1398- ) ;
1399- }
1400-
1401- fn test_grayscale_alpha_discarded ( img : super :: DynamicImage ) {
1402- test_grayscale ( img, true ) ;
1403- }
1404-
1405- fn test_grayscale_alpha_preserved ( img : super :: DynamicImage ) {
1406- test_grayscale ( img, false ) ;
1407- }
1408-
1409- #[ test]
1410- fn test_grayscale_luma8 ( ) {
1411- test_grayscale_alpha_discarded ( super :: DynamicImage :: new_luma8 ( 1 , 1 ) ) ;
1412- test_grayscale_alpha_discarded ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: L8 ) ) ;
1413- }
1414-
1415- #[ test]
1416- fn test_grayscale_luma_a8 ( ) {
1417- test_grayscale_alpha_preserved ( super :: DynamicImage :: new_luma_a8 ( 1 , 1 ) ) ;
1418- test_grayscale_alpha_preserved ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: La8 ) ) ;
1419- }
1420-
1421- #[ test]
1422- fn test_grayscale_rgb8 ( ) {
1423- test_grayscale_alpha_discarded ( super :: DynamicImage :: new_rgb8 ( 1 , 1 ) ) ;
1424- test_grayscale_alpha_discarded ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgb8 ) ) ;
1425- }
1426-
1427- #[ test]
1428- fn test_grayscale_rgba8 ( ) {
1429- test_grayscale_alpha_preserved ( super :: DynamicImage :: new_rgba8 ( 1 , 1 ) ) ;
1430- test_grayscale_alpha_preserved ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgba8 ) ) ;
1431- }
1432-
1433- #[ test]
1434- fn test_grayscale_luma16 ( ) {
1435- test_grayscale_alpha_discarded ( super :: DynamicImage :: new_luma16 ( 1 , 1 ) ) ;
1436- test_grayscale_alpha_discarded ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: L16 ) ) ;
1437- }
1438-
1439- #[ test]
1440- fn test_grayscale_luma_a16 ( ) {
1441- test_grayscale_alpha_preserved ( super :: DynamicImage :: new_luma_a16 ( 1 , 1 ) ) ;
1442- test_grayscale_alpha_preserved ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: La16 ) ) ;
1443- }
1444-
1445- #[ test]
1446- fn test_grayscale_rgb16 ( ) {
1447- test_grayscale_alpha_discarded ( super :: DynamicImage :: new_rgb16 ( 1 , 1 ) ) ;
1448- test_grayscale_alpha_discarded ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgb16 ) ) ;
1449- }
1450-
1451- #[ test]
1452- fn test_grayscale_rgba16 ( ) {
1453- test_grayscale_alpha_preserved ( super :: DynamicImage :: new_rgba16 ( 1 , 1 ) ) ;
1454- test_grayscale_alpha_preserved ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgba16 ) ) ;
1455- }
1456-
1457- #[ test]
1458- fn test_grayscale_rgb32f ( ) {
1459- test_grayscale_alpha_discarded ( super :: DynamicImage :: new_rgb32f ( 1 , 1 ) ) ;
1460- test_grayscale_alpha_discarded ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgb32F ) ) ;
1461- }
1462-
1463- #[ test]
1464- fn test_grayscale_rgba32f ( ) {
1465- test_grayscale_alpha_preserved ( super :: DynamicImage :: new_rgba32f ( 1 , 1 ) ) ;
1466- test_grayscale_alpha_preserved ( super :: DynamicImage :: new ( 1 , 1 , ColorType :: Rgba32F ) ) ;
1467- }
1468-
14691335 #[ test]
14701336 fn test_dynamic_image_default_implementation ( ) {
14711337 // Test that structs wrapping a DynamicImage are able to auto-derive the Default trait
0 commit comments