4coder/platform_linux/gen_linux_icon.c

49 lines
1.1 KiB
C
Raw Permalink Normal View History

// NOTE(inso): how to use:
//
// load up the icon in gimp and choose export, select "c source code (*.c)" as the format
// call the file gimp_icon.c, then include it by uncommenting line below.
//
// make sure the struct in the .c file is called gimp_image (the default).
//
// then just compile and run this program and it'll create linux_icon.h
#include "stdio.h"
// #include "gimp_icon.c"
#define OUTPUT_FILE "linux_icon.h"
int main(void){
2018-10-06 01:42:56 +00:00
FILE* f = fopen(OUTPUT_FILE, "w");
2018-10-06 01:42:56 +00:00
fputs("/* Generated by gen_linux_icon.c */\n", f);
2018-10-06 01:42:56 +00:00
int w = gimp_image.width, h = gimp_image.height;
fprintf(f, "static const unsigned long linux_icon[] = {\n %d, %d,", w, h);
2018-10-06 01:42:56 +00:00
const unsigned char* p = gimp_image.pixel_data;
2018-10-06 01:42:56 +00:00
int i;
for(i = 0; i < (w*h); ++i){
2018-10-06 01:42:56 +00:00
2016-03-22 18:47:03 +00:00
if((i % 6) == 0){
fputs("\n ", f);
}
2018-10-06 01:42:56 +00:00
2016-03-22 18:47:03 +00:00
unsigned int pixel = 0;
2018-10-06 01:42:56 +00:00
pixel |= *p++ << 16L;
pixel |= *p++ << 8L;
pixel |= *p++;
pixel |= *p++ << 24L;
2018-10-06 01:42:56 +00:00
2016-03-22 18:47:03 +00:00
fprintf(f, " 0x%08x,", pixel);
}
2018-10-06 01:42:56 +00:00
fputs("\n};\n", f);
2018-10-06 01:42:56 +00:00
fclose(f);
2018-10-06 01:42:56 +00:00
puts("Generated linux icon in " OUTPUT_FILE);
}