int main(int argc, char** argv) { const char* pathRoot = ""; const char* match = NULL; for (int i = 1; i < argc; ++i) { if (0 == strcmp(argv[i], "--write") && i+1 < argc) { pathRoot = argv[++i]; } else if (0 == strcmp(argv[i], "--match") && i+1 < argc) { match = argv[++i]; } } std::string root(pathRoot); if (root.size() > 0 && root[root.size() - 1] != '/') { root += "/"; } for (int j = 0; j < GARRAY_COUNT(gMatrixRec); ++j) { for (int i = 0; i < GARRAY_COUNT(gRec); ++i) { std::string path(pathRoot); path += gRec[i].fName; path += gMatrixRec[j].fSuffix; path += ".png"; if (match && !strstr(path.c_str(), match)) { continue; } handle_proc(gRec[i], path.c_str(), gMatrixRec[j]); } } return 0; }
static void draw_solid_ramp(GCanvas* canvas) { const float c = 1.0 / 512; const float d = 1.0 / 256; const struct { GColor fC0, fDC; } rec[] = { { GColor::MakeARGB(1, c, c, c), GColor::MakeARGB(0, d, d, d) }, // grey { GColor::MakeARGB(1, 1-c, 0, 0), GColor::MakeARGB(0, -d, 0, 0) }, // red { GColor::MakeARGB(1, 0, c, c), GColor::MakeARGB(0, 0, d, d) }, // cyan { GColor::MakeARGB(1, 0, 1-c, 0), GColor::MakeARGB(0, 0, -d, 0) }, // green { GColor::MakeARGB(1, c, 0, c), GColor::MakeARGB(0, d, 0, d) }, // magenta { GColor::MakeARGB(1, 0, 0, 1-c), GColor::MakeARGB(0, 0, 0, -d) }, // blue { GColor::MakeARGB(1, c, c, 0), GColor::MakeARGB(0, d, d, 0) }, // yellow }; for (int y = 0; y < GARRAY_COUNT(rec); ++y) { GColor color = rec[y].fC0; GColor delta = rec[y].fDC; for (int x = 0; x < 256; x++) { const GRect rect = GRect::MakeXYWH(x * RAMP_W, y * RAMP_H, RAMP_W, RAMP_H); canvas->fillRect(rect, color); color.fA += delta.fA; color.fR += delta.fR; color.fG += delta.fG; color.fB += delta.fB; } } }
static void draw_tri(GCanvas* canvas) { GPoint pts[] = { { 10, 10 }, { 200, 50 }, { 100, 200 }, }; canvas->fillConvexPolygon(pts, GARRAY_COUNT(pts), GColor::MakeARGB(1, 1, 0, 0)); }
static void draw_blocks(GCanvas* canvas) { const struct { GRect fRect; GColor fColor; } rec[] = { { GRect::MakeXYWH( 0, 0, 50, 50), GColor::MakeARGB(1, 1, 0, 0) }, { GRect::MakeXYWH(50, 0, 50, 50), GColor::MakeARGB(1, 0, 1, 0) }, { GRect::MakeXYWH( 0, 50, 50, 50), GColor::MakeARGB(1, 0, 0, 1) }, { GRect::MakeXYWH(50, 50, 50, 50), GColor::MakeARGB(1, 0, 0, 0) }, { GRect::MakeXYWH(25, 25, 50, 50), GColor::MakeARGB(0.75, 1, 1, 1) }, }; for (int i = 0; i < GARRAY_COUNT(rec); ++i) { canvas->fillRect(rec[i].fRect, rec[i].fColor); } }
static Shape* cons_up_shape(int index) { const char* names[] = { "apps/spock.png", "expected/blend_black.png", "expected/circles_blend.png", "expected/solid_ramp.png", "expected/spocks_zoom.png", "expected/blend_white.png", "expected/circles_fat.png", "expected/spocks_quad.png", }; GBitmap bm; if (index < GARRAY_COUNT(names) && bm.readFromFile(names[index])) { return new BitmapShape(bm); } return NULL; }
int main(int argc, char** argv) { int N = 256; std::string root; for (int i = 1; i < argc; ++i) { if (0 == strcmp(argv[i], "--size") && i+1 < argc) { N = atoi(argv[++i]); } if (0 == strcmp(argv[i], "--write") && i+1 < argc) { root = argv[++i]; } } if (N < 1 || N > 1024) { fprintf(stderr, "specify a reasonable size for the image (e.g. 256)\n"); return -1; } if (root.size() > 0 && root[root.size() - 1] != '/') { root += "/"; if (!mk_dir(root.c_str())) { return -1; } } GBitmap bitmap; bitmap.fWidth = N; bitmap.fHeight = N; bitmap.fRowBytes = N * sizeof(GPixel); bitmap.fPixels = (GPixel*)malloc(bitmap.rowBytes() * bitmap.height()); for (int i = 0; i < GARRAY_COUNT(gRec); ++i) { handle_proc(bitmap, gRec[i].fProc, root, gRec[i].fName); } free(bitmap.fPixels); return 0; }