void Gobby::HueButton::on_clicked() { if(!m_dialog.get()) { m_dialog.reset(new Gtk::Dialog(m_title, m_parent)); m_hue_chooser = inf_text_gtk_hue_chooser_new_with_hue(get_hue()); gtk_box_pack_start(GTK_BOX(m_dialog->get_vbox()->gobj()), m_hue_chooser, FALSE, FALSE, 0); gtk_widget_show(m_hue_chooser); m_dialog->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); m_dialog->add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); m_dialog->set_default_response(Gtk::RESPONSE_OK); m_dialog->set_resizable(false); m_dialog->signal_response().connect( sigc::mem_fun(*this, &HueButton::on_dialog_response)); } else { inf_text_gtk_hue_chooser_set_hue( INF_TEXT_GTK_HUE_CHOOSER(m_hue_chooser), get_hue()); } m_dialog->present(); }
void kbd_hit(char key) { set_active(); switch (key) { case 'd': dump_screen(0); break; case 'w': case 'W': save_image(); break; case 'q': case 'Q': case 'x': case 'X': /* exit the program */ end_display(); exit(0); case 'v': show_video_settings = !show_video_settings; refresh_screen = 1; break; case 'h': set_hue(get_hue() - 1); refresh_screen = 1; break; case 'H': set_hue(get_hue() + 1); refresh_screen = 1; break; case 's': set_saturation(get_saturation() - 1); refresh_screen = 1; break; case 'S': set_saturation(get_saturation() + 1); refresh_screen = 1; break; case 'b': set_brightness(get_brightness() - 1); refresh_screen = 1; break; case 'B': set_brightness(get_brightness() + 1); refresh_screen = 1; break; case 'c': set_contrast(get_contrast() - 1); refresh_screen = 1; break; case 'C': set_contrast(get_contrast() + 1); refresh_screen = 1; break; } }
void hsv_colorize_node_t::do_process( const image::const_image_view_t& src, const image::image_view_t& dst, const render::context_t& context) { image::convert_rgb_to_hsv( src, dst); boost::gil::tbb_transform_pixels( dst, dst, hsv_colorize_fun( get_hue( get_value<Imath::Color4f>( param( "color"))), get_value<float>( param( "sat")), get_value<float>( param( "value")))); image::convert_hsv_to_rgb( dst, dst); image::lerp_images( dst, src, get_value<float>( param( "strength")), dst); boost::gil::tbb_transform_pixels( dst, dst, clamp_blacks_fun()); }
//these color functions need to be tested! color RGB2HSV(color rgb) { long saturation; long value; //foldl? long rgb_max = std::max(std::max(rgb[0], rgb[1]), rgb[2]); long rgb_min = std::min(std::min(rgb[0], rgb[1]), rgb[2]); value = rgb_max; long chroma = rgb_max - rgb_min; if (!value || !chroma) { return make_color(0, 0, (guint8)value); } saturation = (255 * chroma) / value; return make_color(get_hue(rgb), (guint8)saturation, (guint8)value); }
int main() { //int r = 145, g = 200, b = 47; //int r = 255, g = 255, b = 255; float h = 82, s = 62, l = 48; float rgb[3]; printf("The RGB values are %d, %d, and %d\n", r, g, b); printf("The HSV values are %g, %g, and %g\n", h, s, l); printf("The values we got are %g, %g, and %g\n", get_hue(r, g, b), get_saturation(r, g, b), get_lightness(r, g, b)); HSL_to_rgb( get_hue(r, g, b), get_saturation(r, g, b), get_lightness(r, g, b), rgb ); return 0; }
color RGB2HSI(color rgb) { long saturation; long intensity; //foldl? long rgb_max = std::max(std::max(rgb[0], rgb[1]), rgb[2]); long rgb_min = std::min(std::min(rgb[0], rgb[1]), rgb[2]); intensity = rgb[0] + rgb[1] + rgb[2]; intensity /= 3; long chroma = rgb_max - rgb_min; if (!chroma) { return make_color(0, 0, (guint8)intensity); } saturation = 255 - ((255 * rgb_min)/intensity); return make_color(get_hue(rgb), (guint8)saturation, (guint8)intensity); }
color RGB2HSL(color rgb) { long saturation; long lightness; //foldl? long rgb_max = std::max(std::max(rgb[0], rgb[1]), rgb[2]); long rgb_min = std::min(std::min(rgb[0], rgb[1]), rgb[2]); lightness = (rgb_min + rgb_max) / 2; long chroma = rgb_max - rgb_min; if (!chroma) { return make_color(0, 0, (guint8)lightness); } long div = 2 * lightness; div -= 255; if (div > 0) { div = -div; } saturation = chroma / (255 - div); return make_color(get_hue(rgb), (guint8)saturation, (guint8)lightness); }
/******************************************************************************************* Video capture routines - set input - setup_pixelformat - set_geometry - set_brightness - set_chroma - set_contrast - set_channelset - set_channel - set_capture_mode */ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, unsigned short input, unsigned short norm, unsigned long freq) { int dev_bktr = viddev->fd_bktr; struct sigaction act, old; //int dev_tunner = viddev->fd_tuner; /* to ensure that all device will be support the capture mode _TODO_ : Autodected the best capture mode . */ int dummy = 1; // int pixelformat = BSD_VIDFMT_I420; void *map; /* if we have choose the tuner is needed to setup the frequency */ if ((viddev->tuner_device != NULL) && (input == IN_TV)) { if (!freq) { motion_log(LOG_ERR, 0, "%s: Not valid Frequency [%lu] for Source input [%i]", __FUNCTION__, freq, input); return NULL; } else if (set_freq(viddev, freq) == -1) { motion_log(LOG_ERR, 0, "%s: Frequency [%lu] Source input [%i]", __FUNCTION__, freq, input); return NULL; } } /* FIXME if we set as input tuner , we need to set option for tuner not for bktr */ if ((dummy = set_input(viddev, input)) == -1) { motion_log(LOG_ERR, 0, "%s: set input [%d]", __FUNCTION__, input); return NULL; } viddev->input = dummy; if ((dummy = set_input_format(viddev, norm)) == -1) { motion_log(LOG_ERR, 0, "%s: set input format [%d]", __FUNCTION__, norm); return NULL; } viddev->norm = dummy; if (set_geometry(viddev, width, height) == -1) { motion_log(LOG_ERR, 0, "%s: set geometry [%d]x[%d]", __FUNCTION__, width, height); return NULL; } /* if (ioctl(dev_bktr, METEORSACTPIXFMT, &pixelformat) < 0) { motion_log(LOG_ERR, 1, "set encoding method BSD_VIDFMT_I420"); return NULL; } NEEDED !? FIXME if (setup_pixelformat(viddev) == -1) return NULL; */ if (freq) { if (debug_level >= CAMERA_DEBUG) motion_log(-1, 0, "%s: Frequency set (no implemented yet", __FUNCTION__); /* TODO missing implementation set_channelset(viddev); set_channel(viddev); if (set_freq (viddev, freq) == -1) { return NULL; } */ } /* set capture mode and capture buffers */ /* That is the buffer size for capture images , so is dependent of color space of input format / FIXME */ viddev->v4l_bufsize = (((width * height * 3 / 2)) * sizeof(unsigned char *)); viddev->v4l_fmt = VIDEO_PALETTE_YUV420P; map = mmap((caddr_t)0, viddev->v4l_bufsize, PROT_READ|PROT_WRITE, MAP_SHARED, dev_bktr, (off_t)0); if (map == MAP_FAILED){ motion_log(LOG_ERR, 1, "%s: mmap failed", __FUNCTION__); return NULL; } /* FIXME double buffer */ if (0) { viddev->v4l_maxbuffer = 2; viddev->v4l_buffers[0] = map; viddev->v4l_buffers[1] = (unsigned char *)map + 0; /* 0 is not valid just a test */ //viddev->v4l_buffers[1] = map+vid_buf.offsets[1]; } else { viddev->v4l_buffers[0] = map; viddev->v4l_maxbuffer = 1; } viddev->v4l_curbuffer = 0; /* Clear the buffer */ if (ioctl(dev_bktr, BT848SCBUF, &dummy) < 0) { motion_log(LOG_ERR, 1, "%s: BT848SCBUF", __FUNCTION__); return NULL; } /* signal handler to know when data is ready to be read() */ memset(&act, 0, sizeof(act)); sigemptyset(&act.sa_mask); act.sa_handler = catchsignal; sigaction(SIGUSR2, &act, &old); dummy = SIGUSR2; //viddev->capture_method = METEOR_CAP_CONTINOUS; //viddev->capture_method = METEOR_CAP_SINGLE; if ((viddev->capture_method == METEOR_CAP_CONTINOUS) && (ioctl(dev_bktr, METEORSSIGNAL, &dummy) < 0)) { motion_log(LOG_ERR, 1, "%s: METEORSSIGNAL", __FUNCTION__); motion_log(LOG_INFO, 0 , "%s: METEORSSIGNAL", __FUNCTION__); viddev->capture_method = METEOR_CAP_SINGLE; if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) { motion_log(LOG_ERR, 1, "%s: METEORCAPTUR using single method " "Error capturing", __FUNCTION__); motion_log(LOG_INFO, 0, "%s: METEORCAPTUR using single method " "Error capturing", __FUNCTION__); } } else { if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) { viddev->capture_method = METEOR_CAP_SINGLE; if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) { motion_log(LOG_ERR, 1, "%s: METEORCAPTUR using single method " "Error capturing", __FUNCTION__); motion_log(LOG_INFO, 0, "%s: METEORCAPTUR using single method " "Error capturing", __FUNCTION__); } } } if (viddev->capture_method == METEOR_CAP_CONTINOUS) motion_log(LOG_INFO, 0, "%s: METEORCAPTUR METEOR_CAP_CONTINOUS", __FUNCTION__); else motion_log(LOG_INFO, 0, "%s: METEORCAPTUR METEOR_CAP_SINGLE", __FUNCTION__); // settle , sleep(1) replaced SLEEP(1, 0); /* FIXME*/ switch (viddev->v4l_fmt) { case VIDEO_PALETTE_YUV420P: viddev->v4l_bufsize = (width * height * 3) / 2; break; case VIDEO_PALETTE_YUV422: viddev->v4l_bufsize = (width * height * 2); break; case VIDEO_PALETTE_RGB24: viddev->v4l_bufsize = (width * height * 3); break; case VIDEO_PALETTE_GREY: viddev->v4l_bufsize = width * height; break; } motion_log(LOG_INFO, 0, "HUE [%d]", get_hue(dev_bktr, &dummy)); motion_log(LOG_INFO, 0, "SATURATION [%d]", get_saturation(dev_bktr, &dummy)); motion_log(LOG_INFO, 0, "BRIGHTNESS [%d]", get_brightness(dev_bktr, &dummy)); motion_log(LOG_INFO, 0, "CONTRAST [%d]", get_contrast(dev_bktr, &dummy)); return map; }
void Gobby::HueButton::set_value(double value) { m_value = value; set_hue(get_hue()); // Update view }
void Gobby::HueButton::set_saturation(double saturation) { m_saturation = saturation; set_hue(get_hue()); // Update view }
void repaint (ppm_t *p, ppm_t *a) { int x, y; int tx = 0, ty = 0; ppm_t tmp = {0, 0, NULL}; ppm_t atmp = {0, 0, NULL}; int r, g, b, h, i, j, on, sn; int num_brushes, maxbrushwidth, maxbrushheight; guchar back[3] = {0, 0, 0}; ppm_t *brushes, *shadows; ppm_t *brush, *shadow = NULL; double *brushes_sum; int cx, cy, maxdist; double scale, relief, startangle, anglespan, density, bgamma; int max_progress; ppm_t paper_ppm = {0, 0, NULL}; ppm_t dirmap = {0, 0, NULL}; ppm_t sizmap = {0, 0, NULL}; int *xpos = NULL, *ypos = NULL; int progstep; static int running = 0; int dropshadow = pcvals.general_drop_shadow; int shadowblur = pcvals.general_shadow_blur; if (running) return; running++; runningvals = pcvals; /* Shouldn't be necessary, but... */ if (img_has_alpha) if ((p->width != a->width) || (p->height != a->height)) { g_printerr ("Huh? Image size != alpha size?\n"); return; } num_brushes = runningvals.orient_num * runningvals.size_num; startangle = runningvals.orient_first; anglespan = runningvals.orient_last; density = runningvals.brush_density; if (runningvals.place_type == PLACEMENT_TYPE_EVEN_DIST) density /= 3.0; bgamma = runningvals.brushgamma; brushes = g_malloc (num_brushes * sizeof (ppm_t)); brushes_sum = g_malloc (num_brushes * sizeof (double)); if (dropshadow) shadows = g_malloc (num_brushes * sizeof (ppm_t)); else shadows = NULL; brushes[0].col = NULL; brush_get_selected (&brushes[0]); resize (&brushes[0], brushes[0].width, brushes[0].height * pow (10, runningvals.brush_aspect)); scale = runningvals.size_last / MAX (brushes[0].width, brushes[0].height); if (bgamma != 1.0) ppm_apply_gamma (&brushes[0], 1.0 / bgamma, 1,1,1); resize (&brushes[0], brushes[0].width * scale, brushes[0].height * scale); i = 1 + sqrt (brushes[0].width * brushes[0].width + brushes[0].height * brushes[0].height); ppm_pad (&brushes[0], i-brushes[0].width, i-brushes[0].width, i - brushes[0].height, i - brushes[0].height, back); for (i = 1; i < num_brushes; i++) { brushes[i].col = NULL; ppm_copy (&brushes[0], &brushes[i]); } for (i = 0; i < runningvals.size_num; i++) { double sv; if (runningvals.size_num > 1) sv = i / (runningvals.size_num - 1.0); else sv = 1.0; for (j = 0; j < runningvals.orient_num; j++) { h = j + i * runningvals.orient_num; free_rotate (&brushes[h], startangle + j * anglespan / runningvals.orient_num); rescale (&brushes[h], ( sv * runningvals.size_first + (1.0-sv) * runningvals.size_last ) / runningvals.size_last); autocrop (&brushes[h],1); } } /* Brush-debugging */ #if 0 for (i = 0; i < num_brushes; i++) { char tmp[1000]; g_snprintf (tmp, sizeof (tmp), "/tmp/_brush%03d.ppm", i); ppm_save (&brushes[i], tmp); } #endif for (i = 0; i < num_brushes; i++) { if (!runningvals.color_brushes) prepare_brush (&brushes[i]); brushes_sum[i] = sum_brush (&brushes[i]); } brush = &brushes[0]; maxbrushwidth = maxbrushheight = 0; for (i = 0; i < num_brushes; i++) { if (brushes[i].width > maxbrushwidth) maxbrushwidth = brushes[i].width; if (brushes[i].height > maxbrushheight) maxbrushheight = brushes[i].height; } for (i = 0; i < num_brushes; i++) { int xp, yp; guchar blk[3] = {0, 0, 0}; xp = maxbrushwidth - brushes[i].width; yp = maxbrushheight - brushes[i].height; if (xp || yp) ppm_pad (&brushes[i], xp / 2, xp - xp / 2, yp / 2, yp - yp / 2, blk); } if (dropshadow) { for (i = 0; i < num_brushes; i++) { shadows[i].col = NULL; ppm_copy (&brushes[i], &shadows[i]); ppm_apply_gamma (&shadows[i], 0, 1,1,0); ppm_pad (&shadows[i], shadowblur*2, shadowblur*2, shadowblur*2, shadowblur*2, back); for (j = 0; j < shadowblur; j++) blur (&shadows[i], 2, 2); #if 0 autocrop (&shadows[i],1); #endif } #if 0 maxbrushwidth += shadowdepth*3; maxbrushheight += shadowdepth*3; #endif } /* For extra annoying debugging :-) */ #if 0 ppm_save (brushes, "/tmp/__brush.ppm"); if (shadows) ppm_save (shadows, "/tmp/__shadow.ppm"); system ("xv /tmp/__brush.ppm & xv /tmp/__shadow.ppm & "); #endif if (runningvals.general_paint_edges) { edgepad (p, maxbrushwidth, maxbrushwidth, maxbrushheight, maxbrushheight); if (img_has_alpha) edgepad (a, maxbrushwidth, maxbrushwidth, maxbrushheight, maxbrushheight); } if (img_has_alpha) { /* Initially fully transparent */ if (runningvals.general_background_type == BG_TYPE_TRANSPARENT) { guchar tmpcol[3] = {255, 255, 255}; ppm_new (&atmp, a->width, a->height); fill (&atmp, tmpcol); } else { ppm_copy (a, &atmp); } } if (runningvals.general_background_type == BG_TYPE_SOLID) { guchar tmpcol[3]; ppm_new (&tmp, p->width, p->height); gimp_rgb_get_uchar (&runningvals.color, &tmpcol[0], &tmpcol[1], &tmpcol[2]); fill (&tmp, tmpcol); } else if (runningvals.general_background_type == BG_TYPE_KEEP_ORIGINAL) { ppm_copy (p, &tmp); } else { int dx, dy; ppm_new (&tmp, p->width, p->height); ppm_load (runningvals.selected_paper, &paper_ppm); if (runningvals.paper_scale != 100.0) { scale = runningvals.paper_scale / 100.0; resize (&paper_ppm, paper_ppm.width * scale, paper_ppm.height * scale); } if (runningvals.paper_invert) ppm_apply_gamma (&paper_ppm, -1.0, 1, 1, 1); dx = runningvals.general_paint_edges ? paper_ppm.width - maxbrushwidth : 0; dy = runningvals.general_paint_edges ? paper_ppm.height - maxbrushheight : 0; for (y = 0; y < tmp.height; y++) { int lx; int ry = (y + dy) % paper_ppm.height; for (x = 0; x < tmp.width; x+=lx) { int rx = (x + dx) % paper_ppm.width; lx = MIN (tmp.width - x, paper_ppm.width - rx); memcpy (&tmp.col[y * tmp.width * 3 + x * 3], &paper_ppm.col[ry * paper_ppm.width * 3 + rx * 3], 3 * lx); } } } cx = p->width / 2; cy = p->height / 2; maxdist = sqrt (cx * cx + cy * cy); switch (runningvals.orient_type) { case ORIENTATION_VALUE: ppm_new (&dirmap, p->width, p->height); for (y = 0; y < dirmap.height; y++) { guchar *dstrow = &dirmap.col[y * dirmap.width * 3]; guchar *srcrow = &p->col[y * p->width * 3]; for (x = 0; x < dirmap.width; x++) { dstrow[x * 3] = (srcrow[x * 3] + srcrow[x * 3 + 1] + srcrow[x * 3 + 2]) / 3; } } break; case ORIENTATION_RADIUS: ppm_new (&dirmap, p->width, p->height); for (y = 0; y < dirmap.height; y++) { guchar *dstrow = &dirmap.col[y * dirmap.width * 3]; double ysqr = (cy - y) * (cy - y); for (x = 0; x < dirmap.width; x++) { dstrow[x*3] = sqrt ((cx - x) * (cx - x) + ysqr) * 255 / maxdist; } } break; case ORIENTATION_RADIAL: ppm_new (&dirmap, p->width, p->height); for (y = 0; y < dirmap.height; y++) { guchar *dstrow = &dirmap.col[y * dirmap.width * 3]; for (x = 0; x < dirmap.width; x++) { dstrow[x * 3] = (G_PI + atan2 (cy - y, cx - x)) * 255.0 / (G_PI * 2); } } break; case ORIENTATION_FLOWING: ppm_new (&dirmap, p->width / 6 + 5, p->height / 6 + 5); mkgrayplasma (&dirmap, 15); blur (&dirmap, 2, 2); blur (&dirmap, 2, 2); resize (&dirmap, p->width, p->height); blur (&dirmap, 2, 2); if (runningvals.general_paint_edges) edgepad (&dirmap, maxbrushwidth, maxbrushheight, maxbrushwidth, maxbrushheight); break; case ORIENTATION_HUE: ppm_new (&dirmap, p->width, p->height); for (y = 0; y < dirmap.height; y++) { guchar *dstrow = &dirmap.col[y * dirmap.width * 3]; guchar *srcrow = &p->col[y * p->width * 3]; for (x = 0; x < dirmap.width; x++) { dstrow[x * 3] = get_hue (&srcrow[x * 3]); } } break; case ORIENTATION_ADAPTIVE: { guchar tmpcol[3] = {0, 0, 0}; ppm_new (&dirmap, p->width, p->height); fill (&dirmap, tmpcol); } break; case ORIENTATION_MANUAL: ppm_new (&dirmap, p->width-maxbrushwidth*2, p->height-maxbrushheight*2); for (y = 0; y < dirmap.height; y++) { guchar *dstrow = &dirmap.col[y * dirmap.width * 3]; double tmpy = y / (double)dirmap.height; for (x = 0; x < dirmap.width; x++) { dstrow[x * 3] = get_pixel_value(90 - get_direction(x / (double)dirmap.width, tmpy, 1)); } } edgepad (&dirmap, maxbrushwidth, maxbrushwidth, maxbrushheight, maxbrushheight); break; } if (runningvals.size_type == SIZE_TYPE_VALUE) { ppm_new (&sizmap, p->width, p->height); for (y = 0; y < sizmap.height; y++) { guchar *dstrow = &sizmap.col[y * sizmap.width * 3]; guchar *srcrow = &p->col[y * p->width * 3]; for (x = 0; x < sizmap.width; x++) { dstrow[x * 3] = (srcrow[x * 3] + srcrow[x * 3 + 1] + srcrow[x * 3 + 2]) / 3; } } } else if (runningvals.size_type == SIZE_TYPE_RADIUS) { ppm_new (&sizmap, p->width, p->height); for (y = 0; y < sizmap.height; y++) { guchar *dstrow = &sizmap.col[y * sizmap.width * 3]; double ysqr = (cy - y) * (cy - y); for (x = 0; x < sizmap.width; x++) { dstrow[x * 3] = sqrt ((cx - x) * (cx - x) + ysqr) * 255 / maxdist; } } } else if (runningvals.size_type == SIZE_TYPE_RADIAL) { ppm_new (&sizmap, p->width, p->height); for (y = 0; y < sizmap.height; y++) { guchar *dstrow = &sizmap.col[y * sizmap.width * 3]; for (x = 0; x < sizmap.width; x++) { dstrow[x * 3] = (G_PI + atan2 (cy - y, cx - x)) * 255.0 / (G_PI * 2); } } } else if (runningvals.size_type == SIZE_TYPE_FLOWING) { ppm_new (&sizmap, p->width / 6 + 5, p->height / 6 + 5); mkgrayplasma (&sizmap, 15); blur (&sizmap, 2, 2); blur (&sizmap, 2, 2); resize (&sizmap, p->width, p->height); blur (&sizmap, 2, 2); if (runningvals.general_paint_edges) edgepad (&sizmap, maxbrushwidth, maxbrushheight, maxbrushwidth, maxbrushheight); } else if (runningvals.size_type == SIZE_TYPE_HUE) { ppm_new (&sizmap, p->width, p->height); for (y = 0; y < sizmap.height; y++) { guchar *dstrow = &sizmap.col[y * sizmap.width * 3]; guchar *srcrow = &p->col[y * p->width * 3]; for (x = 0; x < sizmap.width; x++) { dstrow[ x * 3] = get_hue (&srcrow[x * 3]); } } } else if (runningvals.size_type == SIZE_TYPE_ADAPTIVE) { guchar tmpcol[3] = {0, 0, 0}; ppm_new (&sizmap, p->width, p->height); fill (&sizmap, tmpcol); } else if (runningvals.size_type == SIZE_TYPE_MANUAL) { ppm_new (&sizmap, p->width-maxbrushwidth * 2, p->height-maxbrushheight * 2); for (y = 0; y < sizmap.height; y++) { guchar *dstrow = &sizmap.col[y * sizmap.width * 3]; double tmpy = y / (double)sizmap.height; for (x = 0; x < sizmap.width; x++) { dstrow[x * 3] = 255 * (1.0 - get_siz_from_pcvals (x / (double)sizmap.width, tmpy)); } } edgepad (&sizmap, maxbrushwidth, maxbrushwidth, maxbrushheight, maxbrushheight); } #if 0 ppm_save(&sizmap, "/tmp/_sizmap.ppm"); #endif if (runningvals.place_type == PLACEMENT_TYPE_RANDOM) { i = tmp.width * tmp.height / (maxbrushwidth * maxbrushheight); i *= density; } else if (runningvals.place_type == PLACEMENT_TYPE_EVEN_DIST) { i = (int)(tmp.width * density / maxbrushwidth) * (int)(tmp.height * density / maxbrushheight); #if 0 g_printerr("i=%d\n", i); #endif } if (i < 1) i = 1; max_progress = i; progstep = max_progress / 30; if (progstep < 10) progstep = 10; if (runningvals.place_type == PLACEMENT_TYPE_EVEN_DIST) { int j; xpos = g_new (int, i); ypos = g_new (int, i); for (j = 0; j < i; j++) { int factor = (int)(tmp.width * density / maxbrushwidth + 0.5); if (factor < 1) factor = 1; xpos[j] = maxbrushwidth/2 + (j % factor) * maxbrushwidth / density; ypos[j] = maxbrushheight/2 + (j / factor) * maxbrushheight / density; } for (j = 0; j < i; j++) { int a, b; a = g_rand_int_range (random_generator, 0, i); b = xpos[j]; xpos[j] = xpos[a]; xpos[a] = b; b = ypos[j]; ypos[j] = ypos[a]; ypos[a] = b; } }