示例#1
0
char *pschar(char *s, char *hex, int *wid, int *ht)
{
	Point chpt, spt;
	Image *b;
	uchar rowdata[100];
	char *hp = hex;
	int y, i;

	chpt = stringsize(font, s);		/* bounding box of char */
	*wid = ((chpt.x+7) / 8) * 8;
	*ht = chpt.y;
	/* postscript is backwards to video, so draw white (ones) on black (zeros) */
	b = allocimage(display, Rpt(ZP, chpt), GREY1, 0, DBlack);	/* place to put it */
	spt = string(b, Pt(0,0), display->white, ZP, font, s);	/* put it there */
/* Bprint(&bout, "chpt %P, spt %P, wid,ht %d,%d\n", chpt, spt, *wid, *ht);
/* Bflush(&bout); */
	for (y = 0; y < chpt.y; y++) {	/* read bits a row at a time */
		memset(rowdata, 0, sizeof rowdata);
		unloadimage(b, Rect(0, y, chpt.x, y+1), rowdata, sizeof rowdata);
		for (i = 0; i < spt.x; i += 8) {	/* 8 == byte */
			sprint(hp, "%2.2x", rowdata[i/8]);
			hp += 2;
		}
	}
	*hp = 0;
	freeimage(b);
	return hex;
}
void Fl_ImageViewer::image(Fl_Image* aimg)
{
    if( aimg == NULL )
        return;

#ifdef DEBUG
    if ( dispbox->label() != NULL )
    {
        dispbox->label( NULL );
    }
#endif

    unloadimage();

    imgsrc = aimg->copy( aimg->w(), aimg->h() );

    if ( imgsrc != NULL )
    {
        dispbox->resize( x(), y(), x()+1, y()+1 );
        dispbox->image( imgsrc );
        dispbox->resize( x(), y(), x() + imgsrc->w(), y() + imgsrc->h() );
        dispbox->show();
        scroll_to(0, 0);
        redraw();
    }
}
示例#3
0
Fl_ImageViewer::~Fl_ImageViewer()
{
    unloadimage();

    if ( dispbox != NULL )
    {
        delete dispbox;
        dispbox = NULL;
    }
}
示例#4
0
int
unloadimage(Image *i, Rectangle r, uchar *data, int ndata)
{
    int bpl, n, chunk, dx, dy;
    uchar *a, *start;
    Display *d;

    if(!rectinrect(r, i->r)) {
        werrstr("unloadimage: bad rectangle");
        return -1;
    }
    bpl = bytesperline(r, i->depth);
    if(ndata < bpl*Dy(r)) {
        werrstr("unloadimage: buffer too small");
        return -1;
    }
    start = data;
    d = i->display;
    chunk = d->bufsize;
    flushimage(d, 0);	/* make sure subsequent flush is for us only */
    while(r.min.y < r.max.y) {
        dx = Dx(r);
        dy = chunk/bpl;
        if(dy <= 0) {
            dy = 1;
            dx = ((chunk*dx)/bpl) & ~7;
            n = bytesperline(Rect(r.min.x, r.min.y, r.min.x+dx, r.min.y+dy), i->depth);
            if(unloadimage(i, Rect(r.min.x+dx, r.min.y, r.max.x, r.min.y+dy), data+n, bpl-n) < 0)
                return -1;
        } else {
            if(dy > Dy(r))
                dy = Dy(r);
            n = bpl*dy;
        }
        a = bufimage(d, 1+4+4*4);
        if(a == nil) {
            werrstr("unloadimage: %r");
            return -1;
        }
        a[0] = 'r';
        BPLONG(a+1, i->id);
        BPLONG(a+5, r.min.x);
        BPLONG(a+9, r.min.y);
        BPLONG(a+13, r.min.x+dx);
        BPLONG(a+17, r.min.y+dy);
        if(flushimage(d, 0) < 0)
            return -1;
        if(read(d->fd, data, n) < 0)
            return -1;
        data += bpl*dy;
        r.min.y += dy;
    }
    return data - start;
}
示例#5
0
static void previmage()
{
	int n;
	unloadimage();
	for (n = cmdopts.numfiles; n > 0; --n) {
		--gs.filenum;
		if (gs.filenum < 0) {
			if (cmdopts.loop) {
				gs.filenum = cmdopts.numfiles - 1;
			} else {
				cleanupandexit(EXIT_SUCCESS);
			}
		}
		if (!loadimage()) {
			return;
		}
	}
	cleanupandexit(EXIT_SUCCESS);
}
示例#6
0
void Fl_ImageViewer::image(Fl_Image* aimg)
{
    if( aimg == NULL )
        return;

    unloadimage();

    imgsrc = aimg->copy( aimg->w(), aimg->h() );

    if ( imgsrc != NULL )
    {
        dispbox->resize( x(),
                         y(),
                         x() + imgsrc->w(),
                         y() + imgsrc->h() );
        dispbox->image( imgsrc );
        dispbox->show();
        this->redraw();
    }
}
示例#7
0
static void nextimage()
{
	int n;
	unloadimage();
	for (n = cmdopts.numfiles; n > 0; --n) {
		++gs.filenum;
		if (gs.filenum >= cmdopts.numfiles) {
			if (cmdopts.loop) {
				gs.filenum = 0;
			} else {
				cleanupandexit(EXIT_SUCCESS);
			}
		}
		if (!loadimage()) {
			return;
		}
		jas_eprintf("cannot load image\n");
	}
	cleanupandexit(EXIT_SUCCESS);
}
示例#8
0
static int loadimage()
{
	int reshapeflag;
	jas_stream_t *in;
	int scrnwidth;
	int scrnheight;
	int vh;
	int vw;
	char *pathname;
	jas_cmprof_t *outprof;

	assert(!gs.image);
	assert(!gs.altimage);

	gs.image = 0;
	gs.altimage = 0;

	pathname = cmdopts.filenames[gs.filenum];

	if (pathname && pathname[0] != '\0') {
#if 1
	jas_eprintf("opening %s\n", pathname);
#endif
		/* The input image is to be read from a file. */
		if (!(in = jas_stream_fopen(pathname, "rb"))) {
			jas_eprintf("error: cannot open file %s\n", pathname);
			goto error;
		}
	} else {
		/* The input image is to be read from standard input. */
		in = streamin;
	}

	/* Get the input image data. */
	if (!(gs.image = jas_image_decode(in, -1, 0))) {
		jas_eprintf("error: cannot load image data\n");
		goto error;
	}

	/* Close the input stream. */
	if (in != streamin) {
		jas_stream_close(in);
	}

	if (!(outprof = jas_cmprof_createfromclrspc(JAS_CLRSPC_SRGB)))
		goto error;
	if (!(gs.altimage = jas_image_chclrspc(gs.image, outprof, JAS_CMXFORM_INTENT_PER)))
		goto error;

	if ((scrnwidth = glutGet(GLUT_SCREEN_WIDTH)) < 0) {
		scrnwidth = 256;
	}
	if ((scrnheight = glutGet(GLUT_SCREEN_HEIGHT)) < 0) {
		scrnheight = 256;
	}

	vw = min(jas_image_width(gs.image), 0.95 * scrnwidth);
	vh = min(jas_image_height(gs.image), 0.95 * scrnheight);

	gs.vcx = (jas_image_tlx(gs.image) + jas_image_brx(gs.image)) / 2.0;
	gs.vcy = (jas_image_tly(gs.image) + jas_image_bry(gs.image)) / 2.0;
	gs.sx = 1.0;
	gs.sy = 1.0;
	if (gs.altimage) {
		gs.monomode = 0;
	} else {
		gs.monomode = 1;
		gs.cmptno = 0;
	}

#if 1
	jas_eprintf("num of components %d\n", jas_image_numcmpts(gs.image));
#endif

	if (vw < jas_image_width(gs.image)) {
		gs.sx = jas_image_width(gs.image) / ((float) vw);
	}
	if (vh < jas_image_height(gs.image)) {
		gs.sy = jas_image_height(gs.image) / ((float) vh);
	}
	if (gs.sx > gs.sy) {
		gs.sy = gs.sx;
	} else if (gs.sx < gs.sy) {
		gs.sx = gs.sy;
	}
	vw = jas_image_width(gs.image) / gs.sx;
	vh = jas_image_height(gs.image) / gs.sy;
	gs.dirty = 1;

	reshapeflag = 0;
	if (vw != glutGet(GLUT_WINDOW_WIDTH) ||
	  vh != glutGet(GLUT_WINDOW_HEIGHT)) {
		glutReshapeWindow(vw, vh);
		reshapeflag = 1;
	}
	if (cmdopts.title) {
		glutSetWindowTitle(cmdopts.title);
	} else {
		glutSetWindowTitle((pathname && pathname[0] != '\0') ? pathname :
		  "stdin");
	}
	/* If we reshaped the window, GLUT will automatically invoke both
	  the reshape and display callback (in this order).  Therefore, we
	  only need to explicitly force the display callback to be invoked
	  if the window was not reshaped. */
	if (!reshapeflag) {
		glutPostRedisplay();
	}

	if (cmdopts.tmout != 0) {
		glutTimerFunc(cmdopts.tmout, timer, gs.nexttmid);
		gs.activetmid = gs.nexttmid;
		++gs.nexttmid;
	}

	return 0;

error:
	unloadimage();
	return -1;
}
示例#9
0
static void cleanupandexit(int status)
{
	unloadimage();
	exit(status);
}