Init from working directory of svn repository.
/** convertMap.h
Functions for converting from one Map form to another
and extracting smaller maps. There are four polymorphic
functions. The general format is
convertMap(MapType * source,MapType * target, Point ul, Point lr)
MapTypes can be - BitMap or RLEMap,
source - the map to be converted from
target - The map to be converted to. Memory will be allocated
for target's contents.
ul and lr mark a range to copy. If both are the global var NOPNT
the entire map will be copied.
Functions return a MapStatus which will be VALID or OTHERERROR
if there was an error in the conversion. An error might be due
to a user specifying an out of range ul and lr
**************************************************************/
#include "system.h"
#include "Point.h"
#include "BitMap.h"
#include "RLEMap.h"
#include "convertMap.h"
/**** BitMap Conversion ***/
MapStatus convertMap(BitMap * source, RLEMap * target, Point ul, Point lr)
/*--------------------------------------------------------------
Primary Purpose: Convert a bitMap to a RLEMap
Arguments: Right now just does full bit map coversion ul/lr dont work
Return Value: Returns valid if copy did not encounter any errors.
Effects:
Constraints: target is a pointer to an RLEMap
Rev: 10/24/95
---------------------------------------------------------------*/
{
uchar * rowdata;
int numChars;
assert(target != NULL); // target must be allocated with new RLEMap
// before being passed to this function.
assert(source !=NULL);
if (ul == NOPNT) ul = Point(0,0);
if (lr == NOPNT) lr = Point(source->imageWidth()-1,
source->imageLength()-1);
if (!(lr > ul)) return OTHERERROR;
target->imageWidth() = lr.x() - ul.x()+1;
target->imageLength() = lr.y() - ul.y()+1;
target->status() = source->status();
target->fMapData = new (RLEPairs*)[target->imageLength()];
for (int i = 0; i <= (lr.y() - ul.y()); i++)
{
numChars= target->imageWidth() /8 + 1; // number of char entries
// Create a list of RLEPairs for this row and fill with buffer data
rowdata = source->row(i+ul.y());
target->fMapData[i] = new RLEPairs(i);
target->fMapData[i]->fill(&(rowdata[ul.x()/8]), numChars, i);
}
return VALID;
}
/**** RLEMap Conversion ***/
MapStatus convertMap(RLEMap * source, BitMap * target, Point ul, Point lr)
/*--------------------------------------------------------------
Purpose: Converts an RLEMap to a BitMap;
Arguments: Right now just does full bit map coversion ul/lr dont work
Return Value: Returns valid if copy did not encounter any errors.
Effects:
Constraints: target is a pointer to a BitMap which must be previously
allocated with new BitMap;
Rev: 10/24/95
---------------------------------------------------------------*/
{
RLEPairs * rmapRowData;
RLEPair * item;
int numChars,startX,endX;
assert(target != NULL); // target must be allocated with new BitMap
// before being passed to this function.
assert(source !=NULL);
target->imageWidth() = source->imageWidth();
target->imageLength() = source->imageLength();
target->status() = source->status();
target->fMapData = new (uchar *)[target->imageLength()];
for (int i = 0; i < source->imageLength(); i++)
{
numChars= source->imageWidth() /8 + 1; // number of char entries
// Convert RLEPairs to uchar array
rmapRowData = source->row(i);
target->fMapData[i] = new uchar[numChars];
for(int j=0; j < numChars; j++)target->fMapData[i][j] = 0;
// convert this row from RLE to uchars
ListElement *ptr = rmapRowData->first;
for (; ptr != NULL; ptr = ptr->next)
{
item = (RLEPair *)(ptr->item);
startX = item->start;
endX = item->end;
setRange(target->fMapData[i], startX, endX);
}
}
return VALID;
}
//MapStatus convertMap(RLEMap * source, RLEMap * target, Point ul, Point lr)
/*--------------------------------------------------------------
Primary Purpose:
Arguments:
Return Value:
Effects:
Constraints:
Rev:
---------------------------------------------------------------*/
//{
//return EMPTY;
//}
void testConvertMap(char * filename)
// Reads in BitMap and converts to RLEMap then prints on screen
// Next converts back to BitMap, back to RLEMap and prints
{
BitMap * m = new BitMap;
RLEMap * rm = new RLEMap;
m->readMap(filename);
convertMap(m,rm);
cout << "length chk " << m->imageLength()<< "==" << rm->imageLength()<< endl;
cout << "width chk " << m->imageWidth()<< "==" << rm->imageWidth() << endl;
cout << "status chk"<<m->status() << "==" << rm->status() << endl;
printMap(rm);
// Now test conversion the other way
delete m;
m = new BitMap;
convertMap(rm,m);
delete rm;
rm = new RLEMap;
convertMap(m,rm);
printMap(rm);
}