Esempio n. 1
0
int render_clock()
{
	static char buflasttime[128];
	char buftime[128];
	time_t current_time;
	current_time = time(0);
	strftime(buftime, sizeof(buftime), theme->clock.format, localtime(&current_time));
	if (!strcmp(buflasttime, buftime))
		return 0;
	strcpy(buflasttime, buftime);
	
	tile_image(theme->tile_img, clock_pos, clock_width);
	int ox = clock_pos;
	draw_clock_background(ox, clock_width);
	int gap = theme->clock.space_gap;
	int lgap = get_image_width(theme->clock.left_img);
	int rgap = get_image_width(theme->clock.right_img);
	int x = ox + gap + lgap;
	int w = clock_width - ((gap * 2) + lgap + rgap);

	imlib_context_set_cliprect(x, 0, w, bbheight);
	draw_text(theme->clock.font, theme->clock.text_align, x, w,
			theme->clock.text_offset_x, theme->clock.text_offset_y,
			buftime, &theme->clock.text_color);
	imlib_context_set_cliprect(0, 0, bbwidth, bbheight);
	return 1;
}
int HaarDetector::init(unsigned int image_width, unsigned int image_height)
{        
        if (m_object_sizes.size() == 0)
                return -1;
        if (m_ai_classifiers.size() == 0)            
                return -2;

        AiClassifier* pai = m_ai_classifiers[m_ai_classifiers.size() - 1];
        if (pai->ai_type() != AiClassifier::SIGMOID_ANN)
                return -3;


        m_image_width = image_width;
        m_image_height = image_height;

        m_integral_image = new vec2Di(get_image_height(), get_image_width());

        for (unsigned int i = 0; i < (unsigned int)m_object_sizes.size(); i++) {
                const ObjectSize& osize = m_object_sizes[i];
                ObjectMap* omap = new ObjectMap(get_image_width(), get_image_height(),
                                                osize.width, osize.height);
                m_object_maps.push_back(omap);
        }

        m_search_mask = new vec2Di(get_image_height(), get_image_width());
        m_tmp_search_mask = new vec2Di(get_image_height(), get_image_width());
        
        m_status = 0;

        return 0;
}
Esempio n. 3
0
void render_taskbar(struct task *tasks, struct desktop *desktops)
{
	tile_image(theme->tile_img, taskbar_pos, taskbar_width);
	int activedesktop = 0;
	struct desktop *iter = desktops;
	while (iter) {
		if (iter->focused)
			break;
		activedesktop++;
		iter = iter->next;
	}
	
	struct task *t = tasks;
	uint state;
	int gap = theme->taskbar.space_gap;

	while (t) {
		if (t->desktop == activedesktop || t->desktop == -1) {
			state = t->focused ? BSTATE_PRESSED : BSTATE_IDLE;
			/* draw bg */
			draw_taskbar_button(state, t->posx, t->width);
			int lgap = get_image_width(theme->taskbar.left_img[state]);
			int rgap = get_image_width(theme->taskbar.right_img[state]);
			int x = t->posx + gap + lgap;
			int w = t->width - ((gap * 2) + lgap + rgap);

			/* draw icon */
			if (theme->taskbar.icon_h && theme->taskbar.icon_w) {
				int srcw, srch;
				int y = (theme->height - theme->taskbar.icon_h) / 2;
				imlib_context_set_image(t->icon);
				srcw = imlib_image_get_width();
				srch = imlib_image_get_height();
				y += theme->taskbar.icon_offset_y;
				x += theme->taskbar.icon_offset_x;
				w -= theme->taskbar.icon_offset_x;
				imlib_context_set_image(bb);
				imlib_context_set_blend(1);
				imlib_blend_image_onto_image(t->icon, 1, 0, 0, srcw, srch,
						x, y, theme->taskbar.icon_w, theme->taskbar.icon_h);
				imlib_context_set_blend(0);
				x += theme->taskbar.icon_w;
				w -= theme->taskbar.icon_w;
			}

			/* draw text */
			imlib_context_set_cliprect(x, 0, w, bbheight);
			draw_text(theme->taskbar.font, theme->taskbar.text_align, x, w,
				theme->taskbar.text_offset_x, theme->taskbar.text_offset_y,
				t->name, &theme->taskbar.text_color[state]);
			imlib_context_set_cliprect(0, 0, bbwidth, bbheight);

			/* draw separator if exists */
			if (t->next && t->next->desktop == activedesktop)
				draw_image(theme->taskbar.separator_img, x+w+gap+rgap);
		}
		t = t->next;
	}
}
Esempio n. 4
0
static void draw_tile_sequence(Imlib_Image left, Imlib_Image tile, Imlib_Image right,
		int ox, int width)
{
	int lw = get_image_width(left);
	int rw = get_image_width(right);
	int tilew = width - lw - rw;
	if (tilew < 0)
		return;

	draw_image(left, ox);
	ox += lw;
	tile_image(tile, ox, tilew);
	ox += tilew;
	draw_image(right, ox);
}
Esempio n. 5
0
static void
autovscale(DDLSymbolTable *st, float *vmin, float *vmax)
{
    int i;
    int n;
    float min;
    float max;

    // Find max and min values in the data
    int npts = (get_image_width(st) * get_image_height(st)
		* get_image_depth(st));
    get_min_max(st, &min, &max);

    // Get intensity distribution
    int nbins = 10000;
    int *histogram = new int[nbins];
    get_histogram(st, min, max, histogram, nbins);

    // Estimate percentile points from distribution
    int percentile = (int)(0.01 * npts);
    if (percentile < 1) percentile = 1;
    float scale = (nbins - 1) / (max - min);
    for (i=n=0; n<percentile && i<nbins; n += histogram[i++]);
    *vmin = min + (i-1) / scale;
    for (i=nbins, n=0; n<percentile && i>0; n += histogram[--i]);
    *vmax = min + i / scale;

    // Set vmin to 0 if it looks plausible
    if (*vmin > 0 && *vmin / *vmax < 0.05){
	*vmin = 0;
    }

    delete [] histogram;
}   
Esempio n. 6
0
    __kernel void resize_image(__read_only image2d_t input,
                               const sampler_t sampler,
                               __write_only image2d_t output)
    {
        const uint x = get_global_id(0);
        const uint y = get_global_id(1);

        const float w = get_image_width(output);
        const float h = get_image_height(output);

        float2 coord = { ((float) x / w) * get_image_width(input),
                         ((float) y / h) * get_image_height(input) };

        float4 pixel = read_imagef(input, sampler, coord);
        write_imagef(output, (int2)(x, h - y - 1), pixel);
    };
