Esempio n. 1
0
// extrapolate by periodicity
inline
static float getsample_per(float *x, int w, int h, int pd, int i, int j, int l)
{
	i = good_modulus(i, w);
	j = good_modulus(j, w);
	return getsample_abort(x, w, h, pd, i, j, l);
}
Esempio n. 2
0
static uint8_t bygetpixel_s(uint8_t *xx, int w, int h, int i, int j)
{
	uint8_t (*x)[w] = (void*)xx;
	i = good_modulus(i, w);
	j = good_modulus(j, h);
	return x[j][i];
}
Esempio n. 3
0
static float getsample_s(float *xx, int w, int h, int pd, int i, int j, int l)
{
	float (*x)[w][pd] = (void*)xx;
	i = good_modulus(i, w);
	j = good_modulus(j, h);
	l = good_modulus(l, pd);
	return x[j][i][l];
}
Esempio n. 4
0
// instance of "extrapolator_t", extrapolate by periodicity
static float getsample_per(float *x, int w, int h, int pd, int i, int j, int l)
{
	i = good_modulus(i, w);
	j = good_modulus(j, h);
	if (l >= pd)
		l = pd - 1;
	return x[(i+j*w)*pd + l];
}
Esempio n. 5
0
static void action_cycle(struct FTR *f, int d)
{
	struct pan_state *e = f->userdata;
	e->current_image = good_modulus(e->current_image + d, e->n_images);
	fprintf(stderr, "current image %d \"%s\"\n",
			e->current_image,
			e->t[e->current_image].fname
			);
	f->changed = 1;
}
Esempio n. 6
0
static int positive_reflex(int n, int p)
{
	int r = good_modulus(n, 2*p);
	if (r == p) r -= 1;
	if (r > p)
		r = 2*p - r;
	if (n < 0 && p > 1) r += 1;
	//assert(r >= 0);
	//assert(r < p);
	return r;
}
Esempio n. 7
0
// like n%p, but works for all numbers
static int good_modulus(int n, int p)
{
	if (!p) return 0;
	if (p < 1) return good_modulus(n, -p);

	int r = n % p;
	r = r < 0 ? r + p : r;

	assert(r >= 0);
	assert(r < p);
	return r;
}
Esempio n. 8
0
static void action_kill_windowed_rectangle(struct pan_state *e, int x, int y)
{
	int f_good[2] = { BAD_MIN(e->paint_handle[0], x),
			  BAD_MIN(e->paint_handle[1], y) };
	int t_good[2] = { BAD_MAX(e->paint_handle[0], x),
			  BAD_MAX(e->paint_handle[1], y) };
	double from[2], to[2];
	window_to_image(from, e, f_good[0], f_good[1]);
	window_to_image(to,   e, t_good[0], t_good[1]);
	int ifrom[2], ito[2];
	ifrom[0] = good_modulus(from[0], e->w);
	ifrom[1] = good_modulus(from[1], e->h);
	ito[0] = good_modulus(to[0], e->w);
	ito[1] = good_modulus(to[1], e->h);
	fprintf(stderr, "\twill kill %g %g to %g %g\n", from[0], from[1], to[0], to[1]);
	fprintf(stderr, "\twill kill %d %d to %d %d\n", ifrom[0], ifrom[1], ito[0], ito[1]);
	int rw = lrint(fabs(from[0] - to[0]));
	int rh = lrint(fabs(from[1] - to[1]));
	for (int j = 0; j <= rh; j++)
	for (int i = 0; i <= rw; i++)
	{
		int ii = good_modulus(from[0] + i, e->w);
		int jj = good_modulus(from[1] + j, e->h);
		e->mask[jj*e->w+ii] = 0;
	}
}
Esempio n. 9
0
// auxiliary function: compute n%p correctly, even for huge and negative numbers
static int good_modulus(int nn, int p)
{
	if (!p) return 0;
	if (p < 1) return good_modulus(nn, -p);

	unsigned int r;
	if (nn >= 0)
		r = nn % p;
	else {
		unsigned int n = nn;
		r = p - (-n) % p;
		if ((int)r == p)
			r = 0;
	}
	return r;
}
Esempio n. 10
0
static int good_modulus(int n, int p)
{
	if (!p) return 0;
	if (p < 1) return good_modulus(n, -p);

	int r;
	if (n >= 0)
		r = n % p;
	else {
		r = p - (-n) % p;
		if (r == p)
			r = 0;
	}
	//assert(r >= 0);
	//assert(r < p);
	return r;
}
Esempio n. 11
0
static int good_modulus(int nn, int p)
{
	if (!p) return 0;
	if (p < 1) return good_modulus(nn, -p);

	unsigned int r;
	if (nn >= 0)
		r = nn % p;
	else {
		unsigned int n = nn;
		r = p - (-n) % p;
		if (r == p)
			r = 0;
	}
	//assert(r >= 0);
	if (!(r<p)) fprintf(stderr, "bad modulus nn=%d r=%d p=%d\n", nn, r, p);
	//assert(r < p);
	return r;
}