void _odccm_connection_broker_take_connection (OdccmConnectionBroker *self, GConn *conn) { OdccmConnectionBrokerPrivate *priv = ODCCM_CONNECTION_BROKER_GET_PRIVATE (self); GRand *rnd; GIOChannel *chan; guint uid; g_assert (priv->conn == NULL); priv->conn = conn; rnd = g_rand_new (); priv->filename = g_strdup_printf ("/tmp/odccm-%08x%08x%08x%08x.sock", g_rand_int (rnd), g_rand_int (rnd), g_rand_int (rnd), g_rand_int (rnd)); g_rand_free (rnd); priv->server = gnet_unix_socket_server_new (priv->filename); _odccm_get_dbus_sender_uid (dbus_g_method_get_sender (priv->ctx), &uid); chmod (priv->filename, S_IRUSR | S_IWUSR); chown (priv->filename, uid, -1); chan = gnet_unix_socket_get_io_channel (priv->server); g_io_add_watch (chan, G_IO_IN, server_socket_readable_cb, self); dbus_g_method_return (priv->ctx, priv->filename); priv->ctx = NULL; }
/** * oil_rand_u64: * @r: a #GRand, representing a random seed * * Returns: a 64-bit unsigned random integer */ guint64 oil_rand_u64 (GRand *r) { guint64 ret = (guint32) g_rand_int (r); gint32 shift = g_rand_int_range (r, 0, 32); ret <<= shift; ret += (guint32) g_rand_int (r); return ret; }
// Optimized version from one in GIMP (noisify.c), where it was // adapted from ppmforge.c, which is part of PBMPLUS. The algorithm // comes from: 'The Science Of Fractal Images'. Peitgen, H.-O., and // Saupe, D. eds. Springer Verlag, New York, 1988. inline float rand_gauss (GRand * rng) { float sum = 0.0; uint32_t rand1 = g_rand_int(rng); uint32_t rand2 = g_rand_int(rng); sum += rand1 & 0x7FFF; sum += (rand1 >> 16) & 0x7FFF; sum += rand2 & 0x7FFF; sum += (rand2 >> 16) & 0x7FFF; return sum * 5.28596089837e-5 - 3.46410161514; }
END_TEST START_TEST(test_atree_max_value) { ATree *at; gint result; gint key_a; gint data_a; gint key_b; gint data_b; gint *max; GRand *random; at = a_tree_new(); if (at == NULL) { ck_abort_msg ("Failed to create ATree\n"); } else { random = g_rand_new_with_seed( (guint32) at ); key_a = g_rand_int( random ); data_a = g_rand_int( random ); key_b = g_rand_int( random ); data_b = g_rand_int( random ); result = atree_insert( at, GINT_TO_POINTER(&key_a), GINT_TO_POINTER(&data_a) ); ck_assert_int_eq( result, 0 ); result = atree_insert( at, GINT_TO_POINTER(&key_b), GINT_TO_POINTER(&data_b) ); ck_assert_int_eq( result, 0 ); max = atree_max_value( at ); if (max == NULL) { ck_abort_msg ("maximum values is NULL\n"); } else { if (key_a > key_b) { ck_assert_int_eq( *max, data_a ); } else { ck_assert_int_eq( *max, data_b ); } } a_tree_destroy( at ); } }
static GstStateChangeReturn gst_basertppayload_change_state (GstElement * element, GstStateChange transition) { GstBaseRTPPayload *basertppayload; GstBaseRTPPayloadPrivate *priv; GstStateChangeReturn ret; basertppayload = GST_BASE_RTP_PAYLOAD (element); priv = basertppayload->priv; switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: break; case GST_STATE_CHANGE_READY_TO_PAUSED: gst_segment_init (&basertppayload->segment, GST_FORMAT_UNDEFINED); if (priv->seqnum_offset_random) basertppayload->seqnum_base = g_rand_int_range (basertppayload->seq_rand, 0, G_MAXUINT16); else basertppayload->seqnum_base = basertppayload->seqnum_offset; priv->next_seqnum = basertppayload->seqnum_base; basertppayload->seqnum = basertppayload->seqnum_base; if (priv->ssrc_random) basertppayload->current_ssrc = g_rand_int (basertppayload->ssrc_rand); else basertppayload->current_ssrc = basertppayload->ssrc; if (priv->ts_offset_random) basertppayload->ts_base = g_rand_int (basertppayload->ts_rand); else basertppayload->ts_base = basertppayload->ts_offset; basertppayload->timestamp = basertppayload->ts_base; break; default: break; } ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); switch (transition) { case GST_STATE_CHANGE_READY_TO_NULL: break; default: break; } return ret; }
static gboolean gimp_operation_dissolve_mode_process (GeglOperation *operation, void *in_buf, void *aux_buf, void *aux2_buf, void *out_buf, glong samples, const GeglRectangle *result, gint level) { gdouble opacity = GIMP_OPERATION_POINT_LAYER_MODE (operation)->opacity; gfloat *in = in_buf; gfloat *out = out_buf; gfloat *aux = aux_buf; gfloat *mask = aux2_buf; const gboolean has_mask = mask != NULL; gint x, y; for (y = result->y; y < result->y + result->height; y++) { GRand *gr = g_rand_new_with_seed (random_table[y % RANDOM_TABLE_SIZE]); /* fast forward through the rows pseudo random sequence */ for (x = 0; x < result->x; x++) g_rand_int (gr); for (x = result->x; x < result->x + result->width; x++) { gfloat value = aux[ALPHA] * opacity * 255; if (has_mask) value *= *mask; if (g_rand_int_range (gr, 0, 255) >= value) { out[0] = in[0]; out[1] = in[1]; out[2] = in[2]; out[3] = in[3]; } else { out[0] = aux[0]; out[1] = aux[1]; out[2] = aux[2]; out[3] = 1.0; } in += 4; out += 4; aux += 4; if (has_mask) mask ++; } g_rand_free (gr); } return TRUE; }
void mrim_xfer_send_rq(PurpleXfer *xfer) { gchar *file_name = purple_xfer_get_local_filename(xfer); purple_debug_info("mrim-prpl", "[%s] Sending file '%s'\n", __func__, file_name); MrimFT *mrim_ft = xfer->data; mrim_ft->xfer = xfer; mrim_ft->count = 1; mrim_ft->files = g_new0(MrimFT, 1); mrim_ft->files[0].name = basename(file_name); // TODO: strdup??? { GRand *rnd = g_rand_new(); mrim_ft->id = g_rand_int(rnd); g_rand_free(rnd); } { struct stat st; stat(file_name, &st); mrim_ft->files[0].size = st.st_size; } MrimData *mrim = mrim_ft->mrim; MrimPackage *pack = mrim_package_new(mrim->seq++, MRIM_CS_FILE_TRANSFER); mrim_package_add_LPSA(pack, mrim_ft->user_name); mrim_package_add_UL(pack, mrim_ft->id); mrim_package_add_UL(pack, mrim_ft->files[0].size); gchar *file_list = g_strdup_printf("%s;%u;", mrim_ft->files[0].name, mrim_ft->files[0].size); gchar *my_ip = "1.2.3.4:1234;"; // Заведомо некорректное значение, чтобы клиент обломался и пошёл использовать зеркальный прокси TODO mrim_package_add_UL(pack, 4 + strlen(file_list) + 4 + 4 + strlen(my_ip)); mrim_package_add_LPSA(pack, file_list); mrim_package_add_UL(pack, 0); mrim_package_add_LPSA(pack, my_ip); //mrim_add_ack_cb(mrim, pack->header->seq, mrim_xfer_ack, xfer); g_hash_table_insert(mrim->transfers, GUINT_TO_POINTER(mrim_ft->id), xfer); mrim_package_send(pack, mrim); }
const guint8* token_key_new ( Algorithm algorithm, guint *length ) { const guint8 *key; GRand *rng; guint32 *buf; guint i, il=0; rng = g_rand_new (); switch ( algorithm ) { case HOTP: il = DEFAULT_HOTP_KEY_LENGTH / 32; break; case MOTP: il = DEFAULT_MOTP_KEY_LENGTH / 32; break; default:; } buf = g_malloc ( il * 32 ); for ( i=0; i < il ; ++ i ) buf[i] = g_rand_int ( rng ); key = (guint8*)buf; *length = il * 4; // 4 guint8's per guint32 g_rand_free ( rng ); return key; }
/* Simple AI: 1. If AI can win with the following move, make it. 2. If human can win with the following move, block it. 3. Otherwise, random spot. */ void gb_logic() { int i; if( gb_get_spaces() > 0) { i = gb_table_check('o'); if( i >= 0) gb_add_mark(i, 'o'); else { i = gb_table_check('x'); if(i >= 0) gb_add_mark(i, 'o'); else { gboolean done = FALSE; GRand *r = g_rand_new(); while(!done) { i = g_rand_int(r)%9; if( mark[i] == 'k') { gb_add_mark(i, 'o'); done = TRUE; } } g_rand_free(r); } } } }
/* Generate Pink noise values between -1.0 and +1.0 */ static gdouble gst_audio_test_src_generate_pink_noise_value (GstAudioTestSrc * src) { GstPinkNoise *pink = &src->pink; glong new_random; glong sum; /* Increment and mask index. */ pink->index = (pink->index + 1) & pink->index_mask; /* If index is zero, don't update any random values. */ if (pink->index != 0) { /* Determine how many trailing zeros in PinkIndex. */ /* This algorithm will hang if n==0 so test first. */ gint num_zeros = 0; gint n = pink->index; while ((n & 1) == 0) { n = n >> 1; num_zeros++; } /* Replace the indexed ROWS random value. * Subtract and add back to RunningSum instead of adding all the random * values together. Only one changes each time. */ pink->running_sum -= pink->rows[num_zeros]; new_random = 32768.0 - (65536.0 * (gulong) g_rand_int (src->gen) / (G_MAXUINT32 + 1.0)); pink->running_sum += new_random; pink->rows[num_zeros] = new_random; }
static void gimp_operation_dissolve_mode_class_init (GimpOperationDissolveModeClass *klass) { GeglOperationClass *operation_class; GeglOperationPointComposer3Class *point_composer_class; GRand *gr; gint i; operation_class = GEGL_OPERATION_CLASS (klass); point_composer_class = GEGL_OPERATION_POINT_COMPOSER3_CLASS (klass); gegl_operation_class_set_keys (operation_class, "name", "gimp:dissolve-mode", "description", "GIMP dissolve mode operation", "categories", "compositors", NULL); operation_class->prepare = gimp_operation_dissolve_mode_prepare; point_composer_class->process = gimp_operation_dissolve_mode_process; /* generate a table of random seeds */ gr = g_rand_new_with_seed (314159265); for (i = 0; i < RANDOM_TABLE_SIZE; i++) random_table[i] = g_rand_int (gr); g_rand_free (gr); }
static GByteArray * generate_duid_from_machine_id (void) { GByteArray *duid; char *contents = NULL; GChecksum *sum; guint8 buffer[32]; /* SHA256 digest size */ gsize sumlen = sizeof (buffer); const guint16 duid_type = g_htons (4); uuid_t uuid; GRand *generator; guint i; gboolean success = FALSE; /* Get the machine ID from /etc/machine-id; it's always in /etc no matter * where our configured SYSCONFDIR is. Alternatively, it might be in * LOCALSTATEDIR /lib/dbus/machine-id. */ if ( g_file_get_contents ("/etc/machine-id", &contents, NULL, NULL) || g_file_get_contents (LOCALSTATEDIR "/lib/dbus/machine-id", &contents, NULL, NULL)) { contents = g_strstrip (contents); success = machine_id_parse (contents, uuid); if (success) { /* Hash the machine ID so it's not leaked to the network */ sum = g_checksum_new (G_CHECKSUM_SHA256); g_checksum_update (sum, (const guchar *) &uuid, sizeof (uuid)); g_checksum_get_digest (sum, buffer, &sumlen); g_checksum_free (sum); } g_free (contents); } if (!success) { nm_log_warn (LOGD_DHCP6, "Failed to read " SYSCONFDIR "/machine-id " "or " LOCALSTATEDIR "/lib/dbus/machine-id to generate " "DHCPv6 DUID; creating non-persistent random DUID."); generator = g_rand_new (); for (i = 0; i < sizeof (buffer) / sizeof (guint32); i++) ((guint32 *) buffer)[i] = g_rand_int (generator); g_rand_free (generator); } /* Generate a DHCP Unique Identifier for DHCPv6 using the * DUID-UUID method (see RFC 6355 section 4). Format is: * * u16: type (DUID-UUID = 4) * u8[16]: UUID bytes */ duid = g_byte_array_sized_new (18); g_byte_array_append (duid, (guint8 *) &duid_type, sizeof (duid_type)); /* Since SHA256 is 256 bits, but UUID is 128 bits, we just take the first * 128 bits of the SHA256 as the DUID-UUID. */ g_byte_array_append (duid, buffer, 16); return duid; }
gboolean gimp_operation_dissolve_mode_process_pixels (gfloat *in, gfloat *aux, gfloat *mask, gfloat *out, gfloat opacity, glong samples, const GeglRectangle *result, gint level) { const gboolean has_mask = mask != NULL; gint x, y; for (y = result->y; y < result->y + result->height; y++) { GRand *gr = g_rand_new_with_seed (random_table[y % RANDOM_TABLE_SIZE]); /* fast forward through the rows pseudo random sequence */ for (x = 0; x < result->x; x++) g_rand_int (gr); for (x = result->x; x < result->x + result->width; x++) { gfloat value = aux[ALPHA] * opacity * 255; if (has_mask) value *= *mask; if (g_rand_int_range (gr, 0, 255) >= value) { out[0] = in[0]; out[1] = in[1]; out[2] = in[2]; out[3] = in[3]; } else { out[0] = aux[0]; out[1] = aux[1]; out[2] = aux[2]; out[3] = 1.0; } in += 4; out += 4; aux += 4; if (has_mask) mask ++; } g_rand_free (gr); } return TRUE; }
/** * Retourne un identifiant "unique" sous forme d'une chaine hexa allouée * * @return identifiant "unique" hexa (à libérer par g_free) */ gchar *synutil_get_unique_hexa_identifier() { GRand *rand = __get_grand(); gchar *res = g_malloc(sizeof(gchar) * 33); guint32 ri; int i; for (i = 0 ; i < 4 ; i++) { ri = g_rand_int(rand); sprintf(res + (i * 8) * sizeof(gchar), "%08x", ri); } return res; }
/* * Set a canary value to be placed between memchunks. */ void emem_canary(guint8 *canary) { int i; static GRand *rand_state = NULL; if (rand_state == NULL) { rand_state = g_rand_new(); } for (i = 0; i < EMEM_CANARY_DATA_SIZE; i ++) { canary[i] = (guint8) g_rand_int(rand_state); } return; }
static void _gba_randomize(GRand *r, GByteArray *gba) { gint i, max; g_byte_array_set_size(gba, 0); max = g_rand_int_range(r, 1, 15); for (i=0; i<max ; i+=4) { guint32 u32 = g_rand_int(r); g_byte_array_append(gba, (guint8*)&u32, sizeof(u32)); } g_byte_array_set_size(gba, max); }
char get_rand_ascii_print(void) { GRand *rand ; struct timeval tv ; gettimeofday(&tv, NULL) ; g_usleep(tv.tv_usec % 256) ; rand = g_rand_new_with_seed((guint32) tv.tv_usec); return (char) ((g_rand_int(rand) % 26) + 97) ; }
static void gradient_put_pixel (gint x, gint y, GimpRGB *color, gpointer put_pixel_data) { PutPixelData *ppd = put_pixel_data; gfloat *dest = ppd->row_data + 4 * x; if (ppd->dither_rand) { gint i = g_rand_int (ppd->dither_rand); *dest++ = color->r + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8; *dest++ = color->g + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8; *dest++ = color->b + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8; *dest++ = color->a + (gdouble) (i & 0xff) / 256.0 / 256.0; }
guint IMInvoker::purpleEventInputAdd(int fd, PurpleInputCondition cond, PurpleInputFunction func, gpointer data) { PurpleEventContext* ctx = new PurpleEventContext(); ctx->function = NULL; ctx->input = func; ctx->inputFD = fd; ctx->cond = cond; ctx->data = data; short opMask = 0; if (cond & PURPLE_INPUT_READ) opMask |= DelayedEventQueue::DEQ_READ; if (cond & PURPLE_INPUT_WRITE) opMask |= DelayedEventQueue::DEQ_WRITE; guint eventId = g_rand_int(_gRand); // std::cout << "-- Input add " << eventId << " --------" << fd << std::endl; _eventQueue->addEvent(toStr(eventId), fd, opMask, purpleCallback, ctx, true); return eventId; }
static gboolean _zmq2agent_receive_events (GRand *r, struct _zmq2agent_ctx_s *ctx) { int rc, ended = 0; guint i = 0; do { zmq_msg_t msg; zmq_msg_init (&msg); rc = zmq_msg_recv (&msg, ctx->zpull, ZMQ_DONTWAIT); ended = (rc == 0); // empty frame is an EOF if (rc > 0) { ++ ctx->q->counter_received; if (!_zmq2agent_manage_event (g_rand_int(r), ctx, &msg)) rc = 0; // make it break } zmq_msg_close (&msg); } while (rc > 0 && i++ < ctx->q->max_recv_per_round); return !ended; }
static void create_server_auth(LXSession *s) { GRand *h; int i; char *authfile; h = g_rand_new(); for( i = 0; i < 16; i++ ) { s->mcookie[i] = g_rand_int(h)&0xff; } g_rand_free(h); authfile = g_strdup_printf("/var/run/lxdm/lxdm-:%d.auth",s->display); //setenv("XAUTHORITY",authfile,1); remove(authfile); xauth_write_file(authfile,s->display,s->mcookie); g_free(authfile); }
static void gegl_random_init (void) { if (random_data_inited) return; else { GRand *gr = g_rand_new_with_seed (42); gint i; /* Ensure alignment, needed with the use of CL_MEM_USE_HOST_PTR */ gegl_random_data = gegl_malloc (RANDOM_DATA_SIZE * sizeof (guint32)); for (i = 0; i < RANDOM_DATA_SIZE; i++) gegl_random_data[i] = g_rand_int (gr); g_rand_free (gr); random_data_inited = TRUE; } }
int xmi_get_random_numbers(unsigned long int *numbers,long int n) { //assume numbers is already allocated!!! /* * *This works perfect on Windows * */ #ifdef HAVE_RAND_S long int i; unsigned int number; errno_t err; for (i=0 ; i < n ; i++) { err = rand_s(&number); if (err != 0) { fprintf(stderr,"rand_s error\n"); return 0; } numbers[i] = number; } #else long int i; guint32 result; unsigned long int result2; GRand *rng; for (i = 0 ; i < n ; i++) { //size of unsigned long int is 4 bytes -> 32 rng = g_rand_new(); result = g_rand_int(rng); numbers[i] = result; g_rand_free(rng); } #endif return 1; }
void test_math_scale_random() { guint64 val, num, denom, res; GRand *rand; gint i; xmlfile = "gstutils_test_math_scale_random"; std_log(LOG_FILENAME_LINE, "Test Started gstutils_test_math_scale_random"); rand = g_rand_new (); i = 100000; while (i--) { guint64 check, diff; val = ((guint64) g_rand_int (rand)) << 32 | g_rand_int (rand); num = ((guint64) g_rand_int (rand)) << 32 | g_rand_int (rand); denom = ((guint64) g_rand_int (rand)) << 32 | g_rand_int (rand); res = gst_util_uint64_scale (val, num, denom); check = gst_gdouble_to_guint64 (gst_guint64_to_gdouble (val) * gst_guint64_to_gdouble (num) / gst_guint64_to_gdouble (denom)); if (res < G_MAXUINT64 && check < G_MAXUINT64) { if (res > check) diff = res - check; else diff = check - res; /* some arbitrary value, really.. someone do the proper math to get * the upper bound */ if (diff > 20000) fail_if (diff > 20000); } } g_rand_free (rand); std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
static inline void filter (void) { static void (* overlap)(guchar *, const guchar *); GimpPixelRgn src; GimpPixelRgn dst; GimpRGB color; guchar pixel[4]; gint division_x; gint division_y; gint offset_x; gint offset_y; Tile *tiles; gint numof_tiles; Tile *t; gint i; gint x; gint y; gint move_max_pixels; gint clear_x0; gint clear_y0; gint clear_x1; gint clear_y1; gint clear_width; gint clear_height; guchar *pixels; guchar *buffer; gint dindex; gint sindex; gint px, py; GRand *gr; gr = g_rand_new (); /* INITIALIZE */ gimp_pixel_rgn_init (&src, p.drawable, 0, 0, p.drawable->width, p.drawable->height, FALSE, FALSE); gimp_pixel_rgn_init (&dst, p.drawable, 0, 0, p.drawable->width, p.drawable->height, TRUE, TRUE); pixels = g_new (guchar, p.drawable->bpp * p.drawable->width * p.drawable->height); buffer = g_new (guchar, p.drawable->bpp * p.params.tile_width * p.params.tile_height); overlap = p.drawable_has_alpha ? overlap_RGBA : overlap_RGB; gimp_progress_init (_("Paper Tile")); gimp_drawable_mask_bounds (p.drawable->drawable_id, &p.selection.x0, &p.selection.y0, &p.selection.x1, &p.selection.y1); p.selection.width = p.selection.x1 - p.selection.x0; p.selection.height = p.selection.y1 - p.selection.y0; gimp_tile_cache_ntiles (2 * (p.selection.width / gimp_tile_width () + 1)); /* TILES */ division_x = p.params.division_x; division_y = p.params.division_y; if (p.params.fractional_type == FRACTIONAL_TYPE_FORCE) { if (0 < p.drawable->width % p.params.tile_width) division_x++; if (0 < p.drawable->height % p.params.tile_height) division_y++; if (p.params.centering) { if (1 < p.drawable->width % p.params.tile_width) { division_x++; offset_x = (p.drawable->width % p.params.tile_width) / 2 - p.params.tile_width; } else { offset_x = 0; } if (1 < p.drawable->height % p.params.tile_height) { division_y++; offset_y = (p.drawable->height % p.params.tile_height) / 2 - p.params.tile_height; } else { offset_y = 0; } } else { offset_x = 0; offset_y = 0; } } else { if (p.params.centering) { offset_x = (p.drawable->width % p.params.tile_width) / 2; offset_y = (p.drawable->height % p.params.tile_height) / 2; } else { offset_x = 0; offset_y = 0; } } move_max_pixels = p.params.move_max_rate * p.params.tile_width / 100.0; numof_tiles = division_x * division_y; t = tiles = g_new(Tile, numof_tiles); for (y = 0; y < division_y; y++) { gint srcy = offset_y + p.params.tile_height * y; for (x = 0; x < division_x; x++, t++) { gint srcx = offset_x + p.params.tile_width * x; if (srcx < 0) { t->x = 0; t->width = srcx + p.params.tile_width; } else if (srcx + p.params.tile_width < p.drawable->width) { t->x = srcx; t->width = p.params.tile_width; } else { t->x = srcx; t->width = p.drawable->width - srcx; } if (srcy < 0) { t->y = 0; t->height = srcy + p.params.tile_height; } else if (srcy + p.params.tile_height < p.drawable->height) { t->y = srcy; t->height = p.params.tile_height; } else { t->y = srcy; t->height = p.drawable->height - srcy; } t->z = g_rand_int (gr); random_move (&t->move_x, &t->move_y, move_max_pixels); } } qsort (tiles, numof_tiles, sizeof *tiles, tile_compare); gimp_pixel_rgn_get_rect (&src, pixels, 0, 0, p.drawable->width, p.drawable->height); if (p.params.fractional_type == FRACTIONAL_TYPE_IGNORE) { clear_x0 = offset_x; clear_y0 = offset_y; clear_width = p.params.tile_width * division_x; clear_height = p.params.tile_height * division_y; } else { clear_x0 = 0; clear_y0 = 0; clear_width = p.drawable->width; clear_height = p.drawable->height; } clear_x1 = clear_x0 + clear_width; clear_y1 = clear_y0 + clear_height; switch (p.params.background_type) { case BACKGROUND_TYPE_TRANSPARENT: for (y = clear_y0; y < clear_y1; y++) { for (x = clear_x0; x < clear_x1; x++) { dindex = p.drawable->bpp * (p.drawable->width * y + x); for (i = 0; i < p.drawable->bpp; i++) { pixels[dindex+i] = 0; } } } break; case BACKGROUND_TYPE_INVERTED: for (y = clear_y0; y < clear_y1; y++) { for (x = clear_x0; x < clear_x1; x++) { dindex = p.drawable->bpp * (p.drawable->width * y + x); pixels[dindex+0] = 255 - pixels[dindex+0]; pixels[dindex+1] = 255 - pixels[dindex+1]; pixels[dindex+2] = 255 - pixels[dindex+2]; } } break; case BACKGROUND_TYPE_IMAGE: break; case BACKGROUND_TYPE_FOREGROUND: gimp_context_get_foreground (&color); gimp_rgb_get_uchar (&color, &pixel[0], &pixel[1], &pixel[2]); pixel[3] = 255; for (y = clear_y0; y < clear_y1; y++) { for (x = clear_x0; x < clear_x1; x++) { dindex = p.drawable->bpp * (p.drawable->width * y + x); for (i = 0; i < p.drawable->bpp; i++) { pixels[dindex+i] = pixel[i]; } } } break; case BACKGROUND_TYPE_BACKGROUND: gimp_context_get_background (&color); gimp_rgb_get_uchar (&color, &pixel[0], &pixel[1], &pixel[2]); pixel[3] = 255; for (y = clear_y0; y < clear_y1; y++) { for (x = clear_x0; x < clear_x1; x++) { dindex = p.drawable->bpp * (p.drawable->width * y + x); for(i = 0; i < p.drawable->bpp; i++) { pixels[dindex+i] = pixel[i]; } } } break; case BACKGROUND_TYPE_COLOR: gimp_rgba_get_uchar (&p.params.background_color, pixel, pixel + 1, pixel + 2, pixel + 3); for (y = clear_y0; y < clear_y1; y++) { for (x = clear_x0; x < clear_x1; x++) { dindex = p.drawable->bpp * (p.drawable->width * y + x); for(i = 0; i < p.drawable->bpp; i++) { pixels[dindex+i] = pixel[i]; } } } break; } /* DRAW */ for (t = tiles, i = 0; i < numof_tiles; i++, t++) { gint x0 = t->x + t->move_x; gint y0 = t->y + t->move_y; gimp_pixel_rgn_get_rect (&src, buffer, t->x, t->y, t->width, t->height); for (y = 0; y < t->height; y++) { py = y0 + y; for (x = 0; x < t->width; x++) { px = x0 + x; sindex = p.drawable->bpp * (t->width * y + x); if (0 <= px && px < p.drawable->width && 0 <= py && py < p.drawable->height) { dindex = p.drawable->bpp * (p.drawable->width * py + px); overlap(&pixels[dindex], &buffer[sindex]); } else if (p.params.wrap_around) { px = (px + p.drawable->width) % p.drawable->width; py = (py + p.drawable->height) % p.drawable->height; dindex = p.drawable->bpp * (p.drawable->width * py + px); overlap(&pixels[dindex], &buffer[sindex]); } } } gimp_progress_update ((gdouble) i / (gdouble) numof_tiles); } gimp_pixel_rgn_set_rect (&dst, pixels, 0, 0, p.drawable->width, p.drawable->height); gimp_progress_update (1.0); gimp_drawable_flush (p.drawable); gimp_drawable_merge_shadow (p.drawable->drawable_id, TRUE); gimp_drawable_update (p.drawable->drawable_id, p.selection.x0, p.selection.y0, p.selection.width, p.selection.height); g_rand_free (gr); g_free (buffer); g_free (pixels); g_free (tiles); }
static char *generate_calname() { GRand *rand = g_rand_new(); return g_strdup_printf("%08x", g_rand_int(rand)); }
static void prepare_coef (params *p) { GimpRGB color1; GimpRGB color2; gdouble scalex = svals.scalex; gdouble scaley = svals.scaley; GRand *gr; gr = g_rand_new (); g_rand_set_seed (gr, svals.seed); switch (svals.colorization) { case BILINEAR: p->blend = bilinear; break; case SINUS: p->blend = cosinus; break; case LINEAR: default: p->blend = linear; } if (svals.perturbation==IDEAL) { /* Presumably the 0 * g_rand_int ()s are to pop random * values off the prng, I don't see why though. */ p->c11= 0 * g_rand_int (gr); p->c12= g_rand_double_range (gr, -1, 1) * scaley; p->c13= g_rand_double_range (gr, 0, 2 * G_PI); p->c21= 0 * g_rand_int (gr); p->c22= g_rand_double_range (gr, -1, 1) * scaley; p->c23= g_rand_double_range (gr, 0, 2 * G_PI); p->c31= g_rand_double_range (gr, -1, 1) * scalex; p->c32= 0 * g_rand_int (gr); p->c33= g_rand_double_range (gr, 0, 2 * G_PI); } else { p->c11= g_rand_double_range (gr, -1, 1) * scalex; p->c12= g_rand_double_range (gr, -1, 1) * scaley; p->c13= g_rand_double_range (gr, 0, 2 * G_PI); p->c21= g_rand_double_range (gr, -1, 1) * scalex; p->c22= g_rand_double_range (gr, -1, 1) * scaley; p->c23= g_rand_double_range (gr, 0, 2 * G_PI); p->c31= g_rand_double_range (gr, -1, 1) * scalex; p->c32= g_rand_double_range (gr, -1, 1) * scaley; p->c33= g_rand_double_range (gr, 0, 2 * G_PI); } if (svals.tiling) { p->c11= ROUND (p->c11/(2*G_PI))*2*G_PI; p->c12= ROUND (p->c12/(2*G_PI))*2*G_PI; p->c21= ROUND (p->c21/(2*G_PI))*2*G_PI; p->c22= ROUND (p->c22/(2*G_PI))*2*G_PI; p->c31= ROUND (p->c31/(2*G_PI))*2*G_PI; p->c32= ROUND (p->c32/(2*G_PI))*2*G_PI; } color1 = svals.col1; color2 = svals.col2; if (drawable_is_grayscale) { gimp_rgb_set (&color1, 1.0, 1.0, 1.0); gimp_rgb_set (&color2, 0.0, 0.0, 0.0); } else { switch (svals.colors) { case USE_COLORS: break; case B_W: gimp_rgb_set (&color1, 1.0, 1.0, 1.0); gimp_rgb_set (&color2, 0.0, 0.0, 0.0); break; case USE_FG_BG: gimp_context_get_background (&color1); gimp_context_get_foreground (&color2); break; } } gimp_rgba_get_uchar (&color1, &p->r, &p->g, &p->b, &p->a); gimp_rgba_subtract (&color2, &color1); p->dr = color2.r * 255.0; p->dg = color2.g * 255.0; p->db = color2.b * 255.0; p->da = color2.a * 255.0; g_rand_free (gr); }
/** * oil_rand_s32: * @r: a #GRand, representing a random seed * * Returns: a 32-bit signed random integer */ gint32 oil_rand_s32 (GRand *r) { return (gint32) g_rand_int (r); }
/** * oil_rand_u32 * @r: a #GRand, representing a random seed * * Returns: a 32-bit unsigned random integer */ guint32 oil_rand_u32 (GRand *r) { return (guint32) g_rand_int (r); }
/** * crank_bench_run_rand_int: (skip) * @run: A benchmark run. * * Returns random integer. * * Returns: A random integer. */ gint32 crank_bench_run_rand_int (CrankBenchRun *run) { return g_rand_int (run->random); }