bool SioImporter::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { // Read the statistics from the file and set into the raster element RasterElement* pRaster = NULL; if (pInArgList != NULL) { pRaster = pInArgList->getPlugInArgValue<RasterElement>(Importer::ImportElementArg()); } if (pRaster != NULL) { // Get the filename string filename = pRaster->getFilename(); // Read the file FileResource pFile(filename.c_str(), "rb"); SioFile sioFile; if (sioFile.deserialize(pFile.get()) == true) { if (sioFile.mOriginalVersion == 9 && isBatch()) { //Since version 9 sio's are not officially supported //don't load them in batch to force users to load them //interactively which will show them the reason why. return false; } const RasterDataDescriptor* pDescriptor = dynamic_cast<const RasterDataDescriptor*>(pRaster->getDataDescriptor()); if (pDescriptor != NULL && RasterUtilities::isSubcube(pDescriptor, false) == false && Service<SessionManager>()->isSessionLoading() == false) { const vector<DimensionDescriptor>& bands = pDescriptor->getBands(); for (unsigned int i = 0; i < bands.size(); ++i) { Statistics* pStatistics = pRaster->getStatistics(bands[i]); if (pStatistics != NULL) { // Bad values if (i < sioFile.mBadValues.size()) { vector<int> badValues = sioFile.mBadValues[i]; pStatistics->setBadValues(badValues); } // Min if (i < sioFile.mStatMin.size()) { double dMin = sioFile.mStatMin[i]; pStatistics->setMin(dMin); } // Max if (i < sioFile.mStatMax.size()) { double dMax = sioFile.mStatMax[i]; pStatistics->setMax(dMax); } // Average if (i < sioFile.mStatAvg.size()) { double dAverage = sioFile.mStatAvg[i]; pStatistics->setAverage(dAverage); } // Standard deviation if (i < sioFile.mStatStdDev.size()) { double dStdDev = sioFile.mStatStdDev[i]; pStatistics->setStandardDeviation(dStdDev); } // Percentiles if (i < sioFile.mStatPercentile.size()) { double* pPercentiles = sioFile.mStatPercentile[i]; pStatistics->setPercentiles(pPercentiles); } // Histogram if ((i < sioFile.mStatBinCenter.size()) && (i < sioFile.mStatHistogram.size())) { double* pBinCenters = sioFile.mStatBinCenter[i]; unsigned int* pCounts = sioFile.mStatHistogram[i]; pStatistics->setHistogram(pBinCenters, pCounts); } } } } } } return RasterElementImporterShell::execute(pInArgList, pOutArgList); }
bool NefImporter::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { if (pInArgList == NULL || pOutArgList == NULL) { return false; } //setting up mpRasterElement parseInputArgList(pInArgList); RasterElement* pRaster = getRasterElement(); VERIFY(pRaster != NULL); RasterDataDescriptor *pDescriptor = dynamic_cast<RasterDataDescriptor*>(pRaster->getDataDescriptor()); VERIFY(pDescriptor != NULL); FileDescriptor *pFileDescriptor = pDescriptor->getFileDescriptor(); VERIFY(pFileDescriptor != NULL); //data accessor //RED DimensionDescriptor firstBand = pDescriptor->getActiveBand(0); FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BSQ); pRequest->setBands(firstBand, firstBand); pRequest->setWritable(true); DataAccessor firstBandDa = pRaster->getDataAccessor(pRequest.release()); //GREEN DimensionDescriptor secondBand = pDescriptor->getActiveBand(1); FactoryResource<DataRequest> qRequest; qRequest->setInterleaveFormat(BSQ); qRequest->setBands(secondBand, secondBand); qRequest->setWritable(true); DataAccessor secondBandDa = pRaster->getDataAccessor(qRequest.release()); //BLUE DimensionDescriptor thirdBand = pDescriptor->getActiveBand(2); FactoryResource<DataRequest> rRequest; rRequest->setInterleaveFormat(BSQ); rRequest->setBands(thirdBand, thirdBand); rRequest->setWritable(true); DataAccessor thirdBandDa = pRaster->getDataAccessor(rRequest.release()); std::string filename = pRaster->getFilename(); Progress *pProgress = getProgress(); FactoryResource<Filename> pFilename; pFilename->setFullPathAndName(filename); LibRaw RawProcessor; putenv ((char*)"TZ=UTC"); #define P1 RawProcessor.imgdata.idata #define S RawProcessor.imgdata.sizes #define C RawProcessor.imgdata.color #define T RawProcessor.imgdata.thumbnail #define P2 RawProcessor.imgdata.other #define OUT RawProcessor.imgdata.params const char *fname=filename.c_str(); RawProcessor.open_file(fname); // Let us unpack the image if (RawProcessor.unpack() != LIBRAW_SUCCESS) { return false; } /* unsigned int *r=NULL; unsigned int *g=NULL; unsigned int *b=NULL; unsigned int *h=NULL; */ unsigned int *zero=0; int row=0,col=0,r=0,c=0; /* r=(unsigned int*)(&RawProcessor.imgdata.image[i][0]); g=(unsigned int*)(&RawProcessor.imgdata.image[i][1]); b=(unsigned int*)(&RawProcessor.imgdata.image[i][2]); h=(unsigned int*)(&RawProcessor.imgdata.image[i][3]); */ //secondBandDa->toPixel(row,col); //thirdBandDa->toPixel(row,col); unsigned short *pData=reinterpret_cast<unsigned short*>(pRaster->getRawData()); if (pData == NULL) { return NULL; } memcpy(pData, RawProcessor.imgdata.rawdata.raw_image, sizeof(unsigned short) * RawProcessor.imgdata.sizes.raw_height * RawProcessor.imgdata.sizes.raw_width); /* if(i%2==0) //RG1 {memcpy(firstBandDa->getColumn(),(unsigned int*)RawProcessor.imgdata.image[i][0],sizeof(unsigned int)); memcpy(thirdBandDa->getColumn(),(unsigned int*)RawProcessor.imgdata.image[i][2],sizeof(unsigned int)); memcpy(secondBandDa->getColumn(),zero,sizeof(unsigned int)); } else{ //G2B memcpy(thirdBandDa->getColumn(),(unsigned int*)RawProcessor.imgdata.image[i][3],sizeof(unsigned int)); memcpy(secondBandDa->getColumn(),(unsigned int*)RawProcessor.imgdata.image[i][1],sizeof(unsigned int)); memcpy(firstBandDa->getColumn(),zero,sizeof(unsigned int)); } */ unsigned short *ptr=NULL; //band 0 Red for(row=0,r=0;row<S.iheight;row++,r++) { for(col=0,c=0;col<S.iwidth;col++,c++) { if(row%2==0) //RG row { if(col%2==0) //Red pixel { ptr=reinterpret_cast<unsigned short*>(firstBandDa->getColumn()); *ptr=pData[c+(r*S.iwidth)+(0*S.iheight*S.iwidth)]; } else { *ptr=0; c--; } } else //GB row { *ptr=0; } firstBandDa->nextColumn(); } if(row%2!=0) r--; firstBandDa->nextRow(); } //band 2 Blue for(row=0,r=0;row<S.iheight;row++,r++) { for(col=0,c=0;col<S.iwidth;col++,c++) { if(row%2!=0) //GB row { if(col%2!=0) //Blue pixel { ptr=reinterpret_cast<unsigned short*>(secondBandDa->getColumn()); *ptr=pData[c+(r*S.iwidth)+(2*S.iheight*S.iwidth)]; } else { *ptr=0; c--; } } else //RG row { *ptr=0; } secondBandDa->nextColumn(); } if(row%2==0) r--; secondBandDa->nextRow(); } //band 1 Green for(row=0,r=0;row<S.iheight;row++,r++) { for(col=0,c=0;col<S.iwidth;col++,c++) { if(row%2==0) //RG row { if(col%2!=0) //Green pixel { ptr=reinterpret_cast<unsigned short*>(thirdBandDa->getColumn()); *ptr=pData[c+(r*S.iwidth)+(1*S.iheight*S.iwidth)]; //g1 } else { *ptr=0; c--; } } else //GB row { if(col%2==0) //Green pixel { ptr=reinterpret_cast<unsigned short*>(thirdBandDa->getColumn()); *ptr=pData[c+(r*S.iwidth)+(3*S.iheight*S.iwidth)]; //g2 } else { *ptr=0; c--; } } thirdBandDa->nextColumn(); } thirdBandDa->nextRow(); } if (createView() == NULL) { return false; } RawProcessor.recycle(); return true; }