예제 #1
0
ossimRefPtr<ossimImageData> ossimMaskFilter::executeMaskFilterInvertSelection(
   inputT /* dummyInput */,
   maskT  /* dummyMask */,
   ossimRefPtr<ossimImageData> imageSourceData,
   ossimRefPtr<ossimImageData> maskSourceData)
{
   ossimDataObjectStatus maskDataStatus  = maskSourceData->getDataObjectStatus();
   ossimDataObjectStatus inputDataStatus = imageSourceData->getDataObjectStatus();

   if((maskDataStatus == OSSIM_NULL) ||
      (maskDataStatus == OSSIM_EMPTY))
   {
      return theTile;
   }
   if( (inputDataStatus == OSSIM_NULL)||
       (inputDataStatus == OSSIM_EMPTY))
   {
      return theTile;
   }
      
   if(maskDataStatus == OSSIM_FULL)
   {
      theTile->makeBlank();
      
      return theTile;
   }
   
   ossim_uint32 maskBands  = maskSourceData->getNumberOfBands();
   ossim_uint32 inputBands = imageSourceData->getNumberOfBands();
   if(maskBands&&inputBands)
   {
      ossim_uint32 maxOffset = theTile->getWidth()*theTile->getHeight();
      for(ossim_uint32 band = 0; band < inputBands; ++band)
      {
         maskT*    bufMask = (maskT*)maskSourceData->getBuf();
         inputT* bufIn     = (inputT*)imageSourceData->getBuf(band);
         inputT* bufOut    = (inputT*)theTile->getBuf(band);
         inputT  np        = (inputT)theTile->getNullPix(band);
         ossim_uint32 offset = 0;
         for(offset = 0; offset < maxOffset; ++offset)
         {
            if(!*bufMask)
            {
               *bufOut = *bufIn;
            }
            else
            {
               *bufOut = np;
            }
            ++bufOut;
            ++bufIn;
            ++bufMask;
         }
      }
      theTile->validate();
   }
   
   return theTile;
}
예제 #2
0
void ossimEdgeFilter::runLocalMax8Filter(T /* dummyVariable */,
                                         ossimRefPtr<ossimImageData> inputData)
{
   ossim_uint32 bandIdx = 0;
   ossim_uint32 numberOfBands = inputData->getNumberOfBands();
  
   ossim_uint32 x = 0;
   ossim_uint32 y = 0;
   ossim_uint32 width  = theTile->getWidth();
   ossim_uint32 height = theTile->getHeight();
   ossim_int32 rowIncrement  = inputData->getWidth();
   ossim_int32 rowIncrement2 = 2*inputData->getWidth(); 
         
   for(bandIdx = 0; bandIdx < numberOfBands; ++bandIdx)
   {
      //inputBuf has a 1 pixel edge compared to outputBuf
      T* inputBuf  = static_cast<T*>(inputData->getBuf(bandIdx));
      T* outputBuf = static_cast<T*>(theTile->getBuf(bandIdx));
      T np         = static_cast<T>(inputData->getNullPix(bandIdx)); //changed to input Null            

      if(inputBuf&&outputBuf)
      {
         //one pass: maybe faster if changed to two passes
         T* outB;
         T* inB;
         
      	outB = outputBuf;         
         inB  = inputBuf;         
         for(y = 0; y < height; ++y)
         {
            for(x = 0; x < width; ++x)
            {
               if (inB[1+rowIncrement] != np)
               {
                  *outB = max<T>(
                           max<T>(
                            max<T>(inB[0],inB[1]),
                            max<T>(inB[2],inB[rowIncrement])),
                           max<T>(
                            max<T>(inB[rowIncrement+2],inB[rowIncrement2]),
                            max<T>(inB[rowIncrement2+1],inB[rowIncrement2+2])
                            ));
               }
               else
               {
                  *outB = np;
               }
               ++outB;
               ++inB;
            }
            inB+=2; //go to next line, jump due to edge
         }       
      }      
   }
   theTile->validate();
}
ossim_uint32 ossimMultiResLevelHistogram::getNumberOfBands(ossim_uint32 resLevel) const
{
   const ossimRefPtr<ossimMultiBandHistogram> h = getMultiBandHistogram(resLevel);
   if (h.valid())
   {
      return h->getNumberOfBands();
   }

   return 0;
}  
void ossimQtScrollingImageWidget::fillImage(ossimRefPtr<ossimImageData>& data,
                                            QImage* tempImage)
{
   if(data.valid() && data->getBuf() && !tempImage->isNull())
   {
      ossim_uint8* buf[3];
      int numberOfBands = data->getNumberOfBands();
      int aWidth        = tempImage->size().width();
      int aHeight       = tempImage->size().height();
      int maxPixels     = aWidth*aHeight;
      int offset;
      
      if(numberOfBands >= 3)
      {
         buf[0] = static_cast<ossim_uint8*>(data->getBuf(0));
         buf[1] = static_cast<ossim_uint8*>(data->getBuf(1));
         buf[2] = static_cast<ossim_uint8*>(data->getBuf(2));
      }
      else 
      {
         buf[0] = static_cast<ossim_uint8*>(data->getBuf(0));
         buf[1] = static_cast<ossim_uint8*>(data->getBuf(0));
         buf[2] = static_cast<ossim_uint8*>(data->getBuf(0));
      }
      QRgb *bits = (QRgb*)tempImage->bits();
      if(tempImage->bits())
      {
         for(offset = 0; offset < maxPixels;++offset)
         {
            *bits = qRgb(*buf[0], *buf[1], *buf[2]);
            ++buf[0];++buf[1];++buf[2];
            ++bits;
         }
      }
      else
      {
         tempImage->fill(0);
      }
   }
   else
   {
      tempImage->fill(0);
   }
}
예제 #5
0
void ossimFftFilter::runFft(ossimRefPtr<ossimImageData>& input,
                            ossimRefPtr<ossimImageData>& output)
{

   NEWMAT::Matrix* realIn = new NEWMAT::Matrix(input->getHeight(),
                                               input->getWidth());
   NEWMAT::Matrix* imgIn = new NEWMAT::Matrix(input->getHeight(),
                                              input->getWidth());
   NEWMAT::Matrix* realOut = new NEWMAT::Matrix(input->getHeight(),
                                                input->getWidth());
   NEWMAT::Matrix* imgOut = new NEWMAT::Matrix(input->getHeight(),
                                               input->getWidth());
   ossim_uint32 bandIdx = 0;
   ossim_uint32 w = input->getWidth();
   ossim_uint32 h = input->getHeight();
   ossim_uint32 x = 0;
   ossim_uint32 y = 0;
   if(theDirectionType == FORWARD)
   {
      ossim_uint32 bands = input->getNumberOfBands();
      for(bandIdx = 0; bandIdx < bands; ++bandIdx)
      {
         ossim_float64* bandReal = 0;
         ossim_float64* bandImg  = 0;
         fillMatrixForward((ossim_float64*)input->getBuf(bandIdx),
                           (ossim_float64)input->getNullPix(bandIdx),
                           *realIn,
                           *imgIn);
         NEWMAT::FFT2(*realIn, *imgIn, *realOut, *imgOut);
         bandReal = (ossim_float64*)output->getBuf(2*bandIdx);
         bandImg  = (ossim_float64*)output->getBuf(2*bandIdx + 1);
         if(bandReal&&bandImg)
         {
            for(y = 0; y < h; ++y)
            {
               for(x = 0; x < w; ++x)
               {
                  *bandReal = (ossim_float64)((*realOut)[y][x]);
                  *bandImg  = (ossim_float64)((*imgOut)[y][x]);
                  ++bandReal;
                  ++bandImg;
               }
            }
         }
      }
   }
   else
   {
      ossim_float64* bandReal = 0;
      ossim_uint32 bands = input->getNumberOfBands();
      for(bandIdx = 0; bandIdx < bands; bandIdx+=2)
      {
         bandReal = (ossim_float64*)output->getBuf(bandIdx/2);
         if(input->getBuf(bandIdx)&&
            input->getBuf(bandIdx+1))
         {
            fillMatrixInverse((double*)input->getBuf(bandIdx),
                              (double*)input->getBuf(bandIdx+1),
                              *realIn,
                              *imgIn);
            NEWMAT::FFT2I(*realIn, *imgIn, *realOut, *imgOut);
            for(y = 0; y < h; ++y)
            {
               for(x = 0; x < w; ++x)
               {
                  *bandReal = (ossim_float64)((*realOut)[y][x]);
//                  if(*bandReal > 1.0)
//                  {
//                     *bandReal = 1.0;
//                  }
//                  if(*bandReal < 0.0)
//                  {
//                     *bandReal = 0.0;
//                  }
                  ++bandReal;
               }
            }
         }
      }
   }
   
   delete realIn;
   delete imgIn;
   delete realOut;
   delete imgOut;
}
ossimRefPtr<ossimImageData> ossimHistogramEqualization::runEqualizationAlgorithm(T, ossimRefPtr<ossimImageData> tile)
{
   
   if(!theAccumulationHistogram ||
      !getHistogram())
   {
      return tile;
   }

   // for now we will always pull from res 0 information
   ossimRefPtr<ossimMultiBandHistogram> histo = getHistogram()->getMultiBandHistogram(0);

   if(histo.valid())
   {
      ossim_uint32 maxBands = ( (histo->getNumberOfBands() >
                                 tile->getNumberOfBands())?
                                tile->getNumberOfBands():
                                histo->getNumberOfBands());
      
      long offsetUpperBound = tile->getHeight()*tile->getWidth();

      for(ossim_uint32 band = 0; band < maxBands; ++band)
      {
         ossimRefPtr<ossimHistogram> bandHisto = histo->getHistogram(band);
         T* buf = static_cast<T*>(tile->getBuf(band));
         double *histoLut = band<theForwardLut.size()?theForwardLut[band]:NULL;
         ossim_uint32 actualBand = theBandList[band];
         if(bandHisto.valid())
         {
            if(buf&&histoLut&&(actualBand <  histo->getNumberOfBands()))
            {
               if(theInverseFlag)
               {
                  histoLut = theInverseLut[actualBand];
               }
               if(histoLut)
               {
                  if(tile->getDataObjectStatus() == OSSIM_FULL)
                  {
                     T minPix = (T)tile->getMinPix(actualBand);
                     T maxPix = (T)tile->getMaxPix(actualBand);
                     for(long offset = 0; offset < offsetUpperBound; ++offset)
                     {
                        ossim_int32 idx = bandHisto->GetIndex(buf[offset]);
                           
                        if(idx>=0)
                        {
                           T value = (T)(histoLut[idx]);

                           //---
                           // Assign clamping to min max.
                           // 
                           // ESH 03/2009 -- Clamping to within min-max fixed
                           //--- 
                           buf[offset] = value < minPix ? minPix :
                              (value > maxPix ? maxPix : value);
                        }
                     }
                  }
                  else
                  {
                     T minPix  = (T)tile->getMinPix(actualBand);
                     T maxPix  = (T)tile->getMaxPix(actualBand);
                     T nullPix = (T)tile->getNullPix(actualBand);
                     for(long offset = 0; offset < offsetUpperBound; ++offset)
                     {
                        ossim_int32 idx = bandHisto->GetIndex(buf[offset]);
                        
                        if((buf[offset]!=nullPix)&&(idx>=0))
                        {
                           T value = (T)(histoLut[idx]);

                           //---
                           // Assign clamping to min max.
                           // 
                           // ESH 03/2009 -- Clamping to within min-max fixed
                           //--- 
                           buf[offset] = value < minPix ? minPix :
                              (value > maxPix ? maxPix : value);
                        }
                        else
                        {
                           buf[offset] = nullPix;
                        }
                     }
                  }
               }
            }
         }
      }
      
      tile->validate();
   }
   
   return tile;
}
template<class T> void ossimCFARFilter::convolveFull(
   T,
   ossimRefPtr<ossimImageData> inputData,
   ossimRefPtr<ossimImageData> outputData)
{
   // let's set up some temporary variables so we don't
   // have to call the functions in loops.  Iknow that compilers
   // typically optimize this out but if we are in debug mode 
   // with no optimization it will still run fast
   //
   double sum = 0.0,sqrsum = 0.0,variance = 0.0;
   ossim_int32 inputW = static_cast<ossim_int32>(inputData->getWidth());
   ossim_uint32 outputW       = outputData->getWidth();
   ossim_uint32 outputH       = outputData->getHeight();
   ossim_uint32 numberOfBands = inputData->getNumberOfBands();
   ossimIpt outputOrigin = outputData->getOrigin();
   ossimIpt inputOrigin  = inputData->getOrigin();
   
   ossim_int32 startInputOffset = std::abs(outputOrigin.y - inputOrigin.y)*
      inputW + std::abs(outputOrigin.x - inputOrigin.x);
   
   ossim_int32 ulKernelStart    = -(2*inputW) - 2;
   ossim_int32 ul1KernelStart    = -inputW - 1;
   ossim_int32 leftKernelStart  = -2;
   ossim_int32 ll1KernelStart    = inputW  - 1;
   ossim_int32 llKernelStart    = (2*inputW)  - 2;
   
   //populate kernel offset indices
   
   ossim_int32 KernelStart[BOXSIZE];
   T* KernelStartBuf[BOXSIZE];
   
   for(ossim_uint16 i=0;i<BOXSIZE;i++)
   {
   	int offset = i-(BOXSIZE/2);
   	KernelStart[i] = offset*inputW + offset;
   	KernelStartBuf[i] = NULL;
   }
   
   T* ulKernelStartBuf   = NULL;
   T* ul1KernelStartBuf   = NULL;
   T* leftKernelStartBuf = NULL;
   T* ll1KernelStartBuf   = NULL;   
   T* llKernelStartBuf   = NULL;
   
   for(ossim_uint32 band = 0; band < numberOfBands; ++band)
   {
      T* inputBuf  = static_cast<T*>(inputData->getBuf(band))+startInputOffset;
      T* outputBuf = static_cast<T*>(outputData->getBuf(band));
      T maxPix     = static_cast<T>(getMaxPixelValue(band));
      T minPix     = static_cast<T>(getMinPixelValue(band));
      
      if(inputBuf&&outputBuf)
      {
         for(ossim_uint32 row = 0; row < outputW; ++row)
         {
            ossim_int32 rowOffset    = inputW*row;
            ulKernelStartBuf   = inputBuf + (rowOffset + ulKernelStart);
            ul1KernelStartBuf   = inputBuf + (rowOffset + ul1KernelStart);
            leftKernelStartBuf = inputBuf + (rowOffset + leftKernelStart);
            ll1KernelStartBuf   = inputBuf + (rowOffset + ll1KernelStart);
            llKernelStartBuf   = inputBuf + (rowOffset + llKernelStart);
            
            for(ossim_uint16 i=0;i<BOXSIZE;i++)
            {
            	KernelStartBuf[i] = inputBuf + (rowOffset + KernelStart[i]);
            }
            
            for(ossim_uint32 col = 0; col < outputH; ++col)
            {
            	//calculate mean
            	sum = 0.0;
            	sqrsum = 0.0;
            	
            	for(ossim_uint32 r=0; r<5; ++r)
            		sum += theKernel[0][r]*(double)ulKernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sum += theKernel[1][r]*(double)ul1KernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sum += theKernel[2][r]*(double)leftKernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sum += theKernel[3][r]*(double)ll1KernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sum += theKernel[4][r]*(double)llKernelStartBuf[r];
            	/*
            	for(ossim_uint16 i=0;i<BOXSIZE;i++)
	   	      {
	   	         for(ossim_uint32 r=0; r<5; ++r)
	   	         {
							sum += theKernel[i][r]*(double)KernelStartBuf[i][r];
							sqrsum += theKernel[i][r]*(double)KernelStartBuf[i][r]
         	   		*(double)KernelStartBuf[i][r];
         	   	}
   	      	}
   	      	*/
            	
            	//calculate mean of squares
            	
            	for(ossim_uint32 r=0; r<5; ++r)
            		sqrsum += theKernel[0][r]*(double)ulKernelStartBuf[r]
            		*(double)ulKernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sqrsum += theKernel[1][r]*(double)ul1KernelStartBuf[r]
            		*(double)ul1KernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sqrsum += theKernel[2][r]*(double)leftKernelStartBuf[r]
            		*(double)leftKernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sqrsum += theKernel[3][r]*(double)ll1KernelStartBuf[r]
            		*(double)ll1KernelStartBuf[r];
            	for(ossim_uint32 r=0; r<5; ++r)
            		sqrsum += theKernel[4][r]*(double)llKernelStartBuf[r]
            		*(double)llKernelStartBuf[r];
					
					//calculate variance
					variance = sqrsum - (sum*sum);
					
					//calculate k-value
					sum = ((double)leftKernelStartBuf[2] - sum)/sqrt(variance);
					
					//Threshold k-value
					if(sum < theThreshold)
						sum = minPix;
					else
						sum = maxPix;
					
					/*            
               sum = theKernel[0][0]*(double)ulKernelStartBuf[0] +
                     theKernel[0][1]*(double)ulKernelStartBuf[1] +
                     theKernel[0][2]*(double)ulKernelStartBuf[2] +
                     theKernel[1][0]*(double)leftKernelStartBuf[0] +
                     theKernel[1][1]*(double)leftKernelStartBuf[1] +
                     theKernel[1][2]*(double)leftKernelStartBuf[2] +
                     theKernel[2][0]*(double)llKernelStartBuf[0] +
                     theKernel[2][1]*(double)llKernelStartBuf[1] +
                     theKernel[2][2]*(double)llKernelStartBuf[2];
               */
               if(sum > maxPix)
               {
                  *outputBuf = maxPix;
               }
               else if(sum < minPix)
               {
                  *outputBuf = minPix;
               }
               else
               {
                  *outputBuf = static_cast<T>(sum);
               }
               //
               // Need to implement the convolution here.
               //

               
               ++ulKernelStartBuf;
               ++ul1KernelStartBuf;
               ++leftKernelStartBuf;
               ++ll1KernelStartBuf;
               ++llKernelStartBuf;
               ++outputBuf;
            }
         }
      }
   }
}
예제 #8
0
void ossimEdgeFilter::runLaplacianFilter(T /* dummyVariable */,
                                         ossimRefPtr<ossimImageData> inputData)
{
   ossim_uint32 bandIdx = 0;
   ossim_uint32 numberOfBands = inputData->getNumberOfBands();
   // double horizontalValue = 0.0;
   // double verticalValue = 0.0;
   double value = 0.0;
   // ossim_uint32 valueIdx = 0;
   ossim_uint32 x = 0;
   ossim_uint32 y = 0;
   ossim_uint32 width  = theTile->getWidth();
   ossim_uint32 height = theTile->getHeight();
   ossim_int32 rowIncrement  = inputData->getWidth();
   ossim_int32 rowIncrement2 = 2*inputData->getWidth();
   
   for(bandIdx = 0; bandIdx < numberOfBands; ++bandIdx)
   {
      T* inputBuf  = static_cast<T*>(inputData->getBuf(bandIdx));
      T* outputBuf = static_cast<T*>(theTile->getBuf(bandIdx));
      T np         = static_cast<T>(theTile->getNullPix(bandIdx));
      T minP       = static_cast<T>(theTile->getMinPix(bandIdx));
      T maxP       = static_cast<T>(theTile->getMaxPix(bandIdx));

      if(inputBuf&&outputBuf)
      {
         for(y = 0; y < height; ++y)
         {
            for(x = 0; x < width; ++x)
            {
               if( (*(inputBuf + rowIncrement + 1) != np))
               {
                  
                  value = fabs(((double)inputBuf[rowIncrement + 1]*4.0) -
                               ((double)inputBuf[1] + (double)inputBuf[rowIncrement] + (double)inputBuf[rowIncrement + 2] + (double)inputBuf[rowIncrement2+1]));

                  if((value == np) ||
                     (value < minP))
                  {
                     *outputBuf = (static_cast<T>(minP));
                  }
                  else if(value > maxP)
                  {
                     *outputBuf = (static_cast<T>(maxP));
                  }
                  else
                  {
                     *outputBuf = (static_cast<T>(value));
                  }
                  
               }
               else
               {
                  *outputBuf = np;
               }
               ++outputBuf;
               ++inputBuf;
            }
            inputBuf+=2;
         }
      }
   }
   theTile->validate();
}
예제 #9
0
void ossimEdgeFilter::runRobertsFilter(T /* dummyVariable */,
                                       ossimRefPtr<ossimImageData> inputData)
{
   ossim_uint32 bandIdx = 0;
   ossim_uint32 numberOfBands = inputData->getNumberOfBands();
   double v1 = 0.0;
   double v2 = 0.0;
   double value = 0.0;
   // ossim_uint32 valueIdx = 0;
   ossim_uint32 x = 0;
   ossim_uint32 y = 0;
   ossim_uint32 width  = theTile->getWidth();
   ossim_uint32 height = theTile->getHeight();
   ossim_int32 rowIncrement  = inputData->getWidth();
   
   for(bandIdx = 0; bandIdx < numberOfBands; ++bandIdx)
   {
      T* inputBuf  = static_cast<T*>(inputData->getBuf(bandIdx));
      T* outputBuf = static_cast<T*>(theTile->getBuf(bandIdx));
      T np         = static_cast<T>(theTile->getNullPix(bandIdx));
      T minP       = static_cast<T>(theTile->getMinPix(bandIdx));
      T maxP       = static_cast<T>(theTile->getMaxPix(bandIdx));

      if(inputBuf&&outputBuf)
      {
         for(y = 0; y < height; ++y)
         {
            for(x = 0; x < width; ++x)
            {
               if( (*inputBuf) != np)
               {
                  v1 = (double)inputBuf[0] - (double)(inputBuf[rowIncrement+1]);

                  v2   = (double)inputBuf[1] - (double)inputBuf[rowIncrement];
                  
                  value = sqrt(v1*v1 +  v2*v2);

                  if((value == np) ||
                     (value < minP))
                  {
                     *outputBuf = (static_cast<T>(minP));
                  }
                  else if(value > maxP)
                  {
                     *outputBuf = (static_cast<T>(maxP));
                  }
                  else
                  {
                     *outputBuf = (static_cast<T>(value));
                  }
                  
               }
               else
               {
                  *outputBuf = np;
               }
               ++outputBuf;
               ++inputBuf;
            }
            ++inputBuf;
         }
      }
   }
   theTile->validate();
}
예제 #10
0
ossimRefPtr<ossimImageData> ossimMaskFilter::executeMaskFilterWeighted(
   inputT /* dummyInput */,
   maskT  /* dummyMask */,
   ossimRefPtr<ossimImageData> imageSourceData,
   ossimRefPtr<ossimImageData> maskSourceData)
{
   ossimDataObjectStatus maskDataStatus  = maskSourceData->getDataObjectStatus();
   ossimDataObjectStatus inputDataStatus = imageSourceData->getDataObjectStatus();

   if( (maskDataStatus == OSSIM_NULL)||
       (maskDataStatus == OSSIM_EMPTY))
   {
      theTile->makeBlank();
      return theTile;
      
   }
   if( (inputDataStatus == OSSIM_NULL)||
       (inputDataStatus == OSSIM_EMPTY))
   {
      return theTile;
   }
   
   ossim_uint32 maskBands  = maskSourceData->getNumberOfBands();
   ossim_uint32 inputBands = imageSourceData->getNumberOfBands();
   if(maskBands&&inputBands)
   {
      ossim_uint32 maxOffset = theTile->getWidth()*theTile->getHeight();
      for(ossim_uint32 band = 0; band < inputBands; ++band)
      {
         maskT*    bufMask = (maskT*)maskSourceData->getBuf();
         inputT* bufIn     = (inputT*)imageSourceData->getBuf(band);
         inputT* bufOut    = (inputT*)theTile->getBuf(band);
         inputT  np        = (inputT)theTile->getNullPix(band);
         inputT  minp      = (inputT)theTile->getMinPix(band);
         ossim_uint32 offset = 0;

         if(inputDataStatus == OSSIM_PARTIAL)
         {
            for(offset = 0; offset < maxOffset; ++offset)
            {
               if(*bufIn != np)
               {
                  *bufOut = (inputT)((*bufIn)*((double)(*bufMask)/255.0));
                  if((*bufOut != np)&&
                     (*bufOut < minp))
                  {
                     *bufOut = minp;
                  }
               }
               else
               {
                  *bufOut = np;
               }
               ++bufOut;
               ++bufIn;
               ++bufMask;
            }
         }
         else
         {
            for(offset = 0; offset < maxOffset; ++offset)
            {
               *bufOut = (inputT)((*bufIn)*((double)(*bufMask)/255.0));
               if((*bufOut != np)&&
                  (*bufOut < minp))
               {
                  *bufOut = minp;
               }
               ++bufOut;
               ++bufIn;
               ++bufMask;
            }
         }
      }
      theTile->validate();
   }
   
   return theTile;
}
예제 #11
0
bool ossimCodecFactory::encodeJpeg( ossim_uint32 quality,
                                    const ossimRefPtr<ossimImageData>& in,
                                    std::vector<ossim_uint8>& out ) const
{
   bool result = false;

   if ( in.valid() && (in->getDataObjectStatus() != OSSIM_NULL) )
   {
      if ( in->getScalarType() == OSSIM_UINT8 )
      {
         // Open a memory stream up to put the jpeg image in memory:
         std::stringstream jpegStreamBuf;
         
         //---
         // Initialize JPEG compression library:
         // NOTE: JDIMENSION is an "unsigned int"
         //---
         struct jpeg_compress_struct cinfo;
         struct jpeg_error_mgr jerr;
         cinfo.err = jpeg_std_error( &jerr );
         jpeg_create_compress(&cinfo);
      
         // Define a custom stream destination manager for jpeglib to write compressed block:
         jpeg_cpp_stream_dest(&cinfo, jpegStreamBuf);
      
         /* Setting the parameters of the output file here */
         cinfo.image_width = in->getWidth();
         cinfo.image_height = in->getHeight();
   
         // Bands must be one or three for this writer.
         const ossim_uint32 INPUT_BANDS = in->getNumberOfBands();
         if ( (INPUT_BANDS == 1) || (INPUT_BANDS == 3) )
         {
            cinfo.input_components = INPUT_BANDS;
         }
         else
         {
            if ( INPUT_BANDS < 3 )
            {
               cinfo.input_components = 1; // Use first band.
            }
            else
            {
               cinfo.input_components = 3; // Use the first 3 bands.
            }
         }
      
         // colorspace of input image 
         if ( cinfo.input_components == 3)
         {
            cinfo.in_color_space = JCS_RGB;
         }
         else
         {
            cinfo.in_color_space = JCS_GRAYSCALE;
         }
      
         // Default compression parameters, we shouldn't be worried about these.
         jpeg_set_defaults( &cinfo );
      
         jpeg_set_quality(&cinfo, quality, TRUE); //limit to baseline-JPEG values
      
         // Now do the compression...
         jpeg_start_compress( &cinfo, TRUE );
      
         // Line buffer:
         ossim_uint32 buf_size = cinfo.input_components*cinfo.image_width;
         std::vector<ossim_uint8> buf(buf_size);
      
         // Compress the tile on line at a time:
      
         JSAMPROW row_pointer[1]; // Pointer to a single row.
         row_pointer[0] = (JSAMPLE*)&buf.front();

         // Get pointers to the input data:
         std::vector<const ossim_uint8*> inBuf(cinfo.input_components);
         for ( ossim_int32 band = 0; band < cinfo.input_components; ++band )
         {
            inBuf[band] = in->getUcharBuf(band);
         }

         ossim_uint32 inIdx = 0;
         for (ossim_uint32 line=0; line< cinfo.image_height; ++line)
         {
            // Convert from band sequential to band interleaved by pixel.
            ossim_uint32 outIdx = 0;
            for ( ossim_uint32 p = 0; p < cinfo.image_width; ++p )
            {
               for ( ossim_int32 band = 0; band < cinfo.input_components; ++band )
               {
                  buf[outIdx++] = inBuf[band][inIdx];
               }
               ++inIdx;
            }

            // Write it...
            jpeg_write_scanlines( &cinfo, row_pointer, 1 );
         }
      
         // Similar to read file, clean up after we're done compressing.
         jpeg_finish_compress( &cinfo );
         jpeg_destroy_compress( &cinfo );

         // Copy the memory stream to output vector.
         out.resize(jpegStreamBuf.str().size());
         jpegStreamBuf.seekg(0, std::ios_base::beg);
         jpegStreamBuf.read((char*)&out.front(), jpegStreamBuf.str().size());

         result = true;
      }
      else // Scalar type check...
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << "ossimCodecFactory::encodeJpeg ERROR:"
            << "\nPassing non-eight bit data to eight bit encoder!" << std::endl;
      }
      
   } // Matches: if ( in.valid() ... )
   
   return result;
}
void ossimTileToIplFilter::CopyIplImageToTile(T dummyVariable, ossimRefPtr<ossimImageData> inputTile, IplImage *output)
{
    // Determine if tile is full or partially filled
    ossimDataObjectStatus status = inputTile->getDataObjectStatus();

    uchar *outputData = (uchar *)output->imageData;
    int outputStep = output->widthStep/sizeof(uchar);

    int pixVal;
    long outputOffset = 0;

    T maxPix = static_cast<T>(getMaxPixelValue(0));
    T minPix = static_cast<T>(getMinPixelValue(0));
    T np = static_cast<T>(inputTile->getNullPix(0));

    if (status == OSSIM_PARTIAL)
    {
        for (ossim_uint32 bandIdx = 0; bandIdx < inputTile->getNumberOfBands(); ++bandIdx)
        {
            T* outBuf = static_cast<T*>(inputTile->getBuf(bandIdx));

            if (outBuf)
            {
                outputOffset = 0;
                for (long y = 0; y < output->height; ++y)
                {
                    for (long x = 0; x < output->width; ++x)
                    {
                        if (!inputTile->isNull(outputOffset))
                        {
                            pixVal = (int)round(outputData[y * outputStep + x]);

                            if (pixVal > maxPix)
                                *outBuf = maxPix;
                            else if (pixVal < 0)
                                *outBuf = minPix;
                            else
                                *outBuf = static_cast<T>(pixVal);
                        }
                        else
                            inputTile->setNull(outputOffset);

                        ++outBuf;
                        ++outputOffset;
                    }
                }
            }
        }
    }
    else
    {
        for (ossim_uint32 bandIdx = 0; bandIdx < inputTile->getNumberOfBands(); ++bandIdx)
        {
            T* outBuf = (T*)(inputTile->getBuf(bandIdx));

            if (outBuf)
            {
                for (int y = 0; y < output->height; ++y)
                {
                    for (int x = 0; x < output->width; ++x)
                    {
                        pixVal = (int)round(outputData[y * outputStep + x]);

                        if (pixVal > maxPix)
                            *outBuf = (maxPix);
                        else if (pixVal < 0)
                            *outBuf = (minPix);
                        else
                            *outBuf = static_cast<T>(pixVal);

                        // Increment the output buffer to the next pixel value
                        ++outBuf;
                    }
                }
            }
            else
                *outBuf = np;
        }
    }
}