Esempio n. 7
0
int main(int argc, char* argv[])
{
	create_image_world();
	
	int image = create_image(100, 100);
	
	for(int x = 0; x < 100; x++)
	{
		for(int y = 0; y < 100; y++)
		{
			if (x == y)
			{
				set_pixel(image, x, y, 255, 0, 0, 255);
			}
			else if (x+y == 100)
			{
				set_pixel(image, x, y, 255, 255, 0, 0);
			}
			else
			{
				set_pixel(image, x, y, 255, 0, 255, 0);
			}
		}
	}
	
	put_image(image, get_screen_width()/2-get_image_width(image)/2, get_screen_height()/2-get_image_height(image)/2);
	
	return p1world_shutdown();	
}
Esempio n. 8
0
int2 OVERLOAD get_image_dim(image2d_t image)
{
    int2 result;

    result.x = get_image_width(image);
    result.y = get_image_height(image);

    return result;
}
void HaarDetector::compute_integral_image(const vec2Di& image)
{
        if (status() < 0)
                return;

        //copy image -> m_integral_image
        vec2Di& v = *m_integral_image;
        v = image;

        for (unsigned int i = 1; i < get_image_height(); i++)
                v(i, 0) += v(i - 1, 0);
        for (unsigned int j = 1; j < get_image_width(); j++)
                v(0, j) += v(0, j - 1);

        for (unsigned int i = 1; i < get_image_height(); i++) 
                for (unsigned int j = 1; j < get_image_width(); j++) 
                        v(i, j) += (v(i, j - 1) + v(i - 1, j)) - v(i - 1, j - 1);                                                
}
Esempio n. 10
0
void set_pixel(int target, int x, int y, int a, int r, int g, int b)
{
	unsigned char* bytes = get_pixel_bytes(target);
	int starting_byte = convertion(get_image_width(target), x, y);
	bytes[starting_byte+0] = b;
	bytes[starting_byte+1] = g;
	bytes[starting_byte+2] = r;
	bytes[starting_byte+3] = a;
}
Esempio n. 11
0
static int update_clock_positions(int ox)
{
	clock_pos = ox;
	int w = 0;
	w += theme->clock.space_gap * 2;
	w += get_image_width(theme->clock.left_img);
	w += get_image_width(theme->clock.right_img);
	
	char buftime[128];
	time_t current_time;
	memset(&current_time, 0, sizeof(time_t));
	strftime(buftime, sizeof(buftime), theme->clock.format, localtime(&current_time));

	int fontw;
	get_text_dimensions(theme->clock.font, buftime, &fontw, 0);
	w += fontw + theme->clock.text_padding;
	clock_width = w;
	return w;
}
Esempio n. 12
0
static void draw_image(Imlib_Image img, int ox)
{
	if (!img)
		return;
	int curw = get_image_width(img);
	imlib_context_set_image(bb);
	imlib_blend_image_onto_image(img, 1,
			0, 0, curw, theme->height,
			ox, 0, curw, theme->height);
}
Esempio n. 13
0
static int update_taskbar_positions(int ox, int width, 
		struct task *tasks, struct desktop *desktops)
{
	taskbar_pos = ox;
	taskbar_width = width;

