/* mkhtml.c: generate html file */ /* usage: mkhtml /.gpx res width height x y smooth internal */ #include #include #include #include #include #include "gridpix.h" #include "utils.h" /* Number of extra resolutions provided by mkhtml -- 4 means up to 1,600% */ #define ExtraRes 4 #ifndef MAINTAINER #define MAINTAINER "please@change.this" #endif int main(int argc, char **argv) { char *progname, *gpx, *filename, *cp ; m_int_t res, maxres, ix, iy, xsize, ysize, xsiz, ysiz, xmax, ymax, xres, yres ; int xnum, ynum ; m_int_t owidth, oheight, width, height, xpos, ypos, bw ; int i, k, l, all ; FILE *ifp ; struct gridpix gp ; double pct, factor ; char *percent ; int numfiles ; int smooth ; int internal ; char *sbdir ; m_int_t space = 18 ; /* XXX space between scrollbars and zoomout/return button in museum version */ m_int_t overflow ; /* > 0 if center of bar is shorter than 0; -1 if it is already been compensated for, -2 if it is not shorter to begin with */ #ifdef SUBDIR char *dir ; #endif progname = argv[0] ; if (argc != 9) { fprintf(stderr, "usage: %s /.gpx \n", progname) ; exit(1) ; } filename = argv[1] ; res = atoi(argv[2]) ; owidth = atoi(argv[3]) ; oheight = atoi(argv[4]) ; ix = atoi(argv[5]) ; iy = atoi(argv[6]) ; smooth = atoi(argv[7]) ; internal = atoi(argv[8]) ; /* get "basename" part of filename */ cp = rindex(filename, '/') ; if (cp) gpx = strdup(cp+1) ; else gpx = strdup(filename) ; gpx[strlen(gpx)-4] = '\0' ; /* remove ".gpx" at end */ #ifdef SUBDIR dir = strdup(gpx) ; dir[strlen(dir)-4] = '\0' ; /* remove last 4 digits */ #endif if ((ifp = fopen(filename, "r")) == NULL) { fprintf(stderr, "\"%s\"", filename) ; perror("") ; printf("Content-type: text/html\n\n") ; printf("%s not found\n", gpx) ; printf("

Image \"%s\" not found

\n\n", gpx) ; printf("\n") ; printf("Sorry, we could not find the image (%s) you requesed.\n", filename) ; /* printf("This is probably due to incorrect information in the database.

