/* genfonthtml.c, 2009 Jan 22 * (C) Copyright Prem Sobel, 2005-2009. All Rights Reseeved. * * This program generates an HTML file for viewing all image files * of types: *.jpg, *.gif, *.png in a directory. Plus for each image file * it also generates another hmtl file which tiles that image and puts * text with a range of colors on top of it (to see which colors can best * be seen on that tiled image). */ #include #include #include #include static int row_size=4; static num_cells, mod_cells; static struct _finddata_t fileinfo; #define NUM_CSTEP 6 int v[NUM_CSTEP] = { 0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF}; static char Usage[] = "Usage: genfonthtml [-r row_size] [-f filename] [-t title]\n" " (default row_size is 4)\n"; void fail(char *msg) { fprintf(stderr,"*** %s\n",msg); exit(1); } // fail void add_cell(FILE *fp_dir, char *pix_fn) { char fn_html[_MAX_PATH]; FILE *fp_pix; unsigned long r, g, b, color; // take care of rows in fp_dir if(!mod_cells) { if(num_cells) fprintf(fp_dir, "\n\n"); fprintf(fp_dir, "\n"); } num_cells++; if(++mod_cells>=row_size) mod_cells=0; // take care of entry in fp_dir for this pix fprintf(fp_dir, "%s
\n", pix_fn, pix_fn); fprintf(fp_dir, "
\n", pix_fn); // create html file for texturing this pix strcpy(fn_html, pix_fn); strcat(fn_html, ".html"); fp_pix=fopen(fn_html,"w"); if(!fp_pix) { printf("@@@ unable to open file %s\n", fn_html); exit(1); } fprintf(fp_pix, "\n"); fprintf(fp_pix, "\n%s (tiled)\n", pix_fn); fprintf(fp_pix, "\n\n", pix_fn); // show different text colors fprintf(fp_pix, "

\n"); for(r=0; r#%06X ", color, color); } fprintf(fp_pix, "
\n"); } } fprintf(fp_pix, "

\n\n"); // finish file fprintf(fp_pix, " \n\n"); fclose(fp_pix); } // add_cel void do_extension(FILE *fp_dir, char *ext) { long h, num=0; num_cells = 0; h = _findfirst(ext, &fileinfo); if(h>=0) { add_cell(fp_dir, fileinfo.name); while(!_findnext(h, &fileinfo)) { add_cell(fp_dir, fileinfo.name); } } _findclose(h); printf(" %d %s\n", num_cells, ext); } // do_extension int main(int argc, char* argv[]) { char *fn="ZZZ.html"; char *title="ZZZ"; FILE *fp_dir; int n, m; // examine command line arguments for(n=1;n\n"); fprintf(fp_dir, "\n\n %s\n\n", title); fprintf(fp_dir, "\n\n"); fprintf(fp_dir, "

%s

\n\n", fn); fprintf(fp_dir, "\n\n"); do_extension(fp_dir, "*.jpg"); do_extension(fp_dir, "*.gif"); do_extension(fp_dir, "*.png"); fprintf(fp_dir, "\n\n"); fprintf(fp_dir, "
\n\n\n\n"); fclose(fp_dir); return 0; } // main