Esempio n. 1
0
static void
pixelize (gfloat              *input,
          gfloat              *output,
          const GeglRectangle *roi,
          const GeglRectangle *extended_roi,
          const GeglRectangle *whole_region,
          GeglProperties          *o)
{
  gint          start_x = block_index (roi->x, o->size_x) * o->size_x;
  gint          start_y = block_index (roi->y, o->size_y) * o->size_y;
  gint          x, y;
  gint          off_shape_x, off_shape_y;
  gfloat        color[4];
  GeglRectangle rect_shape;

  rect_shape.width  = ceilf (o->size_x * (gfloat)o->ratio_x);
  rect_shape.height = ceilf (o->size_y * (gfloat)o->ratio_y);

  off_shape_x = floorf ((o->size_x - (gfloat)o->ratio_x * o->size_x) / 2.0f);
  off_shape_y = floorf ((o->size_y - (gfloat)o->ratio_y * o->size_y) / 2.0f);

  for (y = start_y; y < roi->y + roi->height; y += o->size_y)
    for (x = start_x; x < roi->x + roi->width; x += o->size_x)
      {
        GeglRectangle rect = {x, y, o->size_x, o->size_y};
        GeglRectangle rect2;

        rect_shape.x = x + off_shape_x;
        rect_shape.y = y + off_shape_y;

        gegl_rectangle_intersect (&rect, whole_region, &rect);

        if (rect.width < 1 || rect.height < 1)
          continue;

        rect2.x = rect.x - extended_roi->x;
        rect2.y = rect.y - extended_roi->y;
        rect2.width  = rect.width;
        rect2.height = rect.height;

        mean_rectangle (input, &rect2, extended_roi->width, color);

        gegl_rectangle_intersect (&rect, roi, &rect);

        rect2.x = rect.x - roi->x;
        rect2.y = rect.y - roi->y;
        rect2.width  = rect.width;
        rect2.height = rect.height;

        rect_shape.x -= roi->x;
        rect_shape.y -= roi->y;

        set_rectangle (output, &rect2, &rect_shape,
                       roi->width, color, o->norm);
      }
}
    bool operator()( size_t row, size_t col ) {
        ASSERT_VALID_RANGE( row, 0, m_rows )
        ASSERT_VALID_RANGE( col, 0, m_columns )

        size_t idx = block_index( row, col, m_bpr );
        return ((m_data[ idx ] & bit_helper_type::bit_offset( col )) != 0);
    }
