1 /* $Id: ibitblt.c,v 1.5 2002-08-27 04:03:50 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 * Routines to to inverse bitblitting -- well not really.
17 * We don't inverse bitblt like in the PC, but this code
18 * does set up a structure that blits around the cockpit
32 //added 05/17/99 Matt Mueller
39 #define MAX_WIDTH 1280
40 #define MAX_SCANLINES 1024
43 static short start_points[MAX_SCANLINES][MAX_HOLES];
44 static short hole_length[MAX_SCANLINES][MAX_HOLES];
45 static double *scanline = NULL;
47 // adb: gr_linear_movsd assumes c >= 4
48 #define gr_linear_movsd(s,d,c) memcpy(d,s,c)
50 void gr_ibitblt(grs_bitmap *src_bmp, grs_bitmap *dest_bmp, ubyte pixel_double)
52 int x, y, sw, sh, srowsize, drowsize, dstart, sy, dy;
54 short *current_hole, *current_hole_length;
60 srowsize = src_bmp->bm_rowsize;
61 drowsize = dest_bmp->bm_rowsize;
62 src = src_bmp->bm_data;
63 dest = dest_bmp->bm_data;
66 while (start_points[sy][0] == -1) {
72 ubyte *scan = (ubyte *)scanline; // set up for byte processing of scanline
75 for (y = sy; y < sy + sh; y++) {
76 gr_linear_rep_movsd_2x(src, scan, sw);
77 current_hole = start_points[dy];
78 current_hole_length = hole_length[dy];
79 for (x = 0; x < MAX_HOLES; x++) {
80 if (*current_hole == -1)
82 dstart = *current_hole;
83 gr_linear_movsd(&(scan[dstart]), &(dest[dstart]), *current_hole_length);
85 current_hole_length++;
89 current_hole = start_points[dy];
90 current_hole_length = hole_length[dy];
91 for (x = 0;x < MAX_HOLES; x++) {
92 if (*current_hole == -1)
94 dstart = *current_hole;
95 gr_linear_movsd(&(scan[dstart]), &(dest[dstart]), *current_hole_length);
97 current_hole_length++;
104 Assert(sw <= MAX_WIDTH);
105 Assert(sh <= MAX_SCANLINES);
106 for (y = sy; y < sy + sh; y++) {
107 for (x = 0; x < MAX_HOLES; x++) {
108 if (start_points[y][x] == -1)
110 dstart = start_points[y][x];
111 gr_linear_movsd(&(src[dstart]), &(dest[dstart]), hole_length[y][x]);
119 void gr_ibitblt_create_mask(grs_bitmap *mask_bmp, int sx, int sy, int sw, int sh, int srowsize)
125 Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
127 for (y = 0; y < MAX_SCANLINES; y++) {
128 for (x = 0; x < MAX_HOLES; x++) {
129 start_points[y][x] = -1;
130 hole_length[y][x] = -1;
134 for (y = sy; y < sy+sh; y++) {
137 for (x = sx; x < sx + sw; x++) {
138 if ((mode == FIND_START) && (mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x] == TRANSPARENCY_COLOR)) {
139 start_points[y][count] = x;
141 } else if ((mode == FIND_STOP) && (mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x] != TRANSPARENCY_COLOR)) {
142 hole_length[y][count] = x - start_points[y][count];
147 if (mode == FIND_STOP) {
148 hole_length[y][count] = x - start_points[y][count];
151 Assert(count <= MAX_HOLES);
155 //added 7/11/99 by adb to prevent memleaks
156 static void free_scanline(void)
158 if (scanline) d_free(scanline);
160 //end additions - adb
163 void gr_ibitblt_find_hole_size(grs_bitmap *mask_bmp, int *minx, int *miny, int *maxx, int *maxy)
168 Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
169 Assert( mask_bmp->bm_flags&BM_FLAG_TRANSPARENT );
171 *minx = mask_bmp->bm_w - 1;
173 *miny = mask_bmp->bm_h - 1;
176 //changed 7/11/99 by adb to prevent memleaks
177 if (scanline == NULL) {
178 scanline = (double *)d_malloc(sizeof(double) * (MAX_WIDTH / sizeof(double)));
179 atexit(free_scanline);
183 for (y = 0; y < mask_bmp->bm_h; y++) {
184 for (x = 0; x < mask_bmp->bm_w; x++) {
185 c = mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x];
186 if (c == TRANSPARENCY_COLOR) { // don't look for transparency color here.
188 if (x < *minx) *minx = x;
189 if (y < *miny) *miny = y;
190 if (x > *maxx) *maxx = x;
191 if (y > *maxy) *maxy = y;