Ejemplo n.º 1
0
VImage VImageManager::vtimestep( VAttrList list, VImage dest, int step )
{
	VFillImage( dest, VAllBands, 0 );
	VPointer src_pp = NULL;
	VPointer dest_pp = NULL;
	VAttrListPosn posn;
	VShort *ptr1 = NULL;
	VShort *ptr2 = NULL;
	VString str;
	VImage src;

	int n = 0;
	int npixels = 0;

	bool revert = false;

	for ( VFirstAttr ( list, & posn ); VAttrExists ( & posn ); VNextAttr ( & posn ) ) {
		if ( VGetAttrRepn ( & posn ) != VImageRepn )
			continue;

		VGetAttrValue ( &posn, NULL, VImageRepn, &src );

		if ( VPixelRepn( src ) != VShortRepn )
			continue;


		if ( ( VGetAttr ( VImageAttrList ( src ), "MPIL_vista_0", NULL,
						  VStringRepn, ( VPointer ) & str ) != VAttrFound ) &&
			 ( VGetAttr ( VImageAttrList ( src ), "repetition_time", NULL,
						  VStringRepn, ( VPointer ) & str ) != VAttrFound ) )
			continue;


		/* doch nicht rumdrehen!
		   if (VGetAttr (VImageAttrList (src), "extent", NULL,
		   VStringRepn, (VPointer) & str) != VAttrFound)
		   revert = true;
		*/

		if ( n == 0 )
			VCopyImageAttrs ( src, dest );

		if ( VImageNRows( src ) > 1 ) {
			if ( VSelectBand ( "vtimestep", src, step, &npixels, &src_pp ) == FALSE )
				VError( "err reading data" );

			int destBand = ( revert ) ? VImageNBands( dest ) - n - 1 : n;

			dest_pp = VPixelPtr( dest, destBand, 0, 0 );

			ptr1 = ( VShort * ) src_pp;
			ptr2 = ( VShort * ) dest_pp;
			memcpy ( ptr2, ptr1, npixels * sizeof( VShort ) );
		}

		n++;
	}

	return dest;
}
Ejemplo n.º 2
0
VBoolean VImageStats(VImage src, VBand band, VDouble *pmin, VDouble *pmax,
		      VDouble *pmean, VDouble *pvar)
{
    int npixels, i;
    VPointer first_pixel;
    VDouble pixel, tmin, tmax, tmean, tvar;

    /* Prepare to iterate over the specified band(s) of source pixels: */
    if (! VSelectBand ("VImageStats", src, band, & npixels, & first_pixel))
	return FALSE;

    /* Initialize accumulators: */
    tmin = tmax = tmean = tvar = 0.0;

    /* Tally pixels: */
    switch (VPixelRepn (src)) {
    case VBitRepn:	TallyStats (VBit); break;
    case VUByteRepn:	TallyStats (VUByte); break;
    case VSByteRepn:	TallyStats (VSByte); break;
    case VShortRepn:	TallyStats (VShort); break;
    case VLongRepn:	TallyStats (VLong); break;
    case VFloatRepn:	TallyStats (VFloat); break;
    case VDoubleRepn:	TallyStats (VDouble); break;
    default:		break;
    }

    /* Compute and return the final results: */
    tmean /= npixels;
    tvar = tvar / npixels - (tmean * tmean);
    if (pmin) *pmin = tmin;
    if (pmax) *pmax = tmax;
    if (pmean) *pmean = tmean;
    if (pvar) *pvar = tvar;
    return TRUE;
}
Ejemplo n.º 3
0
VBoolean VCopyBand (VImage src, VBand src_band, VImage dest, VBand dest_band)
{
  int nbands, src_npixels, dest_npixels;
  VPointer src_pixels, dest_pixels;

  /* The destination image must exist: */
  if (! dest) {
    VWarning ("VCopyBand: No destination specified");
    return FALSE;
  }

  /* VAllBands not accepted for destination band: */
  if (dest_band < 0 || dest_band >= VImageNBands (dest)) {
    VWarning ("VCopyBand: Band %d referenced in image of %d bands",
	      (int) dest_band, (int) VImageNBands (dest));
    return FALSE;
  }

  /* Ensure that the destination image has the appropriate dimensions
     and pixel representation: */
  nbands = dest_band;
  if (src_band == VAllBands)
    nbands += VImageNBands (src) - 1;
  if (nbands < VImageNBands (dest))
    nbands = VImageNBands (dest);
  if (! VSelectDestImage ("VCopyBand", dest, nbands, VImageNRows (src),
			  VImageNColumns (src), VPixelRepn (src)))
    return FALSE;

  /* Locate the specified source and destination bands: */
  if (! VSelectBand ("VCopyBand", src, src_band,
		     & src_npixels, & src_pixels))
    return FALSE;
  if (! VSelectBand ("VCopyBand", dest, dest_band,
		     & dest_npixels, & dest_pixels))
    return FALSE;

  /* Copy from the source band to the destination band: */
  memcpy (dest_pixels, src_pixels, src_npixels * VPixelSize (src));

  return TRUE;
}
Ejemplo n.º 4
0
VBoolean VFillImage (VImage image, VBand band, VDoublePromoted value)
{
  int i, npixels;
  VPointer first_pixel;

#define Fill(type)					\
	{						\
	    type d = value, *pp = first_pixel;		\
	    for (i = npixels; i > 0; i--)		\
		*pp++ = d;				\
	}

  /* Locate the specified band(s) in the image: */
  if (! VSelectBand ("VFillImage", image, band, & npixels, & first_pixel))
    return FALSE;

  /* To avoid surprises when filling integer pixels, round the fill
     value to the nearest integer: */
  if (VIsIntegerRepn (VPixelRepn (image)))
    value += (value > 0.0) ? 0.5 : -0.5;

  /* The memset() routine is probably the fastest way of filling memory, but
     it can only be used here in certain situations. We only check for
     these, the most straightforward of the situations:
     (a) pixel values occupy a byte
     (b) the value to be filled is all 0's
     It is when the value to be filled is all 0's and the pixel
     representation is floating point that we take advantage of the
     assumption that 0.0 is represented as all-bits-zero. */
  if (VPixelSize (image) == 1 || value == 0.0)
    memset (first_pixel, (int) value, npixels * VPixelSize (image));

  /* Otherwise, fill by looping over all pixels: */
  else
    switch (VPixelRepn (image)) {
    case VBitRepn:	Fill (VBit);	break;
    case VUByteRepn:	Fill (VUByte);  break;
    case VSByteRepn:	Fill (VSByte);  break;
    case VShortRepn:	Fill (VShort);  break;
    case VLongRepn:	Fill (VLong);   break;
    case VFloatRepn:	Fill (VFloat);  break;
    case VDoubleRepn:	Fill (VDouble); break;
    default: break;
    }

  return TRUE;
}
Ejemplo n.º 5
0
VImage VCopyImagePixels (VImage src, VImage dest, VBand band)
{
  int npixels;
  VPointer src_pixels;
  VImage result;

  /* Locate the source and destination of the copy: */
  if (! VSelectBand ("VCopyImagePixels", src, band, & npixels, & src_pixels))
    return NULL;
  result = VSelectDestImage ("VCopyImagePixels", dest,
			     band == VAllBands ? VImageNBands (src) : 1,
			     VImageNRows (src), VImageNColumns (src),
			     VPixelRepn (src));
  if (! result)
    return NULL;

  /* Copy pixel values from src to dest: */
  memcpy (VImageData (result), src_pixels, npixels * VPixelSize (src));

  return result;
}