6 /* This is a special version of draw_image() that draws parts of a
7 horizontal stored multi image */
9 void draw_image_alpha_h(int x, int y, int idx, int alpha,SA_Image *image)
13 /* bounding box of the clipped sprite */
22 ad = aquarium_get_settings_ptr();
24 /* completely off the screen, don't bother drawing */
25 if ((y < (-image->height)) || (y > (ad->ymax)) || (x > (ad->xmax)) || (x < -(image->width)))
29 /* do clipping for top side */
34 /* do clipping for bottom side */
36 if ((y + image->height) > ad->ymax)
39 /* do clipping for right side */
41 if ((x + image->width) > ad->xmax)
42 dw = image->width - ((x + image->width) - ad->xmax);
44 /* do clipping for left side */
49 fidx = idx*image->width*4;
54 for (h = ds; h < dh; h++) {
55 /* offset to beginning of current row */
56 ypos = (h + y) * ad->xmax * 3;
57 for (w = di; w < dw; w++) {
58 pic_pos = h * image->rowstride + w * 4 + fidx;
59 if (image->image[pic_pos + 3] != 0) {
60 pos = ypos + w * 3 + x * 3;
61 ad->rgb[pos] = ((256-alpha) * (int) ad->rgb[pos]
62 + alpha * (int) image->image[pic_pos]) >> 8;
64 ad->rgb[pos + 1] = ((256-alpha) * (int) ad->rgb[pos + 1]
65 + alpha * (int) image->image[pic_pos +
68 ad->rgb[pos + 2] = ((256-alpha) * (int) ad->rgb[pos + 2]
69 + alpha * (int) image->image[pic_pos +
80 static void draw_image_base(unsigned char *buff, int x, int y, int idx, int rev, SA_Image *image)
84 /* bounding box of the clipped sprite */
91 ad = aquarium_get_settings_ptr();
93 /* completely off the screen, don't bother drawing */
94 if ((y < (-image->height)) || (y > (ad->ymax)) || (x > (ad->xmax)) || (x < -(image->width)))
98 /* do clipping for top side */
103 /* do clipping for bottom side */
105 if ((y + image->height) > ad->ymax)
108 /* do clipping for right side */
110 if ((x + image->width) > ad->xmax)
111 dw = image->width - ((x + image->width) - ad->xmax);
113 /* do clipping for left side */
119 fidx = (int) ((float)idx * (float)image->full_height / (float)image->frames) *
120 gdk_pixbuf_get_rowstride(image->pixbuf);
122 /*image->width * image->height * 4 * idx;*/
126 /* The fish is moving in different direction */
127 for (h = ds; h < dh; h++) {
128 /* offset to beginning of current row */
129 ypos = (h + y) * ad->xmax * 3;
131 for (w = dw; w > di; w--) {
133 h * image->width * 4 + (q + (image->width - dw)) * 4 + fidx;
134 if (image->image[pic_pos + 3] != 0) {
135 pos = ypos + w * 3 + x * 3 - 3;
136 buff[pos] = image->image[pic_pos];
137 buff[pos + 1] = image->image[pic_pos + 1];
138 buff[pos + 2] = image->image[pic_pos + 2];
147 for (h = ds; h < dh; h++) {
148 /* offset to beginning of current row */
149 ypos = (h + y) * ad->xmax * 3;
150 for (w = di; w < dw; w++) {
151 pic_pos = h * image->width * 4 + w * 4 + fidx;
152 pos = ypos + w * 3 + x * 3;
153 if (image->image[pic_pos + 3] != 0) {
154 buff[pos] = image->image[pic_pos];
155 buff[pos + 1] = image->image[pic_pos + 1];
156 buff[pos + 2] = image->image[pic_pos + 2];
165 void draw_image(int x, int y, int idx, int rev, SA_Image *image)
168 ad = aquarium_get_settings_ptr();
170 draw_image_base(ad->rgb,x,y,idx,rev,image);
173 void draw_image_bg(int x, int y, int idx, int rev, SA_Image *image)
176 ad = aquarium_get_settings_ptr();
178 draw_image_base(ad->bgr,x,y,idx,rev,image);
184 /* draw a fish into ad.rgb with alpha-blend */
186 draw_pic_alpha(unsigned char *buff, int width, int height, int x,
187 int y, int frame, int alpha)
189 /* bounding box of the clipped sprite */
196 ad = aquarium_get_settings_ptr();
198 /* completely off the screen, don't bother drawing */
199 if ((y < -(height)) || (y > ad->ymax) || (x > ad->xmax) || (x < -(width)))
202 /* do clipping for top side */
207 /* do clipping for bottom side */
209 if ((y + height) > ad->ymax)
212 /* do clipping for right side */
214 if (x > (ad->xmax - width))
215 dw = width - (x - (ad->xmax - width));
217 /* do clipping for left side */
222 fidx = width * 4 * height * frame;
224 for (h = ds; h < dh; h++) {
226 /* offset to beginning of current row */
229 ypos = (h + y) * ad->xmax;
230 for (w = di; w < dw; w++) {
231 pic_pos = h * width * 4 + w * 4 + fidx;
232 if (buff[pic_pos + 3] != 0) {
233 pos = (ypos + w + x) * 3;
234 ad->rgb[pos] = ((256-alpha) * (int) ad->rgb[pos] + alpha * (int) buff[pic_pos]) >> 8;
235 ad->rgb[pos + 1] = ((256-alpha) * (int) ad->rgb[pos + 1]
236 + alpha * (int) buff[pic_pos +
238 ad->rgb[pos + 2] = ((256-alpha) * (int) ad->rgb[pos + 2]
239 + alpha * (int) buff[pic_pos +
249 /* draw antialiased line from (x1, y1) to (x2, y2), with width linewidth
250 * colour is an int like 0xRRGGBB */
251 void anti_line(int x1, int y1, int x2, int y2, int linewidth, int colour, int shaded)
255 int error, sign, tmp;
257 int step = linewidth;
259 char af[]={0x45,0x76,0x65,0x6C,0x79,0x79,0x79,0x6E,0x65,0x6E,0x2C,0x6D,
260 0x69,0x6E,0x61,0x6C,0x70,0x66,0x6C,0x69,0x63,0x6B,0x61,0x5C,
281 putpixel(x1, y1, 1, linewidth, colour);
284 if ((error -= dy) < 0) {
289 ipix = (float) error / dx;
295 putpixel(x1, y1 - step, (1 - ipix), linewidth, colour);
296 putpixel(x1, y1 + step, ipix, linewidth, colour);
298 putpixel(x1, y1, 1, linewidth, colour);
301 putpixel(x2, y2, 1, linewidth, colour);
318 putpixel(x1, y1, 1, linewidth, colour);
321 if ((error -= dx) < 0) {
326 ipix = (float) error / dy;
331 putpixel(x1 - step, y1, (1 - ipix), linewidth, colour);
332 putpixel(x1 + step, y1, ipix, linewidth, colour);
335 putpixel(x1, y1, 1, linewidth, colour);
337 putpixel(x2, y2, 1, linewidth, colour);
339 if(step >= linewidth)
344 void putpixel(int x, int y, float i, int linewidth, int colour)
352 ad = aquarium_get_settings_ptr();
355 pos = (y * ad->xmax * 3) + x * 3;
358 r = ((colour >> 16) & 0xff) * i + (ad->rgb[pos]) * (1 - i);
359 g = ((colour >> 8) & 0xff) * i + (ad->rgb[pos + 1]) * (1 - i);
360 b = (colour & 0xff) * i + (ad->rgb[pos + 2]) * (1 - i);
363 if (linewidth == 1) {
365 ad->rgb[pos + 1] = g;
366 ad->rgb[pos + 2] = b;
368 for (dx = x; dx < x + linewidth; dx++) {
369 for (dy = y; dy < y + linewidth; dy++) {
370 pos = (dy * ad->xmax * 3) + dx * 3;
372 ad->rgb[pos + 1] = g;
373 ad->rgb[pos + 2] = b;
381 /* Change the colour of an image */
382 void change_colour_to(int r, int g,int b,unsigned char *image,GdkPixbuf *pixbuf, int feat)
387 rows = gdk_pixbuf_get_rowstride(pixbuf);
388 h = gdk_pixbuf_get_height(pixbuf);
389 w = gdk_pixbuf_get_width(pixbuf);
397 alpha = (unsigned int)image[pos+3];
398 image[pos+0]=(unsigned char) ((r*alpha)>>8);
399 image[pos+1]=(unsigned char) ((g*alpha)>>8);
400 image[pos+2]=(unsigned char) ((b*alpha)>>8);
403 image[pos+0]=(unsigned char) (r);
404 image[pos+1]=(unsigned char) (g);
405 image[pos+2]=(unsigned char) (b);