forked from brendan-duncan/image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pvrtc_test.dart
72 lines (61 loc) · 2.2 KB
/
pvrtc_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
import 'dart:io';
import 'package:image/image.dart';
import 'package:test/test.dart';
void main() {
group('PVRTC', () {
test('encode_rgb_4bpp', () {
List<int> bytes = File('test/res/tga/globe.tga').readAsBytesSync();
Image image = TgaDecoder().decodeImage(bytes);
File('out/pvrtc/globe_before.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(image));
// Encode the image to PVRTC
var pvrtc = PvrtcEncoder().encodeRgb4Bpp(image);
Image decoded =
PvrtcDecoder().decodeRgb4bpp(image.width, image.height, pvrtc);
File('out/pvrtc/globe_after.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(decoded));
List<int> pvr = PvrtcEncoder().encodePvr(image);
File('out/pvrtc/globe.pvr')
..createSync(recursive: true)
..writeAsBytesSync(pvr);
});
test('encode_rgba_4bpp', () {
List<int> bytes = File('test/res/png/alpha_edge.png').readAsBytesSync();
Image image = PngDecoder().decodeImage(bytes);
File('out/pvrtc/alpha_before.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(image));
// Encode the image to PVRTC
var pvrtc = PvrtcEncoder().encodeRgba4Bpp(image);
Image decoded =
PvrtcDecoder().decodeRgba4bpp(image.width, image.height, pvrtc);
File('out/pvrtc/alpha_after.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(decoded));
List<int> pvr = PvrtcEncoder().encodePvr(image);
File('out/pvrtc/alpha.pvr')
..createSync(recursive: true)
..writeAsBytesSync(pvr);
});
});
group('PVR Decode', () {
Directory dir = Directory('test/res/pvr');
var files = dir.listSync();
for (var f in files) {
if (f is! File || !f.path.endsWith('.pvr')) {
continue;
}
String name = f.path.split(RegExp(r'(/|\\)')).last;
test(name, () {
List<int> bytes = (f as File).readAsBytesSync();
Image img = PvrtcDecoder().decodePvr(bytes);
assert(img != null);
File('out/pvrtc/pvr_$name.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(img));
});
}
});
}