	int activedesktop = 0;
	struct desktop *iter = desktops;
	while (iter) {
		if (iter->focused)
			break;
		activedesktop++;
		iter = iter->next;
	}

	int taskscount = 0;
	struct task *t = tasks;
	while (t) {
		if (t->desktop == activedesktop || t->desktop == -1)
			taskscount++;
		t = t->next;
	}
	if (!taskscount)
		return width;

	int taskw = width / taskscount;
	int sep = get_image_width(theme->taskbar.separator_img);
	if (sep)
		taskw -= sep;

	t = tasks;
	while (t) {
		if (t->desktop == -1) {
			t->posx = ox;
			t->width = taskw;
			ox += taskw;
			if (t->next)
				ox += sep;
		}
		if (t->desktop == activedesktop) {
			t->posx = ox;
			t->width = taskw;
			ox += taskw;
			if (t->next)
				ox += sep;
			/* hack, fill empty space in the end of the task bar */
			if (!t->next || t->next->desktop != activedesktop)
				t->width += taskbar_pos + width - ox;
		}
		t = t->next;
	}

	return width;
}
Esempio n. 14
0
int4 OVERLOAD get_image_dim(image3d_t image)
{
    int4 result;

    result.x = get_image_width(image);
    result.y = get_image_height(image);
    result.z = get_image_depth(image);
    result.w = 0;

    return result;
}
Esempio n. 15
0
int main(int argc, char* argv)
{
	turn_on_debug_output();
	create_image_world();
	
	// Write your code here
	int v = load_bmp("plane.bmp");
	put_image(v, (get_screen_width() / 2) - (get_image_width(v) / 2), (get_screen_height() / 2) - (get_image_height(v) / 2));
	
	return p1world_shutdown();

}
Esempio n. 16
0
void
set_glyph_image(font_t* font, int codepoint, image_t* image)
{
	image_t*           old_image;
	struct font_glyph* p_glyph;
	
	p_glyph = &font->glyphs[codepoint];
	old_image = p_glyph->image;
	p_glyph->image = ref_image(image);
	p_glyph->width = get_image_width(image);
	p_glyph->height = get_image_height(image);
	free_image(old_image);
}
Esempio n. 17
0
static int update_switcher_positions(int ox, struct desktop *desktops)
{
	struct desktop *iter, *prev;
	switcher_pos = ox;
	switcher_width = 0;

	if (!desktops)
		return 0;

	int lastw = 0, w = 0, state, textw;
	iter = prev = desktops;
	state = iter->focused ? BSTATE_PRESSED : BSTATE_IDLE;
	w += theme->switcher.space_gap;
	ox += w; lastw = w;
	w += get_image_width(theme->switcher.left_corner_img[state]);
	get_text_dimensions(theme->switcher.font, iter->name, &textw, 0);
	w += textw + theme->switcher.text_padding;

	while (iter->next) {
		prev = iter;
		iter = iter->next;
		state = iter->focused ? BSTATE_PRESSED : BSTATE_IDLE;
		get_text_dimensions(theme->switcher.font, iter->name, &textw, 0);
		w += get_image_width(theme->switcher.right_img[state]);
		prev->posx = ox;
		prev->width = w - lastw;
		w += get_image_width(theme->switcher.separator_img);
		ox += w - lastw; lastw = w;
		w += get_image_width(theme->switcher.left_img[state]);
		w += textw + theme->switcher.text_padding;
	}
	w += get_image_width(theme->switcher.right_corner_img[state]);
	iter->posx = ox;
	iter->width = w - lastw;
	w += theme->switcher.space_gap;

	switcher_width = w;
	return w;
}
    kernel void sobel_rgb(read_only image2d_t src, write_only image2d_t dst)
    {
        int x = (int)get_global_id(0);
        int y = (int)get_global_id(1);

        if (x >= get_image_width(src) || y >= get_image_height(src))
                return;

        //  [(x-1, y+1), (x, y+1), (x+1, y+1)]
        //  [(x-1, y  ), (x, y  ), (x+1, y  )]
        //  [(x-1, y-1), (x, y-1), (x+1, y-1)]

        //  [p02, p12,   p22]
        //  [p01, pixel, p21]
        //  [p00, p10,   p20]

        //Basically finding influence of neighbour pixels on current pixel
        float4 p00 = read_imagef(src, sampler, (int2)(x - 1, y - 1));
        float4 p10 = read_imagef(src, sampler, (int2)(x,     y - 1));
        float4 p20 = read_imagef(src, sampler, (int2)(x + 1, y - 1));

        float4 p01 = read_imagef(src, sampler, (int2)(x - 1, y));
        //pixel that we are working on
        float4 p21 = read_imagef(src, sampler, (int2)(x + 1, y));

        float4 p02 = read_imagef(src, sampler, (int2)(x - 1, y + 1));
        float4 p12 = read_imagef(src, sampler, (int2)(x,     y + 1));
        float4 p22 = read_imagef(src, sampler, (int2)(x + 1, y + 1));

        //Find Gx = kernel + 3x3 around current pixel
        //           Gx = [-1 0 +1]     [p02, p12,   p22]
        //                [-2 0 +2]  +  [p01, pixel, p21]
        //                [-1 0 +1]     [p00, p10,   p20]
        float3 gx = -p00.xyz + p20.xyz +
                    2.0f * (p21.xyz - p01.xyz)
                    -p02.xyz + p22.xyz;

        //Find Gy = kernel + 3x3 around current pixel
        //           Gy = [-1 -2 -1]     [p02, p12,   p22]
        //                [ 0  0  0]  +  [p01, pixel, p21]
        //                [+1 +2 +1]     [p00, p10,   p20]
        float3 gy = p00.xyz + p20.xyz +
                    2.0f * (- p12.xyz + p10.xyz) -
                    p02.xyz - p22.xyz;
        //Find G
        float3 g = native_sqrt(gx * gx + gy * gy);

        // we could also approximate this as g = fabs(gx) + fabs(gy)
        write_imagef(dst, (int2)(x, y), (float4)(g.x, g.y, g.z, 1.0f));
    }
