Example #1
0
void Map::draw(float elapsed)
{
	CL_Vec2<float> fieldSize;
	CL_Pointf p;

	CL_Rect viewport = window.get_viewport();
	
	fieldSize.x = (float)viewport.get_width() / size.width;
	fieldSize.y = (float)viewport.get_height() / size.height;

	for (int row = 0; row < size.height; row++)
		for (int col = 0; col < size.width; col++)
		{
			p = CL_Pointf(col * fieldSize.x, row * fieldSize.y) + fieldSize / 2;	

			if (row < size.height - 1)
			{
				CL_Colorf color(getEdge(CL_Point(col, row), CL_Point(col, row + 1)).pheromone / 10, 0, 0);
				CL_Draw::line(window.get_gc(), p, p + CL_Vec2<float>(0, fieldSize.y), color);
			}

			if (col < size.width - 1)
			{
				CL_Colorf color(getEdge(CL_Point(col, row), CL_Point(col + 1, row)).pheromone / 10, 0, 0);
				CL_Draw::line(window.get_gc(), p, p + CL_Vec2<float>(fieldSize.x, 0), color);
			}
		}

	p = CL_Pointf(start.x * fieldSize.x, start.y * fieldSize.y);
	CL_Draw::fill(window.get_gc(), p, p + fieldSize, CL_Colorf::red);

	p = CL_Pointf(target.x * fieldSize.x, target.y * fieldSize.y);
	CL_Draw::fill(window.get_gc(), p, p + fieldSize, CL_Colorf::green);
}
Example #2
0
void
WindowImpl::draw()
{
  CL_Display::push_translate (parent->get_screen_x(), parent->get_screen_y());

  CL_Color highlight(255, 255, 255);
  CL_Color midtone(150, 150, 150);

  CL_Rect rect = parent->get_position() ;

  Box::draw_window(CL_Rect(CL_Point(0, 0), CL_Size(rect.get_width()-1, rect.get_height()-1)));
  Box::draw_panel_down(client_area->get_position());

  /*
    CL_Display::fill_rect(CL_Rect(CL_Point(0, 0), rect.get_size()), CL_Color(220, 220, 220));
    CL_Display::draw_rect(CL_Rect(CL_Point(0, 0), rect.get_size()), CL_Color(0, 0, 0));
 
    CL_Display::draw_line(1, rect.get_height()-2,
    rect.get_width()-2, rect.get_height()-2, midtone);
    CL_Display::draw_line(rect.get_width()-2, 1,
    rect.get_width()-2, rect.get_height()-2, midtone);

    CL_Display::draw_line(1, 1,
    rect.get_width()-2, 1, highlight);
    CL_Display::draw_line(1, 1,
    1, rect.get_height()-2, highlight);
  */

  CL_Display::pop_modelview();
}
Example #3
0
Viewport::Viewport(CL_Component* child, const CL_Rect& rect, CL_Component* parent)
  : CL_Component(rect, parent),
    impl(new ViewportImpl())
{
  impl->child = child;
  impl->gc_state.set_size(rect.get_width(), rect.get_height());
}
Example #4
0
void CL_GUIComponent_Impl::set_geometry(CL_Rect new_geometry, bool client_area)
{
	if (parent == 0)
	{
		CL_GUITopLevelWindow *handle = gui_manager.lock()->get_toplevel_window(component);
		gui_manager.lock()->window_manager.set_geometry(handle, new_geometry, client_area);
		new_geometry = gui_manager.lock()->window_manager.get_geometry(handle, true);
	}

	// repaint parent at old geometry
	if (component->get_parent_component())
		component->get_parent_component()->request_repaint(geometry);

	// Check for resize
	if ((geometry.get_width() != new_geometry.get_width()) || (geometry.get_height() != new_geometry.get_height()) )
	{
		geometry = new_geometry;
		geometry_updated();
	}
	else
	{
		geometry = new_geometry;
		component->request_repaint();
	}
}
void CL_ListViewHeader_Impl::on_render(CL_GraphicContext &gc, const CL_Rect &update_rect)
{
	CL_Rect rect = listview_header->get_geometry();
	part_component.render_box(gc, rect.get_size(), update_rect);
	
	// draw listview column headers and backgrounds
	text_height = font.get_text_size(gc, "l").height;
	CL_ListViewColumnHeader col = first_column;
	while (!col.is_null())
	{
		CL_GUIThemePart &part = col.impl->part;
		CL_Rect &crect = col.impl->rect;
		if (display_mode != listview_mode_details)
			crect.right = rect.right;
		part.render_box(gc, crect, update_rect);
		CL_Rect content_rect = part.get_content_box(crect);

		part.render_text(gc, col.get_caption(), content_rect, update_rect);

		col = col.get_next_sibling();

		if (display_mode != listview_mode_details)
			break;
	}
}
Example #6
0
void Sandpit::build()
{
	CL_Rect bounds = calculateCircleBounds();

	setPosition(CL_Pointf(bounds.left, bounds.top));

	const float MAX_WIDTH = 512;
	const float MAX_HEIGHT = 512;

	// prepare image data
	const int width = bounds.get_width() + 1;
	const int height = bounds.get_height() + 1;

	assert(width <= MAX_WIDTH && width > 0);
	assert(height <= MAX_HEIGHT && height > 0);

	// prepare pixel data
	m_pixelData = CL_SharedPtr<CL_PixelBuffer>(new CL_PixelBuffer(width, height, width * 4, CL_PixelFormat::rgba8888));

	fillCircles(width, height, bounds);

	// unset the texture to create is at the next draw
	m_texture.disconnect();

	m_built = true;
}
Example #7
0
void ShaderImpl::begin(CL_GraphicContext &p_gc)
{
	G_ASSERT(m_initialized);
	G_ASSERT(!m_began);

	// new texture
	m_drawRect = m_parent->getDrawRect(m_boundRect);
	m_texture = CL_Texture(p_gc, m_drawRect.get_width(), m_drawRect.get_height());

	// attach frame buffer
	m_frameBuffer.attach_color_buffer(0, m_texture);
	p_gc.set_frame_buffer(m_frameBuffer);

	// clear to transparent
	p_gc.clear(CL_Colorf::transparent);

	// set proper matrix
	p_gc.push_modelview();

	// get scaling in count
	const CL_Mat4f &matrix = p_gc.get_modelview();
	const float scaleX = matrix[0];
	const float scaleY = matrix[5];

	p_gc.mult_translate(-m_drawRect.left / scaleX, -m_drawRect.top / scaleY);

	m_began = true;
}
Example #8
0
Window::Window(const CL_Rect& rect, const std::string& title, CL_Component* parent)
  : CL_Component(rect, parent), impl(new WindowImpl())
{
  impl->titlebar = new Titlebar(CL_Rect(CL_Point(3+16,3), 
                                        CL_Size(get_width()-6-18-18-18, 12+3)), title,
                                this);
  //Fonts::verdana11.draw(8+15, 3, title);

  impl->close = new Icon(CL_Rect(CL_Point(3, 3), CL_Size(18,18)), 
                         make_sprite(datadir + "/images/window/close.png"),
                         "", this);
  impl->minimize = new Icon(CL_Rect(CL_Point(get_width()-3-18-18, 3), CL_Size(18,18)), 
                            make_sprite(datadir + "/images/window/minimize.png"),
                            "", this);
  impl->maximize = new Icon(CL_Rect(CL_Point(get_width()-3-18, 3), CL_Size(18,18)), 
                            make_sprite(datadir + "/images/window/maximize.png"),
                            "", this);

  impl->client_area = new CL_Component(CL_Rect(CL_Point(4, 3+12+7), 
                                               CL_Size(rect.get_width()-10,
                                                       rect.get_height()-28)), this);
  impl->parent  = this;
  impl->is_maximized = false;

  impl->slots.push_back(sig_resize().connect(impl.get(),      &WindowImpl::on_resize));

  impl->slots.push_back(sig_paint().connect(impl.get(),      &WindowImpl::draw));
  impl->slots.push_back(impl->maximize->sig_clicked().connect(impl.get(), &WindowImpl::do_maximize));
  impl->slots.push_back(impl->close->sig_clicked().connect(impl.get(), &WindowImpl::do_close));
}
bool CL_OpenGLWindowProvider_GLX::on_clicked(XButtonEvent &event)
{
	if (event.button != 1)	// Left mouse button
		return true;

	int height = get_viewport().get_height();

	glDrawBuffer(GL_BACK);
	glReadBuffer(GL_FRONT);

	CL_Rect rect = CL_Rect(event.x,event.y, CL_Size(1,1));

	CL_PixelBuffer pixelbuffer(rect.get_width(), rect.get_height(), cl_rgba8);
	glReadPixels(
		rect.left, height - rect.bottom,
		rect.right - rect.left, rect.bottom - rect.top,
		GL_RGBA,
		GL_UNSIGNED_INT_8_8_8_8,
		pixelbuffer.get_data());

	const cl_ubyte32 *xptr = (const cl_ubyte32 *) (pixelbuffer.get_data());
	if (((*xptr) & 0xFF) < 10)
	{
		XLowerWindow(x11_window.get_display(), x11_window.get_window());
		return false;
	}

	return true;
}
CL_Rect CL_GUIThemePart::get_content_box(const CL_Rect &render_box_rect) const
{
	impl->check_content_shrink_box_is_cached(*this);
	CL_Rect box = render_box_rect;
	CL_Rect &R = impl->cached_content_box_shrink_rect;
	box.shrink(R.left, R.top, R.right, R.bottom);
	return box;
}
Example #11
0
void CL_GUIComponent::set_clip_children(bool clip, const CL_Rect &rect)
{
	impl->clip_children = clip;
	if (rect.get_width() == 0 || rect.get_height() == 0)
		impl->clip_children_rect = get_size();
	else
		impl->clip_children_rect = rect;
}
std::vector<CL_ClanImageStretch::ImagePart> CL_ClanImageStretch::calc_stretch_image_parts(const CL_Rect &dest, CL_Image &sprite, int sizing_left, int sizing_top, int sizing_right, int sizing_bottom)
{
	int src_width = sprite.get_width();
	int src_height = sprite.get_height();
	int dest_width = dest.get_width();
	int dest_height = dest.get_height();

	int src_grid_x[4];
	int src_grid_y[4];
	int dest_grid_x[4];
	int dest_grid_y[4];

	int rows = 0;
	int cols = 0;

	src_grid_x[cols++] = 0;
	src_grid_x[cols++] = sizing_left;
	src_grid_x[cols++] = src_width - sizing_right;
	src_grid_x[cols++] = src_width;

	src_grid_y[rows++] = 0;
	src_grid_y[rows++] = sizing_top;
	src_grid_y[rows++] = src_height - sizing_bottom;
	src_grid_y[rows++] = src_height;

	rows = 0;
	cols = 0;

	dest_grid_x[cols++] = dest.left;
	dest_grid_x[cols++] = dest.left + sizing_left;
	dest_grid_x[cols++] = dest.right - sizing_right;
	dest_grid_x[cols++] = dest.right;

	dest_grid_y[rows++] = dest.top;
	dest_grid_y[rows++] = dest.top + sizing_top;
	dest_grid_y[rows++] = dest.bottom - sizing_bottom;
	dest_grid_y[rows++] = dest.bottom;

	std::vector<ImagePart> image_parts;
	for (int y = 0; y < rows-1; y++)
	{
		for (int x = 0; x < cols-1; x++)
		{
			ImagePart part;
			part.source_rect = CL_Rect(src_grid_x[x], src_grid_y[y], src_grid_x[x+1], src_grid_y[y+1]);
			part.dest_rect = CL_Rect(dest_grid_x[x], dest_grid_y[y], dest_grid_x[x+1], dest_grid_y[y+1]);
			if (part.source_rect.get_width() > 0 && part.source_rect.get_height() > 0 &&
				part.dest_rect.get_width() > 0 && part.dest_rect.get_height() > 0)
			{
				image_parts.push_back(part);
			}
		}
	}

	return image_parts;
}
void CL_TreeItem_Silver::on_paint()
{
	CL_Rect rect = item->get_screen_rect();
	
	int height = rect.get_height();
	int font_height = font->get_height(item->get_text(0));
	
	if(item->has_mouse_over())
		CL_Display::fill_rect(rect, CL_Color(232, 236, 241));
	if(item->get_node()->is_selected())
		CL_Display::fill_rect(rect, CL_Color(184, 195, 209, 150));

	CL_TreeView *treeview = item->get_node()->get_treeview();
	int columns = treeview->get_column_count();
	if(columns == 0)
		columns = 1;

	// Draw columns
	for(int x = 0, i = 0; i < columns; ++i)
	{
		int dx = 0;
		if(i == 0)
		{
			dx += item->get_text_margin();

			CL_Surface *icon = item->get_icon();
			if(icon)
			{
				icon->draw(
					rect.left + x + 1,
					rect.top + (height - icon->get_height()) / 2);
				dx += icon->get_width();
			}
		}

		CL_Component *comp = item->get_component(i);
		if(comp)
		{
			comp->set_position(CL_Rect(x + dx + 4, 0, x + dx + 4 + treeview->get_column_width(i), height));
			comp->paint();
		}
		else
		{
			font->draw(
				rect.left + x + dx + 4,
				rect.top + (height - font_height) / 2,
				item->get_text(i));
		}

		x += treeview->get_column_width(i);
		if(i == 0)
			x -= item->get_node()->get_placement_offset();
	}
}
void CL_InputBox_Silver::on_get_preferred_size(CL_Size &size)
{
	border_size = 3;
	
	// Override height for font-height
	CL_Rect position = inputbox->get_position();
	position.bottom = position.top + font->get_height() + border_size * 2;

	size.width = position.get_width();
	size.height = position.get_height();
}
Example #15
0
CL_Vec2f Firework::scale(const CL_Vec2f& v) const
{
	CL_Vec2f scaled;

	CL_Rect viewport = window.get_viewport();

	scaled.x = v.x + viewport.get_width() / 2.0f;
	scaled.y = viewport.get_height() - v.y;
	
	return scaled;
}
Example #16
0
void CL_GUIComponent::render(CL_GraphicContext &gc, const CL_Rect &clip_rect, bool include_children)
{
	if (!impl->visible)
		return;

	if (!impl->css_layout.is_null())
	{
		impl->css_layout.layout(gc, get_size());
		impl->css_layout.render(gc, this);
	}

	if (impl->func_render.is_null() == false)
	{
		impl->func_render.invoke(gc, clip_rect);
	}
	else
	{
		CL_GUIThemePart part(this);
		CL_Rect geometry = get_size();
		part.render_box(gc, CL_RectPS(0, 0, geometry.get_width(), geometry.get_height()), clip_rect);
	}

	if (include_children)
	{
		if (impl->clip_children)
		{
			push_cliprect(gc, impl->clip_children_rect);
		}

		CL_GUIComponent *cur = impl->first_child;
		while (cur)
		{
			CL_Rect cur_geometry = cur->get_geometry();

			CL_Rect update_rect = component_to_window_coords(clip_rect);
			update_rect.overlap(component_to_window_coords(cur_geometry));
			if (update_rect.get_width() > 0 && update_rect.get_height() > 0)
			{
				CL_Rect child_dirty_rect = cur->window_to_component_coords(update_rect);

				gc.push_translate((float)cur_geometry.left, (float)cur_geometry.top);
				cur->render(gc, child_dirty_rect, true);
				gc.pop_modelview();
			}
			cur = cur->impl->next_sibling;
		}

		if (impl->clip_children)
		{
			pop_cliprect(gc);
		}
	}
}
bool CL_MenuModalLoop::is_above_menubar(const CL_Point &mouse_screen_pos)
{
	if (menubar)
	{
		CL_Point menu_pos  = menubar->screen_to_component_coords(mouse_screen_pos);
		CL_Rect r = menubar->get_geometry().get_size();
		if (r.contains(menu_pos))
			return true;
	}

	return false;
}
Example #18
0
void
WindowImpl::on_resize(int, int)
{
  titlebar->set_position(CL_Rect(CL_Point(3+16,3), CL_Size(parent->get_width()-6-18-18-18, 12+3)));
  close->set_position(3, 3);
  minimize->set_position(parent->get_width()-3-18-18, 3);
  maximize->set_position(parent->get_width()-3-18, 3);
  CL_Rect rect = parent->get_position();
  client_area->set_position(CL_Rect(CL_Point(4, 3+12+7), 
                                    CL_Size(rect.get_width()-10,
                                            rect.get_height()-28)));
}
Example #19
0
ObjMapControlPoint
ObjectLayer::find_control_point(const CL_Pointf& click_pos)
{
  for(ControlPoints::reverse_iterator i = impl->control_points.rbegin();
      i != impl->control_points.rend();
      ++i)
  {
    CL_Rect rect = (*i).get_bound_rect();

    if (rect.is_inside(CL_Point(click_pos)))
      return *i;
  }
  return ObjMapControlPoint();
}
CL_PopupMenuWindow *CL_MenuModalLoop::find_popup_at(const CL_Point &mouse_screen_pos)
{
	std::vector<CL_PopupMenuWindow*>::size_type i;
	for (i=0; i<popup_windows.size(); i++)
	{
		CL_Point pos = popup_windows[i]->screen_to_component_coords(mouse_screen_pos);
		CL_Rect r = popup_windows[i]->get_size();
		if (r.contains(pos))
		{
			return popup_windows[i];
		}
	}

	return 0;
}
Example #21
0
void CL_ListView_Impl::on_render(CL_GraphicContext &gc, const CL_Rect &update_rect)
{
	CL_Rect rect = listview->get_geometry();
	part_component.render_box(gc, rect.get_size(), update_rect);
	part_columns_bg.render_box(gc, rect_columns, update_rect);

	listview->push_cliprect(gc, rect_columns_content);

	std::vector<ListViewShownItem> &items = layout->get_shown_items();
	std::vector<ListViewColumn> &columns = layout->get_columns();
	std::vector<ListViewRow> &rows = layout->get_rows();
	renderer->render(gc, columns, rows, items, update_rect);

	listview->pop_cliprect(gc);
}
Example #22
0
const CL_Rect &MotionBlurShaderImpl::getDrawRect(const CL_Rect &p_requested)
{
	m_drawRect = p_requested;
	m_drawRect.expand(m_radius);

	return m_drawRect;
}
CL_Rect CL_ListViewLayoutIcons::get_icon_rect(const CL_Rect &cell_content_rect, CL_ListViewItem item, int offset_x)
{
	int icon_x = cell_content_rect.get_center().x - size_icon.width/2;
	int icon_y = cell_content_rect.get_center().y - size_icon.height/2;
	CL_Rect rect_icon(CL_Point(icon_x, icon_y), size_icon);
	return rect_icon;
}
void CL_ListViewHeader_Impl::on_mouse_move(CL_GUIMessage_Input &input, CL_InputEvent &input_event)
{
	CL_Point pos = input_event.mouse_pos;
	bool current_rect_set = false;

	if (!current_mouse_in_rect.contains(pos))
	{
		CL_ListViewColumnHeader col = first_column;
		while (!col.is_null())
		{
			bool inside = col.impl->rect.contains(pos);
			col.impl->part.set_state(CssStr::hot, inside);
			col.impl->part.set_state(CssStr::normal, !inside);
			if (inside)
			{
				current_rect_set = true;
				current_mouse_in_rect = col.impl->rect;
			}
			col = col.get_next_sibling();
		}
	}

	if (!current_rect_set)
	{
		current_mouse_in_rect = CL_Rect(0,0,0,0);
	}

	listview_header->request_repaint();
}
Example #25
0
void CL_MenuBar_Impl::select_item_at(const CL_Point &mouse_pos)
{
	std::vector<CL_TopMenu>::size_type index;
	for (index = 0; index < menus.size(); index++)
	{
		CL_Rect r = get_menu_item_rect(index);
		r.top = 0;
		r.bottom = menubar->get_geometry().bottom;
		if (r.contains(mouse_pos))
		{
			selected_index = index;
			menubar->request_repaint();
			return;
		}
	}

	// Selection isn't changed if the mouse is on the menubar but not on an item.
}
Example #26
0
void CL_CSSLayout::layout(CL_GraphicContext &gc, const CL_Rect &viewport)
{
	impl->throw_if_disposed();

	CL_CSSLayoutGraphics graphics(gc, &impl->resource_cache, impl->viewport);
	impl->box_tree.prepare(&impl->resource_cache);
	impl->layout_tree.create(impl->box_tree.get_root_element());
	impl->layout_tree.layout(&graphics, &impl->resource_cache, viewport.get_size());
	impl->viewport = viewport;
}
void CL_TreeView_Silver::on_paint_header()
{
	// Header
	if(treeview->is_header_visible())
	{
		CL_Rect rect = header_area->get_screen_rect();

		// Header background
		CL_Display::fill_rect(
			CL_Rect(
				rect.left + 1,
				rect.top + 1,
				rect.left + rect.get_width() - 1,
				rect.top + rect.get_height() - 4),
			CL_Gradient(
				CL_Color(245, 246, 247), CL_Color(245, 246, 247), CL_Color(235, 238, 241), CL_Color(235, 238, 241)));

		CL_Display::fill_rect(
			CL_Rect(
				rect.left + 1,
				rect.top + rect.get_height() - 4,
				rect.left + rect.get_width() - 1,
				rect.top + rect.get_height()),
			CL_Gradient(
				CL_Color(235, 238, 241), CL_Color(235, 238, 241), CL_Color(186, 187, 188), CL_Color(186, 187, 188)));

		// Draw columns
		int x = 0;
		int columns = treeview->get_column_count();
		for(int i = 0; i < columns; ++i)
		{
			font->draw(
				rect.left + x + 6,
				rect.top + 4, treeview->get_column_name(i));
				
			x += treeview->get_column_width(i);
			
			CL_Display::draw_line(
				rect.left + x,
				rect.top + 1,
				rect.left + x,
				rect.top + rect.get_height(),
				CL_Color(128, 142, 159));
			CL_Display::draw_line(
				rect.left + x + 1,
				rect.top + 1,
				rect.left + x + 1,
				rect.top + rect.get_height(),
				CL_Color::white);
		}
	}
}
Example #28
0
void ShaderImpl::end(CL_GraphicContext &p_gc)
{
	G_ASSERT(m_initialized);
	G_ASSERT(m_began);

	// detach frame buffer
	p_gc.reset_frame_buffer();
	m_frameBuffer.detach_color_buffer(0, m_texture);

	// prepare shader
	m_program.set_uniform1i("tex", 0);
	m_program.set_uniform1i("textureWidth", m_drawRect.get_width());
	m_program.set_uniform1i("textureHeight", m_drawRect.get_height());

	m_parent->setUniforms(m_program);

	// draw texture using shader
	p_gc.set_modelview(CL_Mat4f::identity());
	p_gc.mult_translate(m_drawRect.left, m_drawRect.top);
	p_gc.mult_scale(m_drawRect.get_width(), m_drawRect.get_height());

	p_gc.set_texture(0, m_texture);
	p_gc.set_program_object(m_program);

	p_gc.draw_primitives(cl_quads, 4, m_quad);

	p_gc.reset_program_object();
	p_gc.reset_texture(0);

#if defined(DRAW_WIREFRAME)
	CL_Draw::line(p_gc, 0, 0, 1, 0, CL_Colorf::red);
	CL_Draw::line(p_gc, 1, 0, 1, 1, CL_Colorf::red);
	CL_Draw::line(p_gc, 1, 1, 0, 1, CL_Colorf::red);
	CL_Draw::line(p_gc, 0, 1, 0, 0, CL_Colorf::red);
#endif // DRAW_WIREFRAME

	// reset modelview matrix
	p_gc.pop_modelview();

	m_began = false;
}
Example #29
0
	void EditorPoint::findPointAt(const CL_Pointf &p_pos, int &p_index)
	{
		if (getKeys().size() == 0)
		{
			p_index = -1;
			m_impl->m_state = EditorPointImpl::None;

			CL_Rect rect = getPointRect(p_pos);

			for (int i = 0; i < m_track.getPointCount(); ++i)
			{
				if (rect.contains(m_track.getPoint(i).getPosition()))
				{
					m_impl->m_state = EditorPointImpl::Point;
					p_index = i;

					return;
				}
			}
		}
	}
