[Freeciv-Dev] Re: uhm ... two bugs already
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Sat, 16 Jun 2001, Karl-Ingo Friese wrote:
> I just noticed that a) the flags didnt match the nations
> (already fixed, images are updated) and b) I do not make
> a different between "transparent" pixels and "black"
> pixels. Can anyone help ?
try replacing the default gtk_scale_pixmap() function with this new one:
/**************************************************************************
...
**************************************************************************/
void
new_gtk_scale_pixmap(SPRITE *dst, SPRITE *src)
{
GdkImage *xi_src, *xi_dst, *xb_src, *xb_dst;
int xoffset_table[4096];
int x, xoffset, xadd, xremsum, xremadd;
int y, yoffset, yadd, yremsum, yremadd;
xi_src=gdk_image_get(src->pixmap, 0, 0, src->width, src->height);
xi_dst=gdk_image_new(GDK_IMAGE_FASTEST,
gdk_window_get_visual(src->pixmap),
dst->width, dst->height);
if (src->has_mask) {
xb_src=gdk_image_get(src->mask, 0, 0, src->width, src->height);
xb_dst=gdk_image_new(GDK_IMAGE_FASTEST,
gdk_window_get_visual(src->mask),
dst->width, dst->height);
}
/* for each pixel in dst, calculate pixel offset in src */
xadd=src->width/dst->width;
xremadd=src->width%dst->width;
xoffset=0;
xremsum=dst->width/2;
for(x=0; x<dst->width; ++x) {
xoffset_table[x]=xoffset;
xoffset+=xadd;
xremsum+=xremadd;
if(xremsum>=dst->width) {
xremsum-=dst->width;
++xoffset;
}
}
yadd=src->height/dst->height;
yremadd=src->height%dst->height;
yoffset=0;
yremsum=dst->height/2;
for(y=0; y<dst->height; ++y) {
for(x=0; x<dst->height; ++x) {
guint32 pixel;
pixel=gdk_image_get_pixel(xi_src, xoffset_table[x], yoffset);
gdk_image_put_pixel(xi_dst, x, y, pixel);
if (src->has_mask) {
pixel=gdk_image_get_pixel(xb_src, xoffset_table[x], yoffset);
gdk_image_put_pixel(xb_dst, x, y, pixel);
}
}
yoffset+=yadd;
yremsum+=yremadd;
if(yremsum>=dst->height) {
yremsum-=dst->height;
++yoffset;
}
}
dst->pixmap=gdk_pixmap_new(src->pixmap, dst->width, dst->height, -1);
gdk_draw_image(dst->pixmap, civ_gc, xi_dst, 0, 0, 0, 0, dst->width,
dst->height);
gdk_image_destroy(xi_src);
gdk_image_destroy(xi_dst);
if (src->has_mask) {
dst->mask=gdk_pixmap_new(src->mask, dst->width, dst->height, 1);
gdk_draw_image(dst->mask, mask_fg_gc, xb_dst, 0, 0, 0, 0, dst->width,
dst->height);
gdk_image_destroy(xb_src);
gdk_image_destroy(xb_dst);
}
dst->has_mask=src->has_mask;
return dst;
}
GdkPixmap *
gtk_scale_pixmap(GdkPixmap *src, int src_w, int src_h, int dst_w, int
dst_h)
{
SPRITE dst_s, src_s;
src.has_mask = 0;
src.pixmap = src;
src.mask = NULL;
src.width = src_w;
src.height = src_h;
dst.pixmap = NULL;
dst.mask = NULL;
dst.width = dst_w;
dst.height = dst_h;
new_gtk_scale_pixmap(&dst_s, &src_s);
return dst_s.pixmap;
}
Use new_gtk_scale_pixmap() for your scaling needs.
WARNING: i have not tested this code. it probably won't even compile first
time.
---
Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa
|
|