/* $Id: readtexture.c,v 1.12 2003/03/21 01:10:49 d3august Exp $ */ /* xtraceroute - graphically show traceroute information. * Copyright (C) 1996-2003 Björn Augustsson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #include #include #include #include "xt.h" /** * Readtexture does just what the name suggests. */ GdkPixbuf * readTexture(const char *imgname) { GdkPixbuf *img; DPRINTF("Loading texture from file \"%s\"... ", imgname); img = gdk_pixbuf_new_from_file(imgname); if (img == NULL) { fprintf(stderr, "Couldn't load texture file %s\n", imgname); exit(EXIT_FAILURE); } DPRINTF("Done!\n\tTexture size is %dx%d\n", gdk_pixbuf_get_width(img), gdk_pixbuf_get_height(img)); return img; } extern void get_sun_position(double* , double*); #define DAY 0 #define NIGHT 0xFF #define SET_ALPHA(x, y, val) *(pt+4*(width*y+x)+3) = val #define SET_WHOLE_ROWS(from, to, val) \ { \ int y; \ for(y=from ; y= width) inoon -= width; for (y=polar_rows ; y 1) length_of_day = 1; else if (H0 < -1) length_of_day = 0; else length_of_day = 1.0 - (acos(H0) / M_PI); /* ilight = number of pixels from noon to the terminator. */ ilight = (int) (width/2 * length_of_day + 0.5); /* dark_pixels = number of pixels that are in darkness at the current latitude */ dark_pixels = width - 2 * ilight; // start at the evening terminator { int pos = inoon + ilight; int j; for (j=0 ; j= width) pos -= width; SET_ALPHA(pos, y, NIGHT); pos++; } for (j=dark_pixels ; j= width) pos -= width; SET_ALPHA(pos, y, DAY); pos++; } } } } /** * Makes a composite texture from the day and night images, according to * what time it is. * * dest needs to be at least as big as the biggest one of the night and * day textures. * * Note: Allocates memory. (For the dest argument.) */ void composite_texture(GdkPixbuf* night, const GdkPixbuf* day, GdkPixbuf** dest) { int dest_w = MAX(gdk_pixbuf_get_width(night), gdk_pixbuf_get_width(day)); int dest_h = MAX(gdk_pixbuf_get_height(night), gdk_pixbuf_get_height(day)); if(!gdk_pixbuf_get_has_alpha(night)) night = gdk_pixbuf_add_alpha(night, FALSE, 0,0,0); update_alpha_in_texture(night); { #if 0 // Testpattern. pt += 3; for(i=0; i < height ; i++) { for(j=0; j < width ; j++) { *(pt) = j%255; pt += 4; } } #endif //0 } /* Copy day texture to dest */ *dest = gdk_pixbuf_scale_simple(day, dest_w, dest_h, GDK_INTERP_HYPER); /* Composite night onto dest */ { double scale_x = (double)gdk_pixbuf_get_width(*dest) / (double)gdk_pixbuf_get_width(night); double scale_y = (double)gdk_pixbuf_get_height(*dest) / (double)gdk_pixbuf_get_height(night); gdk_pixbuf_composite(night, *dest, 0,0, // dest_x, dest_y, dest_w, dest_h, 0.0, 0.0, // offset_x, offset_y, scale_x, scale_y, GDK_INTERP_HYPER, 255); } return; }