コード例 #1
0
ファイル: xvgifwr.cpp プロジェクト: msabhijith/dgate
int WriteGIFHeader(FILE *fp, int w, int h, byte *rmap, byte *gmap, byte *bmap,
             int numcols, ColorStyleType colorstyle, char *comment)
{ int   RWidth, RHeight;
  int   LeftOfs, TopOfs;
  int   ColorMapSize;
  int   InitCodeSize, BitsPerPixel;
  int   Background;
  int   i,j;
  int   nc;
  int   Interlace;

  struct GifStore *aGifStore = (struct GifStore *)malloc(sizeof(struct GifStore));
  if (aGifStore==NULL)
  { AVSerror("WriteGIFHeader: out of memory");
    return AVS_ERROR;
  }
  memset(aGifStore, 0, sizeof(struct GifStore));

  Interlace = 0;
  Background = 0;

  for (i=0; i<256; i++)
    aGifStore->pc2nc[i] = aGifStore->r1[i] = aGifStore->g1[i] = aGifStore->b1[i] = 0;

  /* compute number of unique colors */
  nc = 0;

  for (i=0; i<numcols; i++)
  { /* see if color #i is already used */
    for (j=0; j<i; j++)
    { if (rmap[i] == rmap[j] && gmap[i] == gmap[j] && bmap[i] == bmap[j])
        break;
    }

    if (j==i)    /* wasn't found */
    { aGifStore->pc2nc[i] = (byte)nc;
      aGifStore->r1[nc] = rmap[i];
      aGifStore->g1[nc] = gmap[i];
      aGifStore->b1[nc] = bmap[i];
      nc++;
    }
    else
      aGifStore->pc2nc[i] = aGifStore->pc2nc[j];
  }

  /* figure out 'BitsPerPixel' */
  for (i=1; i<8; i++)
    if ( (1<<i) >= nc)
      break;

  BitsPerPixel = (char)i;

  ColorMapSize = 1 << BitsPerPixel;

  RWidth  = w;
  RHeight = h;
  LeftOfs = TopOfs = 0;

  if (BitsPerPixel <= 1) InitCodeSize = 2;
                    else InitCodeSize = BitsPerPixel;

  if (!fp)
  { AVSerror("WriteGIFHeader: file not open for writing");
    free(aGifStore);
    return AVS_ERROR;
  }

  fwrite("GIF89a", (size_t) 1, (size_t) 6, fp);    /* the GIF magic number */

  putword2(RWidth, fp);           /* screen descriptor */
  putword2(RHeight, fp);

  if (colorstyle==csGlobalPalette)
  { i = 0x80;	                   /* Yes, there is a color map */
    i |= (8-1)<<4;                 /* OR in the color resolution (hardwired 8) */
    i |= (BitsPerPixel - 1);       /* OR in the # of bits per pixel */
  }
  else
    i = 0;
  fputc(i,fp);

  fputc(Background, fp);         /* background color */

  fputc(0, fp);                  /* future expansion byte */

  if (colorstyle==csGlobalPalette)
    WritePalette(fp, aGifStore, ColorMapSize);
  WriteComment(fp, comment);

  free(aGifStore);

  return AVS_OK;
}
コード例 #2
0
ファイル: xvgifwr.cpp プロジェクト: msabhijith/dgate
int WriteGIFFrame(FILE *fp, byte *p, int w, int h,
                  byte *rmap, byte *gmap, byte *bmap,
                  int numcols,
                  int frames, int time, ColorStyleType colorstyle) // time in 0.01 sec
{ int   RWidth, RHeight;
  int   LeftOfs, TopOfs;
  int   ColorMapSize, InitCodeSize, Background, BitsPerPixel;
  int   i,j,f;
  int   nc;
  byte *pic8;
  int   Interlace;
  int   cmap;

  struct GifStore *aGifStore = (struct GifStore *)malloc(sizeof(struct GifStore));
  if (aGifStore==NULL)
  { AVSerror("WriteGIFFrame: out of memory");
    return AVS_ERROR;
  }
  memset(aGifStore, 0, sizeof(struct GifStore));

  pic8 = p;

  Interlace = 0;
  Background = 0;

  for (i=0; i<256; i++)
    aGifStore->pc2nc[i] = aGifStore->r1[i] = aGifStore->g1[i] = aGifStore->b1[i] = 0;

  /* compute number of unique colors */
  nc = 0;

  for (i=0; i<numcols; i++)
  { /* see if color #i is already used */
    for (j=0; j<i; j++)
    { if (rmap[i] == rmap[j] && gmap[i] == gmap[j] && bmap[i] == bmap[j])
         break;
    }

    if (j==i)    /* wasn't found */
    { aGifStore->pc2nc[i] = (byte)nc;
      aGifStore->r1[nc] = rmap[i];
      aGifStore->g1[nc] = gmap[i];
      aGifStore->b1[nc] = bmap[i];
      nc++;
    }
    else
      aGifStore->pc2nc[i] = aGifStore->pc2nc[j];
  }

  nc = 256;

  /* figure out 'BitsPerPixel' */
  for (i=1; i<8; i++)
    if ( (1<<i) >= nc)
      break;

  BitsPerPixel = i;

  ColorMapSize = 1 << BitsPerPixel;

  RWidth  = w;
  RHeight = h;
  LeftOfs = TopOfs = 0;

  if (BitsPerPixel <= 1) InitCodeSize = 2;
                    else InitCodeSize = BitsPerPixel;

  if (!fp)
  { AVSerror("WriteGIFFrame: file not open for writing");
    free(aGifStore);
    return AVS_ERROR;
  }

  if (frames<1) frames=1;

  for(f=0; f<frames; f++)
  { /* image extension */
    // Graphic Control Extension starts with 21 F9 04
    fputc(0x21, fp); fputc(0xf9, fp); fputc(0x04, fp);
    fputc(0x00, fp);   // no transparency
    putword2(time, fp); // time in 0.01 sec
    fputc(0x00, fp);   // transparent color (not used)
    fputc(0x00, fp);

    fputc( 0x2c, fp );              /* image separator */

    /* Write the Image header */
    putword2(LeftOfs, fp);
    putword2(TopOfs,  fp);
    putword2(RWidth,   fp);
    putword2(RHeight,  fp);

    if (colorstyle==csLocalPalette)
      cmap = 0x80 | 0x07;
    else
      cmap = 0;

    if (Interlace)
      fputc(cmap | 0x40, fp);   /* Use local Colormap, maybe Interlace */
    else
      fputc(cmap | 0x00, fp);

    if (colorstyle==csLocalPalette)
      WritePalette(fp, aGifStore, 256);

    fputc(InitCodeSize, fp);
    compress((char)(InitCodeSize+1), fp, pic8, w*h, aGifStore);
    pic8 += w * h;

    fputc(0,fp);                      /* Write out a Zero-length packet (EOF) */

  };

  /* GIF file terminator (0x3b) should be written in caller*/

  free(aGifStore);
  if (ferror(fp))
    return AVS_ERROR;
  return AVS_OK;
}
コード例 #3
0
ファイル: ucd_Mz.cpp プロジェクト: nixz/covise
/* *****************************************/
int ucd_Mz_compute(UCD_structure *ucd, UCD_structure *grid, UCD_structure **ucd_out, AVSfield_float **trajectories,
                   float *origin_x, float *origin_y, float *origin_z,
                   int cells_x, int cells_y, int cells_z,
                   float *cell_size,
                   char *velocity,
                   int unsteady,
                   char *velocity_file,
                   int strong_hyperbolicity,
                   int ABC_steady,
                   float *start_time,
                   float *integration_time,
                   int time_intervals,
                   int integ_steps_max, int forward, int smoothing_range,
                   int omit_boundary_cells,
                   int grad_neigh_disabled,
                   int execute)
{

    /* ----> START OF USER-SUPPLIED CODE SECTION #3 (COMPUTE ROUTINE BODY)   */

    // system wrapper
    UniSys us;

    if (ucd_findNodeCompByVeclen(ucd, 3, 0) < 0)
    {
        us.error("UCD must contain at least one 3-vect component");
        return 0;
    }

    //if (AVSparameter_changed("mode")) {
    {
        char *cp1, *cp2;

        if (grid)
        {
            AVScommand("kernel", "manipulator \"$Module:origin x\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:origin y\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:origin z\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells x\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells y\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells z\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cell size\" -hide", &cp1, &cp2);
        }
        else
        {
            AVScommand("kernel", "manipulator \"$Module:origin x\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:origin y\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:origin z\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells x\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells y\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells z\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cell size\" -show", &cp1, &cp2);
        }

        if (unsteady)
        {
            AVScommand("kernel", "manipulator \"$Module:velocity file\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:start time\" -show", &cp1, &cp2);
        }
        else
        {
            AVScommand("kernel", "manipulator \"$Module:velocity file\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:start time\" -hide", &cp1, &cp2);
        }
    }

    if (*integration_time <= 0.0)
    {
        us.error("integration time must be larger than zero");
        return 0;
    }

    // input wrapper
    if (AVSinput_changed("ucd", 0))
    {
        if (unst)
            delete unst;
        unst = new Unstructured(ucd);
    }

    // process component choice selection
    int compVelo = ucd_processCompChoice(ucd, "ucd", velocity, "velocity", 3,
                                         unst->getVectorNodeDataComponent());
    if (compVelo >= 0)
        unst->selectVectorNodeData(compVelo);

    // init

    /* Allocate output UCD */
    if (*ucd_out && *ucd_out != ucd)
        UCDstructure_free(*ucd_out);
    UCD_structure *ucd1 = NULL;
    char labels[256] = "Mz.integration time";
    int components[2] = { 1, 1 };
    if (grid)
    {
        ucd1 = ucdClone(grid, 2, components, "ucd out", labels, ".");
    }
    else
    {
        ucd1 = generateUniformUCD("ucd out", *origin_x, *origin_y, *origin_z,
                                  cells_x, cells_y, cells_z,
                                  *cell_size,
                                  2, components,
                                  labels, ".");
    }
    *ucd_out = ucd1;

    // unstructured wrapper for output
    Unstructured *unst_out = new Unstructured(*ucd_out);

    // allocate field for trajectories
    if (*trajectories)
        AVSfield_free((AVSfield *)*trajectories);
    int dims[2];
    dims[0] = integ_steps_max + 1;
    dims[1] = ucd1->nnodes;
    *trajectories = (AVSfield_float *)AVSdata_alloc("field 2D 2-vector irregular 3-space float", dims);
    if (*trajectories == NULL)
    {
        AVSerror("allocation failed");
        return (0);
    }

    // field wrapper for output
    UniField *unif_traj = new UniField((AVSfield *)*trajectories);

    // compute
    if (execute)
    {
        Mz_impl(&us, unst, compVelo, unsteady, velocity_file,
                strong_hyperbolicity,
                ABC_steady,
                *start_time,
                *integration_time,
                time_intervals, integ_steps_max, forward,
                unst_out, smoothing_range,
                omit_boundary_cells, grad_neigh_disabled, unif_traj);

        // ##### work around, because there is a bug in unsetVector3CB()
        if (unst)
            delete unst;
        unst = new Unstructured(ucd);
    }

    // delete unstructured wrapper for output (but not the field)
    delete unst_out;

    // delete field wrapper (but not the field)
    delete unif_traj;

    /* <---- END OF USER-SUPPLIED CODE SECTION #3              */
    return (1);
}