Beispiel #1
0
static cairo_test_status_t
intersecting_triangles (cairo_t *cr, int width, int height)
{
    int x, y, channel;

    state = 0x12345678;

    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
    cairo_paint (cr);

#if GENERATE_REFERENCE
    for (x = 0; x < WIDTH; x++) {
	cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.75 / (WIDTH * WIDTH));
	cairo_rectangle (cr, x, 0, 1, HEIGHT);
	cairo_fill (cr);
    }
#else
    cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
    for (channel = 0; channel < 3; channel++) {
	switch (channel) {
	default:
	case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
	case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
	}

	for (x = 0; x < WIDTH; x++) {
	    double step = x / (double) WIDTH;
	    for (y = 0; y < HEIGHT; y++) {
		double dx = random_offset (WIDTH - x, TRUE);
		double dy = random_offset (WIDTH - x, TRUE);

		/* left */
		cairo_move_to (cr, x + dx, y + dy);
		cairo_rel_line_to (cr, 0, step);
		cairo_rel_line_to (cr, step, 0);
		cairo_close_path (cr);

		/* right, mirrored */
		cairo_move_to (cr, x + dx + step, y + dy + step);
		cairo_rel_line_to (cr, 0, -step);
		cairo_rel_line_to (cr, -step, step);
		cairo_close_path (cr);
	    }
	}
	cairo_fill (cr);
    }
#endif

    return CAIRO_TEST_SUCCESS;
}
Beispiel #2
0
char * corrupt_zeros(char * data, size_t * dataSz)
{
  // Choose between zero corruption methods
  //   0. Insert zeros in to the bitstream
  //   1. Replace random bytes with zeros

  int choice = randomInt(0, 1);
  size_t corruptLoc = random_offset(*dataSz);
  size_t corruptSize = randomInt(1, 0x100);

  // we can't corrupt this crap TODO fix this
  if(*dataSz < CORRUPT_START_MIN)
    return data;

  char * replacement = calloc(corruptSize, sizeof(char));
  if(!replacement)
    return data;

  memset(replacement, 0x0, corruptSize);

  if(choice == 0)
  {
    data = insertBytes(data, dataSz, replacement,
                       corruptSize, corruptLoc);
  }
  else if(choice == 1)
  {
    data = replaceBytes(data, dataSz, replacement, 
                        corruptSize, corruptLoc);
  }

  return data;
}
Beispiel #3
0
static cairo_test_status_t
rectangles (cairo_t *cr, int width, int height)
{
    int x, y, channel;

    state = 0x12345678;

    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
    cairo_paint (cr);

#if GENERATE_REFERENCE
    for (x = 0; x < WIDTH; x++) {
	cairo_set_source_rgba (cr, 1, 1, 1, x * x * 1.0 / (WIDTH * WIDTH));
	cairo_rectangle (cr, x, 0, 1, HEIGHT);
	cairo_fill (cr);
    }
#else
    cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
    for (channel = 0; channel < 3; channel++) {
	switch (channel) {
	default:
	case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
	case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
	}

	for (x = 0; x < WIDTH; x++) {
	    for (y = 0; y < HEIGHT; y++) {
		double dx = random_offset (WIDTH - x, TRUE);
		double dy = random_offset (WIDTH - x, TRUE);
		cairo_rectangle (cr, x + dx, y + dy, x / (double) WIDTH, x / (double) WIDTH);
	    }
	}
	cairo_fill (cr);
    }
#endif

    return CAIRO_TEST_SUCCESS;
}
Beispiel #4
0
static cairo_test_status_t
row_triangles (cairo_t *cr, int width, int height)
{
    int x, y, i, channel;

    state = 0x12345678;

    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
    cairo_paint (cr);

#if GENERATE_REFERENCE
    for (x = 0; x < WIDTH; x++) {
	cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / WIDTH);
	cairo_rectangle (cr, x, 0, 1, HEIGHT);
	cairo_fill (cr);
    }
