Opened 19 years ago

Closed 16 years ago

#773 closed defect (fixed)

RasterIO() "expansion" doesn't work right in most cases.

Reported by: warmerdam Owned by: warmerdam
Priority: high Milestone: 1.6.0
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords: rasterio expansion
Cc:

Description

Hi Frank again,

OK, the Fill() seems to be a reasonable way to assure that
you put some appropriate "background" value. That's OK.
However, I'm still noticing something wrong regarding my
original posting: replicating a value. The attached test
program creates a 10x6 1-band raster of type byte; fills
it with '_' and then calls RasterIO to set the upper left
7x3 region with 'X':

$ g++ rasteriotest.cc -lgdal -Wall
$ ./a.out
result = 0
$ cat raster
_____________X______________________________________________

but it should be:
XXXXXXXXXXXXXXXXXXXXX_______________________________________

Right?



... test code:

#include "gdal.h"           
#include "gdal_priv.h"
#include <iostream>
#include <cassert>
using namespace std; 

/*
	RasterIO bug?
		$ g++ rasteriotest.cc -lgdal -Wall
		$ ./a.out
		result = 0
		$ cat raster
		_____________X______________________________________________
		
		but it should be:
		XXXXXXXXXXXXXXXXXXXXX_______________________________________
*/
int main() {
	GDALAllRegister();
	GDALDriver* hDriver = GetGDALDriverManager()->GetDriverByName("ENVI");
	assert(hDriver);
	GDALDataset* dataset = hDriver->Create(
	   "raster",
	   10,       //nXSize
	   6,       //nYSize
	   1,          //nBands
	   GDT_Byte,  //GDALDataType
	   NULL        //papszParmList
	);
	dataset->GetRasterBand(1)->Fill('_');
	char value = 'X';
	int result = dataset->RasterIO(
		GF_Write,
		0,          //nXOff,
		0,             //nYOff,
		7,           //nXSize,
		3,           //nYSize,
		&value,        //pData,
		1,             //nBufXSize,
		1,             //nBufYSize,
		GDT_Byte,     //eBufType,
		1,             //nBandCount,
		NULL,          //panBandMap,
		0,             //nPixelSpace,
		0,             //nLineSpace,
		0              //nBandSpace
	);     
	cout<< "result = " <<result<< endl;
	dataset->FlushCache();
	delete dataset;
	return 0;
}

Change History (2)

comment:1 by warmerdam, 19 years ago

I have confirmed the problem.  It seems that the default 
GDALRasterBand::IRasterIO() implementation does not properly support 
expansion on write as it ought since the code loops over the buffer size
instead of the output window when writing. 

see IRasterIO() in gcore/rasterio.cpp

Needs a whole seperate case for writing I think.


comment:2 by Even Rouault, 16 years ago

Keywords: rasterio expansion added
Milestone: 1.6.0
Resolution: fixed
Status: assignedclosed

Fixed in trunk in r15132. Test added in r15133

Note: See TracTickets for help on using tickets.