\n") ; */ printf("Please report the problem to %s.\n", MAINTAINER, MAINTAINER) ; printf("Make sure to include the image number (\"%s\") in the report to help us locate the problem.\n", gpx) ; printf("\n") ; exit(1) ; } if (readheader(&gp, ifp) == 0) { fprintf(stderr, "\"%s\"", filename) ; perror("") ; exit(1) ; } fclose(ifp) ; maxres = gp.header.layers + ExtraRes ; if (res > maxres) { fprintf(stderr, "error: unsupported resolution %qd (max is %qd)\n", res, maxres) ; exit(1) ; } factor = pow(2, (double) gp.header.layers-res) ; xres = gp.header.width / factor ; yres = gp.header.height / factor ; xsize = gp.header.tilewidth ; ysize = gp.header.tileheight ; /* round down to multiple of tilesize */ width = owidth - owidth % xsize ; height = oheight - oheight % ysize ; /* number of grids in image window */ xnum = width / xsize ; ynum = height / ysize ; /* number of grids in whole image */ xmax = (xres + xsize - 1) / xsize ; ymax = (yres + ysize - 1) / ysize ; pct = 100 / factor ; /* directory for scrollbar images */ if (internal) sbdir = "sb" ; else sbdir = "sbm" ; /* width of scrollbars */ if (internal) bw = 14 ; else bw = 25 ; printf("Content-type: text/html\n\n") ; printf("%s, %qd x %qd, ", gpx, xres, yres) ; /* XXX */ percent = malloc(10) ; if (pct < 5) sprintf(percent, "%.3f", pct) ; else if (pct < 10) sprintf(percent, "%.2f", pct) ; else if (pct < 20) sprintf(percent, "%.1f", pct) ; else { sprintf(percent, "%d", (int)pct) ; } printf("%s%%\n", percent) ; printf("\n") ; printf("\n") ; if (internal) printf("\n") ; /* printf("\n") ; */ else printf("\n") ; printf("

\n") ; /* count number of tiles in layers up to previous one */ numfiles = 0 ; for (i = 1 ; i < res ; i++) { double fact = pow(gp.header.ratio, gp.header.layers-i) ; int xr = gp.header.width / fact ; int yr = gp.header.height / fact ; numfiles += ((xr+xsize-1)/xsize) * ((yr+ysize-1)/ysize) ; } #ifdef UCB if (internal) { printf("

Image Info | Museum Version", gpx, gpx, res, owidth, oheight, ix, iy, smooth, 0) ; if (factor < 0.9) if (smooth) printf(" | Smooth Off", gpx, res, owidth, oheight, ix, iy) ; else printf(" | Smooth On", gpx, res, owidth, oheight, ix, iy) ; } #endif printf("

") ; printf("") ; if (internal) { printf("") ; } printf("
") ; /* extra width needed for Internet Explorer */ if (internal) printf("") ; printf("") ; printf("") ; printf("") ; printf("
") ; printf("
xsize*xnum) printf("align=left ") ; else printf("align=center ") ; if (yres > ysize*ynum) printf("valign=top>"); else printf("valign=center>") ; for (k = iy ; k < iy + ynum ; k++) { for (l = ix ; l < ix + xnum ; l++) { if (k < ymax && l < xmax) { xpos = ypos = 0 ; /* just in case */ if (res < maxres) { ypos = k*2-ynum/2+1 ; if (ypos+ynum >= (yres*2+ysize-1)/ysize) ypos=(yres*2+ysize-1)/ysize-ynum ; if (ypos < 0) ypos = 0 ; xpos = l*2-xnum/2+1 ; if (xpos+xnum >= (xres*2+xsize-1)/xsize) xpos=(xres*2+xsize-1)/xsize-xnum ; if (xpos < 0) xpos = 0 ; printf("", gpx, res+1, owidth, oheight, xpos, ypos, smooth, internal) ; } xsiz = xsize ; ysiz = ysize ; if (k+1 == ymax) { ysiz = yres % ysize ; if (ysiz == 0) ysiz = ysize ; } if (l+1 == xmax) { xsiz = xres % xsize ; if (xsiz == 0) xsiz = xsize ; } printf("", gpx, numfiles + k*xmax + l + 1, smooth) ; if (res < maxres) printf("") ; } } printf("
") ; } printf("
") ; printf("
", height+4, bw) ; if (iy > 0) if (iy + ynum < ymax) all = height-bw*4 ; else all = height-bw*2 ; else if (iy + ynum < ymax) all = height-bw*2 ; else all = height ; /* for the "back" button */ if (!internal && res > 1) all -= bw + space ; if ((int)((double) ynum / ymax * all - bw*2) > 0) overflow = -2 ; else overflow = -((double) ynum / ymax * all - bw*2) ; if (iy > 0) { printf("", gpx, res, owidth, oheight, ix, 0, smooth, internal, internal ? "onMouseover=\"change('upsA','ups',1)\"\nonMouseout=\"change('upsA','ups',0)\"" : "") ; printf("
", internal ? "name=\"upsA\"" : "", bw, bw, sbdir) ; printf("", gpx, res, owidth, oheight, ix, iy-1, smooth, internal, internal ? "onMouseover=\"change('upA','up',1);change('vbarltA','vbarlt',1)\"\nonMouseout=\"change('upA','up',0);change('vbarltA','vbarlt',0)\"" : "") ; printf("
", internal ? "name=\"upA\"" : "", bw, bw, sbdir) ; if (overflow > 0) { printf("

", internal ? "name=\"vbarltA\"" : "", bw, (m_int_t)((double) iy / ymax * all) - overflow, sbdir) ; overflow = -1 ; } else printf("
", internal ? "name=\"vbarltA\"" : "", bw, (m_int_t)((double) iy / ymax * all), sbdir) ; printf("", bw, bw, sbdir) ; } else { printf("", bw, bw, sbdir) ; } if (ynum > ymax) printf("", bw, (m_int_t)((double) all - bw*2), sbdir) ; else if (overflow == -2) { if (ynum == ymax) printf("", bw, (m_int_t)((double) ynum / ymax * all - bw*2), sbdir) ; else printf("\"Click", bw, (m_int_t)((double) ynum / ymax * all - bw*2), sbdir) ; } if (iy + ynum < ymax) { printf("", bw, bw, sbdir) ; printf("", gpx, res, owidth, oheight, ix, iy+1, smooth, internal, internal ? "onMouseover=\"change('downA','down',1);change('vbarlbA','vbarlb',1)\"\nonMouseout=\"change('downA','down',0);change('vbarlbA','vbarlb',0)\"" : "") ; if (overflow > 0) { printf("
", internal ? "name=\"vbarlbA\"" : "", bw, (m_int_t)((double) (ymax - (iy + ynum)) / ymax * all) - overflow, sbdir) ; overflow = -1 ; } else printf("
", internal ? "name=\"vbarlbA\"" : "", bw, (m_int_t)((double) (ymax - (iy + ynum)) / ymax * all), sbdir) ; printf("

", internal ? "name=\"downA\"" : "", bw, bw, sbdir) ; printf("", gpx, res, owidth, oheight, ix, ymax-ynum, smooth, internal, internal ? "onMouseover=\"change('downsA','downs',1)\"\nonMouseout=\"change('downsA','downs',0)\"" : "") ; printf("
", internal ? "name=\"downsA\"" : "", bw, bw, sbdir) ; } else { printf("", bw, bw, sbdir) ; } if (!internal && res > 1) { printf("
", bw, space, sbdir) ; printf("", gpx, (m_int_t)1, owidth, oheight, (m_int_t)0, (m_int_t)0, 0, 0) ; printf("
", bw, bw, sbdir) ; } printf("
", bw, width+4) ; if (ix > 0) if (ix + xnum < xmax) all = width-bw*4 ; else all = width-bw*2 ; else if (ix + xnum < xmax) all = width-bw*2 ; else all = width ; /* for the zoomout button */ if (!internal && res > 1) all -= bw + space ; if ((int)((double) xnum / xmax * all - bw*2) > 0) overflow = -2 ; else overflow = -((double) xnum / xmax * all - bw*2) ; if (ix > 0) { printf("", gpx, res, owidth, oheight, (m_int_t)0, iy, smooth, internal, internal ? "onMouseover=\"change('leftsA','lefts',1)\"\nonMouseout=\"change('leftsA','lefts',0)\"" : "") ; printf("", internal ? "name=\"leftsA\"" : "", bw, bw, sbdir) ; printf("", gpx, res, owidth, oheight, ix-1, iy, smooth, internal, internal ? "onMouseover=\"change('leftA','left',1);change('hbarllA','hbarll',1)\"\nonMouseout=\"change('leftA','left',0);change('hbarllA','hbarll',0)\"" : "") ; printf("", internal ? "name=\"leftA\"" : "", bw, bw, sbdir) ; if (overflow > 0) { printf("", internal ? "name=\"hbarllA\"" : "", (m_int_t)((double) ix / xmax * all) - overflow, bw, sbdir) ; overflow = -1 ; } else printf("", internal ? "name=\"hbarllA\"" : "", (m_int_t)((double) ix / xmax * all), bw, sbdir) ; printf("", bw, bw, sbdir) ; } else { printf("", bw, bw, sbdir) ; } if (xnum > xmax) printf("", (m_int_t)((double) all - bw*2), bw, sbdir) ; else if (overflow == -2) { if (xnum == xmax) printf("", (m_int_t)((double) xnum / xmax * all - bw*2), bw, sbdir) ; else printf("\"Click", (m_int_t)((double) xnum / xmax * all - bw*2), bw, sbdir) ; } if (ix + xnum < xmax) { printf("", bw, bw, sbdir) ; printf("", gpx, res, owidth, oheight, ix+1, iy, smooth, internal, internal ? "onMouseover=\"change('rightA','right',1);change('hbarlrA','hbarlr',1)\"\nonMouseout=\"change('rightA','right',0);change('hbarlrA','hbarlr',0)\"" : "") ; if (overflow > 0) { printf("", internal ? "name=\"hbarlrA\"" : "", (m_int_t)((double) (xmax - (ix + xnum)) / xmax * all) - overflow, bw, sbdir) ; overflow = -1 ; } else printf("", internal ? "name=\"hbarlrA\"" : "", (m_int_t)((double) (xmax - (ix + xnum)) / xmax * all), bw, sbdir) ; printf("", internal ? "name=\"rightA\"" : "", bw, bw, sbdir) ; printf("", gpx, res, owidth, oheight, xmax-xnum, iy, smooth, internal, internal ? "onMouseover=\"change('rightsA','rights',1)\"\nonMouseout=\"change('rightsA','rights',0)\"" : "") ; printf("", internal ? "name=\"rightsA\"" : "", bw, bw, sbdir) ; } else { printf("", bw, bw, sbdir) ; } if (!internal && res > 1) { ypos = (iy-ynum/2)/2 ; if (ypos+ynum > (yres/2+ysize-1)/ysize) ypos = (yres/2+ysize-1)/ysize-ynum ; if (ypos < 0) ypos = 0 ; xpos = (ix-xnum/2)/2 ; if (xpos+xnum > (xres/2+xsize-1)/xsize) xpos=(xres/2+xsize-1)/xsize-xnum ; if (xpos < 0) xpos = 0 ; printf("", space, bw) ; printf("", gpx, res-1, owidth, oheight, xpos, ypos, smooth, internal) ; printf("", bw, bw) ; } printf("
", bw, bw) ; if (!internal) { printf("", gpx, xres, yres, percent) ; printf("\"Help\"\nsrc=\"/images/sbm/help.png\"", bw, bw) ; } printf("
") ; printf("
") ; printf("") ; #endif printf("
") ; if (pct < 20) printf("12.5") ; else printf("%d", (int)pct) ; printf("%%") ; printf("
") ; if (internal) { #ifdef SUBDIR #ifdef UCB printf("", dir, owidth, oheight) ; #else printf("", GRIDSUBDIR, dir) ; #endif #else /* SUBDIR */ printf("", GRIDSUBDIR) ; #endif printf("
") ; } if (res == 1) printf("\"Can't") ; else { ypos = (iy-ynum/2)/2 ; if (ypos+ynum > (yres/2+ysize-1)/ysize) ypos = (yres/2+ysize-1)/ysize-ynum ; if (ypos < 0) ypos = 0 ; xpos = (ix-xnum/2)/2 ; if (xpos+xnum > (xres/2+xsize-1)/xsize) xpos=(xres/2+xsize-1)/xsize-xnum ; if (xpos < 0) xpos = 0 ; printf("", gpx, res-1, owidth, oheight, xpos, ypos, smooth, internal, internal ? "onMouseover=\"change('zoomoutA','zoomout',1)\"\nonMouseout=\"change('zoomoutA','zoomout',0)\"" : "") ; printf("") ; } printf("
") ; #if RESIZE printf("", gpx, res, owidth, oheight+ysize, ix, iy, smooth, internal) ; printf("\n") ; printf("
") ; if (ynum <= 2) printf("\"Can't\n") ; else { printf("", gpx, res, owidth, oheight-ysize, ix, iy, smooth, internal) ; printf("\n") ; } printf("
") ; printf("", gpx, res, owidth+xsize, oheight, ix, iy, smooth, internal) ; printf("\n") ; printf("
") ; if (xnum <= 2) printf("\"Can't\n") ; else { printf("", gpx, res, owidth-xsize, oheight, ix, iy, smooth, internal) ; printf("\n") ; } #endif printf("
") ; printf("", gpx, xres, yres, percent) ; printf("
") ; #ifdef UCB printf("") ; printf("
") ; printf("
") ; #ifdef UCB if (internal) { char buf[1024], *dir ; int c ; dir = strdup(filename) ; cp = rindex(dir, '/') ; /* cp is now pointing to end of "images/" */ if (cp) { *cp = '\0' ; sprintf(buf, "test -r %s/../converter", dir) ; if (!system(buf)) { printf("This image was processed by ") ; sprintf(buf, "%s/../converter", dir) ; ifp = fopen(buf, "r") ; while ((c = fgetc(ifp)) != EOF) if (c == '\n') break ; else putchar(c) ; fclose(ifp) ; printf(".\n") ; } } } #endif printf("\n") ; printf("\n") ; exit(0) ; }