static void handle_proc(const GBitmap& bitmap, void (*proc)(const GBitmap&), const std::string& root, const char name[]) { std::string path(root); path += name; path += ".png"; // fill the bitmap with transparent black memset(bitmap.pixels(), 0, bitmap.rowBytes() * bitmap.height()); proc(bitmap); if (!bitmap.writeToFile(path.c_str())) { fprintf(stderr, "failed to write %s\n", path.c_str()); } }
static void draw_circle(const GBitmap& bitmap) { const GPixel px = GPixel_PackARGB(0xFF, 0xFF, 0, 0); const float cx = (float)bitmap.width() / 2; const float cy = (float)bitmap.height() / 2; const float radius = cx * 5 / 6; const float radius2 = radius * radius; GPixel* dst = bitmap.pixels(); for (int y = 0; y < bitmap.height(); ++y) { const float dy = y - cy; for (int x = 0; x < bitmap.width(); ++x) { const float dx = x - cx; const float dist2 = dx*dx + dy*dy; if (dist2 <= radius2) { dst[x] = px; } else { dst[x] = 0; // transparent } } dst = (GPixel*)((char*)dst + bitmap.rowBytes()); } }
static void make_circle(const GBitmap& bitmap, const GColor& color) { const GPixel px = pin_and_premul_to_pixel(color); const float cx = (float)bitmap.width() / 2; const float cy = (float)bitmap.height() / 2; const float radius = cx - 1; const float radius2 = radius * radius; GPixel* dst = bitmap.pixels(); for (int y = 0; y < bitmap.height(); ++y) { const float dy = y - cy; for (int x = 0; x < bitmap.width(); ++x) { const float dx = x - cx; const float dist2 = dx*dx + dy*dy; if (dist2 <= radius2) { dst[x] = px; } else { dst[x] = 0; // transparent } } dst = (GPixel*)((char*)dst + bitmap.rowBytes()); } }