[Gdal-dev] Problems with writing RasterIO on WinXP
J.Krueger
kruegerj at gmx.de
Sun Aug 1 15:26:01 EDT 2004
Hello,
While toying around with gdal today I encountered a strange problem:
I was familarizing myself with image calculations and basic io and
therefore wrote a simple 'fusion' program that worked fine when running
on a Win2k machine at work. But when I tried it on my WinXP Pro machine
at home it suddenly started crashing as soon as it encountered the
following instruction:
-cut-
fusionBand->RasterIO( GF_Write, 0, j, xsize, 1,
fusionBuffer, xsize, 1, GDT_Float32,
0, 0 );
-cut-
I tried the binary I compiled on the Win2k, but neither that nor
binaries compiled on the WinXP machine itself work. I also tried the 1.2
stable release of the library and the latest CVS (30th May) - without
any differences. At work I'm a simple user with restricted rights, while
on the XP machine I have admin rights, so it can't be a problem with the
permissions.
Is this a known problem? I attached the source, so you may check it for
yourself.
Jochen
-------------- next part --------------
#include <iostream>
#include <stdlib.h>
#include <gdal_priv.h>
#ifndef test
#define test
#endif
using namespace std;
// global variable definitions
int errorvalue;
GDALDataset *highresDataset, *lowresDataset, *fusionDataset;
GDALDriver *outputDriver;
// function definitions
void rotatingCursor ();
float *analyseBuffer(float *hrBuffer, float *lrBuffer, int bsize);
int main(int argc, char *argv[])
{
cout << "SimpleFusion Demo" << endl << endl;
// read command line arguments
const char* highresFilename = argv[1];
const char* lowresFilename = argv[2];
const char* fusionFilename = argv[3];
// load highres dataset
GDALAllRegister();
#ifdef test
cout << "loading highres dataset" << endl;
#endif
highresDataset = (GDALDataset *) GDALOpen( highresFilename, GA_ReadOnly );
if( highresDataset == NULL ) {
cout << endl << "can't load highresDataset" << endl;
return 1;
};
// load lowres dataset
#ifdef test
cout << "loading lowres dataset" << endl;
#endif
lowresDataset = (GDALDataset *) GDALOpen( lowresFilename, GA_ReadOnly );
if( lowresDataset == NULL ) {
cout << endl << "can't load lowresDataset" << endl;
return 1;
};
// get basic stats
int maxbands = lowresDataset->GetRasterCount();
int xsize = lowresDataset->GetRasterXSize();
int ysize = lowresDataset->GetRasterYSize();
#ifdef test
cout << endl << "image size: " << xsize << "x" << ysize << "x" << maxbands << endl;
#endif
// create fusion dataset
remove(fusionFilename);
#ifdef test
cout << endl << "creating fusion dataset" << endl;
#endif
char* outputFormat = "HFA";
outputDriver = GetGDALDriverManager()->GetDriverByName(outputFormat);
fusionDataset = outputDriver->CreateCopy( fusionFilename, lowresDataset, FALSE,
NULL, NULL, NULL );
// load bands
GDALRasterBand *highresBand, *lowresBand, *fusionBand;
float *highresBuffer, *lowresBuffer, *fusionBuffer;
#ifdef test
cout << endl << "loading highres band" << endl;
#endif
highresBand = highresDataset->GetRasterBand( 1 );
// defining bandsize
xsize = highresBand->GetXSize();
ysize = highresBand->GetYSize();
// creating buffers
int bufferSize = xsize * 1;
highresBuffer = (float *) CPLMalloc(sizeof(float)*bufferSize);
lowresBuffer = (float *) CPLMalloc(sizeof(float)*bufferSize);
fusionBuffer = (float *) CPLMalloc(sizeof(float)*bufferSize);
// looping through lowres bands
int i=1;
while (i < (maxbands+1)) {
cout << endl << "loading lowres band " << i << endl;
lowresBand = lowresDataset->GetRasterBand( i );
fusionBand = fusionDataset->GetRasterBand( i );
// looping through image lines
cout << "Processing... ";
int j=0;
while (j < (ysize)) {
// load highres line
highresBand->RasterIO( GF_Read, 0, j, xsize, 1,
highresBuffer, xsize, 1, GDT_Float32,
0, 0 );
// load lowres line
lowresBand->RasterIO( GF_Read, 0, j, xsize, 1,
lowresBuffer, xsize, 1, GDT_Float32,
0, 0 );
// process image
fusionBuffer = analyseBuffer(highresBuffer,lowresBuffer,bufferSize);
rotatingCursor();
// save fusion line
fusionBand->RasterIO( GF_Write, 0, j, xsize, 1,
fusionBuffer, xsize, 1, GDT_Float32,
0, 0 );
j += 1;
};
cout << "\bdone!" << endl;
i += 1;
};
}
float *analyseBuffer(float *hrBuffer, float *lrBuffer, int bsize) {
float *fuBuffer;
fuBuffer = (float *) CPLMalloc(sizeof(float)*bsize);
int i=1;
while (i <= bsize) {
fuBuffer[i]=(hrBuffer[i] + hrBuffer[i] + lrBuffer[i]) / 3;
i += 1;
};
return fuBuffer;
}
int rotatingCursorSelector = 0;
void rotatingCursor () {
char *symbols = "|/-\\|/-\\";
if (rotatingCursorSelector == 8) rotatingCursorSelector = 0;
cout << "\b" << symbols[(rotatingCursorSelector++)];
}
More information about the Gdal-dev
mailing list