|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T l
Length: 10472 (0x28e8)
Types: TextFile
Names: »long_image.c++«
└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
└─⟦this⟧ »EUUGD11/euug-87hel/sec1/image/varc++/long_image.c++«
/*
This file contains the routines necessary to manipulate an image
of 8 bit data that do not need to know about the image file format
*/
#include <stream.h>
#include <stdio.h>
#include "for.h++"
#include "long_image.h++"
/* the constructor when the image is built */
long_image::long_image
(
const create_image_type cit , // marker that the image is being created
const card n_rows , // the number of rows in the image
const card n_cols , // the number of collumns in the image
const FILE * image_file , // file for image
const card w_width = 1 , // window width
const card w_length = 1 // window length
)
: ( CREATE , image_file , n_rows , n_cols , w_width , w_length )
{
/* check that the constructor is called correctly */
if ( cit != CREATE )
{
cerr << "constructor for long_image being called in obscure way\n";
abort();
}
/* allocate space for image */
image_buffer = new long [ n_rows*n_cols ];
/* allocate space for dope vector */
image_rows = new long * [ n_rows ];
/* allocate space for window dope vector */
window_rows = new long * [ w_length ];
/* initialize dope vector */
FOR(int i1 = 0 ; i1 < n_rows; i1++)
{
image_rows[i1] = image_buffer + i1*n_cols;
}
ENDFOR
/* set up the protection so the image can be written */
prot = CAN_WRITE;
/* initialize function pointers */
next = &uninitialized_next;
prev = &uninitialized_prev;
get_w_e_pointer = &uninitialized_get_w_e;
write_w_e_pointer = &uninitialized_write_w_e;
}
/* functions for function pointers */
/* this version of next assumes the window has been initialized */
int
long_image::initialized_next ()
{
// if at the end of a row
if ( collumn + window_width == number_cols )
{
// if at the end of the image
if ( row + window_length == number_rows )
{
return 0;
}
// otherwise go to the beginning of the next row
collumn = 0;
row++;
// reset the pointers in the window
FOR(int i1 = 0 ; i1 < window_length ; i1++)
{
window_rows[i1] = image_rows[row + i1];
}
ENDFOR
// return successfully
return 1;
}
// otherwise move along row
collumn++;
// move the pointers in the window
FOR(int i1 = 0 ; i1 < window_length ; i1++)
{
window_rows[i1]++;
}
ENDFOR
// return successfully
return 1;
}
/* this version of prev assumes the window has been initialized */
int
long_image::initialized_prev ()
{
// if at beginning of a row
if ( collumn == 0 )
{
// if at the beginning of the image
if ( row == 0 )
{
return 0;
}
// otherwise go to the end of the previous row
collumn = number_cols - window_width;
row--;
// reset the pointers in the window
FOR(int i1 = 0 ; i1 < window_length ; i1++)
{
window_rows[i1] = image_rows[row + i1] + collumn;
}
ENDFOR
// return successfully
return 1;
}
// otherwise move back on the row
collumn--;
// move the pointers in the window
FOR(int i1 = 0 ; i1 < window_length ; i1++)
{
window_rows[i1]--;
}
ENDFOR
// return successfully
return 1;
}
/* this version of next initializes the window */
int
long_image::uninitialized_next ()
{
// check that the window fits in the image
if ( (window_width > number_cols) || (window_length > number_rows) )
{
return 0;
}
// set row and collumn to 0
row = 0;
collumn = 0;
// set the window row pointers
FOR(int i1 = 0 ; i1 < window_length ; i1++)
{
window_rows[i1] = image_rows[row + i1];
}
ENDFOR
// set the function pointers
next = &initialized_next;
prev = &initialized_prev;
get_w_e_pointer = &initialized_get_w_e;
write_w_e_pointer = &initialized_write_w_e;
// set the window status
window_status = INITIALIZED;
return 1;
}
/* this version of prev initializes the window */
int
long_image::uninitialized_prev ()
{
// check that the window fits in the image
if ( (window_width > number_cols) || (window_length > number_rows) )
{
return 0;
}
// set row and collumn to bottom right of image
row = number_rows - window_length;
collumn = number_cols - window_width;
// set the window row pointers
FOR(int i1 = 0 ; i1 < window_length ; i1++)
{
window_rows[i1] = image_rows[row + i1] + collumn;
}
ENDFOR
// set the function pointers
next = &initialized_next;
prev = &initialized_prev;
get_w_e_pointer = &initialized_get_w_e;
write_w_e_pointer = &initialized_write_w_e;
// set the window status
window_status = INITIALIZED;
return 1;
}
// this version of next says that applying the next operation is impossible
int
long_image::impossible_next ( )
{
cerr << "Trying to apply the next operation to an image for which it is impossible!\n";
return 0;
}
// this version of prev says that applying the next operation is impossible
int
long_image::impossible_prev ( )
{
cerr << "Trying to apply the prev operation to an image for which it is impossible!\n";
return 0;
}
/* uninitialized version of get_w_e will just die */
long
long_image::uninitialized_get_w_e ( const card i , const card j )
{
cerr << "Trying to get an element of an uninitialized window\n";
cerr << "The element was " << i << "," << j << "\n";
abort ();
return 0;
}
/* initialized version of get_w_e */
long
long_image::initialized_get_w_e ( const card i , const card j )
{
// check that i,j is in the window
if ( ( i >= window_length ) || ( j >= window_width ) )
{
cerr << "Tried to access element outside window\n";
cerr << "Window size " << window_length << "," << window_width << "\n";
cerr << "Accessed " << i << "," << j << "\n";
abort ();
return 0;
}
// otherwise return the element
return window_rows[i][j];
}
/* uninitialized version of write_w_e will just die */
void
long_image::uninitialized_write_w_e ( const card i , const card j , const long value )
{
cerr << "Trying to write to an element of an uninitialized window\n";
cerr << "Trying to write " << value << "\n";
cerr << "To " << i << "," << j << "\n";
abort ();
}
/* initialized version of write_w_e */
void
long_image::initialized_write_w_e ( const card i , const card j , const long value)
{
// check that i,j is in the window
if ( ( i >= window_length ) || ( j >= window_width ) )
{
cerr << "Tried to access element outside window\n";
cerr << "Window size " << window_length << "," << window_width << "\n";
cerr << "Accessed " << i << "," << j << "\n";
abort ();
}
// otherwise set the element
window_rows[i][j] = value;
}
/*
move in row n steps
returns 1 when that motion is legal 0 otherwise
*/
int
long_image::move_collumn ( const int n )
{
// the version in image does the checking and most of the work
int result = image_class::move_collumn ( n );
// if the move was successful move the window
if ( result == 1 )
{
FOR(int i1 = 0 ; i1 < window_length ; i1++)
{
window_rows[i1] += n;
}
ENDFOR
}
return result;
}
/*
move in collumn n steps
returns 1 when that motion is legal 0 otherwise
*/
int
long_image::move_row ( const int n )
{
// the version in image does the checking and most of the work
int result = image_class::move_row ( n );
// if the move was successful move the window
if ( result == 1 )
{
FOR(int i1 = 0 ; i1 < window_length ; i1++)
{
window_rows[i1] = image_rows[row + i1] + collumn ;
}
ENDFOR
}
return result;
}
/*
move to specified row
*/
void
long_image::move_to_row ( const card n )
{
// the version in image does the checking and most of the work
image_class::move_to_row ( n );
// move the window to the specified place
FOR(int i1 = 0 ; i1 < window_length ; i1++)
{
window_rows[i1] = image_rows[row + i1] + collumn ;
}
ENDFOR
}
/*
move to specified collumn
*/
void
long_image::move_to_collumn ( const card n )
{
// the version in image does the checking and most of the work
image_class::move_to_collumn ( n );
// move the window to the specified place
FOR(int i1 = 0 ; i1 < window_length ; i1++)
{
window_rows[i1] = image_rows[row + i1] + collumn ;
}
ENDFOR
}
/*
Gets a pointer to a row
of the image
*/
const long *
long_image::get_row( card row )
{
// Checks to make sure request is legal
if ( row >= number_rows )
{
cerr << "Tried to accesses row " << row;
cerr << " when image only has " << number_rows << " rows!\n";
abort();
}
if ( image_status == UNINITIALIZED )
{
cerr << "Trying to read row from unitialized image!\n";
abort();
}
if ( (prot != CAN_READ) && (prot != CAN_READ_AND_WRITE) )
{
cerr << "Trying to access a row of an image protected against reading!\n";
abort();
}
return image_rows[row];
}
/*
Change the size of a window
causes the window to become uninitialized
*/
void
long_image::resize_window ( card width , card length )
{
// set the window
window_width = width;
window_length = length;
window_status = UNINITIALIZED;
/* allocate space for window dope vector */
window_rows = new long * [ window_length ];
/* reset function pointers */
next = &uninitialized_next;
prev = &uninitialized_prev;
get_w_e_pointer = &uninitialized_get_w_e;
write_w_e_pointer = &uninitialized_write_w_e;
}
/*
Causes the window to cover the entire image.
Allows one to access any part of the image with window operations
*/
void
long_image::window_entire_image ( )
{
// set up the window
window_width = number_cols;
window_length = number_rows;
window_status = INITIALIZED;
// make the window dope vector an alias for the image dope vector
window_rows = image_rows;
// set up function pointers so next and previous impossible
next = &impossible_next;
prev = &impossible_prev;
// access functions
get_w_e_pointer = &initialized_get_w_e;
write_w_e_pointer = &initialized_write_w_e;
}
/*
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.
*/