DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T i

⟦3099e6a3d⟧ TextFile

    Length: 4285 (0x10bd)
    Types: TextFile
    Names: »imagesbr.c«

Derivation

└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
    └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« 
        └─⟦d3ac74d73⟧ 
            └─⟦this⟧ »isode-5.0/others/image/imagesbr.c« 

TextFile

/* imagesbr.c - image subroutines */

#ifndef	lint
static char *rcsid = "$Header: /f/osi/others/image/RCS/imagesbr.c,v 6.0 89/03/18 23:35:15 mrose Rel $";
#endif

/* 
 * $Header: /f/osi/others/image/RCS/imagesbr.c,v 6.0 89/03/18 23:35:15 mrose Rel $
 *
 *
 * $Log:	imagesbr.c,v $
 * Revision 6.0  89/03/18  23:35:15  mrose
 * Release 5.0
 * 
 */

/*
 *				  NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */


#include <stdio.h>
#include <varargs.h>
#include "imagesbr.h"

/* \f

   IMAGE */

free_IMAGE_Image (im)
register struct type_IMAGE_Image *im;
{
    if (im == NULL)
	return;

    qb_free (im -> data);

    free ((char *) im);
}

/* \f

 */

static int    passno;
static int    x, y, maxx;

static struct type_IMAGE_Image *im = NULL;


struct type_IMAGE_Image *fetch_image (dn)
char   *dn;
{
    PE	    pe;

    if ((pe = name2value (dn, "photo", NULLPEP)) == NULLPE)
	return NULL;

    if (pe_pullup (pe) == NOTOK) {
	fprintf (stderr, "pe_pullup: %s\n", pe_error (pe -> pe_errno));
	pe_free (pe);
	return NULL;
    }

    if (prim2bit (pe) == NULLPE) {
	fprintf (stderr, "prim2bit: %s\n", pe_error (pe -> pe_errno));
	pe_free (pe);
	return NULL;
    }

    im = NULL;
    for (passno = 1; passno < 3; passno++)
	if (decode_t4 (pe -> pe_prim, "photo", pe -> pe_len) == NOTOK) {
	    fprintf (stderr, "\n");
	    if (im)
		free_IMAGE_Image (im), im = NULL;
	    break;
	}
    
    pe_free (pe);

    return im;
}

/* \f

 */

/* ARGSUSED */

photo_start(name)
char   *name;
{
    if (passno == 1)
	maxx = 0;
    x = y = 0;

    return OK;
}


/* ARGSUSED */

photo_end (name)
char   *name;
{
    int	    len;
    register struct qbuf *qb,
			 *pb;
    
    if (passno == 1) {
	x = maxx, y--;

	if (debug)
	    fprintf (stderr, "ending pass one for \"%s\", %dx%d\n",
		     name, x, y);

	if ((im = (struct type_IMAGE_Image *) calloc (1, sizeof *im))
	        == NULL) {
	    fprintf (stderr, "calloc fails");
	    return NOTOK;
	}
	im -> hot__spot__x = im -> hot__spot__y = -1;
	im -> width = x, im -> height = y;

	len = ((im -> width + 7) / 8) * im -> height;
	if ((im -> data = qb = (struct qbuf *) malloc (sizeof *qb)) == NULL) {
	    fprintf (stderr, "unable to allocate qbuf");
	    return NOTOK;
	}
	qb -> qb_forw = qb -> qb_back = qb;
	qb -> qb_data = NULL, qb -> qb_len = len;
	
	if ((pb = (struct qbuf *) calloc ((unsigned) (sizeof *pb + len), 1))
	        == NULL) {
	    fprintf (stderr, "unable to allocate qbuf (%d+%d)",
		     sizeof *qb, len);
	    return NOTOK;
	}
	pb -> qb_data = pb -> qb_base, pb -> qb_len = len;
	insque (pb, qb);
    }

    return OK;
}


photo_black (length)
int	length;
{
    if (passno == 2) {
	register int    i,
			j;
	register unsigned char *cp;

	cp = (unsigned char *) im -> data -> qb_forw -> qb_data
				       + ((im -> width + 7) / 8) * y + x / 8;
	i = x % 8;
	for (j = length; j > 0; j--) {
	    *cp |= 1 << i;
	    if (++i == 8)
		cp++, i = 0;
	}

    }

    x += length;

    return OK;
}


photo_white (length)
{
    x += length;

    return OK;
}


/* ARGSUSED */

photo_line_end (line)
caddr_t line;
{
    if (passno == 1 && x > maxx)
	maxx = x;
    x = 0, y++;

    return OK;
}

/* \f

   ERRORS */

#ifndef	lint
void	_advise ();


void	adios (va_alist)
va_dcl
{
    va_list ap;

    va_start (ap);

    _advise (ap);

    va_end (ap);

    _exit (1);
}
#else
/* VARARGS */

void	adios (what, fmt)
char   *what,
       *fmt;
{
    adios (what, fmt);
}
#endif


#ifndef	lint
void	advise (va_alist)
va_dcl
{
    va_list ap;

    va_start (ap);

    _advise (ap);

    va_end (ap);
}


static void  _advise (ap)
va_list	ap;
{
    char    buffer[BUFSIZ];

    asprintf (buffer, ap);

    (void) fflush (stdout);

    if (errsw != NOTOK) {
	fprintf (stderr, "%s: ", myname);
	(void) fputs (buffer, stderr);
	(void) fputc ('\n', stderr);

	(void) fflush (stderr);
    }    
}
#else
/* VARARGS */

void	advise (what, fmt)
char   *what,
       *fmt;
{
    advise (what, fmt);
}
#endif

/* \f

   MISC */

char   *strdup (s)
char   *s;
{
    char   *p;

    if (p = malloc ((unsigned) (strlen (s) + 1)))
	(void) strcpy (p, s);

    return p;
}