예제 #1
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;
}
예제 #2
0
파일: Option.c 프로젝트: Rollmops/via
void VReportValidOptions (int noptions, VOptionDescRec options[])
{
  int i, j;
  VDictEntry *dict;
  VStringConst cp;

  /* Print a line describing each possible option: */
  for (i = 0; i < noptions; i++, options++) {

    /* Print the name of the option: */
    fprintf (stderr, "    -%s ", options->keyword);

    /* Get a name for the type of value needed: */
    if (VIsIntegerRepn (options->repn))
      cp = "integer";
    else if (VIsFloatPtRepn (options->repn))
      cp = "number";
    else if (options->repn == VBooleanRepn)
      cp = "boolean";
    else cp = "string";

    /* Print possible option values: */
    if (options->dict && options->number == 1) {
      for (dict = options->dict; dict->keyword; dict++) {
	if (dict > options->dict)
	  fputs (" | ", stderr);
	fputs (dict->keyword, stderr);
      }
    } else if (options->repn == VBooleanRepn && options->number == 1) {
      fputs ("[ true | false ]", stderr);
    } else if (options->number <= 1) {
      fprintf (stderr, "<%s>", options->dict ? "keyword" : cp);
      if (options->number == 0)
	fputs (" ...", stderr);
    } else {
      for (j = 1; j <= options->number; j++) {
	if (j > 1)
	  fputc (' ', stderr);
	fprintf (stderr, "<%s%d>", options->dict ? "keyword" : cp, j);
      }
    }
    if (options->dict && options->number != 1) {
      fputs ("\n\t<keyword> is ", stderr);
      for (dict = options->dict; dict->keyword; dict++) {
	if (dict > options->dict)
	  fputs (" | ", stderr);
	fputs (dict->keyword, stderr);
      }
    }
    fputs ("\n\t", stderr);

    /* Print any blurb available, and default value(s): */
    if (options->blurb)
      fprintf (stderr, "%s. ", options->blurb);
    if (options->found == VRequiredOpt)
      fputs ("Required.", stderr);
    else if (options->number > 0) {
      fprintf (stderr, "Default: ");
      VPrintOptionValue (stderr, options);
    }
    fputc ('\n', stderr);
  }
}