Example #1
0
void CDrawDoc::ComputePageSize()
{
	CSize new_size(850, 1100);  // 8.5" x 11" default

	CPrintDialog dlg(FALSE);
	if (AfxGetApp()->GetPrinterDeviceDefaults(&dlg.m_pd))
	{
		// GetPrinterDC returns a HDC so attach it
		CDC dc;
		HDC hDC= dlg.CreatePrinterDC();
		ASSERT(hDC != NULL);
		dc.Attach(hDC);

		// Get the size of the page in loenglish
		new_size.cx = MulDiv(dc.GetDeviceCaps(HORZSIZE), 1000, 254);
		new_size.cy = MulDiv(dc.GetDeviceCaps(VERTSIZE), 1000, 254);
	}

	// if size changed then iterate over views and reset
	if (new_size != m_size)
	{
		m_size = new_size;
		POSITION pos = GetFirstViewPosition();
		while (pos != NULL)
			((CDrawView*)GetNextView(pos))->SetPageSize(m_size);
	}
}
Example #2
0
static void
rehash(st_table *table)
	/*@modifies *table @*/
{
    register st_table_entry *ptr, *next, **new_bins;
    int i, old_num_bins = table->num_bins, new_num_bins;
    unsigned int hash_val;

    new_num_bins = new_size(old_num_bins+1);
    new_bins = (st_table_entry**)Calloc(new_num_bins, sizeof(st_table_entry*));

    for(i = 0; i < old_num_bins; i++) {
	ptr = table->bins[i];
	while (ptr != 0) {
	    next = ptr->next;
	    hash_val = ptr->hash % new_num_bins;
	    ptr->next = new_bins[hash_val];
	    new_bins[hash_val] = ptr;
	    ptr = next;
	}
    }
    table->bins = _free(table->bins);
    table->num_bins = new_num_bins;
    table->bins = new_bins;
}
Example #3
0
void Sheet::setPuzzle(const Puzzle &puzzle)
{
    setUpdatesEnabled(false);

    int W = puzzle.grid.width, H = puzzle.grid.height;
    QSize new_size(W, H);
    if(grid_size != new_size)
        setGridSize(QSize(W, H));

    for(int n = 0; n < W*H; ++n)
    {
        int v = puzzle.grid.vars[n];
        if(v >= 0)
        {
            cellAt(n).setOpen(true);
            cellAt(n).setCands(puzzle.state.cand[v]);
            cellAt(n - W).setVsum(puzzle.state.sum[puzzle.state.vgrp[v]]);
            cellAt(n - 1).setHsum(puzzle.state.sum[puzzle.state.hgrp[v]]);
        }
        else
        {
            cellAt(n).setOpen(false);
            cellAt(n).setHsum(0);
            cellAt(n).setVsum(0);
        }
    }
    setUpdatesEnabled(true);
}
template <class T> void MemoryRenderHostImpl<T>::Memory_WasResized() {
    if (this->mResizeAckPending || !this->process()->HasConnection() || !this->view() || !this->renderer_initialized_) {
        return;
    }
    
    gfx::Rect view_bounds = this->view()->GetViewBounds();
    gfx::Size new_size(view_bounds.width(), view_bounds.height());
    
    // Avoid asking the RenderWidget to resize to its current size, since it
    // won't send us a PaintRect message in that case.
    if (new_size == current_size_ || current_size_== gfx::Size())
        return;
    
    if (mInFlightSize != gfx::Size())
        return;
    
    // We don't expect to receive an ACK when the requested size is empty.
    if (!new_size.IsEmpty())
        mResizeAckPending = true;
    
    if (!this->process()->Send(new ViewMsg_Resize(this->routing_id(), new_size,
                                                  this->view()->reserved_contents_rect())))
        mResizeAckPending = false;
    else
        mInFlightSize = new_size;
}
Example #5
0
File: Hash.cpp Project: tinysk/ajs
    HashTable::HashTable(HashFunc hashFunc, CompareFunc cmpFunc, st_index_t size)
		:_hashFunc(hashFunc), _cmpFunc(cmpFunc), _numEntries(0)
    {
    	size = new_size(size);
		_numBins = size;
		_entries = static_cast<HashEntry**>(calloc(size, sizeof(HashEntry*)));
    }