Esempio n. 19
0
static gpointer
rectangle_create_info_widget(GtkWidget *frame)
{
   RectangleProperties_t *props = g_new(RectangleProperties_t, 1);
   GtkWidget *table, *label, *chain_button;
   gint max_width = get_image_width();
   gint max_height = get_image_height();

   table = gtk_table_new(4, 4, FALSE);
   gtk_container_add(GTK_CONTAINER(frame), table);

   gtk_table_set_row_spacings(GTK_TABLE(table), 6);
   gtk_table_set_col_spacings(GTK_TABLE(table), 6);
   gtk_widget_show(table);

   label = create_label_in_table(table, 0, 0, _("Upper left _x:"));
   props->x = create_spin_button_in_table(table, label, 0, 1, 1, 0,
                                          max_width - 1);
   g_signal_connect(props->x, "value-changed",
                    G_CALLBACK(x_changed_cb), (gpointer) props);
   create_label_in_table(table, 0, 3, _("pixels"));

   label = create_label_in_table(table, 1, 0, _("Upper left _y:"));
   props->y = create_spin_button_in_table(table, label, 1, 1, 1, 0,
                                          max_height - 1);
   g_signal_connect(props->y, "value-changed",
                    G_CALLBACK(y_changed_cb), (gpointer) props);
   create_label_in_table(table, 1, 3, _("pixels"));

   label = create_label_in_table(table, 2, 0, _("_Width:"));
   props->width = create_spin_button_in_table(table, label, 2, 1, 1, 1,
                                              max_width);
   g_signal_connect(props->width, "value-changed",
                    G_CALLBACK(width_changed_cb), (gpointer) props);
   create_label_in_table(table, 2, 3, _("pixels"));

   label = create_label_in_table(table, 3, 0, _("_Height:"));
   props->height = create_spin_button_in_table(table, label, 3, 1, 1, 1,
                                               max_height);
   g_signal_connect(props->height, "value-changed",
                    G_CALLBACK(height_changed_cb), (gpointer) props);
   create_label_in_table(table, 3, 3, _("pixels"));

   chain_button = gimp_chain_button_new(GIMP_CHAIN_RIGHT);
   props->chain_button = chain_button;
   gtk_table_attach_defaults(GTK_TABLE(table), chain_button, 2, 3, 2, 4);
   gtk_widget_show(chain_button);

   return props;
}
Esempio n. 20
0
static void tile_image(Imlib_Image img, int ox, int width)
{
	int curw = get_image_width(img);
	imlib_context_set_image(bb);

	while (width > 0) {
		width -= curw;
		if (width < 0)
			curw += width;
	
		imlib_blend_image_onto_image(img, 1,
				0, 0, curw, theme->height,
				ox, 0, curw, theme->height);
		ox += curw;
	}
}
Esempio n. 21
0
void render_switcher(struct desktop *desktops)
{		
	tile_image(theme->tile_img, switcher_pos, switcher_width);
	if (!desktops)
		return;
	int ox = switcher_pos;
	int limgw, rimgw;
	ox += theme->switcher.space_gap;
	uint state;
	struct desktop *iter = desktops;
	state = iter->focused ? BSTATE_PRESSED : BSTATE_IDLE;
	if (!iter->next)
		draw_switcher_alone(state, ox, iter->width);
	else 
		draw_switcher_left_corner(state, ox, iter->width);
	limgw = get_image_width(theme->switcher.left_corner_img[state]);
	rimgw = get_image_width(theme->switcher.right_img[state]);
	ox += limgw;
	draw_text(theme->switcher.font, theme->switcher.text_align, ox, iter->width - limgw - rimgw,
			theme->switcher.text_offset_x, theme->switcher.text_offset_y,
			iter->name, &theme->switcher.text_color[state]);
	ox += iter->width - limgw;

	if (!iter->next)
		return;
	iter = iter->next;
	state = iter->focused ? BSTATE_PRESSED : BSTATE_IDLE;
	if (theme->switcher.separator_img) {
		draw_image(theme->switcher.separator_img, ox);
		ox += get_image_width(theme->switcher.separator_img);
	}

	limgw = get_image_width(theme->switcher.left_img[state]);
	while (iter->next) {
		draw_switcher_middle(state, ox, iter->width);
		ox += limgw;
		draw_text(theme->switcher.font, theme->switcher.text_align, ox, iter->width - limgw - rimgw,
				theme->switcher.text_offset_x, theme->switcher.text_offset_y,
				iter->name, &theme->switcher.text_color[state]);
		ox += iter->width - limgw;
		iter = iter->next;
		state = iter->focused ? BSTATE_PRESSED : BSTATE_IDLE;
		if (theme->switcher.separator_img) {
			draw_image(theme->switcher.separator_img, ox);
			ox += get_image_width(theme->switcher.separator_img);
		}
	}

	rimgw = get_image_width(theme->switcher.right_corner_img[state]);
	draw_switcher_right_corner(state, ox, iter->width);
	ox += limgw;
	draw_text(theme->switcher.font, theme->switcher.text_align, ox, iter->width - limgw - rimgw,
			theme->switcher.text_offset_x, theme->switcher.text_offset_y,
			iter->name, &theme->switcher.text_color[state]);
}
Esempio n. 22
0
static void
update_font_metrics(font_t* font)
{
	int max_x = 0, max_y = 0;
	int min_width = INT_MAX;

	uint32_t i;

	for (i = 0; i < font->num_glyphs; ++i) {
		font->glyphs[i].width = get_image_width(font->glyphs[i].image);
		font->glyphs[i].height = get_image_height(font->glyphs[i].image);
		min_width = fmin(font->glyphs[i].width, min_width);
		max_x = fmax(font->glyphs[i].width, max_x);
		max_y = fmax(font->glyphs[i].height, max_y);
	}
	font->min_width = min_width;
	font->max_width = max_x;
	font->height = max_y;
}
Esempio n. 23
0
void mean_image(image *img1, image *img2, image *out)
{
  mblock_t b1, b2;      /* macrobblocks to be averaged */ 
  int   width,          /* width of image */
        height,         /* height of image */ 
        x, y,           /* block loop indexes */
        i, j;           /* pixel loop indexes */

  /* Get image width and height */
  width = get_image_width(img1);
  height = get_image_height(img1);

  /* Scan through the images and process blocks */
  for(y = 0; y < height; y+=16) {  /* block width is 16 pixels */
    for(x = 0; x < width; x+=16) { /* block height is 16 pixels */

      /* get a block from the first input image */
      get_mblock(img1, x, y, b1);

      /* get a block from the second input image */
      get_mblock(img2, x, y, b2);

      /* Scan through the blocks and interpolate */
      /* i.e. pixel_out = (pixel_in + pixel_out) / 2 */
      for(i = 0; i < 16; i++) {
	for(j = 0; j < 16; j++) {

	  /* store the result in block 1 */
	  b1[i][j] = (b1[i][j] + b2[i][j]) / 2;
	}
      }

      /* put the block in the output image */
      put_mblock(out, x, y, b1);
    }
  }
  return;
}
Esempio n. 24
0
static gpointer
circle_create_info_widget(GtkWidget *frame)
{
   CircleProperties_t *props = g_new(CircleProperties_t, 1);
   GtkWidget *table, *label;
   gint max_width = get_image_width();
   gint max_height = get_image_height();

   table = gtk_table_new(3, 3, FALSE);
   gtk_container_add(GTK_CONTAINER(frame), table);

   gtk_table_set_row_spacings(GTK_TABLE(table), 6);
   gtk_table_set_col_spacings(GTK_TABLE(table), 6);
   gtk_widget_show(table);

   label = create_label_in_table(table, 0, 0, _("Center _x:"));
   props->x = create_spin_button_in_table(table, label, 0, 1, 1, 0,
					  max_width - 1);
   g_signal_connect(props->x, "value-changed",
                    G_CALLBACK (x_changed_cb), (gpointer) props);
   create_label_in_table(table, 0, 2, _("pixels"));

   label = create_label_in_table(table, 1, 0, _("Center _y:"));
   props->y = create_spin_button_in_table(table, label, 1, 1, 1, 0,
					  max_height - 1);
   g_signal_connect(props->y, "value-changed",
                    G_CALLBACK (y_changed_cb), (gpointer) props);
   create_label_in_table(table, 1, 2, _("pixels"));

   label = create_label_in_table(table, 2, 0, _("_Radius:"));
   props->r = create_spin_button_in_table(table, label, 2, 1, 1, 1, G_MAXINT);
   g_signal_connect(props->r, "value-changed",
                    G_CALLBACK (r_changed_cb), (gpointer) props);
   create_label_in_table(table, 2, 2, _("pixels"));

   return props;
}
Esempio n. 25
0
void render_panel(struct panel *p)
{
	int ox = 0;
	char *e = theme->elements;
	while (*e) {
		switch (*e) {
		case 'c':
			render_clock();
			ox += clock_width;
			break;
		case 's':
			render_switcher(p->desktops);
			ox += switcher_width;
			break;
		case 't':
			if (!p->trayicons) {
				/* we're skipping if no tray icons here, separator is being drawn only once */
				e++;
				continue;
			}
			if (tray_width)
				tile_image(theme->tile_img, tray_pos, tray_width);
			ox += tray_width;
			break;
		case 'b':
			render_taskbar(p->tasks, p->desktops);
			ox += taskbar_width;
			break;
		}
		if (*++e && theme->separator_img) {
			draw_image(theme->separator_img, ox);
			ox += get_image_width(theme->separator_img);
		}
	}
	render_present();
}
Esempio n. 26
0
int
mathexpr(ParmList inparms, ParmList *outparms)
{
    float x, y, z;		/* User variables */
    float r[100];		/* Many user variables */
    int ii, jj, kk;		/* Integer user variables */
    int n[100];			/* Many integer user variables */

    int i, j, k;		/* Pixel position in row, column, depth */
    int width, height, depth;	/* Size of all images */
    int indx;			/* Running pixel number */

    char msg[128];
    DDLSymbolTable *st;
    DDLSymbolTable *out;
    float **img;		/* Vector of pointers to input data */
    float *iout;		/* Pointer to output data */
    int nsrcs;			/* Number of input images */
    ParmList src_ddls;
    ParmList dst_ddls;

    /*fprintf(stderr,"mathexpr(0x%x, 0x%x)\n", inparms, outparms);/*CMP*/
    /*printParm(inparms);/*CMP*/
    /* Grab the input args */
    src_ddls = findParm(inparms, "src_ddls");
    if (!src_ddls){
	ib_errmsg("MATH: \"src_ddls\" not passed");
	return FALSE;
    }
    nsrcs = countParm(src_ddls);
    img = (float **)malloc(nsrcs * sizeof(float *));
    fdfhandle = (DDLSymbolTable **)malloc(nsrcs * sizeof(DDLSymbolTable *));
    if (!img || !fdfhandle){
	ib_errmsg("MATH: out of memory");
	return FALSE;
    }

    /* Check image sizes */
    width = height = depth = 0;
    for (indx=0; indx<nsrcs; indx++){
	getPtrParm(src_ddls, &st, indx);
	i = get_image_width(st);
	j = get_image_height(st);
	k = get_image_depth(st);
	if (!i || !j){
	    sprintf(msg,"MATH: image size is %dx%d\n", i, j);
	    ib_errmsg(msg);
	    return FALSE;
	}
	if ((width && i != width)
	    || (height && j != height)
	    || (depth && k != depth))
	{
	    ib_errmsg("MATH: images are different sizes\n");
	    return FALSE;
	}
	width = i;
	height = j;
	depth = k;

	/* Point the working source image pointers to the appropriate data */
	img[indx] = get_ddl_data(st);
	fdfhandle[indx] = st;
    }
    /*fprintf(stderr,"MATH: width=%d, height=%d, depth=%d\n",
	    width, height, depth);/*DBG*/

    /* Copy the first input object (for storing the output image) */
    getPtrParm(src_ddls, &st, 0);
    out = clone_ddl(st, 1);
    /*fprintf(stderr,"MATH: out width=%d, data=0x%x, *data=%g\n",
	    get_image_width(out),
	    get_ddl_data(out), *get_ddl_data(out));/*CMP*/
    /*fprintf(stderr,"indata=0x%x, *indata=%g\n", img[0], img[0][0]);/*CMP*/
    iout = get_ddl_data(out);

    /*
     * NOTE: IB_EXPRESSION will be expanded into something like
     *		img[0][indx]+img[1][indx]
     */
    interrupt_begin();
    for (indx=k=0; k<depth; k++){
	for (j=0; j<height; j++){
	    for (i=0; i<width && !interrupt(); i++, indx++){
		iout[indx] = IB_EXPRESSION;
	    }
	}
    }
    interrupt_end();
    /*fprintf(stderr,"MATH: out width=%d, data=0x%x, *data=%g\n",
	    get_image_width(out),
	    get_ddl_data(out), *get_ddl_data(out));/*CMP*/

    /* Pass back the output image */
    *outparms = allocParm("dst_ddls", PL_PTR, 1);
    setPtrParm(*outparms, out, 0);

    return TRUE;
}
Esempio n. 27
0
    __kernel void convolution(__read_only  image2d_t  sourceImage,
                              __write_only image2d_t  outputImage,
                              __constant float* filter,
                              int filterWidth)
    {
        const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE |
                                  CLK_ADDRESS_CLAMP_TO_EDGE   |
                                  CLK_FILTER_NEAREST;

        // Store each work-item’s unique row and column
        int x   = get_global_id(0);
        int y   = get_global_id(1);

        // Half the width of the filter is needed for indexing
        // memory later
        int halfWidth = (int)(filterWidth/2);

        // All accesses to images return data as four-element vector
        // (i.e., float4).
        float4 sum = {0.0f, 0.0f, 0.0f, 0.0f};

        // Iterator for the filter
        int filterIdx = 0;

        // Each work-item iterates around its local area based on the
        // size of the filter
        int2 coords;  // Coordinates for accessing the image

        // Iterate the filter rows
        for(int i = -halfWidth; i <= halfWidth; i++)
        {
            coords.y = y + i;

            // Iterate over the filter columns
            for(int j = -halfWidth; j <= halfWidth; j++)
            {
                coords.x = x + j;

                float4 pixel;

                // Read a pixel from the image.
                // Work on a channel
                pixel = read_imagef(sourceImage, sampler, coords);
                sum.x += pixel.x * filter[filterIdx++];
                //sum.y += pixel.y * filter[filterIdx++];
                //sum.z += pixel.z * filter[filterIdx++];
            }
        }

         barrier(CLK_GLOBAL_MEM_FENCE);
        // Copy the data to the output image if the
        // work-item is in bounds
        if(y < get_image_height(sourceImage) &&
                x < get_image_width(sourceImage))
        {
            coords.x = x;
            coords.y = y;

            //Same channel is copied in all three channels
            //write_imagef(outputImage, coords,
                        // (float4)(sum.x,sum.x,sum.x,1.0f));

            write_imagef(outputImage, coords, sum);
        }
    }
