11use crate :: error:: { ImageError , ImageResult } ;
2- use crate :: flat:: { View , ViewOfPixel } ;
2+ use crate :: flat:: ViewOfPixel ;
33use crate :: math:: Rect ;
44use crate :: traits:: Pixel ;
55use crate :: { ImageBuffer , SubImage } ;
@@ -140,8 +140,17 @@ pub trait GenericImageView {
140140 ImageBuffer :: new ( width, height)
141141 }
142142
143- /// If the buffer has a fitting layout, return a view of the samples descriptor.
144- fn as_samples ( & self ) -> Option < ViewOfPixel < ' _ , Self :: Pixel > > {
143+ /// If the buffer has a fitting layout, return a canonical view of the samples.
144+ ///
145+ /// This is the basis of optimization and by default return `None`. It lets consumers of
146+ /// generic images access the sample data through a canonical descriptor of its layout directly
147+ /// instead of pixel-by-pixel. This provides more efficient forms of access that the
148+ /// [`GenericImageView`] trait itself does not demand from all its implementations.
149+ ///
150+ /// Implementation of this method should be cheap to call.
151+ ///
152+ /// If implemented, a [`SubImage`] proxy of this image will provide a sample view as well.
153+ fn to_pixel_view ( & self ) -> Option < ViewOfPixel < ' _ , Self :: Pixel > > {
145154 None
146155 }
147156}
@@ -254,7 +263,7 @@ pub trait GenericImage: GenericImageView {
254263 where
255264 O : GenericImageView < Pixel = Self :: Pixel > ,
256265 {
257- if let Some ( flat) = other. as_samples ( ) {
266+ if let Some ( flat) = other. to_pixel_view ( ) {
258267 return self . copy_from_samples ( flat, x, y) ;
259268 }
260269
@@ -275,7 +284,7 @@ pub trait GenericImage: GenericImageView {
275284 /// Copy pixels from a regular strided matrix of pixels.
276285 fn copy_from_samples (
277286 & mut self ,
278- samples : View < & [ < Self :: Pixel as Pixel > :: Subpixel ] , Self :: Pixel > ,
287+ samples : ViewOfPixel < ' _ , Self :: Pixel > ,
279288 x : u32 ,
280289 y : u32 ,
281290 ) -> ImageResult < ( ) > {
0 commit comments