@@ -38,6 +38,7 @@ pub trait ImageOps {
38
38
fn to_mode ( & self , mode : ImageMode ) -> DaftResult < Self >
39
39
where
40
40
Self : Sized ;
41
+ fn attribute ( & self , attr : & str ) -> DaftResult < DataArray < UInt32Type > > ;
41
42
}
42
43
43
44
pub ( crate ) fn image_array_from_img_buffers (
@@ -194,8 +195,22 @@ impl ImageOps for ImageArray {
194
195
. collect ( ) ;
195
196
image_array_from_img_buffers ( self . name ( ) , & buffers, Some ( mode) )
196
197
}
198
+
199
+ fn attribute ( & self , attr : & str ) -> DaftResult < DataArray < UInt32Type > > {
200
+ match attr. to_lowercase ( ) . as_str ( ) {
201
+ "height" | "heights" => Ok ( self . heights ( ) . clone ( ) . rename ( self . name ( ) ) ) ,
202
+ "width" | "widths" => Ok ( self . widths ( ) . clone ( ) . rename ( self . name ( ) ) ) ,
203
+ "channel" | "channels" => Ok ( self . channels ( ) . clone ( ) . cast ( & DataType :: UInt32 ) ?. u32 ( ) ?. clone ( ) . rename ( self . name ( ) ) ) ,
204
+ "mode" | "modes" => Ok ( self . modes ( ) . clone ( ) . cast ( & DataType :: UInt32 ) ?. u32 ( ) ?. clone ( ) . rename ( self . name ( ) ) ) ,
205
+ _ => Err ( DaftError :: ValueError ( format ! (
206
+ "Unsupported image attribute: {}, available: [heights, widths, channels, modes]" ,
207
+ attr
208
+ ) ) ) ,
209
+ }
210
+ }
197
211
}
198
212
213
+
199
214
impl ImageOps for FixedShapeImageArray {
200
215
fn encode ( & self , image_format : ImageFormat ) -> DaftResult < BinaryArray > {
201
216
encode_images ( self , image_format)
@@ -254,6 +269,36 @@ impl ImageOps for FixedShapeImageArray {
254
269
} ;
255
270
fixed_image_array_from_img_buffers ( self . name ( ) , & buffers, & mode, * height, * width)
256
271
}
272
+
273
+ fn attribute ( & self , attr : & str ) -> DaftResult < DataArray < UInt32Type > > {
274
+ let ( height, width) = match self . data_type ( ) {
275
+ DataType :: FixedShapeImage ( _, h, w) => ( h, w) ,
276
+ _ => unreachable ! ( "Should be FixedShapeImage type" ) ,
277
+ } ;
278
+
279
+ match attr. to_lowercase ( ) . as_str ( ) {
280
+ "height" | "heights" => Ok ( UInt32Array :: from ( (
281
+ self . name ( ) ,
282
+ vec ! [ * height; self . len( ) ] . as_slice ( ) ,
283
+ ) ) ) ,
284
+ "width" | "widths" => Ok ( UInt32Array :: from ( (
285
+ self . name ( ) ,
286
+ vec ! [ * width; self . len( ) ] . as_slice ( ) ,
287
+ ) ) ) ,
288
+ "channel" | "channels" => Ok ( UInt32Array :: from ( (
289
+ self . name ( ) ,
290
+ vec ! [ self . image_mode( ) . num_channels( ) as u32 ; self . len( ) ] . as_slice ( ) ,
291
+ ) ) ) ,
292
+ "mode" | "modes" => Ok ( UInt32Array :: from ( (
293
+ self . name ( ) ,
294
+ vec ! [ ( * self . image_mode( ) as u8 ) as u32 ; self . len( ) ] . as_slice ( ) ,
295
+ ) ) ) ,
296
+ _ => Err ( DaftError :: ValueError ( format ! (
297
+ "Unsupported image attribute: {}, available: [heights, widths, channels, modes]" ,
298
+ attr
299
+ ) ) ) ,
300
+ }
301
+ }
257
302
}
258
303
259
304
impl AsImageObj for ImageArray {
0 commit comments