1.1 --- a/examples/vga/main.c Sat Nov 10 23:00:40 2018 +0100
1.2 +++ b/examples/vga/main.c Sat Nov 10 23:38:09 2018 +0100
1.3 @@ -93,6 +93,8 @@
1.4 extern image_t screendata;
1.5 extern image_t sprite;
1.6
1.7 +static SpriteOverwriting(scr, &screendata, &display_config, SOURCE_YSTEP);
1.8 +
1.9 extern uint8_t fontchars[];
1.10 extern uint32_t fonttable[];
1.11 extern uint32_t fontbase, fontlimit;
1.12 @@ -108,16 +110,16 @@
1.13 {
1.14 /* Determine positions within the image. */
1.15
1.16 - int xpos = wrap_value(xorigin, screendata.width);
1.17 - int ypos = wrap_value(yorigin, screendata.height);
1.18 + int xpos = wrap_value(xorigin, scr.image->width);
1.19 + int ypos = wrap_value(yorigin, scr.image->height);
1.20
1.21 /* The display region is either the left or right edge. */
1.22
1.23 - int xdisplay = xstep < 0 ? 0 : screendata.width - xstep;
1.24 + int xdisplay = xstep < 0 ? 0 : scr.image->width - xstep;
1.25
1.26 /* The source region depends on the origin within the background image. */
1.27
1.28 - int xsource = wrap_value(xdisplay + xpos, screendata.width);
1.29 + int xsource = wrap_value(xdisplay + xpos, scr.image->width);
1.30
1.31 /* The column width is the absolute increment. */
1.32
1.33 @@ -126,7 +128,7 @@
1.34 /* Not all of the column may be available if close to the edge of the
1.35 image, requiring multiple slices. */
1.36
1.37 - int available = screendata.width - xsource;
1.38 + int available = scr.image->width - xsource;
1.39
1.40 while (width)
1.41 {
1.42 @@ -136,13 +138,10 @@
1.43 upwards (or downwards having wrapped around) on the
1.44 screen. */
1.45
1.46 - display_copy_section(&display_config, screendata.image,
1.47 - screendata.width, screendata.height,
1.48 - xsource, ypos,
1.49 - width, screendata.height - ypos,
1.50 - v->yscale,
1.51 - xdisplay, 0,
1.52 - -1, 1);
1.53 + image_plot_sprite_section(&scr, xsource, ypos,
1.54 + width, scr.image->height - ypos,
1.55 + xdisplay, 0,
1.56 + -1);
1.57
1.58 /* The second column is at (xdisplay, h - ypos) and
1.59 provides the upper part of the background image displaced
1.60 @@ -150,13 +149,10 @@
1.61 screen. */
1.62
1.63 if (ypos)
1.64 - display_copy_section(&display_config, screendata.image,
1.65 - screendata.width, screendata.height,
1.66 - xsource, 0,
1.67 - width, ypos,
1.68 - v->yscale,
1.69 - xdisplay, (screendata.height - ypos) / v->yscale,
1.70 - -1, 1);
1.71 + image_plot_sprite_section(&scr, xsource, 0,
1.72 + width, ypos,
1.73 + xdisplay, (scr.image->height - ypos) / v->yscale,
1.74 + -1);
1.75
1.76 /* Get the next slice of the column. */
1.77
1.78 @@ -164,8 +160,8 @@
1.79 {
1.80 width -= available;
1.81 xsource = 0;
1.82 - xdisplay = wrap_value(xdisplay + available, screendata.width);
1.83 - available = screendata.width;
1.84 + xdisplay = wrap_value(xdisplay + available, scr.image->width);
1.85 + available = scr.image->width;
1.86 }
1.87 else
1.88 width = 0;
1.89 @@ -281,7 +277,6 @@
1.90
1.91 static void setup(void)
1.92 {
1.93 - SpriteOverwriting(scr, &screendata, &display_config, SOURCE_YSTEP);
1.94 int frame;
1.95
1.96 for (frame = 0; frame < display_config.frames; frame++)
2.1 --- a/include/image.h Sat Nov 10 23:00:40 2018 +0100
2.2 +++ b/include/image.h Sat Nov 10 23:38:09 2018 +0100
2.3 @@ -144,10 +144,16 @@
2.4 .yscale=YSCALE, \
2.5 .cfg=CFG};
2.6
2.7 -/* Plotting operations. */
2.8 +/* Sprite plotting operations. */
2.9
2.10 void image_plot_sprite(sprite_t *s, int x, int y, int key);
2.11
2.12 void image_unplot_sprite(sprite_t *s);
2.13
2.14 +/* Convenience operations. */
2.15 +
2.16 +void image_plot_sprite_section(sprite_t *s,
2.17 + int xstart, int ystart, int xsize, int ysize,
2.18 + int x, int y, int key);
2.19 +
2.20 #endif /* __IMAGE_H__ */
3.1 --- a/lib/image.c Sat Nov 10 23:00:40 2018 +0100
3.2 +++ b/lib/image.c Sat Nov 10 23:38:09 2018 +0100
3.3 @@ -96,3 +96,17 @@
3.4 s->image->width, s->image->height / s->yscale, 1,
3.5 p->x, p->y, -1, 1);
3.6 }
3.7 +
3.8 +
3.9 +
3.10 +/* Plot a section of an image without storing the background beforehand. */
3.11 +
3.12 +void image_plot_sprite_section(sprite_t *s,
3.13 + int xstart, int ystart, int xsize, int ysize,
3.14 + int x, int y, int key)
3.15 +{
3.16 + display_copy_section(s->cfg, s->image->image,
3.17 + s->image->width, s->image->height,
3.18 + xstart, ystart, xsize, ysize, s->yscale,
3.19 + x, y, key, 1);
3.20 +}