Пример #1
0
/** Call this function whenever a thread is no longer using the memory
 *  [ a1, a2 [, e.g. because of a call to free() or a stack pointer
 *  increase.
 */
void thread_stop_using_mem(const Addr a1, const Addr a2)
{
  DrdThreadId other_user;
  unsigned i;

  /* For all threads, mark the range [ a1, a2 [ as no longer in use. */
  other_user = DRD_INVALID_THREADID;
  for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++)
  {
    Segment* p;
    for (p = s_threadinfo[i].first; p; p = p->next)
    {
      if (other_user == DRD_INVALID_THREADID
          && i != s_drd_running_tid)
      {
        if (UNLIKELY(bm_test_and_clear(p->bm, a1, a2)))
        {
          other_user = i;
        }
        continue;
      }
      bm_clear(p->bm, a1, a2);
    }
  }

  /* If any other thread had accessed memory in [ a1, a2 [, update the */
  /* danger set. */
  if (other_user != DRD_INVALID_THREADID
      && bm_has_any_access(s_danger_set, a1, a2))
  {
    thread_compute_danger_set(&s_danger_set, thread_get_running_tid());
  }
}
Пример #2
0
static void pathlist_to_tree(path_t *plist, potrace_bitmap_t *bm) {
  path_t *p, *p1;
  path_t *heap, *heap1;
  path_t *cur;
  path_t *head;
  path_t **plist_hook;          /* for fast appending to linked list */
  path_t **hook_in, **hook_out; /* for fast appending to linked list */
  bbox_t bbox;
  
  bm_clear(bm, 0);

  /* save original "next" pointers */
  list_forall(p, plist) {
    p->sibling = p->next;
    p->childlist = NULL;
  }
Пример #3
0
void BMCanvas::clear() {
	bm_clear(bmp);
}
Пример #4
0
static void *interpolate_cubic(greymap_t *gm, int s, int bilevel, double c) {
  int w, h;
  double4 *poly = NULL; /* poly[s][4]: fixed interpolation polynomials */
  double p[4];              /* four current points */
  double4 *window = NULL; /* window[s][4]: current state */
  double t, v;
  int k, l, i, j, x, y;
  double c1 = 0;
  greymap_t *gm_out = NULL;
  potrace_bitmap_t *bm_out = NULL;

  SAFE_MALLOC(poly, s, double4);
  SAFE_MALLOC(window, s, double4);

  w = gm->w;
  h = gm->h;

  /* allocate output bitmap/greymap */
  if (bilevel) {
    bm_out = bm_new(w*s, h*s);
    if (!bm_out) {
      goto malloc_error;
    }
    bm_clear(bm_out, 0);
    c1 = c * 255;
  } else {
    gm_out = gm_new(w*s, h*s);
    if (!gm_out) {
      goto malloc_error;
    }
  }

  /* pre-calculate interpolation polynomials */
  for (k=0; k<s; k++) {
    t = k/(double)s;
    poly[k][0] = 0.5 * t * (t-1) * (1-t);
    poly[k][1] = -(t+1) * (t-1) * (1-t) + 0.5 * (t-1) * (t-2) * t;
    poly[k][2] = 0.5 * (t+1) * t * (1-t) - t * (t-2) * t;
    poly[k][3] = 0.5 * t * (t-1) * t;
  }

  /* interpolate */
  for (y=0; y<h; y++) {
    x=0;
    for (i=0; i<4; i++) {
      for (j=0; j<4; j++) {
	p[j] = GM_BGET(gm, x+i-1, y+j-1);
      }
      for (k=0; k<s; k++) {
	window[k][i] = 0.0;
	for (j=0; j<4; j++) {
	  window[k][i] += poly[k][j] * p[j];
	}
      }
    }
    while (1) {
      for (l=0; l<s; l++) {
	for (k=0; k<s; k++) {
	  v = 0.0;
	  for (i=0; i<4; i++) {
	    v += window[k][i] * poly[l][i];
	  }
	  if (bilevel) {
	    BM_UPUT(bm_out, x*s+l, y*s+k, v < c1);
	  } else {
	    GM_UPUT(gm_out, x*s+l, y*s+k, v);
	  }	    
	}
      }
      x++;
      if (x>=w) {
	break;
      }
      for (i=0; i<3; i++) {
	for (k=0; k<s; k++) {
	  window[k][i] = window[k][i+1];
	}
      }
      i=3;
      for (j=0; j<4; j++) {
        p[j] = GM_BGET(gm, x+i-1, y+j-1);
      }
      for (k=0; k<s; k++) {
	window[k][i] = 0.0;
        for (j=0; j<4; j++) {
          window[k][i] += poly[k][j] * p[j];
        }
      }
    }
  }

  free(poly);
  free(window);

  if (bilevel) {
    return (void *)bm_out;
  } else {
    return (void *)gm_out;
  }

 malloc_error:
  free(poly);
  free(window);
  return NULL;
}
Пример #5
0
static void *interpolate_linear(greymap_t *gm, int s, int bilevel, double c) {
  int p00, p01, p10, p11;
  int i, j, x, y;
  double xx, yy, av;
  double c1 = 0;
  int w, h;
  double p0, p1;
  greymap_t *gm_out = NULL;
  potrace_bitmap_t *bm_out = NULL;

  w = gm->w;
  h = gm->h;

  /* allocate output bitmap/greymap */
  if (bilevel) {
    bm_out = bm_new(w*s, h*s);
    if (!bm_out) {
      return NULL;
    }
    bm_clear(bm_out, 0);
    c1 = c * 255;
  } else {
    gm_out = gm_new(w*s, h*s);
    if (!gm_out) {
      return NULL;
    }
  }

  /* interpolate */
  for (i=0; i<w; i++) {
    for (j=0; j<h; j++) {
      p00 = GM_BGET(gm, i, j);
      p01 = GM_BGET(gm, i, j+1);
      p10 = GM_BGET(gm, i+1, j);
      p11 = GM_BGET(gm, i+1, j+1);
      
      if (bilevel) {
	/* treat two special cases which are very common */
	if (p00 < c1 && p01 < c1 && p10 < c1 && p11 < c1) {
	  for (x=0; x<s; x++) {
	    for (y=0; y<s; y++) {
	      BM_UPUT(bm_out, i*s+x, j*s+y, 1);
	    }
	  }
	  continue;
	}
	if (p00 >= c1 && p01 >= c1 && p10 >= c1 && p11 >= c1) {
	  continue;
	}
      }
      
      /* the general case */
      for (x=0; x<s; x++) {
	xx = x/(double)s;
	p0 = p00*(1-xx) + p10*xx;
	p1 = p01*(1-xx) + p11*xx;
	for (y=0; y<s; y++) {
	  yy = y/(double)s;
	  av = p0*(1-yy) + p1*yy;
	  if (bilevel) {
	    BM_UPUT(bm_out, i*s+x, j*s+y, av < c1);
	  } else {
	    GM_UPUT(gm_out, i*s+x, j*s+y, av);
	  }
	}
      }
    }
  }
  if (bilevel) {
    return (void *)bm_out;
  } else {
    return (void *)gm_out;
  }
}