1
1
import 'dart:typed_data' ;
2
2
3
+ import 'package:lodim/lodim.dart' as lodim;
3
4
import 'package:pxl/src/blend.dart' ;
4
5
import 'package:pxl/src/format.dart' ;
5
6
import 'package:pxl/src/geometry.dart' ;
@@ -196,44 +197,16 @@ abstract base mixin class Buffer<T extends Object?> {
196
197
return _ScaledBuffer (this , scale);
197
198
}
198
199
199
- /// Returns a lazy iterable of pixels in the buffer from [start] to [end] .
200
- ///
201
- /// The returned iterable will contain all pixels in the buffer that are
202
- /// within the rectangle defined by [start] and [end] , inclusive.
203
- ///
204
- /// The provided positions are clamped to the bounds of the buffer, and yield
205
- /// no pixels if `start > end` .
206
- Iterable <T > getRange (Pos start, Pos end) {
207
- final bottomRight = bounds.bottomRight;
208
- start = start.clamp (Pos .zero, bottomRight);
209
- end = end.clamp (Pos .zero, bottomRight);
210
- if (Pos .byRowMajor (start, end) > 0 ) {
211
- return const Iterable .empty ();
212
- }
213
- return getRangeUnsafe (start, end);
214
- }
215
-
216
- /// Returns a lazy iterable of pixels in the buffer from [start] to [end] .
217
- ///
218
- /// The returned iterable will contain all pixels in the buffer that are
219
- /// within the rectangle defined by [start] and [end] , inclusive.
220
- ///
221
- /// The provided positions must be `(0, 0) <= start <= end < (width, height)`
222
- /// or the behavior is undefined.
223
- Iterable <T > getRangeUnsafe (Pos start, Pos end) {
224
- final iStart = start.y * width + start.x;
225
- final iEnd = end.y * width + end.x;
226
- return data.skip (iStart).take (iEnd - iStart + 1 );
227
- }
228
-
229
200
/// Returns a lazy iterable of pixels in the rectangle defined by [rect] .
230
201
///
231
202
/// The returned iterable will contain all pixels in the buffer that are
232
203
/// within the rectangle defined by [rect] .
233
204
///
234
205
/// The provided rectangle is clamped to the bounds of the buffer and yields
235
206
/// no pixels if the rectangle is empty.
236
- Iterable <T > getRect (Rect rect) => getRectUnsafe (rect.intersect (bounds));
207
+ Iterable <T > getRect (Rect rect) {
208
+ return getRectUnsafe (rect.intersect (bounds));
209
+ }
237
210
238
211
/// Returns a lazy iterable of pixels in the rectangle defined by [rect] .
239
212
///
@@ -243,10 +216,7 @@ abstract base mixin class Buffer<T extends Object?> {
243
216
/// The provided rectangle must be contained within the bounds of the buffer
244
217
/// or the behavior is undefined.
245
218
Iterable <T > getRectUnsafe (Rect rect) {
246
- if (rect.width == width) {
247
- return getRangeUnsafe (rect.topLeft, rect.bottomRight - const Pos (1 , 1 ));
248
- }
249
- return rect.positions.map (getUnsafe);
219
+ return lodim.getRect (rect, getUnsafe);
250
220
}
251
221
252
222
@override
0 commit comments