forked from brendan-duncan/image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gif_test.dart
80 lines (68 loc) · 2.22 KB
/
gif_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import 'dart:io';
import 'package:image/image.dart';
import 'package:test/test.dart';
void main() {
Directory dir = Directory('test/res/gif');
var files = dir.listSync();
group('GIF', () {
for (var f in files) {
if (f is! File || !f.path.endsWith('.gif')) {
continue;
}
String name = f.path.split(RegExp(r'(/|\\)')).last;
test('getInfo $name', () {
var bytes = (f as File).readAsBytesSync();
GifInfo data = GifDecoder().startDecode(bytes);
if (data == null) {
throw ImageException('Unable to parse Gif info: $name.');
}
});
}
for (var f in files) {
if (f is! File || !f.path.endsWith('.gif')) {
continue;
}
String name = f.path.split(RegExp(r'(/|\\)')).last;
test('decodeImage $name', () {
var bytes = (f as File).readAsBytesSync();
Image image = GifDecoder().decodeImage(bytes);
File('out/gif/$name.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(image));
});
}
for (var f in files) {
if (f is! File || !f.path.endsWith('cars.gif')) {
continue;
}
String name = f.path.split(RegExp(r'(/|\\)')).last;
test('decodeAnimation $name', () {
List<int> bytes = (f as File).readAsBytesSync();
Animation anim = GifDecoder().decodeAnimation(bytes);
expect(anim.length, equals(30));
expect(anim.loopCount, equals(0));
});
}
test('encodeAnimation', () {
Animation anim = Animation();
anim.loopCount = 10;
for (var i = 0; i < 10; i++) {
Image image = Image(480, 120);
drawString(image, arial_48, 100, 60, i.toString());
anim.addFrame(image);
}
List<int> gif = encodeGifAnimation(anim);
File('out/gif/encodeAnimation.gif')
..createSync(recursive: true)
..writeAsBytesSync(gif);
});
test('encodeImage', () {
List<int> bytes = File('test/res/jpg/jpeg444.jpg').readAsBytesSync();
Image image = JpegDecoder().decodeImage(bytes);
List<int> gif = GifEncoder().encodeImage(image);
File('out/gif/jpeg444.gif')
..createSync(recursive: true)
..writeAsBytesSync(gif);
});
});
}