#else
    cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
    for (channel = 0; channel < 3; channel++) {
	switch (channel) {
	default:
	case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
	case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
	}

	for (x = 0; x < WIDTH; x++) {
	    double step = x / (double) (2 * WIDTH);
	    for (y = 0; y < HEIGHT; y++) {
		for (i = 0; i < PRECISION; i++) {
		    double dx = random_offset (WIDTH - x, FALSE);

		    /* See column_triangles() for a transposed description
		     * of this geometry.
		     */

		    cairo_move_to (cr, x + dx, y + i / (double) PRECISION);
		    cairo_rel_line_to (cr,  step, 0);
		    cairo_rel_line_to (cr,  step, 1 / (double) PRECISION);
		    cairo_rel_line_to (cr, -step, 0);
		    cairo_close_path (cr);
		}
		cairo_fill (cr); /* do these per-pixel due to the extra volume of edges */
	    }
	}
    }
#endif

    return CAIRO_TEST_SUCCESS;
}
Beispiel #5
0
char * corrupt_flipsign(char * data, size_t * dataSz)
{
  size_t bitsToFlip = randomInt(0, 20);
  size_t i;

  // Flip the MSB of a random amount of bytes
  
  for(i = 0; i < bitsToFlip; i++)
  {
    size_t off = random_offset(*dataSz);

    // flip the MSB
    data[off] = data[off] ^ 0x80;
  }

  return data;
}
Beispiel #6
0
char * corrupt_bits(char * data, size_t * dataSz)
{
  size_t bitsToCorrupt = randomInt(0, 20);
  size_t i;

  // Flip the MSB of a random amount of bytes
  
  for(i = 0; i < bitsToCorrupt; i++)
  {
    size_t off = random_offset(*dataSz);
    size_t bit = randomInt(0, 7);

    // flip the bit
    data[off] = data[off] ^ (1 << bit);
  }

  return data;
}
Beispiel #7
0
Instruction*
perform_change_rec (Instruction* inst, guint32 change_off, guint* total_len)
{
  if (change_off < inst->length)
    {
      guint32 to_delete = cmd_deletion_length;
      guint32 avail = inst->length;
      guint32 this_delete = MIN (to_delete, avail);
      Instruction* new_inst;

      // One delete
      inst->length -= this_delete;
      to_delete -= this_delete;

      while (to_delete > 0 && inst->next->length < to_delete)
	{
	  to_delete -= inst->next->length;
	  inst->next = inst->next->next;
	}

      if (to_delete > 0)
	inst->next->offset += to_delete;

      // One insert
      new_inst = g_new0 (Instruction, 1);

      new_inst->offset = random_offset (cmd_insertion_length);
      new_inst->length = cmd_insertion_length;
      new_inst->next = inst->next;
      inst->next = new_inst;

      (* total_len) += cmd_insertion_length - cmd_deletion_length;

      return inst;
    }
  else
    {
      inst->next = perform_change_rec (inst->next, change_off - inst->length, total_len);
      return inst;
    }
}
Beispiel #8
0
char * corrupt_edgenum(char * data, size_t * dataSz)
{
  /* Corruptor: Edgenum
   *
   * Goal: tries to add values determined to be the 'edges'
   * of the common data types. Think 0, -1, MAX_INT, MAX_INT-1,
   * etc.
   *
   * This corruptor should only replace, never insert. We want
   * to mess up length fields.
   */

  size_t corruptLoc = random_offset(*dataSz);

  uint32_t corruptVal = randomInt(0, sizeof(corruptVals32) /
                                     sizeof(corruptVals32[0])-1);

  data = insertBytes(data, dataSz, (char *)&corruptVal, 
                     sizeof(uint32_t), corruptLoc);

  return data;
}
Beispiel #9
0
static cairo_test_status_t
column_triangles (cairo_t *cr, int width, int height)
{
    int x, y, i, channel;

    state = 0x12345678;

    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
    cairo_paint (cr);

#if GENERATE_REFERENCE
    for (x = 0; x < WIDTH; x++) {
	cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / WIDTH);
	cairo_rectangle (cr, x, 0, 1, HEIGHT);
	cairo_fill (cr);
    }
