Example #1
0
static void on_check(struct evwatch *watcher, const struct evwatch_check_cb_info *info, void *arg)
{
	struct timeval actual, delay;
	evutil_gettimeofday(&check_time, NULL);
	evutil_timersub(&check_time, &prepare_time, &actual);
	evutil_timersub(&actual, &expected, &delay);
	if (delay.tv_sec >= 0)
		histogram_update(delays, delay.tv_sec + delay.tv_usec / 1000000.0l);
}
Example #2
0
static void on_prepare(struct evwatch *watcher, const struct evwatch_prepare_cb_info *info, void *arg)
{
	struct timeval duration;
	evutil_gettimeofday(&prepare_time, NULL);
	evwatch_prepare_get_timeout(info, &expected);
	if (check_time.tv_sec != 0) {
		evutil_timersub(&prepare_time, &check_time, &duration);
		histogram_update(durations, duration.tv_sec + duration.tv_usec / 1000000.0l);
	}
}
Example #3
0
/** Update bit sync and get bit integration output
 *
 * \param b                 Pointer to a bit sync structure
 * \param corr_prompt_real  Real part of the prompt correlation
 * \param ms                Integration time (ms) of the correlation
 * \param bit_integrate     Pointer to output bit integration (if valid)
 *
 * \return  True if *bit_integrate contains a valid bit integration,
 *          False otherwise
 */