Example #30
0
CL_Image App::get_stencil(CL_GraphicContext &gc, CL_Rect rect)
{

	// For an unknown reason, stencil reads should be a multiple of 32
	rect.left =  32 * ((rect.left + 31) / 32);
	rect.top =  32 * ((rect.top + 31) / 32);
	rect.right =  32 * ((rect.right + 31) / 32);
	rect.bottom =  32 * ((rect.bottom + 31) / 32);

	int rect_width = rect.get_width();
	int rect_height  = rect.get_height();

	std::vector<unsigned char> buffer;
	buffer.resize(rect_width * rect_height);

	clReadPixels(rect.left, gc.get_height()- rect.bottom, rect_width, rect_height, CL_STENCIL_INDEX, CL_UNSIGNED_BYTE, &buffer[0]);
	CL_PixelBuffer pbuf(rect_width, rect_height, cl_abgr8);
	unsigned int *pdata = (unsigned int *) pbuf.get_data();
	unsigned char *rdata = &buffer[0];
	for (int ycnt=0; ycnt < rect_height; ycnt++)
	{
		for (int xcnt=0; xcnt < rect_width; xcnt++)
		{
			int value = *(rdata++);
			if (value == 0)
			{
				*(pdata++) = 0xFF005500;
			}
			else
			{
				value = value * 16;
				value = 0xFF000000 | value | (value << 8) | (value << 16);
				*(pdata++) = value;
			}
		}
	}
	pbuf.flip_vertical();
	return CL_Image(gc, pbuf, pbuf.get_size());
}