pafScanline = (uchar *) CPLMalloc(xsize * ysize * 4);
Q_CHECK_PTR(pafScanline);
for (int i = 1; i <= 3; ++i) { // R G B
GDALRasterBand *poBand;
poBand = m_dataset->GetRasterBand(i);
Q_CHECK_PTR(poBand);
static int smap[4] = { 0, 2, 1, 0 };
if (poBand->RasterIO(GF_Read, x_off, y_off, xsize, ysize,
pafScanline + smap[i], xsize, ysize, GDT_Byte,
4, xsize * 4) == CE_Failure) {
throw gException
(QString("RasterIO error:%1").
arg(CPLGetLastErrorMsg()));
}
}
Q_CHECK_PTR(result);
for (int y = 0; y < ysize; ++y) {
QRgb *sLine = (QRgb *) result->scanLine(y);
memcpy(sLine, pafScanline + y * xsize * 4, xsize * 4);
}
CPLFree(pafScanline);
pafScanline = (uchar *) CPLMalloc(xsize * ysize * 4);
Q_CHECK_PTR(pafScanline);
for (int i = 1; i <= 3; ++i) { // R G B
GDALRasterBand *poBand;
poBand = m_dataset->GetRasterBand(i);
Q_CHECK_PTR(poBand);
static int smap[4] = { 0, 2, 1, 0 };
if (poBand->RasterIO(GF_Read, x_off, y_off, xsize, ysize,
pafScanline + smap[i], xsize, ysize, GDT_Byte,
4, xsize * 4) == CE_Failure) {
throw gException(QString("RasterIO error:%1").
arg(CPLGetLastErrorMsg()));
}
}
QImage *result = new QImage(xsize, ysize, QImage::Format_RGB32);
Q_CHECK_PTR(result);
for (int y = 0; y < ysize; ++y) {
QRgb *sLine = (QRgb *) result->scanLine(y);
memcpy(sLine, pafScanline + y * xsize * 4, xsize * 4);
}
CPLFree(pafScanline);
To copy to clipboard, switch view to plain text mode
Bookmarks