Skip to content

Commit c379ef6

Browse files
committed
Reuse code moved into pkg/lodim.
1 parent ce147f6 commit c379ef6

File tree

9 files changed

+227
-334
lines changed

9 files changed

+227
-334
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.1.0-alpha+1
4+
5+
- Upgraded to `lodim ^0.1.6`, which now hosts some of the original functionality
6+
of this package in a more general-purpose way (i.e. `fill`, `copy`, ...).
7+
38
## 0.1.0-alpha
49

510
Initial preview release 🎉!

example/example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void main() {
1818
final blue = (y / (imageHeight / 2) * 255).toInt();
1919
image.fill(
2020
abgr8888.create(blue: blue),
21-
target: Rect.fromLTWH(0, y, imageWidth, 1),
21+
Rect.fromLTWH(0, y, imageWidth, 1),
2222
);
2323
}
2424

lib/src/buffer.dart

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:typed_data';
22

3+
import 'package:lodim/lodim.dart' as lodim;
34
import 'package:pxl/src/blend.dart';
45
import 'package:pxl/src/format.dart';
56
import 'package:pxl/src/geometry.dart';
@@ -196,44 +197,16 @@ abstract base mixin class Buffer<T extends Object?> {
196197
return _ScaledBuffer(this, scale);
197198
}
198199

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-
229200
/// Returns a lazy iterable of pixels in the rectangle defined by [rect].
230201
///
231202
/// The returned iterable will contain all pixels in the buffer that are
232203
/// within the rectangle defined by [rect].
233204
///
234205
/// The provided rectangle is clamped to the bounds of the buffer and yields
235206
/// 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+
}
237210

238211
/// Returns a lazy iterable of pixels in the rectangle defined by [rect].
239212
///
@@ -243,10 +216,7 @@ abstract base mixin class Buffer<T extends Object?> {
243216
/// The provided rectangle must be contained within the bounds of the buffer
244217
/// or the behavior is undefined.
245218
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);
250220
}
251221

252222
@override

0 commit comments

Comments
 (0)