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 - download
Index: ┃ T i

⟦6880716b3⟧ TextFile

    Length: 6652 (0x19fc)
    Types: TextFile
    Names: »image.c++«

Derivation

└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
    └─ ⟦this⟧ »EUUGD11/euug-87hel/sec1/image/varc++/image.c++« 

TextFile

/*
    This file contains the implementation of the generic image stuff
    except for handling the and read and write function that 
    requires knowledge of the image file format
*/
#include <stream.h>
#include <stdio.h>
#include <string.h>
#include "for.h++"
#include "image.h++"

/*
    initializer for generic images when image is being created rather
    than read from file
*/
image_class::image_class
    ( 
    const create_image_type cit,	// maker that the image is being created
    const FILE * image_file , 	// the file for the image
    const card n_rows , 		// the number of rows in the image
    const card n_cols , 		// the number of collumns in the image
    const card w_width , 		// the width of the window
    const card w_length 		// the length of the window
    )
    {
    /* check that the constructor is called correctly */
    if ( cit != CREATE )
	{
	cerr << "Generic constructor for image being called in obscure way\n";
	abort();
	}

    /* initialize using arguments */
    file = image_file;
    number_rows = n_rows;
    number_cols = n_cols;
    window_width = w_width;
    window_length = w_length;

    /* a priori initializations */
    /* status */
    image_status = UNINITIALIZED;
    window_status = UNINITIALIZED;
    prot = CAN_NOT_DO_ANYTHING;
    /* comments */
    comment_length = 0;
    comments = NULL;
    /* header info from file format */
    header_info = NULL;
    }

/*
    comment manipulation code
*/
/* 
    returns a null terminated string for comments 
*/
const char * 
comment_string ( image_class& i )
    {
    char * output = new char [ i.comment_length + 1 ];	// output for the data
    char * output_p = output;				// pointer to output
    const char * com = i.comments;			// comments

    /* copy the comments into the new string */
    FOR(int i1 = 0 ; i1 < i.comment_length ; i1++)
	{
	*(output_p++) = *(com++);
	}
    ENDFOR

    /* null terminate the new string */
    *output_p = '\0';

    /* return the new string */
    return output;
    }

/* sets the comments */
void 
image_class::set_comments( char * string , const card length )
    {
    comment_length = length;
    comments = string;
    }

/* adds a string to the comments */
void 
image_class::add_comment( char * string , const card length )
    {
    /* the new comments to be used */
    char * new_comments = new char [ comment_length + length ];
    char * ncp = new_comments;	// pointer into new comments
    char * ocp = comments;	// pointer into old comments

    /* copy the old comments into the new string */
    FOR(int i1 = 0 ; i1 < comment_length ; i1++)
	{
	*(ncp++) = *(ocp++);
	}
    ENDFOR
    
    /* copy the added comments into the new string */
    FOR(int i1 = 0 ; i1 < length ; i1++)
	{
	*(ncp++) = *(string++);
	}
    ENDFOR

    /* make the new string the comments */
    comment_length += length;
    comments = new_comments;
    }

/*
    for moving around in images
*/

/*
    move to specified row
*/
void 
image_class::move_to_row ( const card n ) 
    {
    // test bounds
    if ( n < 0 ) 
	{
	cerr << "Trying to move to a negative row in an image\n";
	cerr << "The row is " << n << "\n";
	abort();
	}
    if ( n + window_length > number_rows )
	{
	cerr << "Trying to move to a nonexistant row in an image\n";
	cerr << "The row is " << n << "\n";
	abort();
	}

    // check status
    if ( window_status == UNINITIALIZED )
	{
	// check collumn boundaries
	if ( window_width > number_cols )
	    {
	    cerr << "Window to wide for image!\n";
	    cerr << "Width of image: " << number_cols;
	    cerr << "Width of window: " << window_width;
	    cerr << "\n";
	    abort();
	    }
	row = n;
	collumn = 0;
	window_status = INITIALIZED;
	}

    // otherwise change the row since it is legal
    row = n;
    }

/*
    move to specified collumn
*/
void 
image_class::move_to_collumn ( const card n ) 
    {
    // test bounds
    if ( n < 0 ) 
	{
	cerr << "Trying to move to a negative collumn in an image\n";
	cerr << "The collumn is " << n << "\n";
	abort();
	}
    if ( n + window_width > number_cols )
	{
	cerr << "Trying to move to a nonexistant collumn in an image\n";
	cerr << "The collumn is " << n << "\n";
	abort();
	}

    // check status
    if ( window_status == UNINITIALIZED )
	{
	// check collumn boundaries
	if ( window_length > number_rows )
	    {
	    cerr << "Window to long for image!\n";
	    cerr << "Height of image: " << number_rows;
	    cerr << "Height of window: " << window_length;
	    cerr << "\n";
	    abort();
	    }
	collumn = n;
	row = 0;
	window_status = INITIALIZED;
	}

    // otherwise change the row since it is legal
    collumn = n;
    }

/*
    move in row n steps 
    returns 1 when that motion is legal 0 otherwise
*/
int 
image_class::move_collumn ( const int n ) 
    {
    // check the status of the window
    if ( window_status == UNINITIALIZED )
	{
	// it is probably an error so print an error message
	cerr << "trying to move in unitialized window\n";
	// but return 0 since  that is the semantics
	return 0;
	}
    
    // check that the movement doesn't lead to a negative position
    if ( n + collumn < 0 )
	{
	return 0;
	}
    
    // check that the movement doesn't lead to a too large position
    if ( n + collumn + window_width > number_rows )
	{
	return 0;
	}
    
    // else increment the collumn position and return successfully
    collumn += n;
    return 1;
    }

/*
    move in collumn n steps
    returns 1 when that motion is legal 0 otherwise
*/
int 
image_class::move_row ( const int n ) 
    {
    // check the status of the window
    if ( window_status == UNINITIALIZED )
	{
	// it is probably an error so print an error message
	cerr << "trying to move in unitialized window\n";
	// but return 0 since  that is the semantics
	return 0;
	}
    
    // check that the movement doesn't lead to a negative position
    if ( n + row < 0 )
	{
	return 0;
	}
    
    // check that the movement doesn't lead to a too large position
    if ( n + row + window_width > number_cols )
	{
	return 0;
	}
    
    // else increment the collumn position and return successfully
    row += n;
    return 1;
    }

/* change the protection from CAN_WRITE to CAN_READ_AND_WRITE */
void image_class::read_and_write ( )
    { 
    if ( prot == CAN_WRITE ) 
	{
	prot = CAN_READ_AND_WRITE;
	}
    else
	{
	cerr << "Protection violation for read_and_write\n";
	abort();
	}
    }

/*
Copyright (C) 1986, David Sher in the University of Rochester
Permission is granted to any individual or institution to use, copy, or
redistribute this software so long as it is not sold for profit, provided
this copyright notice is retained.
*/