2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
14 * Routines to to inverse bitblitting -- well not really.
15 * We don't inverse bitblt like in the PC, but this code
16 * does set up a structure that blits around the cockpit
30 //added 05/17/99 Matt Mueller
37 #define MAX_WIDTH 1280
38 #define MAX_SCANLINES 1024
41 static short start_points[MAX_SCANLINES][MAX_HOLES];
42 static short hole_length[MAX_SCANLINES][MAX_HOLES];
43 static double *scanline = NULL;
45 // adb: gr_linear_movsd assumes c >= 4
46 #define gr_linear_movsd(s,d,c) memcpy(d,s,c)
48 void gr_ibitblt(grs_bitmap *src_bmp, grs_bitmap *dest_bmp, ubyte pixel_double)
50 int x, y, sw, sh, srowsize, drowsize, dstart, sy, dy;
52 short *current_hole, *current_hole_length;
58 srowsize = src_bmp->bm_rowsize;
59 drowsize = dest_bmp->bm_rowsize;
60 src = src_bmp->bm_data;
61 dest = dest_bmp->bm_data;
64 while (start_points[sy][0] == -1) {
70 ubyte *scan = (ubyte *)scanline; // set up for byte processing of scanline
73 for (y = sy; y < sy + sh; y++) {
74 gr_linear_rep_movsd_2x(src, scan, sw);
75 current_hole = start_points[dy];
76 current_hole_length = hole_length[dy];
77 for (x = 0; x < MAX_HOLES; x++) {
78 if (*current_hole == -1)
80 dstart = *current_hole;
81 gr_linear_movsd(&(scan[dstart]), &(dest[dstart]), *current_hole_length);
83 current_hole_length++;
87 current_hole = start_points[dy];
88 current_hole_length = hole_length[dy];
89 for (x = 0;x < MAX_HOLES; x++) {
90 if (*current_hole == -1)
92 dstart = *current_hole;
93 gr_linear_movsd(&(scan[dstart]), &(dest[dstart]), *current_hole_length);
95 current_hole_length++;
102 Assert(sw <= MAX_WIDTH);
103 Assert(sh <= MAX_SCANLINES);
104 for (y = sy; y < sy + sh; y++) {
105 for (x = 0; x < MAX_HOLES; x++) {
106 if (start_points[y][x] == -1)
108 dstart = start_points[y][x];
109 gr_linear_movsd(&(src[dstart]), &(dest[dstart]), hole_length[y][x]);
117 void gr_ibitblt_create_mask(grs_bitmap *mask_bmp, int sx, int sy, int sw, int sh, int srowsize)
123 Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
125 for (y = 0; y < MAX_SCANLINES; y++) {
126 for (x = 0; x < MAX_HOLES; x++) {
127 start_points[y][x] = -1;
128 hole_length[y][x] = -1;
132 for (y = sy; y < sy+sh; y++) {
135 for (x = sx; x < sx + sw; x++) {
136 if ((mode == FIND_START) && (mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x] == TRANSPARENCY_COLOR)) {
137 start_points[y][count] = x;
139 } else if ((mode == FIND_STOP) && (mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x] != TRANSPARENCY_COLOR)) {
140 hole_length[y][count] = x - start_points[y][count];
145 if (mode == FIND_STOP) {
146 hole_length[y][count] = x - start_points[y][count];
149 Assert(count <= MAX_HOLES);
153 //added 7/11/99 by adb to prevent memleaks
154 static void free_scanline(void)
156 if (scanline) d_free(scanline);
158 //end additions - adb
161 void gr_ibitblt_find_hole_size(grs_bitmap *mask_bmp, int *minx, int *miny, int *maxx, int *maxy)
166 Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
167 Assert( mask_bmp->bm_flags&BM_FLAG_TRANSPARENT );
169 *minx = mask_bmp->bm_w - 1;
171 *miny = mask_bmp->bm_h - 1;
174 //changed 7/11/99 by adb to prevent memleaks
175 if (scanline == NULL) {
176 scanline = (double *)d_malloc(sizeof(double) * (MAX_WIDTH / sizeof(double)));
177 atexit(free_scanline);
181 for (y = 0; y < mask_bmp->bm_h; y++) {
182 for (x = 0; x < mask_bmp->bm_w; x++) {
183 c = mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x];
184 if (c == TRANSPARENCY_COLOR) { // don't look for transparancy color here.
186 if (x < *minx) *minx = x;
187 if (y < *miny) *miny = y;
188 if (x > *maxx) *maxx = x;
189 if (y > *maxy) *maxy = y;