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
|
#include "SkBitmap.h"
#include "SkDevice.h"
#include "SkCanvas.h"
#include "SkImageDecoder.h"
#include "SkImageEncoder.h"
#include "SkStream.h"
#include "SkOSFile.h"
#include "SkPicture.h"
#include "SkString.h"
#include "Test.h"
static void make_filepath(SkString* path, const char* dir, const SkString& name) {
size_t len = strlen(dir);
path->set(dir);
if (len > 0 && dir[len - 1] != '/') {
path->append("\\");
}
path->append(name);
}
static void PathOpsSkpClipTest(skiatest::Reporter* reporter) {
const char pictDir[] = "D:\\skp";
const char outSkpClipDir[] = "D:\\skpClip";
const char outOldClipDir[] = "D:\\oldClip";
SkOSFile::Iter iter(pictDir, "skp");
SkString filename;
while (iter.next(&filename)) {
#if 01
if (strcmp(filename.c_str(), "desk_15min-lt.skp")) {
continue;
}
#endif
SkString path;
make_filepath(&path, pictDir, filename);
SkFILEStream stream(path.c_str());
if (!stream.isValid()) {
continue;
}
bool success;
SkPicture* pic = SkNEW_ARGS(SkPicture, (&stream, &success, &SkImageDecoder::DecodeMemory));
if (!success) {
continue;
}
int width = pic->width();
int height = pic->height();
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
bitmap.allocPixels();
SkCanvas canvas(bitmap);
filename.remove(filename.size() - 3, 3);
filename.append("png");
for (int i = 0; i < 2; ++i) {
bool useOp = i ? true : false;
canvas.setAllowSimplifyClip(useOp);
pic->draw(&canvas);
SkString outFile;
make_filepath(&outFile, useOp ? outSkpClipDir : outOldClipDir, filename);
SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
}
SkDELETE(pic);
reporter->bumpTestCount();
}
}
#include "TestClassDef.h"
DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTest)
|