summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/ico2png.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/tools/ico2png.c b/tools/ico2png.c
index 6e79ed7..9065f6f 100644
--- a/tools/ico2png.c
+++ b/tools/ico2png.c
@@ -90,14 +90,11 @@ static void pngData(SDL_RWops *rw, const Uint8 *data, Uint32 len) {
 }
 
 int main(int argc, char *argv[]) {
-	if (argc < 2) return 1;
+	if (argc < 4) return 1;
 	const char *icoPath = argv[1];
-	const char *name = strrchr(icoPath, '/');
-	name = (name ? &name[1] : icoPath);
-	char pngPath[256];
-	snprintf(
-		pngPath, sizeof(pngPath), "%.*s.PNG", (int)strcspn(name, "."), name
-	);
+	const char *pngPath = argv[3];
+	Uint32 scale = strtoul(argv[2], NULL, 10);
+	if (!scale) return 1;
 
 	SDL_RWops *ico = SDL_RWFromFile(icoPath, "rb");
 	if (!ico) err(1, "%s", icoPath);
@@ -148,8 +145,8 @@ int main(int argc, char *argv[]) {
 	// Write the PNG header
 	SDL_RWwrite(png, "\x89PNG\r\n\x1A\n", 8, 1);
 	pngChunk(png, "IHDR", 13);
-	pngUint32(png, bestIcon.width);
-	pngUint32(png, bestIcon.height);
+	pngUint32(png, bestIcon.width * scale);
+	pngUint32(png, bestIcon.height * scale);
 	Uint8 depth = 8;
 	Uint8 color = 3; // indexed
 	Uint8 zero[3] = {0};
@@ -232,10 +229,22 @@ int main(int argc, char *argv[]) {
 		}
 	}
 
-	pngData(png, lines, bestIcon.height * pngStride);
+	// Upscale with nearest neighbor
+	Uint32 scaledWidth = bestIcon.width * scale;
+	Uint32 scaledHeight = bestIcon.height * scale;
+	Uint32 scaledStride = 1 + scaledWidth;
+	Uint8 *scaled = calloc(scaledHeight, scaledStride);
+	for (Uint32 y = 0; y < scaledHeight; ++y) {
+		for (Uint32 x = 0; x < scaledWidth; ++x) {
+			scaled[y * scaledStride + 1 + x] =
+				lines[(y / scale) * pngStride + 1 + (x / scale)];
+		}
+	}
+	pngData(png, scaled, scaledHeight * scaledStride);
 	pngChunk(png, "IEND", 0);
 	pngUint32(png, ~pngCRC);
 
+	free(scaled);
 	free(lines);
 	SDL_RWclose(png);
 	SDL_RWclose(ico);