1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
bool MapWindow::ReadEcw(wxString wxFilename)
{
const char* filename = (const char*)wxFilename.mb_str(wxConvUTF8);
bool retVal = false;
try
{
char * zFilename = const_cast<char*>(filename);
NCSFileView *pNCSFileView;
NCSFileViewFileInfo *pNCSFileInfo;
NCSEcwReadStatus eReadStatus = NCSECW_READ_OK;
NCSError eError = NCS_SUCCESS;
UINT32 nBytesPerLine;
INT32 nWidth, nHeight;
INT32 nBands=3;
INT32 nViewX, nViewY;
UINT32 *pBandList;
nViewX=WindowSize.GetWidth();
nViewY=WindowSize.GetHeight();
pBandList = (UINT32 *) malloc(sizeof(UINT32) * 3);
NCSecwInit();
for( int j = 0; j < nBands; j ++ ){pBandList[j] = j;}
// Open the input NCSFileView
eError = NCScbmOpenFileView(zFilename, &pNCSFileView, NULL);
if (eError != NCS_SUCCESS)
{
//Could not open view for file
wxMessageBox(wxT("Error: Could not open view for ecw file"));
return retVal;
}
eError = NCScbmGetViewFileInfo(pNCSFileView, &pNCSFileInfo);
if (eError != NCS_SUCCESS)
{
//Could not open file infos
wxMessageBox(wxT("Error: Could not get infos for ecw file"));
return retVal;
}
//wxMessageBox(wxString::Format("[ECW INFO] %dx%d, %d bandes, Origine: (%f,%f), Unit:%d", pNCSFileInfo->nSizeX, pNCSFileInfo->nSizeY, pNCSFileInfo->nBands, pNCSFileInfo->fOriginX, pNCSFileInfo->fOriginY, pNCSFileInfo->eCellSizeUnits));
eError = NCScbmSetFileView(pNCSFileView, 3, pBandList,
700, 700, 1300, 1300, nViewX, nViewY);
if (eError != NCS_SUCCESS)
{
//Could not open view for file
wxMessageBox(wxT("Error: Could not set view for ecw file"));
return retVal;
}
// Allocate scanline RGB triplet buffer
nBytesPerLine=(nViewX*3); //pour chaque pixel, bytes B G et R
pRGBTriplets = (UINT8 *) malloc(nViewY*nBytesPerLine); //BGR triplet buffer
pRGBTriplets_wrk = pRGBTriplets;//pointeur de travail
int k = nViewY-1;
while(k--)
{
eReadStatus = NCScbmReadViewLineRGB(pNCSFileView, pRGBTriplets_wrk);
if(eReadStatus==NCSECW_READ_CANCELLED)
{
wxMessageBox(wxT("Error: view line bgr"));
NCScbmCloseFileView(pNCSFileView);
delete(pBandList);
NCSecwShutdown();
return false;
}
pRGBTriplets_wrk+=nBytesPerLine;
}
image = wxImage(nViewX, nViewY, true);
image.SetData(pRGBTriplets);
// Close file view
NCScbmCloseFileView(pNCSFileView);
delete(pBandList);
// Do an explicit Shutdown() to prevent multi-heap issues in DEBUG mode
NCSecwShutdown();
//FlipBuffer();
retVal = true;
}
catch(std::exception e)
{
//Something went wrong
retVal = false;
}
return retVal;
} |
Partager