1 #define greyscale(b)            grayscale(b)
2 
3 inline BITMAP*
grayscale(colorimg)4 grayscale(colorimg)
5 BITMAP *colorimg;
6 {
7         BITMAP *greyimg=create_bitmap(colorimg->w, colorimg->h);
8         int x,y;
9         long color;
10         long gray;
11         int r, g, b;
12 
13         for(y = 0; y < colorimg->h; y++)
14             for(x = 0; x < colorimg->w; x++)
15             {
16                 color = getpixel(colorimg, x, y);
17                 r = getr(color);
18                 g = getg(color);
19                 b = getb(color);
20                 if(r == 255 && g == 0 && b == 255)
21                         putpixel(greyimg, x, y, color);
22                 else
23                 {
24                         gray = (r+g+b)/3;
25                         gray /= 2;
26                         gray += 64;
27                         putpixel(greyimg, x, y, makecol(gray, gray, gray));
28                 }
29 
30             }
31 
32         return(greyimg);
33 }
34 
35 void
draw_gray_sprite(dest,sprite,x,y)36 draw_gray_sprite(dest, sprite, x, y)
37 BITMAP *dest;
38 BITMAP *sprite;
39 int x,y;
40 {
41         BITMAP *gray_sprite;
42 
43         if (!dest || !sprite) return;
44 
45         gray_sprite = grayscale(sprite);
46 
47         draw_sprite(dest, gray_sprite, x, y);
48         destroy_bitmap(gray_sprite);
49 }
50 
51 inline void
tinted_blit(source,dest,source_x,source_y,dest_x,dest_y,width,height,color,alpha)52 tinted_blit(source, dest, source_x, source_y, dest_x, dest_y,
53             width, height, color, alpha)
54 BITMAP *source;
55 BITMAP *dest;
56 int source_x,source_y,dest_x,dest_y,width,height;
57 long color;
58 int alpha;
59 {
60         BITMAP *buffer = create_bitmap(width,height);
61 
62         blit(source, buffer, source_x, source_y, 0, 0, width, height);
63 
64         drawing_mode(DRAW_MODE_TRANS, buffer, 0, 0);
65         set_trans_blender(255,255,255,alpha);
66         rectfill(buffer, 0, 0, width, height, color);
67         drawing_mode(DRAW_MODE_SOLID, buffer, 0, 0);
68 
69         blit(buffer, dest, 0, 0, dest_x, dest_y, width, height);
70         destroy_bitmap(buffer);
71 }
72 
mosaic(bitmap,factor)73 BITMAP* mosaic(bitmap,factor)
74 BITMAP *bitmap;
75 int factor;
76 {
77         int small_w, small_h;
78         int width = bitmap->w;
79         int height = bitmap->h;
80         BITMAP *smallimg;
81         BITMAP *final = create_bitmap(width, height);
82 
83         small_w = width/factor;
84         small_h = height/factor;
85 
86         smallimg = create_bitmap(small_w, small_h);
87 
88         stretch_blit(bitmap, smallimg, 0, 0,
89                      width, height, 0, 0, small_w, small_h);
90 
91         stretch_blit(smallimg, final, 0, 0, small_w, small_h,
92                      0, 0, width, height);
93 
94         destroy_bitmap(smallimg);
95 
96         return(final);
97 }
98 
99 inline void
mosaic_blit(source,dest,source_x,source_y,dest_x,dest_y,width,height,factor)100 mosaic_blit(source, dest, source_x, source_y, dest_x, dest_y,
101             width, height, factor)
102 BITMAP *source;
103 BITMAP *dest;
104 int source_x,source_y,dest_x,dest_y,width,height;
105 int factor;
106 {
107         BITMAP *buffer = create_bitmap(width,height);
108         BITMAP *buffer2;
109 
110         blit(source, buffer, source_x, source_y, 0, 0, width, height);
111 
112         buffer2 = mosaic(buffer, factor);
113 
114         blit(buffer2, dest, 0, 0, dest_x, dest_y, width, height);
115 
116         destroy_bitmap(buffer);
117         destroy_bitmap(buffer2);
118 
119 }
120 
blur(bitmap,factor)121 BITMAP* blur(bitmap,factor)
122 BITMAP *bitmap;
123 int factor;
124 {
125         int small_w, small_h;
126         int width = bitmap->w;
127         int height = bitmap->h;
128         BITMAP *smallimg;
129         BITMAP *final = create_bitmap(width, height);
130 
131         small_w = width/factor;
132         small_h = height/factor;
133 
134         smallimg = create_bitmap(small_w, small_h);
135 
136         nh_stretch_blit(bitmap, smallimg, 0, 0,
137                      width, height, 0, 0, small_w, small_h);
138 
139         nh_stretch_blit(smallimg, final, 0, 0, small_w, small_h,
140                      0, 0, width, height);
141 
142         destroy_bitmap(smallimg);
143 
144         return(final);
145 }
146 
147 inline void
blur_blit(source,dest,source_x,source_y,dest_x,dest_y,width,height,factor)148 blur_blit(source, dest, source_x, source_y, dest_x, dest_y,
149             width, height, factor)
150 BITMAP *source;
151 BITMAP *dest;
152 int source_x,source_y,dest_x,dest_y,width,height;
153 int factor;
154 {
155 	BITMAP *buffer = create_bitmap(width,height);
156 	BITMAP *buffer2;
157 
158 	blit(source, buffer, source_x, source_y, 0, 0, width, height);
159 
160 	buffer2 = blur(buffer, factor);
161 
162 	blit(buffer2, dest, 0, 0, dest_x, dest_y, width, height);
163 	destroy_bitmap(buffer);
164 	destroy_bitmap(buffer2);
165 }
166 
167 
168