1 /* 2 * Common image-related functions. 3 * 4 * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "display.h" 21 #include "image.h" 22 23 24 25 /* Obtain the position for the stored region from the given frame. */ 26 27 position_t *image_get_stored_position(stored_regions_t *r, int frame) 28 { 29 return &r->pos[frame]; 30 } 31 32 /* Obtain the image data for the stored region from the given frame. */ 33 34 uint8_t *image_get_stored_region(stored_regions_t *r, int frame) 35 { 36 return r->image + r->size * frame; 37 } 38 39 40 41 /* Copy a region from the screen to the store, then blit the image. */ 42 43 void image_plot_sprite(sprite_t *s, int x, int y, int key) 44 { 45 int frame = s->cfg->frame; 46 position_t *p = image_get_stored_position(s->regions, frame); 47 48 /* Copy to the stored region. */ 49 50 display_copy(s->cfg, image_get_stored_region(s->regions, frame), 51 s->image->width, s->image->height / s->yscale, 1, 52 x, y, -1, 0); 53 54 /* Plot to the screen. */ 55 56 display_copy(s->cfg, s->image->image, 57 s->image->width, s->image->height, s->yscale, 58 x, y, key, 1); 59 60 /* Record the stored background details. */ 61 62 p->x = x; 63 p->y = y; 64 65 if (frame >= s->regions->stored) 66 s->regions->stored = frame + 1; 67 } 68 69 /* Copy a region from the store to the screen, restoring the original 70 background. */ 71 72 void image_unplot_sprite(sprite_t *s) 73 { 74 int frame = s->cfg->frame; 75 position_t *p = image_get_stored_position(s->regions, frame); 76 77 /* Only unplot the sprite if a region was stored for the frame. */ 78 79 if (s->regions->stored > frame) 80 display_copy(s->cfg, image_get_stored_region(s->regions, frame), 81 s->image->width, s->image->height / s->yscale, 1, 82 p->x, p->y, -1, 1); 83 }