fixed path to external icons
[shermanaquarium] / sherman-aquarium / shermans / images.c
1
2 #include <stdio.h>
3 #include <gtk/gtk.h>
4 #include <gdk-pixbuf/gdk-pixbuf.h>
5 #include "aquarium.h"
6
7 extern int fullscreen, window_id;
8
9 /* Declare it here to avoid warnings */
10 GdkPixbuf *gai_load_image(const char *);
11
12 void load_image(char *fname, SA_Image *image, int frames)
13 {
14
15     image->pixbuf = gai_load_image(fname);
16     image->frames = frames;
17     image->rev = NULL;
18     image->width = gdk_pixbuf_get_width(image->pixbuf);
19     image->full_height = gdk_pixbuf_get_height(image->pixbuf);
20
21     image->rowstride = gdk_pixbuf_get_rowstride(image->pixbuf);
22     image->height = (int)((float)image->full_height / (float)frames+0.5);
23     image->image = gdk_pixbuf_get_pixels(image->pixbuf);
24 }
25
26
27
28 void load_image_n_scale(char *fname, SA_Image *image,
29                         int frames, int scale)
30 {
31
32     int w, h, newh, neww,i;
33     GdkPixbuf *tmpbuff, *workbuff1, *workbuff2;
34
35     if(scale==100){
36         load_image(fname,image,frames);
37         return;
38     }
39
40
41     tmpbuff = gai_load_image(fname);
42     image->frames = frames;
43     image->rev = NULL;
44
45     w = gdk_pixbuf_get_width(tmpbuff);
46     h = gdk_pixbuf_get_height(tmpbuff);
47
48     image->width = neww =(int)((((float)w * (float)scale) / 100.0)+0.5);
49     image->height = newh = (int)((((float)h / (float)frames) * (float)scale) / 100.0 + 0.5);
50     image->full_height = newh * frames; 
51
52     image->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE,8,
53                                    neww,
54                                    frames*newh);
55
56     for(i=0;i<frames;i++){
57         workbuff1 = gdk_pixbuf_new_subpixbuf(tmpbuff,0,i*h/frames,w,h/frames);
58         workbuff2 = gdk_pixbuf_scale_simple(workbuff1, neww, newh, GDK_INTERP_BILINEAR);
59         g_object_unref(workbuff1);
60         gdk_pixbuf_copy_area(workbuff2,0,0,neww,newh,image->pixbuf,0,newh*i);
61         g_object_unref(workbuff2);
62
63     }
64
65     
66
67
68     image->image = gdk_pixbuf_get_pixels(image->pixbuf);
69     image->rowstride = gdk_pixbuf_get_rowstride(image->pixbuf);
70
71     g_object_unref(tmpbuff);
72
73 }