#else
    cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
    for (channel = 0; channel < 3; channel++) {
	switch (channel) {
	default:
	case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
	case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
	}

	for (x = 0; x < WIDTH; x++) {
	    double step = x / (double) (2 * WIDTH);
	    for (y = 0; y < HEIGHT; y++) {
		for (i = 0; i < PRECISION; i++) {
		    double dy = random_offset (WIDTH - x, FALSE);

		    /*
		     * We want to test some sharing of edges to further
		     * stress the rasterisers, so instead of using one
		     * tall triangle, it is split into two, with vertical
		     * edges on either side that may co-align with their
		     * neighbours:
		     *
		     *  s ---  .      ---
		     *  t  |   |\      |
		     *  e  |   | \     |
		     *  p ---  ....    |  2 * step = x / WIDTH
		     *          \ |    |
		     *           \|    |
		     *            .   ---
		     *        |---|
		     *     1 / PRECISION
		     *
		     * Each column contains two triangles of width one quantum and
		     * total height of (x / WIDTH), thus the total area covered by all
		     * columns in each pixel is .5 * (x / WIDTH).
		     */

		    cairo_move_to (cr, x + i / (double) PRECISION, y + dy);
		    cairo_rel_line_to (cr, 0, step);
		    cairo_rel_line_to (cr, 1 / (double) PRECISION, step);
		    cairo_rel_line_to (cr, 0, -step);
		    cairo_close_path (cr);
		}
		cairo_fill (cr); /* do these per-pixel due to the extra volume of edges */
	    }
	}
    }