Esempio n. 28
0
static void
get_histogram(DDLSymbolTable *st, float min, float max,
	      int *histogram, int nbins)
{
    int i;
    char *errmsg;
    int npts = (get_image_width(st) * get_image_height(st)
		* get_image_depth(st));
    float scale = (nbins - 1) / (max - min);
    for (i=0; i<nbins; i++){
	histogram[i] = 0;
    }
    int type = get_data_type(st, &errmsg);
    switch (type){
      case DDL_INT8:
	{
	    u_char *data = (u_char *)get_ddl_data(st);
	    u_char *end = data + npts;
	    while (data < end){
		histogram[(int)((*data++ - min) * scale)]++;
	    }
	}
	break;
      case DDL_INT16:
	{
	    u_short *data = (u_short *)get_ddl_data(st);
	    u_short *end = data + npts;
	    while (data < end){
		histogram[(int)((*data++ - min) * scale)]++;
	    }
	}
	break;
      case DDL_INT32:
	{
	    int *data = (int *)get_ddl_data(st);
	    int *end = data + npts;
	    while (data < end){
		histogram[(int)((*data++ - min) * scale)]++;
	    }
	}
	break;
      case DDL_FLOAT32:
	{
	    float *data = (float *)get_ddl_data(st);
	    float *end = data + npts;
	    while (data < end){
		histogram[(int)((*data++ - min) * scale)]++;
	    }
	}
	break;
      case DDL_FLOAT64:
	{
	    double *data = (double *)get_ddl_data(st);
	    double *end = data + npts;
	    while (data < end){
		histogram[(int)((*data++ - min) * scale)]++;
	    }
	}
	break;
    }
}
Esempio n. 29
0
static void
get_min_max(DDLSymbolTable *st, float *vmin, float *vmax)
{
    char *errmsg;
    int npts = (get_image_width(st) * get_image_height(st)
		* get_image_depth(st));
    int type = get_data_type(st, &errmsg);
    switch (type){
      case DDL_INT8:
	{
	    u_char *data = (u_char *)get_ddl_data(st);
	    u_char *end = data + npts;
	    u_char min = *data;
	    u_char max = *data++;
	    u_char x;
	    while (data < end){
		if ((x=*data++) < min){
		    min = x;
		}else if (x > max){
		    max = x;
		}
	    }
	    *vmin = (float)min;
	    *vmax = (float)max;
	}
	break;
      case DDL_INT16:
	{
	    u_short *data = (u_short *)get_ddl_data(st);
	    u_short *end = data + npts;
	    u_short min = *data;
	    u_short max = *data++;
	    u_short x;
	    while (data < end){
		if ((x=*data++) < min){
		    min = x;
		}else if (x > max){
		    max = x;
		}
	    }
	    *vmin = (float)min;
	    *vmax = (float)max;
	}
	break;
      case DDL_INT32:
	{
	    int *data = (int *)get_ddl_data(st);
	    int *end = data + npts;
	    int min = *data;
	    int max = *data++;
	    int x;
	    while (data < end){
		if ((x=*data++) < min){
		    min = x;
		}else if (x > max){
		    max = x;
		}
	    }
	    *vmin = (float)min;
	    *vmax = (float)max;
	}
	break;
      case DDL_FLOAT32:
	{
	    float *data = (float *)get_ddl_data(st);
	    float *end = data + npts;
	    float min = *data;
	    float max = *data++;
	    float x;
	    while (data < end){
		if ((x=*data++) < min){
		    min = x;
		}else if (x > max){
		    max = x;
		}
	    }
	    *vmin = (float)min;
	    *vmax = (float)max;
	}
	break;
      case DDL_FLOAT64:
	{
	    double *data = (double *)get_ddl_data(st);
	    double *end = data + npts;
	    double min = *data;
	    double max = *data++;
	    double x;
	    while (data < end){
		if ((x=*data++) < min){
		    min = x;
		}else if (x > max){
		    max = x;
		}
	    }
	    *vmin = (float)min;
	    *vmax = (float)max;
	}
	break;
    }
}
Esempio n. 30
0
void render_update_panel_positions(struct panel *p)
{
	char *e = theme->elements;
	int ox = 0;
	int taskbarx = 0;
	/* figure out taskbar position and width */
	while (*e) {
		switch (*e) {
		/* clock */
		case 'c':
			ox += get_clock_width();
			break;
		/* desktop switcher */
		case 's':
			ox += get_switcher_width(p->desktops);
			break;
		/* tray */
		case 't':
			if (!p->trayicons) {
				/* we're skipping if no tray icons here, separator is being drawn only once */
				e++;
				continue;
			}
			ox += get_tray_width(p->trayicons);
			break;
		/* taskbar */
		case 'b': 
			taskbarx = ox;
			e++;
			continue;
		}
		if (theme->separator_img)
			ox += get_image_width(theme->separator_img);
		e++;
	}
	int taskbarw = bbwidth - ox;

	/* now really update all positions */
	ox = 0;
	e = theme->elements;
	while (*e) {
		switch (*e) {
		/* clock */
		case 'c':
			ox += update_clock_positions(ox);
			break;
		/* desktop switcher */
		case 's':
			ox += update_switcher_positions(ox, p->desktops);
			break;
		/* tray */
		case 't':
			if (!p->trayicons) {
				/* we're skipping if no tray icons here, separator is being drawn only once */
				e++;
				continue;
			}
			ox += update_tray_positions(ox, p->trayicons);
			break;
		/* taskbar */
		case 'b': 
			ox += update_taskbar_positions(taskbarx, taskbarw, p->tasks, p->desktops);
			break;
		}
		if (*++e && theme->separator_img) {
			ox += get_image_width(theme->separator_img);
		}
	}
}