Esempio n. 3
0
static void
pixelize_noalloc (GeglBuffer          *input,
                  GeglBuffer          *output,
                  const GeglRectangle *roi,
                  const GeglRectangle *whole_region,
                  GeglProperties          *o)
{
  gint start_x = block_index (roi->x, o->size_x) * o->size_x;
  gint start_y = block_index (roi->y, o->size_y) * o->size_y;
  gint x, y;
  gint off_shape_x, off_shape_y;

  GeglColor *color = gegl_color_new ("white");

  GeglRectangle rect_shape;

  rect_shape.width  = ceilf (o->size_x * (gfloat)o->ratio_x);
  rect_shape.height = ceilf (o->size_y * (gfloat)o->ratio_y);

  off_shape_x = floorf ((o->size_x - (gfloat)o->ratio_x * o->size_x) / 2.0f);
  off_shape_y = floorf ((o->size_y - (gfloat)o->ratio_y * o->size_y) / 2.0f);

  for (y = start_y; y < roi->y + roi->height; y += o->size_y)
    for (x = start_x; x < roi->x + roi->width; x += o->size_x)
      {
        GeglRectangle rect = {x, y, o->size_x, o->size_y};

        gegl_rectangle_intersect (&rect, whole_region, &rect);

        if (rect.width < 1 || rect.height < 1)
          continue;

        mean_rectangle_noalloc (input, &rect, color);

        gegl_rectangle_intersect (&rect, roi, &rect);

        rect_shape.x = x + off_shape_x;
        rect_shape.y = y + off_shape_y;

        set_rectangle_noalloc (output, &rect, &rect_shape, color, o->norm);
      }

  g_object_unref (color);
}
Esempio n. 4
0
int 
hash_state_scrypt_extract (struct hash_state *s, void *out, size_t outlen)
{
  int error;
  uint8_t accumulator[s->block_size];
  memcpy (accumulator, block_index (s, s->n_blocks - 1), s->block_size);

  const uint8_t *blocks[2];
  for (uint64_t i = 0; i < s->n_blocks; i++) {
    uint64_t next_block_idx = integrify (s, accumulator) % s->n_blocks;
    blocks[0] = accumulator;
    blocks[1] = block_index (s, next_block_idx);

    if ((error = compress (accumulator, blocks, 2, &s->opts->comp_opts)))
      return error;
  }

  // Return bytes derived from the last block of the buffer.
  return fill_bytes_from_strings (s, out, outlen, accumulator, s->block_size, NULL, 0);
}
Esempio n. 5
0
static int blockcomp(const void *a,const void *b)
{
  int aa,bb,aind,bind;
  
  aa   = nwat*(*((int *)a));
  bb   = nwat*(*((int *)b));

  aind = block_index(xptr[aa],NBOX);
  bind = block_index(xptr[bb],NBOX);

  if (aind == bind) {
    if (xptr[aa][XX] < xptr[bb][XX])
      return -1;
    else if (xptr[aa][XX] > xptr[bb][XX])
      return 1;
    else 
      return 0;
  }
  else
    return aind-bind;
}
    void flip( size_t row, size_t col ) {
        ASSERT_VALID_RANGE( row, 0, m_rows );
        ASSERT_VALID_RANGE( col, 0, m_columns );

        size_t idx = block_index( row, col, m_bpr );
        std::cerr << "Flipping row: " << row << "; col: " << col << "; bpr: " << m_bpr << std::endl;
#ifdef DEBUGGING
        assert( (m_data[ idx ] & bit_helper_type::bit_offset( col )) == 0 );
#endif  // DEBUGGING

        m_data[ idx ] ^= bit_helper_type::bit_offset( col );

    }
    void flipColumn( const size_t & fixed_index ) {
        block_type mask = bit_helper_type::bit_offset( fixed_index );

        size_t i = 0;
        while( i < m_rows ) {
            size_t idx = block_index( i++, fixed_index, m_bpr );

#ifdef DEBUGGING
            assert( (m_data[idx] & mask) != 0 );
#endif // DEBUGGING
            m_data[ idx ] ^= mask;
        }
    }
Esempio n. 8
0
void record_cpu_cycle() {
    record_t record;

    record.pc = PC;
    last_recorded_pc = PC;

    records[records_cursor] = record;

    records_cursor++;
    records_cursor %= RECORDS_BUFFER_SIZE;

    records_count++;

    if (current_block) {
        if (PC > current_block->end || PC < current_block->begin) {
            current_block = NULL;
        }
    }

    if(!current_block) {
        u16 pc = PC;

        int index = block_index(pc);
        if (index > 0) {
            current_block = &blocks[index];
            //printf("Entered block %i\n", index);
        }
        else {
            current_block = &blocks[block_cursor];
            current_block->begin = pc;

            block_cursor++;
            block_cursor %= BLOCK_BUFFER_SIZE;

            //printf("Entered block %i\n", block_cursor);

            for (;;) {
                op_t op = disasm(pc);

                if (is_branch(op)) {
                    current_block->end = pc;
                    break;
                }

                assert (pc + op_length(op) <= 0xFFFF);

                pc += op_length(op);
            }
        }
    }
}
    bool freeColumn( size_t fr_idx ) {
        block_type mask = bit_helper_type::bit_offset( fr_idx );

        size_t i = 0;
        bool is_free = true;
        size_t idx = 0;
        while( is_free && i < m_rows ) {
            idx = block_index( i++, fr_idx, m_bpr );

            is_free = ((m_data[idx] & mask) == 0);
        }
#ifdef DEBUGGING
        if( !is_free)
            BOOST_LOG_TRIVIAL(info) << "Row " << (i - 1) << " at " << idx << " [" << (m_data + idx) << "] -> " << std::hex << (m_data[idx] & mask) << std::dec;
#endif  // DEBUGGING
        return is_free;
    }
    void flip( const size_t & row, const size_t & col ) {
        ASSERT_VALID_RANGE( row, 0, m_rows )
        ASSERT_VALID_RANGE( col, 0, m_columns )

        size_t idx = block_index( row, col, m_bpr );
        size_t bc = block_column_offset( col ) + 1;
        //std::cerr << "Flipping row: " << row << "; col: " << col << "; bpr: " << m_bpr << "; idx: " << idx << std::endl;
#ifdef DEBUGGING
        assert( (m_data[ idx ] & bit_helper_type::bit_offset( col )) == 0 );
#endif  // DEBUGGING

        m_data[ idx ] ^= bit_helper_type::bit_offset( col );

        if( bc >= m_soft_size[ row ] ) {
            updateSoftSize( row, bc );
        }
    }