Example #6
0
st_table*
st_init_table_with_size(const struct st_hash_type *type, int size)
{
    st_table *tbl;

#ifdef HASH_LOG
    if (init_st == 0) {
	init_st = 1;
	atexit(stat_col);
    }
#endif

    size = new_size(size);	/* round up to prime number */

    tbl = alloc(st_table);
    tbl->type = type;
    tbl->num_entries = 0;
    tbl->entries_packed = type == &type_numhash && size/2 <= MAX_PACKED_NUMHASH;
    tbl->num_bins = size;
    tbl->bins = (st_table_entry **)Calloc(size, sizeof(st_table_entry*));
    tbl->head = 0;
    tbl->tail = 0;

    return tbl;
}
Example #7
0
char const *s_state_insert(register State *sp, char const *key,
                                               char const *subst)
{
    while (*key)
    {
        register char const *cp;
                                        /* if key is in the set, switch to  */
        if ((cp = strchr(sp->d_str, *key)) != 0)         /*  that state  */
            sp = sp->d_next[cp - sp->d_str];
        else
        {                               /* if not, add a new state to the   */
            size_t last = string_length(&sp->d_set);      /*          set */

            string_addchar(&sp->d_set, (char)*key); /* add key's 1st char */
            sp->d_str = string_str(&sp->d_set); /* and set the state's ptr  */

                                                /* add a new state          */
            new_size(&sp->d_next, last + 1, last, sizeof(State *));
            sp = sp->d_next[last] = s_state_new();
        }
        key++;                          /* inspect the next key char        */
    }

                                        /* all key chars exhausted: insert  */
                                        /* replacement text                 */

    if (sp->d_replacement)              /* oops, it's already there         */
        return sp->d_replacement;       /* return the one found             */

    sp->d_replacement = new_str(subst);
    return 0;                           /* here 0 indicates SUCCESS         */
}
Example #8
0
File: gc.c Project: CRogers/obc
static void init_sizes(void) {
    /* Establish size_bytes and size_map.  Single-word objects
       (containing only a descriptor) are not allowed, because we
       need to assume that a pointer to the object itself, i.e. to
       the word after the descriptor, is still inside the object. The
       sequence is 2, 4, 8, 12, 16, 24, 32 ... words, rounded up to
    the biggest multiple of GRANULE that allows the same number
    of objects in a page. */

    int k, i;

    n_sizes = 0;
    new_size(8, GC_PAGESIZE);
    new_size(16, GC_PAGESIZE);
    k = 16;
    while (k < GC_PAGESIZE/8) {
        new_size(2*k, GC_PAGESIZE);
        new_size(3*k, GC_PAGESIZE);
        k *= 2;
    }

    /* Then ... 1/4, 1/3, 1/2, 2/3, 1, 4/3 pages.  The larger sizes
       are enabled only if MULTIBLOCKS is defined; the extra cost in
       compaction overhead may not be worth the reduction in internal
       fragmentation that is achieved. */
    new_size(GC_PAGESIZE/4, GC_PAGESIZE);
    new_size(GC_PAGESIZE/3, GC_PAGESIZE);
    new_size(GC_PAGESIZE/2, GC_PAGESIZE);
#ifdef MULTIBLOCKS
    new_size(2*GC_PAGESIZE/3, 2*GC_PAGESIZE);
    new_size(GC_PAGESIZE, GC_PAGESIZE);
    new_size(4*GC_PAGESIZE/3, 4*GC_PAGESIZE);
#endif

    ASSERT(size_bytes[n_sizes-1] == MAX_SMALL_BYTES);

    k = 0;
    for (i = 0; i < n_sizes; i++)
        while (k * BYTES_PER_WORD <= size_bytes[i]) size_map[k++] = i;

    ASSERT(size_map[MAX_SMALL_WORDS] == n_sizes-1);
}
Example #9
0
void Canvas::set_zoom(int zoom, wxPoint center)
{
    {
        /* Overpaint old image */
        wxClientDC dc(this);
        wxPen pen( *wxLIGHT_GREY );
        wxBrush brush( *wxLIGHT_GREY );
        dc.SetPen( pen );
        dc.SetBrush( brush );
        dc.DrawRectangle( canvas_coords(
            wxRect(0, 0, contents->GetWidth(), contents->GetHeight())) );
    }

    if ( center == wxDefaultPosition ) {
        int xl, yl, xs, ys, xr, yr;
        GetViewStart( &xl, &yl );
        GetScrollPixelsPerUnit( &xr, &yr );
        GetClientSize( &xs, &ys );
        center.x = xl*xr + xs / 2;
        center.y = yl*yr + ys / 2;
        center = image_coords( wxRect( center, wxSize(1,1) ) ).GetTopLeft();
    }

    if ( zoom < 0 ) {
        zoom_out_level = -zoom+1;
        zoom_in_level = 1;
    } else {
        zoom_out_level = 1;
        zoom_in_level = zoom+1;
    }
    if ( zcl )
        zcl->zoom_changed( zoom );
    wxSize new_size( contents->GetWidth(), contents->GetHeight() );
    SetVirtualSize( canvas_coords( new_size ).GetSize() );

    int xr, yr;
    GetScrollPixelsPerUnit( &xr, &yr );
    wxRect viewport = get_visible_region();

    /* Transform center to new scroll coordinates. */
    wxPoint top_left = 
            viewport.CenterIn(
                canvas_coords( wxRect( center, wxSize(1,1) ) )
            ).GetTopLeft();
    Scroll( top_left.x / xr, top_left.y / yr );

    wxClientDC dc(this);
    DoPrepareDC( dc );

    wxRect canvas_region = get_visible_region();
    wxBitmap bitmap = zoomed_bitmap_for_canvas_region( canvas_region );
    dc.DrawBitmap( bitmap, canvas_region.GetTopLeft() );

}
Example #10
0
Result stack_push(register Stack *sp, register StackValue element)
{
    register size_t last = sp->d_n++;

    if (last == sp->d_size)
        new_size(&sp->d_value, sp->d_size += STACK_BLOCK,
                               last, sizeof(StackValue));

    sp->d_value[last] = element;

    return SUCCESS;
}
void ImageData::ResizeImage(
    const double scale_factor,
    const ResizeInterpolationMethod interpolation_method) {

  // Undefined behavior if image is empty.
  CHECK(!channels_.empty()) << "Cannot resize an empty image.";
  CHECK_GT(scale_factor, 0) << "Scale factor must be larger than 0.";
  cv::Size new_size(
      static_cast<int>(image_size_.width * scale_factor),
      static_cast<int>(image_size_.height * scale_factor));
  ResizeImage(new_size, interpolation_method);
}
Example #12
0
bool wxStaticLine::Create( wxWindow *parent, wxWindowID id,
                           const wxPoint &pos, const wxSize &size,
                           long style, const wxString &name )
{
    m_needParent = TRUE;

    if (!PreCreation( parent, pos, size ) ||
        !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
    {
        wxFAIL_MSG( wxT("wxStaticLine creation failed") );
        return FALSE;
    }

    if ( IsVertical() )
    {
        m_widget = gtk_vseparator_new();
        if (size.x == -1)
        {
            wxSize new_size( size );
            new_size.x = 4;
            SetSize( new_size );
        }
    }
    else
    {
        m_widget = gtk_hseparator_new();
        if (size.y == -1)
        {
            wxSize new_size( size );
            new_size.y = 4;
            SetSize( new_size );
        }
    }

    m_parent->DoAddChild( this );

    PostCreation(size);

    return TRUE;
}
Example #13
0
  typename ImageFactory<T>::view_type* thin_hs(const T& in) {
    typedef typename ImageFactory<T>::data_type data_type;
    typedef typename ImageFactory<T>::view_type view_type;
    Dim new_size(in.ncols() + 2, in.nrows() + 2);
    bool upper_left_origin = (in.ul_x() == 0) || (in.ul_y() == 0);
    Point new_origin;
    if (upper_left_origin)
      new_origin = Point(0, 0);
    else
      new_origin = Point(in.ul_x() - 1, in.ul_y() - 1);
    data_type* thin_data = new data_type(new_size, new_origin);
    view_type* thin_view = new view_type(*thin_data);
    try {
      for (size_t y = 0; y != in.nrows(); ++y)
	for (size_t x = 0; x != in.ncols(); ++x)
	  thin_view->set(Point(x + 1, y + 1), in.get(Point(x, y)));
      if (in.nrows() == 1 || in.ncols() == 1)
	goto end;
      data_type* H_M_data = new data_type(new_size, new_origin);
      view_type* H_M_view = new view_type(*H_M_data);
      try {
	bool not_finished = true;
	while (not_finished)
	  not_finished = thin_hs_one_pass(*thin_view, *H_M_view);
      } catch (std::exception e) {
	delete H_M_view;
	delete H_M_data;
	throw;
      }
      delete H_M_view;
      delete H_M_data;
    } catch (std::exception e) {
      delete thin_view;
      delete thin_data;
      throw;
    }
  end:
    if (upper_left_origin) {
      data_type* new_data = new data_type(in.size(), in.origin());
      view_type* new_view = new view_type(*new_data);
      for (size_t y = 0; y != in.nrows(); ++y)
	for (size_t x = 0; x != in.ncols(); ++x)
	  new_view->set(Point(x, y), thin_view->get(Point(x + 1, y + 1)));
      delete thin_view;
      delete thin_data;
      return new_view;
    } else {
      delete thin_view;
      thin_view = new view_type(*thin_data, in);
      return thin_view;
    }
  }
Example #14
0
void Image::assignTexture(const std::function<ci::gl::TextureRef(void)> &fn) {
	glm::vec3		new_size(glm::vec3(0.0f, 0.0f, 0.0f));
	try {
		mTexture.reset();
		if (fn) mTexture = fn();
		if (mTexture) {
			new_size.x = static_cast<float>(mTexture->getWidth());
			new_size.y = static_cast<float>(mTexture->getHeight());
		}
	} catch (std::exception const&) {
	}
	setSize(new_size);
}
Example #15
0
GG::Rect InGameMenu::CalculatePosition() const {
    const GG::X H_MAINMENU_MARGIN(40);  //horizontal empty space
    const GG::Y V_MAINMENU_MARGIN(40);  //vertical empty space

    // Calculate window width and height
    GG::Pt new_size(ButtonWidth() + H_MAINMENU_MARGIN,
                    5.75 * ButtonCellHeight() + V_MAINMENU_MARGIN); // 8 rows + 0.75 before exit button

    // This wnd determines its own position.
    GG::Pt new_ul((HumanClientApp::GetApp()->AppWidth()  - new_size.x) / 2,
                  (HumanClientApp::GetApp()->AppHeight() - new_size.y) / 2);

    return GG::Rect(new_ul, new_ul + new_size);
}
Example #16
0
QImage ImageStitching::getPaddedImage(QImage *image)
{
    int width = image->width();
    int height = image->height();
    QSize new_size(width * 3, height * 3);

    QImage new_image( Utility::blackImage(new_size) );
    for(int y=0; y < image->height(); y++) {
        for (int x=0; x < image->width(); x++) {
            new_image.setPixel(QPoint(x+width, y+height), image->pixel(QPoint(x,y)));
        }
    }

    return new_image;
}
Example #17
0
  static void exec(LHS &lhs, RHS const &rhs)
  {
    // rhs.arg() yields Unary<Scale, ArgumentBlockType>,
    // rhs.arg().arg() thus returns the terminal ArgumentBlockType block...
    ArgumentBlockType const &block = rhs.arg().arg();
    // ...and rhs.arg().operation() the Scale<ArgumentBlockType> functor.
    value_type scale = rhs.arg().operation().value;

    // rhs.operation() yields the Interpolator<Unary<Scale, ...> functor.
    length_type new_size(rhs.operation().size(1, 0));

    // wrap terminal blocks in views for convenience, and evaluate.
    Vector<value_type, LHS> result(lhs);
    const_Vector<value_type, ArgumentBlockType const> argument(block);
    scaled_interpolate(result, argument, scale, new_size);
  }
Example #18
0
cocoa_st_table*
cocoa_st_init_table_with_size(const struct cocoa_st_hash_type *type, int size)
{
    cocoa_st_table *tbl;

    size = new_size(size);      /* round up to prime number */

    tbl = alloc(cocoa_st_table);
    tbl->type = type;
    tbl->num_entries = 0;
    tbl->num_bins = size;
    tbl->bins = (cocoa_st_table_entry **)Calloc(size, sizeof(cocoa_st_table_entry*));
    tbl->head = 0;
    tbl->tail = 0;

    return tbl;
}
Example #19
0
File: st.c Project: sho-h/ruby
static void
rehash(register st_table *table)
{
    register st_table_entry *ptr, **new_bins;
    st_index_t new_num_bins, hash_val;

    new_num_bins = new_size(table->num_bins+1);
    new_bins = st_realloc_bins(table->bins, new_num_bins, table->num_bins);
    table->num_bins = new_num_bins;
    table->bins = new_bins;

    if ((ptr = table->head) != 0) {
	do {
	    hash_val = hash_pos(ptr->hash, new_num_bins);
	    ptr->next = new_bins[hash_val];
	    new_bins[hash_val] = ptr;
	} while ((ptr = ptr->fore) != 0);
    }
}
Example #20
0
    void image::resize(int32_t width, int32_t height, bool cover_crop /* = true */)
    {
        if (m_mat.data == nullptr)
            return;

        cv::Size size(width, height);
        if (cover_crop == true)
        {
            cv::Size mat_size(m_mat.cols, m_mat.rows);
            // This code assumes the cover looks like the following
            //  -------------------------
            // |   front   | |   back    |
            // |           | |           |
            // |           | |           |
            // |           | |           |
            // |           | |           |
            // |           | |           |
            // |           | |           |
            //  -------------------------
            //  We want the front

            if (m_mat.cols > m_mat.rows)
            {
                // Using cv::Rect on the stack always results in bogus values, for whatever reason :/
                std::unique_ptr<cv::Rect> region_front(new cv::Rect(0, 0, get_width() / 2, get_height())); 
                cv::Mat cropped_mat;
                m_mat(*region_front).copyTo(cropped_mat);
                

                cv::Size new_size(region_front->width, region_front->height);
                m_mat = cropped_mat;
                resize(width, height, false);
                /*cv::resize(cropped_mat, m_mat, new_size, 0.0, 0.0, cv::INTER_AREA);*/
                
                return;
            }
        }

        if (m_mat.data != nullptr)
            cv::resize(m_mat, m_mat, size, 0.0, 0.0, cv::INTER_AREA);

    }
Example #21
0
static void
rehash(register cocoa_st_table *table)
{
    register cocoa_st_table_entry *ptr, **new_bins;
    cocoa_st_index_t i, new_num_bins, hash_val;

    new_num_bins = new_size(table->num_bins+1);
    new_bins = (cocoa_st_table_entry**)
        realloc(table->bins, new_num_bins * sizeof(cocoa_st_table_entry*));
    for (i = 0; i < new_num_bins; ++i) new_bins[i] = 0;
    table->num_bins = new_num_bins;
    table->bins = new_bins;

    if ((ptr = table->head) != 0) {
        do {
            hash_val = ptr->hash % new_num_bins;
            ptr->next = new_bins[hash_val];
            new_bins[hash_val] = ptr;
        } while ((ptr = ptr->fore) != 0);
    }
}
Example #22
0
st_table*
st_init_table_with_size(struct st_hash_type *type, int size)
{
    st_table *tbl;

#ifdef HASH_LOG
    if (init_st == 0) {
	init_st = 1;
	atexit(stat_col);
    }
#endif

    size = new_size(size);	/* round up to prime number */

    tbl = alloc(st_table);
    tbl->type = type;
    tbl->num_entries = 0;
    tbl->num_bins = size;
    tbl->bins = (st_table_entry **)Calloc(size, sizeof(st_table_entry*));

    return tbl;
}
Example #23
0
File: Hash.cpp Project: tinysk/ajs
	void HashTable::rehash()
	{
		HashEntry *entry, **newBins;
		st_index_t i, newNumBins, hashVal;

		newNumBins = new_size(_numBins+1);
		newBins = static_cast<HashEntry**>(realloc(_entries, newNumBins * sizeof(HashEntry*)));
		for (i = 0; i < newNumBins; ++i) 
			newBins[i] = NULL;
		
		for(i = 0; i < _numBins; i++)
		{
			entry = _entries[i];
			if(entry != NULL){
				hashVal = entry->hashVal % newNumBins;
				entry->next = newBins[hashVal];
				newBins[hashVal] = entry;
			}
		}

		_numBins = newNumBins;
		_entries = newBins;
	}
Example #24
0
void CDrawDoc::ComputePageSize()
{
	CSize new_size(850, 1100);  // 8.5" x 11" default			//====
	HDC hIC;

	if (hIC = ((CDrawApp*)AfxGetApp()) -> GetDefaultPrinterIC())
	{
	CDC dc;
	dc.Attach(hIC);

	// Get the size of the page in loenglish
	new_size.cx = MulDiv(dc.GetDeviceCaps(HORZSIZE), 1000, 254);  //====
	new_size.cy = MulDiv(dc.GetDeviceCaps(VERTSIZE), 1000, 254);  //====
	}

	// if size changed then iterate over views and reset
	if (new_size != m_size)
	{
	m_size = new_size;
	POSITION pos = GetFirstViewPosition();
	while (pos != NULL)
		((CDrawView*)GetNextView(pos))->SetPageSize(m_size);
	}
}
Example #25
0
File: st.c Project: sho-h/ruby
st_table*
st_init_table_with_size(const struct st_hash_type *type, st_index_t size)
{
    st_table *tbl;

#ifdef HASH_LOG
# if HASH_LOG+0 < 0
    {
	const char *e = getenv("ST_HASH_LOG");
	if (!e || !*e) init_st = 1;
    }
# endif
    if (init_st == 0) {
	init_st = 1;
	atexit(stat_col);
    }
#endif


    tbl = st_alloc_table();
    tbl->type = type;
    tbl->num_entries = 0;
    tbl->entries_packed = size <= MAX_PACKED_HASH;
    if (tbl->entries_packed) {
	size = ST_DEFAULT_PACKED_TABLE_SIZE;
    }
    else {
	size = new_size(size);	/* round up to power-of-two */
    }
    tbl->num_bins = size;
    tbl->bins = st_alloc_bins(size);
    tbl->head = 0;
    tbl->tail = 0;

    return tbl;
}
Example #26
0
void args_construct(int argc, char **argv,
                    char *options,
                    LongOption const *longOption)
{
    char *cp;
    size_t nopt;
    struct option *long_option;
    size_t nlong = 0;

    if (!longOption)
        long_option = new_calloc(1, sizeof(struct option));
    else
    {
        while (longOption[nlong++].d_name)
            ;

        long_option = new_memory(nlong, sizeof(struct option));

        for (nopt = 0; nopt < nlong; nopt++)
        {
            long_option[nopt].name      = longOption[nopt].d_name;
            long_option[nopt].has_arg   = longOption[nopt].d_type;
            long_option[nopt].flag      = 0;
            long_option[nopt].val       = longOption[nopt].d_value;
        }
    }

    memset(&args, 0, sizeof(Args));
    string_construct(&args.d_option, 0);

    args.d_argv = argv;
    args.d_argc = argc;

    if ((cp = getenv("home")) || (cp = getenv("HOME")))     /* set home */
        args.d_home = new_str(cp);

    args.d_programName = basename(argv[0]);         /*  set programname */
    args.d_initial_dir = new_getcwd();              /* set initial dir. */

    args.d_ok = true;
    nopt = 0;

    while (true)
    {
        int optchar = getopt_long(args.d_argc, args.d_argv,
                                  options, long_option, NULL);

        switch (optchar)
        {
            default:
                string_addchar(&args.d_option, optchar);
                new_size(&args.d_optarg, nopt + 1, nopt, sizeof(char *));
                args.d_optarg[nopt++] = optarg ? new_str(optarg) : 0;
            // FALLING THROUGH
            case 'l':
            continue;                   /* at `while(true)' */

            case '?':
                args.d_ok = false;      /* stop processing at failure       */
            break;

            case EOF:
                args.d_optind = optind;
            break;
        }
        break;                          /* leave `while(true)'  */
    }
    free(long_option);
}
Example #27
0
void
FURYSDL::EventProducer::
feed_event(const SDL_Event *ev)
{
  if(ev==NULL)
    {
      return;
    }

  FURYEvent::handle h;
  switch(ev->type)
    {
    default:
      if(st(m_state).m_capture_all)
        {
          h=WRATHNew UnknownEvent(*ev);
        }
      break;

      /*
        TODO:
          SDL_TEXTINPUT/SDL_TEXTEDITING
       */

    case SDL_KEYUP:
    case SDL_KEYDOWN:
      {
        if(!ev->key.repeat || st(m_state).m_repeat_enabled)
          {
            h=WRATHNew FURYKeyEvent(FURYKey(ev->key.keysym.sym), 
                                    ev->key.type==SDL_KEYDOWN,
                                    ev->key.keysym.scancode,
                                    ev->key.keysym.scancode,
                                    compute_modifier(ev->key.keysym.mod));
          }
      }
      break;

    case SDL_MOUSEMOTION:
      {
        h=WRATHNew FURYMouseMotionEvent(ivec2(ev->motion.x, ev->motion.y),
                                        ivec2(ev->motion.xrel, ev->motion.yrel),
                                        FURYMouse(ev->motion.which));
      }
      break;

    case SDL_MOUSEBUTTONDOWN:
    case SDL_MOUSEBUTTONUP:
      {
        h=WRATHNew FURYMouseButtonEvent(ev->button.button,
                                        ivec2(ev->button.x, ev->button.y),
                                        ev->button.state==SDL_PRESSED,
                                        FURYMouse(ev->button.which));
      }
      break;

    case SDL_JOYAXISMOTION:
      {
        h=WRATHNew FURYJoystickAxisEvent(ev->jaxis.value,
                                         FURYJoystickAxis(ev->jaxis.axis),
                                         FURYJoystick(ev->jaxis.which));
      }
      break;

    case SDL_JOYHATMOTION:
      {
        h=WRATHNew FURYJoystickHatMotion(create_hat_code(ev->jhat.value),
                                         FURYJoyHat(ev->jhat.hat),
                                         FURYJoystick(ev->jhat.which));
      } 
      break;

    case SDL_JOYBALLMOTION:
      {
        h=WRATHNew FURYJoystickBallMotionEvent(ivec2(ev->jball.xrel, ev->jball.yrel),
                                               FURYJoyBall(ev->jball.ball),
                                               FURYJoystick(ev->jball.which));
      } 
      break; 
      

    case SDL_JOYBUTTONDOWN:
    case SDL_JOYBUTTONUP:
      {
        h=WRATHNew FURYJoystickButtonEvent(ev->jbutton.type==SDL_JOYBUTTONDOWN,
                                           FURYJoystickButton(ev->jbutton.button),
                                           FURYJoystick(ev->jbutton.which));
      }
      break;

    case SDL_WINDOWEVENT:
      {
        switch(ev->window.event)
          {
          case SDL_WINDOWEVENT_RESIZED:
            {
              ivec2 new_size(ev->window.data1, ev->window.data2);
              h=WRATHNew FURYResizeEvent(st(m_state).m_last_size, 
                                         new_size);
              st(m_state).m_last_size=new_size;
            }
            break;

          case SDL_WINDOWEVENT_CLOSE:
            {
              h=WRATHNew FURYEvent(FURYEvent::Quit);
            }
            break;

          }
      }
      break;

    case SDL_QUIT:
      {
        h=WRATHNew FURYEvent(FURYEvent::Quit);
      }
      break;
    }

  if(h.valid())
    {
      st(m_state).m_sig(h);
    }
}
Example #28
0
int main (int argc, char *argv[])
{
    QApplication app(argc, argv);
    handleCmdParams(argc, argv);
    std::cout << "Loading " << image_path << "... ";
    cv::Mat original_cross = cv::imread(image_path);
    if(!original_cross.data)
    {
        std::cout << "Error" << std::endl;
        return -1;
    }
    //convert to 32 Float for homogeinize formats
    original_cross.convertTo(original_cross, CV_32F, 1.0f/255.0f);

    //resize the image if it's needed
    if(out_face_size != 0)
    {
        //image.resize(image, cv::Size2f(out_face_size*3, out_face_size*4));
        cv::resize(original_cross, original_cross, cv::Size(out_face_size*3, out_face_size*4));

    }
    std::cout << "...Loaded" << std::endl;

    if(show_orig_cross)
    {
        cv::namedWindow("Original Cross", CV_WINDOW_FLAGS);
        cv::imshow("Original Cross", original_cross);
        cv::waitKey();
        cv::destroyWindow("Original Cross");
    }

    ////Filtering
    std::vector<CubeMap> filtered_cubes;
    std::vector<float> pows;
    std::vector<std::vector<cv::Mat> > filtered_face_images;
    std::vector<cv::Mat> filtered_cross_images;

    //Load cubemap
    CubeMap cube;
    cube.loadCubeCross(original_cross);
    if(!mipmaps)
    {
//        //Load cubemap
//        CubeMap cube;
//        cube.loadCubeCross(original_cross);

        int len = (pow_max - pow_min)/pow_step;
        pows = std::vector<float> (len+1);
        for(unsigned int i = 0; i < unsigned(len + 1); ++i)
        {
            pows[i] = pow_min + pow_step*i;
            std::cout << "pows[" << i << "] --> " << pows[i] << std::endl;
        }
        filtered_cubes = CubeMapFilter::cosinePowFilterArrayCube(cube, filter_angle, pows);
        cv::waitKey();
//filtered_cross_images = cubeMapsArrayToCrosses(filtered_cubes);
//cv::namedWindow("Bu", CV_WINDOW_FLAGS);
//cv::imshow("Bu", filtered_cross_images[0]);
//cv::waitKey();

        //filtered_cubes[0].resizeCube(int(4));
        filtered_cubes[0] = CubeMapFilter::edgePullFixup(filtered_cubes[0], fixup_band);
        //filtered_cubes.push_back(CubeMapFilter::cosinePowFilterCube(cube, filter_angle, pows[0]));
    }
    else
    {
        //load cube and get cube size and steps
//        CubeMap cube;
//        cube.loadCubeCross(original_cross);
        int face_size = cube.getFaceSize();
        unsigned int steps = std::log2(face_size)+1;
        std::cout << "Steps: " << steps << std::endl;

        //initialize pow
        float step = (pow_max - pow_min)/float(steps-1);
        std::cout << "Step: " << step << std::endl;
        pows = std::vector<float> (steps);
        for(unsigned int i = 0; i < steps; ++i)
        {
            pows[i] = pow_min + step*float(steps - i - 1);
            std::cout << "pows[" << i << "] --> " << pows[i] << std::endl;
        }
//exit(0);
        filtered_cubes = std::vector<CubeMap> (steps);
        cv::Size cross_size = original_cross.size();
        std::cout << "Original size: (" << cross_size.height << ", " << cross_size.width << ")" << std::endl;
        cv::Mat aux_cross;
        std::cout << "aux_cross" << std::endl;
        for(unsigned int i = 0; i < steps; ++i)
        {
//            CubeMap cube_aux;
//            std::cout << "compute step" << std::endl;
            unsigned int step = std::pow(2,i);
//            std::cout << "Compute new size" << std::endl;
            cv::Size new_size(int(cross_size.width/step), int(cross_size.height/step));
            std::cout << "New size: (" << new_size.height << ", " << new_size.width << ")" << std::endl;
//            std::cout << "Resize" << std::endl;
            #ifdef RESIZE_BEFORE
                cv::resize(original_cross, aux_cross, new_size);
            #endif
//            std::cout << "Load aux cross" << std::endl;
            CubeMap aux_cube;
            #ifdef RESIZE_BEFORE
                aux_cube.loadCubeCross(aux_cross);
            #else
                aux_cube.loadCubeCross(original_cross);
            #endif
//            aux_cube.loadCubeCross(original_cross);
//            std::cout << "Filter!!" << std::endl;
            filtered_cubes[i] = CubeMapFilter::cosinePowFilterCube(aux_cube, filter_angle, pows[i]);
            std::cout << "---Face Size: " << int((cross_size.width/step)/3) << std::endl;
            #ifndef RESIZE_BEFORE
                filtered_cubes[i].resizeCube(int((cross_size.width/step)/3));
            #endif
            std::cout << "---Cube Resized." << std::endl;
            std::cout << "Fixup Band!!!!!" << std::endl;
            filtered_cubes[i] = CubeMapFilter::edgePullFixup(filtered_cubes[i], fixup_band);
        }
    }
std::cout << "Cube Filtered!" << std::endl;
    if(show_filt_faces || export_faces) filtered_face_images = cubeMapsArrayToImages(filtered_cubes);
std::cout << "Cube Images!" << std::endl;
    if(show_filt_cross || export_cross) filtered_cross_images = cubeMapsArrayToCrosses(filtered_cubes);
std::cout << "Cube Crosses!" << std::endl;

////Filtering
    if(show_filt_faces)
    {
        for(unsigned int i = 0; i < filtered_face_images.size(); ++i)
        {
            std::string window_name = "Faces from level "+std::to_string(i);
            cv::namedWindow(window_name, CV_WINDOW_FLAGS);
            for(unsigned int j = 0; j < filtered_face_images[0].size(); ++j)
            {
                cv::imshow(window_name, filtered_face_images[i][j]);
                cv::waitKey();
            }
            cv::destroyWindow(window_name);
        }
    }

    if(show_filt_cross)
    {
        for(unsigned int i = 0; i < filtered_cross_images.size(); ++i)
        {
            std::string window_name = "Cross from level "+std::to_string(i);
            cv::namedWindow(window_name, CV_WINDOW_FLAGS);
            cv::imshow(window_name, filtered_cross_images[i]);
            cv::waitKey();
            cv::destroyWindow(window_name);
        }
    }

    if(export_cross)
    {
        cv::Mat export_cross;
        QString dir = QFileDialog::getExistingDirectory(0, QObject::tr("Save Cube Cross"), "./", QFileDialog::ShowDirsOnly);
        if(!dir.isEmpty())
        {
            std::cout << "Saving crosses into: " << dir.toStdString() << std::endl;
            //QString path = QFileDialog::getSaveFileName(0, QObject::tr("Save cube cross"), "./", QObject::tr("PNG Files (*.png);;All files (*)"));
            for(unsigned int i = 0; i < filtered_cross_images.size(); ++i)
            {
                ///FIXME
                //convert format to be RGB this must be modified if the image was hdr
                filtered_cross_images[i].convertTo(export_cross, CV_8U, 255.0f);
                try {
                    cv::imwrite(dir.toStdString()+"/filtered_cross_level_"+std::to_string(i)+".png", export_cross);
                }
                catch (std::runtime_error& ex) {
                    std::cerr << "Exception exporting cross image: %s\n" <<  ex.what();
                    return 1;
                }
            }
        }
        else std::cout << "Not selected Directory" << std::endl;
    }

    if(export_faces)
    {
        cv::Mat export_face;
        QString dir = QFileDialog::getExistingDirectory(0, QObject::tr("Save Cube Faces"), "./", QFileDialog::ShowDirsOnly);
        std::cout << "Saving faces into: " << dir.toStdString() << std::endl;
        for(unsigned int i = 0; i < filtered_face_images.size(); ++i)
        {
            std::string aux = dir.toStdString()+"/faces_level"+std::to_string(i);
//            std::cout << "Saving faces into: " << aux << std::endl;
            QDir faces_dir(QString::fromStdString(aux));
            if (!faces_dir.exists()) faces_dir.mkpath(".");

            for(unsigned int j = 0; j < filtered_face_images[0].size(); ++j)
            {
//                std::cout << "Exporting: " << faces_dir.absolutePath().toStdString()+"/i_c0"+std::to_string(j)+".png" << std::endl;
                ///FIXME
                //convert format to be RGB this must be modified if the image was hdr
                filtered_face_images[i][j].convertTo(export_face, CV_8U, 255.0f);
//                if(j == 5) cv::flip(export_face, export_face, 0);
                cv::imwrite(faces_dir.absolutePath().toStdString()+"/i_c0"+std::to_string(j)+".png", export_face);

            }
        }
    }

////Show import and export
//    std::vector<cv::Mat> images = cube.exportIntoImages();
//    for(unsigned int i = 0; i < images.size(); ++i)
//    {
//        cv::imshow("Image win", images[i]);
//        cv::waitKey();
//    }

//    cv::Mat cross = cube.exportCubeCross();
//    cv::imshow("Image win", cross);
//    cv::waitKey();

//////Test accessors
//    for(int face = 0; face < 6; ++face)
//    {
//        std::cout << "FACE " << face << std::endl;
//        for(int i = 0; i < 4; ++i)
//        {
//            for(int j = 0; j < 4; ++j)
//            {
//                cv::Vec3f face_coords = cv::Vec3f(face, i, j);
//                cv::Vec3f aux_v = cube.getCubeCoords(face_coords);
//                std::cout << "Face Coords: " << face_coords << ", Cube coords: " << aux_v << std::endl;
//            }
//        }
//    }

//////Cross load and export
//        std::vector<cv::Mat> images = cube.exportIntoImages();
//        for(unsigned int i = 0; i < images.size(); ++i)
//        {
//            cv::imshow("Image win", images[i]);
//            cv::waitKey();
//        }

//        cv::Mat cross = cube.exportCubeCross();
//        cv::imshow("Image win", cross);
//        cv::waitKey();

////Black square
    //    int face_size = cube.getFaceSize();
    //    for(int i = 0; i < 6; ++i)
    //    {
    //        for(int j = 0; j < 50; ++j )
    //        {
    //            for(int k = 0; k < 20; ++k)
    //            {
    //                cube(cv::Vec3f(i, j, k)) = cv::Vec3f(0,0,0);
    //            }
    //        }
    //    }
}
Example #29
0
void wxControl::MacPostControlCreate()
{
    wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
    DoSetWindowVariant( m_windowVariant ) ;
   /* 
    if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
    {
        // no font
    }
    else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) )
    {
        ControlFontStyleRec     controlstyle ;
        controlstyle.flags = kControlUseFontMask ;
        controlstyle.font = kControlFontSmallBoldSystemFont ;
        
        ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
    }
    else
    {
        ControlFontStyleRec     controlstyle ;
        controlstyle.flags = kControlUseFontMask ;
        
        if (IsKindOf( CLASSINFO( wxButton ) ) )
            controlstyle.font = kControlFontBigSystemFont ; // eventually kControlFontBigSystemFont ;
        else
            controlstyle.font = kControlFontSmallSystemFont ;
        
        ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
    }
    */
    ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
    wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
    ::EmbedControl( (ControlHandle) m_macControl , container ) ;
    m_macControlIsShown  = MacIsReallyShown() ;

    wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ;
    if ( wxMacSetupControlBackgroundUPP == NULL )
    {
        wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ;
    }
    if ( wxMacControlActionUPP == NULL )
    {
        wxMacControlActionUPP = NewControlDefUPP( wxMacControlDefinition ) ;
    }
    // The following block of code is responsible for crashes when switching
    // back to windows, which can be seen in the dialogs sample.
    // It is disabled until a proper solution can be found.
#if 0
#if TARGET_CARBON
/*
    only working under classic carbon
    m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
    (**(ControlHandle)m_macControl).contrlDefProc = (Handle) &wxMacControlActionUPP ;
*/
#else
    m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;

    cdefHandle cdef ;
    cdef = (cdefHandle) NewHandle( sizeof(cdefRec) ) ;
    if (  (**(ControlHandle)m_macControl).contrlDefProc != NULL )
    {
        (**cdef).instruction = 0x4EF9;  /* JMP instruction */
        (**cdef).function = (void(*)()) wxMacControlActionUPP;
        (**(ControlHandle)m_macControl).contrlDefProc = (Handle) cdef ;
    }
#endif
#endif
    SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ;
    
    // Adjust the controls size and position
    wxPoint pos(m_x, m_y);
    wxSize best_size( DoGetBestSize() );
    wxSize new_size( m_width, m_height );
    
    m_x = m_y = m_width = m_height = -1;  // Forces SetSize to move/size the control
    
    if (new_size.x == -1) {
        new_size.x = best_size.x;
    }
    if (new_size.y == -1) {
        new_size.y = best_size.y;
    }
    
    SetSize(pos.x, pos.y, new_size.x, new_size.y);
    
#if wxUSE_UNICODE
    UMASetControlTitle( (ControlHandle) m_macControl , wxStripMenuCodes(m_label) , m_font.GetEncoding() ) ;
#endif

    if ( m_macControlIsShown )
        UMAShowControl( (ControlHandle) m_macControl ) ;
    
    SetCursor( *wxSTANDARD_CURSOR ) ;
    
    Refresh() ;
}
Example #30
0
/*** Handle events coming from main window: ***/
void dispatch_events()
{
	extern ULONG sigmainwnd, swinsig;
	extern UBYTE record;
	BYTE  scrolldisp=0, state=0, cnt=0, mark=0, quit = 0;

	while( quit == 0 )
	{
		/* Active collect, when pressing arrow gadgets */
		sigrcvd = (state==0 ? Wait(sigbits) : sigmainwnd);

/*		if(sigrcvd & SIGBREAKF_CTRL_C) break;

		else */ if(sigrcvd & sigport) { handle_port(); continue; }

		else if(sigrcvd & swinsig) { handle_search(); continue; }

		/* Collect messages posted to the window port */
		while( ( msg = (struct IntuiMessage *) GetMsg(Wnd->UserPort) ) )
		{
			/* Copy the entire message into the buffer */
			CopyMemQuick(msg, &msgbuf, sizeof(msgbuf));
			ReplyMsg( (struct Message *) msg );

			switch( msgbuf.Class )
			{
				case IDCMP_CLOSEWINDOW: handle_menu(112); break;
				case IDCMP_RAWKEY:
					handle_kbd(edit);
					if(record) {
						if(record == 1) reg_act_com(MAC_ACT_SHORTCUT, msgbuf.Code, msgbuf.Qualifier);
						else record &= 0x7f;
					}
					break;
				case IDCMP_INTUITICKS:
					/* An error message which needs to be removed? */
					if(err_time == 0) err_time = msgbuf.Seconds;
					if(err_time && msgbuf.Seconds-err_time>4) StopError(Wnd);
					break;
				case IDCMP_MOUSEBUTTONS:
					/* Click somewhere in the text */
					switch( msgbuf.Code )
					{
						case SELECTDOWN:
							/* Click over the project bar ? */
							if(msgbuf.MouseY < gui.top)
							{
								edit = select_panel(edit, msgbuf.MouseX);
								break;
							}

							click(edit, msgbuf.MouseX, msgbuf.MouseY, FALSE);

							/* Shift-click to use columnar selection */
							if( ( move_selection = SwitchSelect(edit, msgbuf.Qualifier & SHIFTKEYS ? 1:0, 1) ) )
								mark=TRUE;
							break;
						case SELECTUP:
							if(mark) unclick(edit);
							mark=FALSE; scrolldisp=0; break;
					}
					break;
				case IDCMP_NEWSIZE:
					new_size(EDIT_ALL);
					break;
				case IDCMP_GADGETDOWN:       /* Left scroll bar */
					if(msgbuf.IAddress == (APTR) &Prop->down) state=1;
					if(msgbuf.IAddress == (APTR) &Prop->up)   state=2;
					break;
				case IDCMP_GADGETUP:        /* Arrows or prop gadget */
					state=0;
					if(msgbuf.IAddress == (APTR) Prop)
						scroll_disp(edit, FALSE), scrolldisp=0;
					break;
				case IDCMP_MOUSEMOVE:
					if(mark) scrolldisp=2;
					else
						if(Prop->scroller.Flags & GFLG_SELECTED) scrolldisp=1;
					break;
				case IDCMP_MENUPICK:
				{	struct MenuItem * Item;
					ULONG             MenuId;

					/* Multi-selection of menu entries */
					while(msgbuf.Code != MENUNULL)
						if( (Item = ItemAddress( Menu, msgbuf.Code )) )
						{
							/* stegerg: get NextSelect here in case menu action causes screen
							   to be closed/reopened in which case item becomes invalid.
							   Also assuming here that user in such case will not use
							   multiselection, ie. that nextselect will be MENUNULL.
							   
							   If that's not the case it would mean more trouble and to protect
							   against that one would need to check if during handle_menu() the
							   screen has been closed/reopened and in that case break out of
							   the menu multiselection loop here. */
							   							   
							UWORD nextselect = Item->NextSelect;
							
							MenuId = (ULONG)GTMENUITEM_USERDATA( Item );
							handle_menu( MenuId );

							if(record) reg_act_com(MAC_ACT_COM_MENU, MenuId, msgbuf.Qualifier);
							else record &= 0x7f;

							msgbuf.Code = nextselect;
						}
				}
			}
		}
		/* Reduces the number of IDCMP mousemove messages to process */
		if(scrolldisp==1) scroll_disp(edit, FALSE), scrolldisp=0;
		if(scrolldisp==2) { scrolldisp=0; goto moveit; }

		/* User may want to auto-scroll the display using arrow gadgets */
		if(state && (mark || (((struct Gadget *)Prop)[state].Flags & GFLG_SELECTED))) {
			/* Slow down animation: */
			WaitTOF(); cnt++;
			if(cnt>1) {
				cnt=0;
				if(autoscroll(edit,state==1 ? 1:-1)==0) state=0;
				else if(mark) {
					LONG x , y; moveit:
					/* Adjust mouse position */
					x = (msgbuf.MouseX-gui.left) / XSIZE;
					y = (msgbuf.MouseY-gui.top) / YSIZE;
					if(x < 0) x =  0; if(x >= gui.nbcol)  x = gui.nbcol-1;
					if(y < 0) y = -1; if(y >  gui.nbline) y = gui.nbline;
					edit->nbrwc = (x += edit->left_pos);
					y += (LONG)edit->top_line;
					if( x != edit->ccp.xc || y != edit->ccp.yc )
						/* Move the selected stream */
						if( !(state = move_selection(edit,x,y)) )
							set_cursor_line(edit, y, edit->top_line),
							inv_curs(edit,TRUE);
				}
			}
		}	/* endif: arrow gadget pressed or autoscroll */
	}
}