1.1 --- a/lib/image.c Sat Nov 10 23:38:09 2018 +0100
1.2 +++ b/lib/image.c Sun Nov 11 18:15:24 2018 +0100
1.3 @@ -19,6 +19,7 @@
1.4
1.5 #include "display.h"
1.6 #include "image.h"
1.7 +#include "utils.h"
1.8
1.9
1.10
1.11 @@ -110,3 +111,67 @@
1.12 xstart, ystart, xsize, ysize, s->yscale,
1.13 x, y, key, 1);
1.14 }
1.15 +
1.16 +
1.17 +
1.18 +/* Tile a sprite, using the given source origin, filling a display region. */
1.19 +
1.20 +void image_tile_sprite(sprite_t *s, int xsource, int ysource,
1.21 + int width, int height,
1.22 + int xdisplay, int ydisplay)
1.23 +{
1.24 + /* Determine the portion of the sprite to be plotted in the first column. */
1.25 +
1.26 + int source_width = s->image->width - xsource;
1.27 + int source_height;
1.28 + int total_height;
1.29 + int x, y;
1.30 + int xs, ys;
1.31 +
1.32 + /* Fill (xdisplay, ydisplay) with (width, height) from source, slice by
1.33 + slice. */
1.34 +
1.35 + x = xdisplay;
1.36 + xs = xsource;
1.37 +
1.38 + while (width)
1.39 + {
1.40 + /* Fill (x, ydisplay) with (source_width, height) from source, with the
1.41 + height being divided into image-sized pieces. */
1.42 +
1.43 + total_height = height;
1.44 + source_height = s->image->height - ysource;
1.45 + y = ydisplay;
1.46 + ys = ysource;
1.47 +
1.48 + while (total_height)
1.49 + {
1.50 + /* Plot as much of the image as is available from the given source
1.51 + coordinates. */
1.52 +
1.53 + image_plot_sprite_section(s, xs, ys,
1.54 + min(width, source_width), min(total_height, source_height),
1.55 + x, y, -1);
1.56 +
1.57 + /* Continue to plot the image again to fill the slice. */
1.58 +
1.59 + if (source_height >= total_height)
1.60 + break;
1.61 +
1.62 + total_height -= source_height;
1.63 + y += source_height / s->yscale;
1.64 + ys = 0;
1.65 + source_height = s->image->height;
1.66 + }
1.67 +
1.68 + /* Get the next slice of the column. */
1.69 +
1.70 + if (source_width >= width)
1.71 + break;
1.72 +
1.73 + width -= source_width;
1.74 + x += source_width;
1.75 + xs = 0;
1.76 + source_width = s->image->width;
1.77 + }
1.78 +}