bool bit_sync_update(bit_sync_t *b, s32 corr_prompt_real, u32 ms,
                     s32 *bit_integrate)
{
  b->bit_phase += ms;
  b->bit_phase %= b->bit_length;
  b->bit_integrate += corr_prompt_real;

  /* Search for bit phase if not yet locked. */
  if (b->bit_phase_ref == BITSYNC_UNSYNCED)
    histogram_update(b, corr_prompt_real);

  /* Return the integration at the end of the bit period */
  if (b->bit_phase == b->bit_phase_ref) {
    *bit_integrate = b->bit_integrate;
    b->bit_integrate = 0;
    return true;
  }

  return false;
}
Example #4
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *roi,
         gint                 level)
{
  GeglProperties *o = GEGL_PROPERTIES (operation);

  gdouble         percentile           = o->percentile       / 100.0;
  gdouble         alpha_percentile     = o->alpha_percentile / 100.0;
  const gint     *neighborhood_outline = o->user_data;

  const Babl     *format               = gegl_operation_get_format (operation, "input");
  gint            n_components         = babl_format_get_n_components (format);
  gboolean        has_alpha            = babl_format_has_alpha (format);

  G_STATIC_ASSERT (sizeof (gint32) == sizeof (gfloat));
  gint32         *src_buf;
  gfloat         *dst_buf;
  GeglRectangle   src_rect;
  gint            src_stride;
  gint            dst_stride;
  gint            n_pixels;

  Histogram      *hist;

  const gint32   *src;
  gfloat         *dst;
  gint            dst_x, dst_y;
  Direction       dir;

  gint            i;
  gint            c;

  src_rect   = gegl_operation_get_required_for_output (operation, "input", roi);
  src_stride = src_rect.width * n_components;
  dst_stride = roi->width * n_components;
  n_pixels   = roi->width * roi->height;
  dst_buf = g_new0 (gfloat, n_pixels                         * n_components);
  src_buf = g_new0 (gint32, src_rect.width * src_rect.height * n_components);

  gegl_buffer_get (input, &src_rect, 1.0, format, src_buf,
                   GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
  convert_values_to_bins (src_buf, n_components, has_alpha,
                          src_rect.width * src_rect.height);

  hist = g_slice_new0 (Histogram);

  src = src_buf + o->radius * (src_rect.width + 1) * n_components;
  dst = dst_buf;

  /* compute the first window */

  for (i = -o->radius; i <= o->radius; i++)
    {
      histogram_modify_vals (hist, src, n_components, src_stride, has_alpha,
                             i, -neighborhood_outline[abs (i)],
                             i, +neighborhood_outline[abs (i)],
                             +1);

      hist->size += 2 * neighborhood_outline[abs (i)] + 1;
    }

  for (c = 0; c < 3; c++)
    dst[c] = histogram_get_median (hist, c, percentile);

  if (has_alpha)
    dst[3] = histogram_get_median (hist, 3, alpha_percentile);

  dst_x = 0;
  dst_y = 0;

  n_pixels--;
  dir = LEFT_TO_RIGHT;

  while (n_pixels--)
    {
      /* move the src coords based on current direction and positions */
      if (dir == LEFT_TO_RIGHT)
        {
          if (dst_x != roi->width - 1)
            {
              dst_x++;
              src += n_components;
              dst += n_components;
            }
          else
            {
              dst_y++;
              src += src_stride;
              dst += dst_stride;
              dir = TOP_TO_BOTTOM;
            }
        }
      else if (dir == TOP_TO_BOTTOM)
        {
          if (dst_x == 0)
            {
              dst_x++;
              src += n_components;
              dst += n_components;
              dir = LEFT_TO_RIGHT;
            }
          else
            {
              dst_x--;
              src -= n_components;
              dst -= n_components;
              dir = RIGHT_TO_LEFT;
            }
        }
      else if (dir == RIGHT_TO_LEFT)
        {
          if (dst_x != 0)
            {
              dst_x--;
              src -= n_components;
              dst -= n_components;
            }
          else
            {
              dst_y++;
              src += src_stride;
              dst += dst_stride;
              dir = TOP_TO_BOTTOM;
            }
        }

      histogram_update (hist, src, n_components, src_stride, has_alpha,
                        o->neighborhood, o->radius, neighborhood_outline,
                        dir);

      for (c = 0; c < 3; c++)
        dst[c] = histogram_get_median (hist, c, percentile);

      if (has_alpha)
        dst[3] = histogram_get_median (hist, 3, alpha_percentile);
    }

  gegl_buffer_set (output, roi, 0, format, dst_buf, GEGL_AUTO_ROWSTRIDE);

  g_slice_free (Histogram, hist);
  g_free (dst_buf);
  g_free (src_buf);

  return TRUE;
}
Example #5
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *roi,
         gint                 level)
{
    GeglProperties *o  = GEGL_PROPERTIES (operation);
    const Babl *format = gegl_operation_get_format (operation, "input");
    gint n_components  = babl_format_get_n_components (format);
    gboolean has_alpha = babl_format_has_alpha (format);

    gfloat *src_buf;
    gfloat *dst_buf;
    gint    n_pixels;
    GeglRectangle src_rect;

    Histogram *hist;
    Direction  dir;

    gint src_x, src_y;
    gint dst_x, dst_y;
    gint dst_idx, src_idx;
    gint xmin, ymin, xmax, ymax;

    src_rect = gegl_operation_get_required_for_output (operation, "input", roi);
    n_pixels = roi->width * roi->height;
    dst_buf = g_new0 (gfloat, n_pixels * n_components);
    src_buf = g_new0 (gfloat, src_rect.width * src_rect.height * n_components);

    gegl_buffer_get (input, &src_rect, 1.0, format, src_buf,
                     GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);

    hist = g_slice_new0 (Histogram);

    dst_x = 0;
    dst_y = 0;
    src_x = o->radius;
    src_y = o->radius;

    /* compute the first window */

    hist->xmin = src_x - o->radius;
    hist->ymin = src_y - o->radius;
    hist->xmax = src_x + o->radius;
    hist->ymax = src_y + o->radius;

    histogram_add_vals (hist, src_buf, &src_rect, n_components,
                        hist->xmin, hist->ymin,
                        hist->xmax, hist->ymax);

    dst_idx = (dst_x + dst_y * roi->width) * n_components;

    dst_buf[dst_idx]     = histogram_get_median (hist, 0);
    dst_buf[dst_idx + 1] = histogram_get_median (hist, 1);
    dst_buf[dst_idx + 2] = histogram_get_median (hist, 2);

    if (has_alpha)
    {
        src_idx = (src_x + src_y * src_rect.width) * n_components;
        dst_buf[dst_idx + 3] = src_buf[src_idx + 3];
    }

    n_pixels--;
    dir = LEFT_TO_RIGHT;

    while (n_pixels--)
    {
        /* move the src coords based on current direction and positions */
        if (dir == LEFT_TO_RIGHT)
        {
            if (dst_x != roi->width - 1)
            {
                src_x++;
                dst_x++;
            }
            else
            {
                src_y++;
                dst_y++;
                dir = TOP_TO_BOTTOM;
            }
        }
        else if (dir == TOP_TO_BOTTOM)
        {
            if (dst_x == 0)
            {
                src_x++;
                dst_x++;
                dir = LEFT_TO_RIGHT;
            }
            else
            {
                src_x--;
                dst_x--;
                dir = RIGHT_TO_LEFT;
            }
        }
        else if (dir == RIGHT_TO_LEFT)
        {
            if (dst_x != 0)
            {
                src_x--;
                dst_x--;
            }
            else
            {
                src_y++;
                dst_y++;
                dir = TOP_TO_BOTTOM;
            }
        }

        xmin = src_x - o->radius;
        ymin = src_y - o->radius;
        xmax = src_x + o->radius;
        ymax = src_y + o->radius;

        histogram_update (hist, src_buf, &src_rect, n_components,
                          xmin, ymin, xmax, ymax, dir);

        dst_idx = (dst_x + dst_y * roi->width) * n_components;

        dst_buf[dst_idx]     = histogram_get_median (hist, 0);
        dst_buf[dst_idx + 1] = histogram_get_median (hist, 1);
        dst_buf[dst_idx + 2] = histogram_get_median (hist, 2);

        if (has_alpha)
        {
            src_idx = (src_x + src_y * src_rect.width) * n_components;
            dst_buf[dst_idx + 3] = src_buf[src_idx + 3];
        }
    }

    gegl_buffer_set (output, roi, 0, format, dst_buf, GEGL_AUTO_ROWSTRIDE);

    g_free (src_buf);
    g_free (dst_buf);
    g_slice_free (Histogram, hist);

    return TRUE;
}