Esempio n. 11
0
static gboolean
cl_pixelize (cl_mem               in_tex,
             cl_mem               aux_tex,
             cl_mem               out_tex,
             const GeglRectangle *src_rect,
             const GeglRectangle *roi,
             gint                 xsize,
             gint                 ysize,
             gfloat               xratio,
             gfloat               yratio,
             gfloat               bg_color[4],
             gint                 norm,
             GeglRectangle       *image_extent)
{
  cl_int cl_err = 0;
  const size_t gbl_size[2]= {roi->width, roi->height};

  gint cx0 = block_index (roi->x, xsize);
  gint cy0 = block_index (roi->y, ysize);
  gint block_count_x = block_index (roi->x + roi->width  + xsize - 1, xsize) - cx0;
  gint block_count_y = block_index (roi->y + roi->height + ysize - 1, ysize) - cy0;
  cl_int4 bbox = {{ image_extent->x, image_extent->y,
                    image_extent->x + image_extent->width,
                    image_extent->y + image_extent->height }};

  cl_int line_width = roi->width + 2 * xsize;

  size_t gbl_size_tmp[2] = {block_count_x, block_count_y};

  if (!cl_data)
  {
    const char *kernel_name[] = {"calc_block_color", "kernel_pixelize", NULL};
    cl_data = gegl_cl_compile_and_build (pixelize_cl_source, kernel_name);
  }

  if (!cl_data) return 1;

  cl_err = gegl_cl_set_kernel_args (cl_data->kernel[0],
                                    sizeof(cl_mem), (void*)&in_tex,
                                    sizeof(cl_mem), (void*)&aux_tex,
                                    sizeof(cl_int), (void*)&xsize,
                                    sizeof(cl_int), (void*)&ysize,
                                    sizeof(cl_int), (void*)&roi->x,
                                    sizeof(cl_int), (void*)&roi->y,
                                    sizeof(cl_int4), &bbox,
                                    sizeof(cl_int), (void*)&line_width,
                                    sizeof(cl_int), (void*)&block_count_x,
                                    NULL);
  CL_CHECK;

  cl_err = gegl_clEnqueueNDRangeKernel (gegl_cl_get_command_queue (),
                                        cl_data->kernel[0], 2,
                                        NULL, gbl_size_tmp, NULL,
                                        0, NULL, NULL);
  CL_CHECK;

  cl_err = gegl_cl_set_kernel_args (cl_data->kernel[1],
                                    sizeof(cl_mem),   (void*)&aux_tex,
                                    sizeof(cl_mem),   (void*)&out_tex,
                                    sizeof(cl_int),   (void*)&xsize,
                                    sizeof(cl_int),   (void*)&ysize,
                                    sizeof(cl_float), (void*)&xratio,
                                    sizeof(cl_float), (void*)&yratio,
                                    sizeof(cl_int),   (void*)&roi->x,
                                    sizeof(cl_int),   (void*)&roi->y,
                                    sizeof(cl_float4),(void*)bg_color,
                                    sizeof(cl_int),   (void*)&norm,
                                    sizeof(cl_int),   (void*)&block_count_x,
                                    NULL);
  CL_CHECK;

  cl_err = gegl_clEnqueueNDRangeKernel (gegl_cl_get_command_queue (),
                                        cl_data->kernel[1], 2,
                                        NULL, gbl_size, NULL,
                                        0, NULL, NULL);
  CL_CHECK;

  return FALSE;

error:
  return TRUE;
}