int PicBuf_to_X11 ( const GEN_PAR * pg, OUT_PAR * po) /** ** Interface to higher-level routines, ** similar in structure to other previewers **/ { int row_c, x, y; int saved_col=0,saved_row=0; int xref = 0, yref = 0; const RowBuf *row; const PicBuf *pb; struct timeval tv; tv.tv_usec = 10; if (pg == NULL || po == NULL) return ERROR; pb = po->picbuf; if (pb == NULL) return ERROR; if (!pg->quiet) { Eprintf ("\nX11 preview follows.\n"); Eprintf ("Press any key to end graphics mode\n"); } if (win_open (pg, po->outfile, (int) (po->xoff * po->dpi_x / 25.4), (int) (po->yoff * po->dpi_y / 25.4), pb->nb << 3, pb->nr)) return ERROR; REDRAW: /* Backward since highest index is lowest line on screen! */ for (row_c = row_start, y = MIN (height-row_start, pb->nr - 1); row_c < pb->nr; row_c++, y--) { row =NULL; if (row_c>=0) row = get_RowBuf (pb, row_c); /*if (row == NULL) return 0;*/ for (x = col_start; x < pb->nc; x++) { if (row_c <0 || x < 0) setXcolor(GRAY); else switch (index_from_RowBuf (row, x, pb)) { case xxBackground: continue; /* case xxForeground: setXcolor (WHITE); break;*/ default: setXcolor (index_from_RowBuf (row, x, pb)); break; } XDrawPoint (XDisplay, XWin, XGcWin, x - col_start, y + row_start); } } /* Wait for KeyPress or mouse Button - exit on keypress or button 3 */ do { XNextEvent (XDisplay, &WaitEvent); if (WaitEvent.type == ButtonPress) { if (WaitEvent.xbutton.button == Button1) { xref = WaitEvent.xbutton.x; yref = WaitEvent.xbutton.y; } if (WaitEvent.xbutton.button == Button2) { if (!zoomed){ zoomed=1; po->HP_to_xdots *=2; po->HP_to_ydots *=2; po->dpi_x *=2; po->dpi_y *=2; saved_row=row_start; saved_col=col_start; row_start = height-WaitEvent.xbutton.y+2*saved_row; if (height < scr_height) row_start = height-WaitEvent.xbutton.y; col_start = WaitEvent.xbutton.x+col_start; } else { zoomed=0; po->dpi_x = po->dpi_x/2; po->dpi_y = po->dpi_y/2; po->HP_to_xdots = po->HP_to_xdots/2; po->HP_to_ydots = po->HP_to_ydots/2; row_start=saved_row; col_start=saved_col; } free(po->picbuf); po->picbuf=NULL; TMP_to_BUF(pg, po); pb=po->picbuf; } if (WaitEvent.xbutton.button == Button3) {win_close();return(0);} } else if (WaitEvent.type == ButtonRelease) { if (WaitEvent.xbutton.button == Button1) { if (oversized) { row_start += WaitEvent.xbutton.y - yref; col_start += xref - WaitEvent.xbutton.x; } XSetForeground (XDisplay, XGcWin, WhitePixel (XDisplay, XScreen)); XFillRectangle (XDisplay, XWin, XGcWin, 0, 0, scr_width, scr_height); goto REDRAW; /* yes, goto in C is ugly */ } if (WaitEvent.xbutton.button == Button2){ XSetForeground (XDisplay, XGcWin, WhitePixel (XDisplay, XScreen)); XFillRectangle (XDisplay, XWin, XGcWin, 0, 0, scr_width, scr_height); goto REDRAW; /* yes, goto in C is ugly */ } break; /* select (0, NULL, NULL, NULL, &tv);*/ } } while (WaitEvent.type != KeyPress ); win_close (); return 0; }
int PicBuf_to_PNG(const GEN_PAR * pg, const OUT_PAR * po) { FILE *fd; int row_c, /*byte_c, */ x; const RowBuf *row; const PicBuf *pb; int ppm[][3] = { {255, 255, 255}, {0, 0, 0} }; /*, {255,0,0}, {0,255,0}, {0,0,255},{0,255,255},{255,0,255},{255,255,0}}; */ int colour; /** ** gifdraw-parts **/ pdImagePtr im; int pdcol; if (pg == NULL || po == NULL) return ERROR; pb = po->picbuf; if (pb == NULL) return ERROR; if (!pg->quiet) Eprintf("\nWriting PNG output: %s\n", po->outfile); if (*po->outfile != '-') { /* #ifdef VAX if ((fd = fopen(po->outfile, WRITE_BIN, "rfm=var", "mrs=512")) == NULL) #else */ if ((fd = fopen(po->outfile, WRITE_BIN)) == NULL) /* #endif */ goto ERROR_EXIT; } else fd = stdout; /** ** create image structure **/ im = pdImageCreate(pb->nc, pb->nr); if (pb->depth > 1) { /** ** allocate some colors ( ?? eight colors supported by hp2xx ?? ) **/ for (colour = 0; colour < PDNCOL; colour++) /* pdcol = pdImageColorAllocate(im, ppm[colour][0], ppm[colour][1], ppm[colour][2]); */ pdcol = pdImageColorAllocate(im, pt.clut[colour][0], pt.clut[colour][1], pt.clut[colour][2]); for (row_c = 0; row_c < pb->nr; row_c++) { row = get_RowBuf(pb, pb->nr - row_c - 1); if (row == NULL) continue; for (x = 0; x < pb->nc; x++) { colour = index_from_RowBuf(row, x, pb); pdImageSetPixel(im, x, row_c, colour); } if ((!pg->quiet) && (row_c % 10 == 0)) /* For the impatients among us ... */ Eprintf("."); } } else { /** ** allocate two colors ( ?? eight colors supported by hp2xx ?? ) **/ for (colour = 0; colour < 2; colour++) pdcol = pdImageColorAllocate(im, ppm[colour][0], ppm[colour][1], ppm[colour][2]); for (row_c = 0; row_c < pb->nr; row_c++) { row = get_RowBuf(pb, pb->nr - row_c - 1); if (row == NULL) continue; for (x = 0; x < pb->nc; x++) { colour = index_from_RowBuf(row, x, pb); pdImageSetPixel(im, x, row_c, colour); } if ((!pg->quiet) && (row_c % 10 == 0)) /* For the impatients among us ... */ Eprintf("."); } } pdImagePNG(im, fd); pdImageDestroy(im); fflush(fd); if (!pg->quiet) Eprintf("\n"); if (fd != stdout) fclose(fd); return 0; ERROR_EXIT: PError("write_PNG"); return ERROR; }