2012-03-24 08:30:28 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2009-08-28 23:08:00 +00:00
|
|
|
#include "inttypes.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "kplib.h"
|
|
|
|
#include "compat.h"
|
|
|
|
|
|
|
|
struct icon {
|
2012-03-23 20:23:46 +00:00
|
|
|
int32_t width,height;
|
|
|
|
intptr_t *pixels;
|
2012-03-14 06:25:26 +00:00
|
|
|
unsigned char *mask;
|
2006-04-13 20:47:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int writeicon(FILE *fp, struct icon *ico)
|
|
|
|
{
|
2012-03-14 06:25:26 +00:00
|
|
|
int i;
|
|
|
|
|
2012-03-23 20:23:46 +00:00
|
|
|
Bfprintf(fp,
|
2012-03-14 06:25:26 +00:00
|
|
|
"#include \"sdlayer.h\"\n"
|
|
|
|
"\n"
|
|
|
|
);
|
2012-03-23 20:23:46 +00:00
|
|
|
Bfprintf(fp,"static unsigned int sdlappicon_pixels[] = {\n");
|
2012-03-14 06:25:26 +00:00
|
|
|
for (i=0;i<ico->width*ico->height;i++) {
|
2012-03-23 20:23:46 +00:00
|
|
|
if ((i%6) == 0) Bfprintf(fp,"\t");
|
|
|
|
else Bfprintf(fp," ");
|
2012-04-08 15:52:24 +00:00
|
|
|
Bfprintf(fp, "0x%08lx,", (long)B_LITTLE32(ico->pixels[i]));
|
2012-03-23 20:23:46 +00:00
|
|
|
if ((i%6) == 5) Bfprintf(fp,"\n");
|
2012-03-14 06:25:26 +00:00
|
|
|
}
|
2012-03-23 20:23:46 +00:00
|
|
|
if ((i%16) > 0) Bfprintf(fp, "\n");
|
|
|
|
Bfprintf(fp, "};\n\n");
|
2012-03-14 06:25:26 +00:00
|
|
|
|
2012-03-23 20:23:46 +00:00
|
|
|
Bfprintf(fp,"static unsigned char sdlappicon_mask[] = {\n");
|
2012-03-14 06:25:26 +00:00
|
|
|
for (i=0;i<((ico->width+7)/8)*ico->height;i++) {
|
2012-03-23 20:23:46 +00:00
|
|
|
if ((i%14) == 0) Bfprintf(fp,"\t");
|
|
|
|
else Bfprintf(fp," ");
|
|
|
|
Bfprintf(fp, "%3d,", ico->mask[i]);
|
|
|
|
if ((i%14) == 13) Bfprintf(fp,"\n");
|
2012-03-14 06:25:26 +00:00
|
|
|
}
|
2012-03-23 20:23:46 +00:00
|
|
|
if ((i%16) > 0) Bfprintf(fp, "\n");
|
|
|
|
Bfprintf(fp, "};\n\n");
|
2012-03-14 06:25:26 +00:00
|
|
|
|
2012-03-23 20:23:46 +00:00
|
|
|
Bfprintf(fp,
|
2012-03-14 06:25:26 +00:00
|
|
|
"struct sdlappicon sdlappicon = {\n"
|
|
|
|
" %d,%d, // width,height\n"
|
|
|
|
" sdlappicon_pixels,\n"
|
|
|
|
" sdlappicon_mask\n"
|
|
|
|
"};\n",
|
|
|
|
ico->width, ico->height
|
|
|
|
);
|
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2012-03-14 06:25:26 +00:00
|
|
|
struct icon icon;
|
2013-10-06 07:50:16 +00:00
|
|
|
int32_t bpl = 0;
|
2012-03-14 06:25:26 +00:00
|
|
|
int i;
|
|
|
|
unsigned char *maskp, bm, *pp;
|
|
|
|
|
|
|
|
if (argc<2) {
|
2012-03-23 20:23:46 +00:00
|
|
|
Bfprintf(stderr, "generateicon <picture file>\n");
|
2012-03-14 06:25:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&icon, 0, sizeof(icon));
|
|
|
|
|
2012-04-08 04:25:06 +00:00
|
|
|
kpzload(argv[1], (intptr_t*)&icon.pixels, (int32_t*)&bpl, (int32_t*)&icon.width, (int32_t*)&icon.height);
|
2012-03-14 06:25:26 +00:00
|
|
|
if (!icon.pixels) {
|
2012-03-23 20:23:46 +00:00
|
|
|
Bfprintf(stderr, "Failure loading %s\n", argv[1]);
|
2012-03-14 06:25:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bpl != icon.width * 4) {
|
2012-03-23 20:23:46 +00:00
|
|
|
Bfprintf(stderr, "bpl != icon.width * 4\n");
|
|
|
|
Bfree(icon.pixels);
|
2012-03-14 06:25:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-03-23 20:23:46 +00:00
|
|
|
icon.mask = (unsigned char *)Bcalloc(icon.height, (icon.width+7)/8);
|
2012-03-14 06:25:26 +00:00
|
|
|
if (!icon.mask) {
|
2012-03-23 20:23:46 +00:00
|
|
|
Bfprintf(stderr, "Out of memory\n");
|
|
|
|
Bfree(icon.pixels);
|
2012-03-14 06:25:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
maskp = icon.mask;
|
|
|
|
bm = 1;
|
|
|
|
pp = (unsigned char *)icon.pixels;
|
|
|
|
for (i=0; i<icon.height*icon.width; i++) {
|
|
|
|
if (bm == 0) {
|
|
|
|
bm = 1;
|
|
|
|
maskp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
unsigned char c = pp[0];
|
|
|
|
pp[0] = pp[2];
|
|
|
|
pp[2] = c;
|
|
|
|
}
|
|
|
|
if (pp[3] > 0) *maskp |= bm;
|
|
|
|
|
|
|
|
bm <<= 1;
|
|
|
|
pp += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
writeicon(stdout, &icon);
|
|
|
|
|
2012-03-23 20:23:46 +00:00
|
|
|
Bfree(icon.pixels);
|
|
|
|
Bfree(icon.mask);
|
2012-03-14 06:25:26 +00:00
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|