head	1.1;
access;
symbols
	r2_1:1.1
	r2_0:1.1
	r1_1_beta:1.1
	r1_0:1.1
	r0_10:1.1
	Eglin_alpha_1:1.1;
locks; strict;
comment	@ * @;


1.1
date	93.05.26.16.06.39;	author thoth;	state Exp;
branches;
next	;


desc
@Test program to display a PGM image.
@



1.1
log
@Initial revision
@
text
@// Emacs: -*- C++ -*-
static char rcsid[] = "$Id: test011.c,v 1.2 92/11/04 12:03:15 thoth Exp Locker: thoth $";

//
// $Log:	test011.c,v $
//

#include "IntPointSet.h"
#include "IPSIter.h"
#include "ImageDisplayProtocol.h"

int main(int argc, char **argv)
{
    char	*disp=getenv("DISPLAY");
    if (disp==0) {
	cerr << "No DISPLAY environment variable, hasta.\n";
	exit(1);
    }

    if (argc!=2) {
	cerr << "Usage:\n" << argv[0] << " fname\n";
	exit(1);
    }
    char	*fname=argv[1];

    IDP::ClientID	cid;
    cid = IDP::NewClient("iac++ test013");
    IDP::LinkID		lid;
    lid = IDP::CreateDisplay(cid, disp, IDP::READ_WRITE);

    FILE	*fp;
    fp = fopen(fname, "r");
    if (!fp) {
	perror("opening file");
	exit(1);
    }

    int	width,height, maxval;
    if (3!=fscanf(fp, "P5 %d %d %d", &width, &height, &maxval)) {
	cerr << "Error: was expecting raw PGM (P5) image in file "
	     << fname << "\n";
	exit(1);
    }
    Array<unsigned> dimensions(2);
    dimensions[0] = height;
    dimensions[1] = width;

    int	ch;
    if ((ch=getc(fp))!='\n')
	ungetc(ch, fp);

    int	size = width*height;
    unsigned char	*arr;

    arr = new unsigned char[size];

    if (!fread(arr, size, 1, fp)) {
	perror("reading");
	exit(1);
    }
    cout << "ping" << endl;
    sleep(5);
    IDP::WriteImage(lid, "me", IDP::U_BYTE, 1, dimensions, arr);

    delete[] arr;
}
@
