static void Screen_for_PAC (const PicBuf *picbuf, Byte *screen, int x, int y) /** *picbuf; structure of hp2xx-bitmap ** *screen; 32000 byte buffer (1 screen) ** x, y; actual screen ** copies bitmap section into screen-buffer **/ { RowBuf *row; /* pointer to one row */ int buf_x, buf_y; /* position in bitmap */ int scr_x, scr_y; /* position in screen */ int row_nr; /* actual row-number */ for (buf_y = PAC_YRES * y, scr_y = 0; scr_y < PAC_YRES; buf_y++, scr_y++) { for (buf_x = PAC_BPL * x, scr_x = 0; scr_x < PAC_BPL; buf_x++, scr_x++) { if (buf_y < picbuf->nr && buf_x < picbuf->nb) { row_nr = picbuf->nr - (buf_y + 1); row = get_RowBuf(picbuf, row_nr); screen[scr_x + scr_y * PAC_BPL] = (Byte) row->buf[buf_x]; } else screen[scr_x + scr_y * PAC_BPL] = (Byte) 0; } } }
static Byte get_byte_IMG (int row_c, int pos, const PicBuf *picbuf) /* yields one byte which should be analyzed */ { int row_nr; /* "real" row number */ RowBuf *row; /* pointer to one row */ Byte get_byte; /* byte to be returned */ row_nr = picbuf->nr - (row_c + 1); row = get_RowBuf(picbuf, row_nr); get_byte = (Byte) row->buf[pos]; return (get_byte); }
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; }
int PicBuf_to_UIS(const GEN_PAR * pg, const OUT_PAR * po) { int byte_c, xoff, yoff; unsigned long row_c, x1, x2, rw, rh, bpp, zero = 0, two = 2; const RowBuf *row; const PicBuf *pb; float x0f, y0f, x1f, y1f, w, h; int c_old, c_new, i; unsigned vd_id, wd_id; char *target = "sys$workstation"; static float intens[2] = { 1.0, 0.0 }; static unsigned atb = 1; struct dsc$descriptor_s s_desc; if (pg == NULL || po == NULL) return ERROR; pb = po->picbuf; if (pb == NULL) return ERROR; if (pb->depth > 1) { Eprintf ("\nUIS preview does not support colors yet -- sorry\n"); return ERROR; } if (!pg->quiet) { Eprintf("\nUIS preview follows\n"); Eprintf("Press <return> to end\n"); } xoff = po->xoff * po->dpi_x / 25.4; yoff = po->yoff * po->dpi_y / 25.4; if ((!pg->quiet) && (((pb->nb << 3) + xoff > 1024) || (pb->nr + yoff > 1024))) { Eprintf("\n\007WARNING: Picture won't fit!\n"); Eprintf("Current range: (%d..%d) x (%d..%d) pels\n", xoff, (pb->nb << 3) + xoff, yoff, pb->nr + yoff); Eprintf("Continue anyway (y/n)?: "); if (toupper(getchar()) != 'Y') return; } x0f = y0f = 0.0; /* No offsets yet */ x1f = (float) (pb->nb << 3); y1f = (float) pb->nr; w = (float) po->width / 10.0; /* VAX needs cm, not mm */ h = (float) po->height / 10.0; vd_id = uis$create_display(&x0f, &y0f, &x1f, &y1f, &w, &h); uis$disable_display_list(&vd_id); uis$set_intensities(&vd_id, &zero, &two, intens); s_desc.dsc$w_length = strlen(target); s_desc.dsc$a_pointer = target; s_desc.dsc$b_class = DSC$K_CLASS_S; s_desc.dsc$b_dtype = DSC$K_DTYPE_T; wd_id = uis$create_window(&vd_id, &s_desc); x1 = 0; x2 = pb->nc; rw = pb->nc; rh = 1; bpp = 1; for (row_c = 0; row_c < pb->nr; row_c++) { /* for all pixel rows */ /** ** Unfortunately, we need a bit reversal in each byte here: **/ row = get_RowBuf(pb, row_c); if (row == NULL) continue; for (byte_c = 0; byte_c < pb->nb; byte_c++) { c_old = row->buf[byte_c]; if (c_old == 0) /* all white */ continue; if (c_old == 0xff) /* all black */ continue; for (i = 0, c_new = 0;;) { if (c_old & 1) c_new |= 1; if (++i == 8) /* 8 bits, 7 shifts */ break; c_new <<= 1; c_old >>= 1; } row->buf[byte_c] = c_new; } uisdc$image(&wd_id, &atb, &x1, &row_c, &x2, &row_c, &rw, &rh, &bpp, row->buf); } getchar(); uis$delete_display(&vd_id); return 0; }