X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_Image.cxx;h=a957d7f9f97a78c51cc9b1e644ef2b87172871c5;hb=b86ee42a0010ef6bde30373a8741dd865d557dd3;hp=74c278b4c3328957c03c1145e96e9a075b9f4791;hpb=05d82ada59110252be57aaa774095a18ebdca455;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_Image.cxx b/src/HYDROData/HYDROData_Image.cxx index 74c278b4..a957d7f9 100644 --- a/src/HYDROData/HYDROData_Image.cxx +++ b/src/HYDROData/HYDROData_Image.cxx @@ -31,6 +31,9 @@ #include #include +#include +#include + #ifdef WIN32 #pragma warning ( disable: 4251 ) #endif @@ -40,6 +43,7 @@ #include #include +#include #ifdef WIN32 #pragma warning ( default: 4251 ) @@ -307,11 +311,113 @@ void HYDROData_Image::SetImage(const QImage& theImage) bool HYDROData_Image::LoadImage( const QString& theFilePath ) { - QImage anImage( theFilePath ); + QFileInfo aFI(theFilePath); + QImage anImage; + HYDROData_Image::ECW_FileInfo* theECWInfo; + if (aFI.suffix().toLower() == "ecw") + { + theECWInfo = new HYDROData_Image::ECW_FileInfo; + HYDROData_Image::OpenECW(theFilePath.toLatin1().data(), anImage, theECWInfo); + } + else + anImage = QImage(theFilePath); SetImage( anImage ); - SetFilePath( theFilePath ); + return !anImage.isNull(); +} + +bool HYDROData_Image::OpenECW(char* theFileName, QImage& theImage, ECW_FileInfo* theECWInfo) +{ + NCSFileView *pNCSFileView; + NCSFileViewFileInfo *pNCSFileInfo; + NCSError eError = NCS_SUCCESS; + UINT32 band, nBands; + UINT32 XSize, YSize; + NCSecwInit(); + + eError = NCScbmOpenFileView(theFileName, &pNCSFileView, NULL); + if(eError != NCS_SUCCESS) + return false; + + eError = NCScbmGetViewFileInfo(pNCSFileView, &pNCSFileInfo); + if(eError != NCS_SUCCESS) + return false; + + XSize = pNCSFileInfo->nSizeX; + YSize = pNCSFileInfo->nSizeY; + nBands = pNCSFileInfo->nBands; + if (theECWInfo) + { + //ECW_CellUnits myCellSizeUnits; + CellSizeUnits aCellUnits = pNCSFileInfo->eCellSizeUnits; + if (aCellUnits == ECW_CELL_UNITS_METERS) + theECWInfo->myCellSizeUnits = ECW_CellUnits_Meters; + else if (aCellUnits == ECW_CELL_UNITS_DEGREES) + theECWInfo->myCellSizeUnits = ECW_CellUnits_Deg; + else if (aCellUnits == ECW_CELL_UNITS_FEET) + theECWInfo->myCellSizeUnits = ECW_CellUnits_Feet; + else + theECWInfo->myCellSizeUnits = ECW_CellUnits_Unknown; + theECWInfo->myCellIncrementX = pNCSFileInfo->fCellIncrementX; + theECWInfo->myCellIncrementY = pNCSFileInfo->fCellIncrementY; + theECWInfo->myOriginX = pNCSFileInfo->fOriginX; + theECWInfo->myOriginY = pNCSFileInfo->fOriginY; + theECWInfo->myXSize = pNCSFileInfo->nSizeX; + theECWInfo->myYSize = pNCSFileInfo->nSizeY; + } + + std::vector band_list(nBands); + for( band = 0; band < nBands; band++ ) + band_list[band] = band; + + eError = NCScbmSetFileView(pNCSFileView, nBands, &band_list[0], 0, 0, XSize - 1, YSize - 1, XSize, YSize); //view an image into the original size + if(eError != NCS_SUCCESS) + { + NCScbmCloseFileView(pNCSFileView); + return false; + } + + UINT8 *pRGBTriplets; + pRGBTriplets = (UINT8 *) malloc(XSize*3); + + QImage anImage(XSize, YSize, QImage::Format_RGB32); + + for(UINT32 line = 0; line < YSize; line++) + { + NCSEcwReadStatus eStatus; + eStatus = NCScbmReadViewLineRGB(pNCSFileView, pRGBTriplets); + if(eStatus == NCSECW_READ_OK) + { + QRgb* crp = (QRgb*)anImage.scanLine(line); + for(UINT32 j = 0; j < XSize; j++) + { + QRgb val = qRgb((int)pRGBTriplets[j*3],(int)pRGBTriplets[j*3+1],(int)pRGBTriplets[j*3+2]); + memcpy((void*)(crp+j), &val, sizeof(QRgb)); + } + } + else + { + free(pRGBTriplets); + NCScbmCloseFileView(pNCSFileView); + return false; + } + } + + free(pRGBTriplets); + NCScbmCloseFileView(pNCSFileView); + theImage = anImage; + return true; +} + +bool HYDROData_Image::LoadImageECW( const QString& theFilePath ) +{ + QImage anImage; + if (HYDROData_Image::OpenECW(theFilePath.toLatin1().data(), anImage, NULL)) + { + SetImage( anImage ); + SetFilePath( theFilePath ); + } return !anImage.isNull(); }