void rot4(GdkPixbuf *src, GdkPixbuf *dist, gint r, gfloat m)
{
gint w1, h1, w2, h2;
gint x1, y1, x2, y2;
gint dx1, dy1, dx2, dy2;
gint px1, py1, px2, py2;
gint i, j;
guint32 *ptr2;
w1 = gdk_pixbuf_get_width(src);
h1 = gdk_pixbuf_get_height(src);
w2 = gdk_pixbuf_get_width(dist);
h2 = gdk_pixbuf_get_height(dist);
px1 = w1 / 2;
py1 = h1 / 2;
px2 = w2 / 2;
py2 = h2 / 2;
ptr2 = (guint32*)gdk_pixbuf_get_pixels(dist);
x1 = (((0 - px2) * cos(M_PI*2/360*r) + (0 - py2) * sin(M_PI*2/360*r)) * (1 / m) + px1) * 0x10000;
y1 = (((0 - py2) * cos(M_PI*2/360*r) - (0 - px2) * sin(M_PI*2/360*r)) * (1 / m) + py1) * 0x10000;
dx1 = (((1 - px2) * cos(M_PI*2/360*r) + (0 - py2) * sin(M_PI*2/360*r)) * (1 / m) + px1) * 0x10000;
dy1 = (((0 - py2) * cos(M_PI*2/360*r) - (1 - px2) * sin(M_PI*2/360*r)) * (1 / m) + py1) * 0x10000;
dx2 = (((0 - px2) * cos(M_PI*2/360*r) + (1 - py2) * sin(M_PI*2/360*r)) * (1 / m) + px1) * 0x10000;
dy2 = (((1 - py2) * cos(M_PI*2/360*r) - (0 - px2) * sin(M_PI*2/360*r)) * (1 / m) + py1) * 0x10000;
dx1 -= x1;
dy1 -= y1;
dx2 -= x1;
dy2 -= y1;
w1 <<= 16;
h1 <<= 16;
for(j=0; j
= 0) && (x2 < w1) && (y2 >= 0) && (y2 < h1)) {
*ptr2 = smooth_pixel(src, x2, y2, dx1, dy1, dx2, dy2, m, m);
}
else {
*ptr2 = 0;
}
ptr2++;
x2 += dx1;
y2 += dy1;
}
x1 += dx2;
y1 += dy2;
}
}
/* -------------------------------------------------------------
ピクセルスムージング
-------------------------------------------------------------- */
guint32 smooth_pixel(GdkPixbuf *pic,
gint x, gint y,
gint dx1, gint dy1, gint dx2, gint dy2,
gfloat mx, gfloat my)
{
guchar *ptr1, *ptr2;
guint r, g, b, a;
guint r1, g1, b1, a1;
guint r2, g2, b2, a2;
guint ro, go, bo, ao;
gint blend, times;
gint x_loop, y_loop, tx, ty;
ro = go = bo = ao = 0;
blend = 0;
x_loop = (gint)(1 / mx) + 1;
y_loop = (gint)(1 / my) + 1;
dx1 /= x_loop;
dy1 /= y_loop;
dx2 /= x_loop;
dy2 /= y_loop;
do {
tx = x;
ty = y;
do {
ptr1 = gdk_pixbuf_get_pixels(pic) +
gdk_pixbuf_get_rowstride(pic) * (y >> 16) + ((x >> 16) * 4);
ptr2 = gdk_pixbuf_get_pixels(pic) +
gdk_pixbuf_get_rowstride(pic) * ((y >> 16) + 1) + ((x >> 16) * 4);
if (((x >> 16) >= gdk_pixbuf_get_width(pic))
|| ((y >> 16) >= gdk_pixbuf_get_height(pic))) {
break;
}
r = g = b = a = 0;
times = (x & 0xffff) >> 8;
if (times > 0x40) {
times -= 0x40;
r1 = ptr1[0] * (0xc0 - times) + ptr1[4] * times;
g1 = ptr1[1] * (0xc0 - times) + ptr1[5] * times;
b1 = ptr1[2] * (0xc0 - times) + ptr1[6] * times;
a1 = ptr1[3] * (0xc0 - times) + ptr1[7] * times;
r2 = ptr2[0] * (0xc0 - times) + ptr2[4] * times;
g2 = ptr2[1] * (0xc0 - times) + ptr2[5] * times;
b2 = ptr2[2] * (0xc0 - times) + ptr2[6] * times;
a2 = ptr2[3] * (0xc0 - times) + ptr2[7] * times;
}
else {
r1 = ptr1[0] * 0xc0;
g1 = ptr1[1] * 0xc0;
b1 = ptr1[2] * 0xc0;
a1 = ptr1[3] * 0xc0;
r2 = ptr2[0] * 0xc0;
g2 = ptr2[1] * 0xc0;
b2 = ptr2[2] * 0xc0;
a2 = ptr2[3] * 0xc0;
}
times = (y & 0xffff) >> 8;
if (times > 0x40) {
times -= 0x40;
r = r1 * (0xc0 - times) + r2 * times;
g = g1 * (0xc0 - times) + g2 * times;
b = b1 * (0xc0 - times) + b2 * times;
a = a1 * (0xc0 - times) + a2 * times;
}
else {
r = r1 * 0xc0;
g = g1 * 0xc0;
b = b1 * 0xc0;
a = a1 * 0xc0;
}
r /= 0xc0 * 0xc0;
g /= 0xc0 * 0xc0;
b /= 0xc0 * 0xc0;
a /= 0xc0 * 0xc0;
ro += r;
go += g;
bo += b;
ao += a;
blend++;
x += dx1;
y += dy1;
x_loop--;
} while(x_loop > 1);
x = tx;
y = ty;
x += dx2;
y += dy2;
y_loop--;
}while(y_loop > 1);
r = ro / blend;
g = go / blend;
b = bo / blend;
a = ao / blend;
if (r > 0x100) r = 0xff;
if (g > 0x100) g = 0xff;
if (b > 0x100) b = 0xff;
if (a > 0x100) a = 0xff;
return(r | (g<<8) | (b<<16) | (a<<24));
}