#endif

    return CAIRO_TEST_SUCCESS;
}
Beispiel #10
0
void
test1 (TestProfile *test_profile,
       File        *from_file,
       File        *to_file,
       File        *out_file,
       File        *re_file)
{
  int ret;
  guint i, change, current_size = cmd_size;
  guint end_size = (cmd_changes * cmd_insertion_length) + cmd_size;
  Instruction* inst;
  struct stat sbuf;
  int zlevel_i, slevel_i;

  seed48 (cmd_seed);

  if ((ret = stat (cmd_data_source, & sbuf)))
    {
      perror (cmd_data_source);
      fail ();
    }

  if (! (data_source_handle = fopen (cmd_data_source, "r")))
    {
      perror (cmd_data_source);
      fail ();
    }

  data_source_length = sbuf.st_size;

  /* arbitrary checks */
  if (data_source_length < (1.5 * end_size))
    g_warning ("data source should be longer\n");

  if ((cmd_changes * cmd_deletion_length) > cmd_size)
    {
      g_warning ("no copies are expected\n");
      fail ();
    }

  inst = g_new0 (Instruction, 1);

  inst->offset = random_offset (cmd_size);
  inst->length = cmd_size;

  current_from_size = write_file (from_file, inst);

  for (change = 0; change < cmd_changes; change += 1)
    inst = perform_change (inst, & current_size);

  current_to_size = write_file (to_file, inst);

  for (slevel_i = 0; slevel_i < ARRAY_LENGTH(cmd_slevels); slevel_i += 1)
    {
      int slevel = cmd_slevels[slevel_i];

      if ((test_profile->flags & TEST_IS_XDELTA) == 0 && slevel_i != 0)
	{
	  continue;
	}

      for (zlevel_i = 0; zlevel_i < ARRAY_LENGTH(cmd_zlevels); zlevel_i += 1)
	{
	  int zlevel = cmd_zlevels[zlevel_i];

	  if (test_profile->flags & TEST_IS_GZIP)
	    {
	      if (zlevel != 1 && zlevel != 9)
		continue;
	    }

	  reset_stats ();

	  for (i = 0; i < cmd_warmups + cmd_reps; i += 1)
	    {
	      if (! run_command (test_profile,
				 zlevel,
				 slevel,
				 from_file,
				 to_file,
				 out_file,
				 re_file,
				 (i >= cmd_warmups) /* true => accounting */))
		{
		  fail ();
		}
	    }

	  report (test_profile, zlevel, slevel);
	}

      g_print ("\n");
    }
}
Beispiel #11
0
void vtFence3d::AddFenceMeshes(vtHeightField3d *pHeightField)
{
	// Trigger the creation of any materials we may need
	GetMatIndex("");

	uint i, j;
	uint numfencepts = m_pFencePts.GetSize();

	FLine3 p3;

	FPoint3 diff, fp;
	FPoint3 PostSize(m_Params.m_fPostWidth, m_Params.m_fPostHeight,
		m_Params.m_fPostDepth);

	// All culture (roads and buildings) can be draped on
	int iIncludeCulture = CE_ALL;

	// first, project the posts from earth to world
	m_Posts3d.SetSize(numfencepts);
	for (i = 0; i < numfencepts; i++)
		pHeightField->ConvertEarthToSurfacePoint(m_pFencePts[i], m_Posts3d[i], iIncludeCulture);

	// Find highest point
	m_fMaxGroundY = -1E8;
	for (i = 0; i < numfencepts; i++)
		if (m_Posts3d[i].y > m_fMaxGroundY)
			m_fMaxGroundY = m_Posts3d[i].y;

	if (m_Params.m_PostType != "none")
	{
		// has posts
		// determine where the fence posts go
		for (i = 0; i < numfencepts; i++)
		{
			if (i == numfencepts-1)
			{
				p3.Append(m_Posts3d[i]);
				continue;
			}
			// get start and end group points for this section
			FPoint3 wpos1 = m_Posts3d[i];
			FPoint3 wpos2 = m_Posts3d[i+1];

			// look at world distance (approximate meters, _not_ earth
			//  coordinates, which might be in e.g. feet or degrees)
			diff = wpos2 - wpos1;
			float distance = sqrt(diff.x*diff.x+diff.z*diff.z);
			uint segments = (uint) (distance / m_Params.m_fPostSpacing);
			if (segments < 1) segments = 1;
			FPoint3 diff_per_segment = diff / (float) segments;

			for (j = 0; j < segments; j++)
			{
				fp = wpos1 + (diff_per_segment * (float)j);

				if (i > 0 && i < numfencepts-1)
				{
					// randomly offset by up to 4% of fence spacing, for "realism"
					fp.x += random_offset(0.04f * m_Params.m_fPostSpacing);
					fp.z += random_offset(0.04f * m_Params.m_fPostSpacing);
				}
				// false: true elevation, true: include culture (structures and roads)
				pHeightField->FindAltitudeAtPoint(fp, fp.y, false, CE_ALL);
				p3.Append(fp);
			}
		}
		// generate the posts
		// Look first for post materials (type 3)
		int iMatIdx = GetMatIndex(m_Params.m_PostType, RGBf(), 3);

		// If that didn't work, look for any material by that name
		if (iMatIdx == -1)
			int iMatIdx = GetMatIndex(m_Params.m_PostType);
		for (i = 0; i < p3.GetSize(); i++)
			AddFencepost(p3[i], iMatIdx);
	}
	else
	{
		// no post spacing to consider, so just use the input vertices
		p3.SetSize(numfencepts);
		for (i = 0; i < numfencepts; i++)
			p3[i] = m_Posts3d[i];
	}

	if (m_Params.m_PostExtension != "none")
		AddPostExtensions(p3);

	// if not enough points, nothing connections to create
	if (p3.GetSize() < 2)
		return;

	if (m_Params.m_iConnectType == 0)	// none
	{
		// nothing to do
	}
	else if (m_Params.m_iConnectType == 1)	// wire
	{
		AddWireMeshes(p3);
	}

	if (m_Params.m_ConnectMaterial == "none")
		return;

	if (m_Params.m_iConnectType == 2)	// simple
	{
		if (m_Params.m_fConnectWidth == 0.0f)
			AddFlatConnectionMesh(p3);
		else if (m_Params.m_fConnectWidth > 0.0f)
			AddThickConnectionMesh(p3);
	}
	else if (m_Params.m_iConnectType == 3)	// profile
	{
		AddProfileConnectionMesh(p3);
	}
}