Beispiel #1
0
void ossimRgbImage::setCurrentImageData(ossimRefPtr<ossimImageData>& imageData)
{
   if(imageData.valid())
   {
      if((imageData->getScalarType() == OSSIM_UCHAR)&&
         (imageData->getDataObjectStatus()!=OSSIM_NULL))
      {
         theImageData = imageData;
         initialize();
      }
   }
}
void ossimImageToPlaneNormalFilter::computeNormals(
   ossimRefPtr<ossimImageData>& inputTile,
   ossimRefPtr<ossimImageData>& outputTile)
{
   switch(inputTile->getScalarType())
   {
      case OSSIM_SSHORT16:
      {
         computeNormalsTemplate((ossim_sint16)0,
                                inputTile,
                                outputTile);
         break;
      }
      case OSSIM_UCHAR:
      {
         computeNormalsTemplate((ossim_uint8)0,
                                inputTile,
                                outputTile);
         break;
      }
      case OSSIM_USHORT11:
      case OSSIM_USHORT16:
      {
         computeNormalsTemplate((ossim_uint16)0,
                                inputTile,
                                outputTile);
         break;
      }
      case OSSIM_NORMALIZED_DOUBLE:
      case OSSIM_DOUBLE:
      {
         computeNormalsTemplate((ossim_float64)0,
                                inputTile,
                                outputTile);
         break;
      }
      case OSSIM_NORMALIZED_FLOAT:
      case OSSIM_FLOAT:
      {
         computeNormalsTemplate((ossim_float32)0,
                                inputTile,
                                outputTile);
         break;
      }
      default:
         break;
   }
}
ossimGeoAnnotationBitmap::ossimGeoAnnotationBitmap(
   const ossimGpt& center,
   ossimRefPtr<ossimImageData> imageData,
   unsigned char r,
   unsigned char g,
   unsigned char b)
   :ossimGeoAnnotationObject(r, g, b),
    theCenterPoint(center),
    theProjectedPoint(0,0),
    theImageData(NULL)
{
   if(imageData.valid() &&
      (imageData->getScalarType()==OSSIM_UCHAR))
   {
      theImageData = imageData;
   }
   else
   {
      ossimNotify(ossimNotifyLevel_WARN)
         << "ossimGeoAnnotationBitmap::ossimGeoAnnotationBitmap\n"
         << "Invalid image data passed to ossimGeoAnnotationBitmap "
         << "constructor" << endl;
   }
}
//*****************************************************************************
//  METHOD: ossimHsvGridRemapEngine::remapTile
//  
//*****************************************************************************
void ossimHsvGridRemapEngine::remapTile(const ossimDpt&       origin,
                                        ossimGridRemapSource* remapper,
                                        ossimRefPtr<ossimImageData>& tile)
{
   static const char MODULE[] = "ossimHsvGridRemapEngine::remapTile";
   if (traceExec())  CLOG << "entering..." << endl;

   //***
   // Fetch tile size and NULL pixel value:
   //***
   int    width         = tile->getWidth();
   int    height        = tile->getHeight();
   int    offset        = 0;
   
   void* red_buf = tile->getBuf(0);
   void* grn_buf = tile->getBuf(1);
   void* blu_buf = tile->getBuf(2);

   ossimDblGrid& gridH = *(remapper->getGrid(0));
   ossimDblGrid& gridS = *(remapper->getGrid(1));
   ossimDblGrid& gridV = *(remapper->getGrid(2));
      
   //---
   // Remap according to pixel type:
   //---
   switch(tile->getScalarType())
   {
      case OSSIM_UINT8:
      {
         for (double line=origin.line; line<origin.line+height; line+=1.0)
         {
            for (double samp=origin.samp; samp<origin.samp+width; samp+=1.0)
            {
               //---
               // Fetch pixel from the input tile band buffers and convert
               // to HSV:
               //---
               ossimRgbVector rgb_pixel (((ossim_uint8*)red_buf)[offset],
                                         ((ossim_uint8*)grn_buf)[offset],
                                         ((ossim_uint8*)blu_buf)[offset]);
               ossimHsvVector hsv_pixel (rgb_pixel);
               
               //---
               // Remap pixel HSV  with spatially variant bias value:
               //---
               hsv_pixel.setH(hsv_pixel.getH() + gridH(samp,line));
               hsv_pixel.setS(hsv_pixel.getS() + gridS(samp,line));
               hsv_pixel.setV(hsv_pixel.getV() + gridV(samp,line));
               
               //---
               // Convert back to RGB and write to the tile:
               //---
               rgb_pixel = hsv_pixel;  // auto-clamped
               ((ossim_uint8*)red_buf)[offset] = rgb_pixel.getR();
               ((ossim_uint8*)grn_buf)[offset] = rgb_pixel.getG();
               ((ossim_uint8*)blu_buf)[offset] = rgb_pixel.getB();
               
               offset++;
            }
         }
         break;
      }
      
      case OSSIM_USHORT11:
         break;
         
      case OSSIM_UINT16:
         break;
         
      case OSSIM_SINT16:
         break;	

      case OSSIM_FLOAT64:
         break;	

      case OSSIM_NORMALIZED_DOUBLE:
         break;	

      case OSSIM_FLOAT32:
         break;	

      case OSSIM_NORMALIZED_FLOAT:
         break;	

      case OSSIM_SCALAR_UNKNOWN:
      default:
         break;

   }   // end switch statement

   if (traceExec())  CLOG << "returning..." << endl;
   return;
};
Beispiel #5
0
ossimRefPtr<ossimImageData> ossimMaskFilter::executeMaskFilterWeighted(ossimRefPtr<ossimImageData> imageSourceData,
                                                                       ossimRefPtr<ossimImageData> maskSourceData)
{
   if(maskSourceData->getScalarType() != OSSIM_UCHAR)
   {
      ossimNotify(ossimNotifyLevel_WARN) << "ossimMaskFilter::executeMaskFilterSelect WARNING: Only uchar masks are supported" << endl;
      return imageSourceData;
   }

   switch(imageSourceData->getScalarType())
   {
   case OSSIM_UCHAR:
   {
      executeMaskFilterWeighted((ossim_uint8)0,
                                (ossim_uint8)0,
                                imageSourceData,
                                maskSourceData);
      break;
   }
   case OSSIM_USHORT11:
   case OSSIM_USHORT16:
   {
      executeMaskFilterWeighted((ossim_uint16)0,
                                (ossim_uint8)0,
                                imageSourceData,
                                maskSourceData);
      break;
   }
   case OSSIM_SSHORT16:
   {
      executeMaskFilterWeighted((ossim_sint16)0,
                                (ossim_uint8)0,
                                imageSourceData,
                                maskSourceData);
      break;
   }
   case OSSIM_FLOAT:
   case OSSIM_NORMALIZED_FLOAT:
   {
      executeMaskFilterWeighted((float)0,
                                (ossim_uint8)0,
                                imageSourceData,
                                maskSourceData);
      break;
   }
   case OSSIM_DOUBLE:
   case OSSIM_NORMALIZED_DOUBLE:
   {
      executeMaskFilterWeighted((double)0,
                                (ossim_uint8)0,
                                imageSourceData,
                                maskSourceData);
      break;
   }
   default:
   {
      ossimNotify(ossimNotifyLevel_WARN) << "ossimMaskFilter::executeMaskFilterSelect WARNING: Unknown scalar type" << endl;
      break;
   }   
   }

   return theTile;
}
Beispiel #6
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::CopyTileToIplImage(T dummyVariable, ossimRefPtr<ossimImageData> inputTile, IplImage *output, ossimIrect neighborhoodRect)
{
    ossimDataObjectStatus status = inputTile->getDataObjectStatus();

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

    ossimScalarType inputType = inputTile->getScalarType();
    double scFactor;

    if (inputType == OSSIM_UINT16)
        scFactor = 0.0039; // 255 / 65535
    else if (inputType == OSSIM_USHORT11)
        scFactor = 0.1246; //255 / 2047
    else if (inputType == OSSIM_UINT8)
        scFactor = 1;
    else
        scFactor = 1;

    int pixVal;

    if (status == OSSIM_PARTIAL)
    {
        for( int band = 0; band < outputChannels; band++) {
            T* inBuf = static_cast<T*>(inputTile->getBuf(band));
            for (long y = 0; y < output->height; ++y)
            {
                for (long x = 0; x < output->width; ++x)
                {

                    pixVal = (int)(*inBuf);

                    if ((int)round(pixVal * scFactor) > 255)
                        outputData[y * outputStep + x*outputChannels + band] = 255;
                    else if ((int)round(pixVal * scFactor) < 0)
                        outputData[y * outputStep + x*outputChannels + band] = 0;
                    else
                        outputData[y * outputStep + x*outputChannels + band] = (uchar)round(pixVal * scFactor);

                    ++inBuf;
                }
            }
        }
    }
    else
    {
        for(int band = 0; band < outputChannels; band++) {
            T* inBuf = static_cast<T*>(inputTile->getBuf(band));
            for (int y = 0; y < output->height; ++y)
            {
                for (int x = 0; x < output->width; ++x)
                {
                    pixVal = (int)(*inBuf);

                    if ((int)round(pixVal * scFactor) > 255)
                        outputData[y * outputStep + x*outputChannels + band] = 255;
                    else if ((int)round(pixVal * scFactor) < 0)
                        outputData[y * outputStep + x*outputChannels + band] = 0;
                    else
                        outputData[y * outputStep + x*outputChannels + band] = (uchar)round(pixVal * scFactor);

                    ++inBuf;
                }
            }
        }
    }
}