@@ -181,35 +181,19 @@ impl ImageSampler {
181
181
182
182
/// Describes the image content of a filled or stroked shape.
183
183
///
184
- /// See also [`ImageBrushRef`] which can be used to avoid reference counting overhead.
185
- #[ derive( Clone , PartialEq , Debug ) ]
184
+ /// This type is generic over the storage used for the image data.
185
+ /// By default, the generic parameter is [`ImageData`], which is a shared image with dynamic lifetime.
186
+ /// However, different renderers can use different types here, such as a pre-registered id.
187
+ #[ derive( Copy , Clone , PartialEq , Debug ) ]
186
188
#[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
187
- pub struct ImageBrush {
189
+ pub struct ImageBrush < D = ImageData > {
188
190
/// The image to render.
189
- pub image : ImageData ,
191
+ pub image : D ,
190
192
/// Parameters which specify how to sample from the image during rendering.
191
193
pub sampler : ImageSampler ,
192
194
}
193
195
194
- impl ImageBrush {
195
- /// Creates a new `ImageBrush` for the specified `ImageData` with default `ImageSampler`.
196
- #[ must_use]
197
- pub fn new ( image : ImageData ) -> Self {
198
- Self {
199
- image,
200
- sampler : ImageSampler :: default ( ) ,
201
- }
202
- }
203
-
204
- /// Converts an owned `ImageBrush` into a borrowed `ImageBrushRef`.
205
- #[ must_use]
206
- pub fn as_ref ( & self ) -> ImageBrushRef < ' _ > {
207
- ImageBrushRef {
208
- image : & self . image ,
209
- sampler : self . sampler ,
210
- }
211
- }
212
-
196
+ impl < D > ImageBrush < D > {
213
197
/// Builder method for setting the image [extend mode](Extend) in both
214
198
/// directions.
215
199
#[ must_use]
@@ -269,89 +253,36 @@ impl ImageBrush {
269
253
}
270
254
}
271
255
272
- /// Borrowed version of [`ImageBrush`] for avoiding reference counting overhead.
273
- #[ derive( Copy , Clone , PartialEq , Debug ) ]
274
- pub struct ImageBrushRef < ' a > {
275
- /// The image to render.
276
- pub image : & ' a ImageData ,
277
- /// Parameters which specify how to sample from the image during rendering.
278
- pub sampler : ImageSampler ,
279
- }
280
-
281
- impl ImageBrushRef < ' _ > {
282
- /// Creates a new image with the given data, [format](ImageFormat) and dimensions.
256
+ impl ImageBrush {
257
+ /// Creates a new `ImageBrush` for the specified `ImageData` with default `ImageSampler`.
283
258
#[ must_use]
284
- pub fn new < ' a > ( image : & ' a ImageData ) -> ImageBrushRef < ' a > {
285
- ImageBrushRef {
259
+ pub fn new ( image : ImageData ) -> Self {
260
+ Self {
286
261
image,
287
262
sampler : ImageSampler :: default ( ) ,
288
263
}
289
264
}
290
265
291
- /// Converts the `ImageBrushRef` to an owned `ImageBrush `.
266
+ /// Converts an owned `ImageBrush` into a borrowed `ImageBrushRef `.
292
267
#[ must_use]
293
- pub fn to_owned ( & self ) -> ImageBrush {
268
+ pub fn as_ref ( & ' _ self ) -> ImageBrushRef < ' _ > {
294
269
ImageBrush {
295
- image : ( * self . image ) . clone ( ) ,
270
+ image : & self . image ,
296
271
sampler : self . sampler ,
297
272
}
298
273
}
274
+ }
299
275
300
- /// Builder method for setting the image [extend mode](Extend) in both
301
- /// directions.
302
- #[ must_use]
303
- pub fn with_extend ( mut self , mode : Extend ) -> Self {
304
- self . sampler . x_extend = mode;
305
- self . sampler . y_extend = mode;
306
- self
307
- }
308
-
309
- /// Builder method for setting the image [extend mode](Extend) in the
310
- /// horizontal direction.
311
- #[ must_use]
312
- pub fn with_x_extend ( mut self , mode : Extend ) -> Self {
313
- self . sampler . x_extend = mode;
314
- self
315
- }
316
-
317
- /// Builder method for setting the image [extend mode](Extend) in the
318
- /// vertical direction.
319
- #[ must_use]
320
- pub fn with_y_extend ( mut self , mode : Extend ) -> Self {
321
- self . sampler . y_extend = mode;
322
- self
323
- }
324
-
325
- /// Builder method for setting a hint for the desired image [quality](ImageQuality)
326
- /// when rendering.
327
- #[ must_use]
328
- pub fn with_quality ( mut self , quality : ImageQuality ) -> Self {
329
- self . sampler . quality = quality;
330
- self
331
- }
332
-
333
- /// Returns the image with the alpha multiplier set to `alpha`.
334
- #[ must_use]
335
- #[ track_caller]
336
- pub fn with_alpha ( mut self , alpha : f32 ) -> Self {
337
- debug_assert ! (
338
- alpha. is_finite( ) && alpha >= 0.0 ,
339
- "A non-finite or negative alpha ({alpha}) is meaningless."
340
- ) ;
341
- self . sampler . alpha = alpha;
342
- self
343
- }
276
+ /// Borrowed version of [`ImageBrush`] for avoiding reference counting overhead.
277
+ pub type ImageBrushRef < ' a > = ImageBrush < & ' a ImageData > ;
344
278
345
- /// Returns the image with the alpha multiplier multiplied again by `alpha`.
346
- /// The behaviour of this transformation is undefined if `alpha` is negative .
279
+ impl ImageBrushRef < ' _ > {
280
+ /// Converts the `ImageBrushRef` to an owned `ImageBrush` .
347
281
#[ must_use]
348
- #[ track_caller]
349
- pub fn multiply_alpha ( mut self , alpha : f32 ) -> Self {
350
- debug_assert ! (
351
- alpha. is_finite( ) && alpha >= 0.0 ,
352
- "A non-finite or negative alpha ({alpha}) is meaningless."
353
- ) ;
354
- self . sampler . alpha *= alpha;
355
- self
282
+ pub fn to_owned ( & self ) -> ImageBrush {
283
+ ImageBrush {
284
+ image : ( * self . image ) . clone ( ) ,
285
+ sampler : self . sampler ,
286
+ }
356
287
}
357
288
}
0 commit comments