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
28 //added 05/17/99 Matt Mueller
35 #define MAX_WIDTH 1280
36 #define MAX_SCANLINES 1024
39 static short start_points[MAX_SCANLINES][MAX_HOLES];
40 static short hole_length[MAX_SCANLINES][MAX_HOLES];
41 static double *scanline = NULL;
43 // adb: gr_linear_movsd assumes c >= 4
44 #define gr_linear_movsd(s,d,c) memcpy(d,s,c)
46 void gr_ibitblt(grs_bitmap *src_bmp, grs_bitmap *dest_bmp, ubyte pixel_double)
48 int x, y, sw, sh, srowsize, drowsize, dstart, sy, dy;
50 short *current_hole, *current_hole_length;
56 srowsize = src_bmp->bm_rowsize;
57 drowsize = dest_bmp->bm_rowsize;
58 src = src_bmp->bm_data;
59 dest = dest_bmp->bm_data;
62 while (start_points[sy][0] == -1) {
68 ubyte *scan = (ubyte *)scanline; // set up for byte processing of scanline
71 for (y = sy; y < sy + sh; y++) {
72 gr_linear_rep_movsd_2x(src, scan, sw);
73 current_hole = start_points[dy];
74 current_hole_length = hole_length[dy];
75 for (x = 0; x < MAX_HOLES; x++) {
76 if (*current_hole == -1)
78 dstart = *current_hole;
79 gr_linear_movsd(&(scan[dstart]), &(dest[dstart]), *current_hole_length);
81 current_hole_length++;
85 current_hole = start_points[dy];
86 current_hole_length = hole_length[dy];
87 for (x = 0;x < MAX_HOLES; x++) {
88 if (*current_hole == -1)
90 dstart = *current_hole;
91 gr_linear_movsd(&(scan[dstart]), &(dest[dstart]), *current_hole_length);
93 current_hole_length++;
100 Assert(sw <= MAX_WIDTH);
101 Assert(sh <= MAX_SCANLINES);
102 for (y = sy; y < sy + sh; y++) {
103 for (x = 0; x < MAX_HOLES; x++) {
104 if (start_points[y][x] == -1)
106 dstart = start_points[y][x];
107 gr_linear_movsd(&(src[dstart]), &(dest[dstart]), hole_length[y][x]);
115 void gr_ibitblt_create_mask(grs_bitmap *mask_bmp, int sx, int sy, int sw, int sh, int srowsize)
121 Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
123 for (y = 0; y < MAX_SCANLINES; y++) {
124 for (x = 0; x < MAX_HOLES; x++) {
125 start_points[y][x] = -1;
126 hole_length[y][x] = -1;
130 for (y = sy; y < sy+sh; y++) {
133 for (x = sx; x < sx + sw; x++) {
134 if ((mode == FIND_START) && (mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x] == TRANSPARENCY_COLOR)) {
135 start_points[y][count] = x;
137 } else if ((mode == FIND_STOP) && (mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x] != TRANSPARENCY_COLOR)) {
138 hole_length[y][count] = x - start_points[y][count];
143 if (mode == FIND_STOP) {
144 hole_length[y][count] = x - start_points[y][count];
147 Assert(count <= MAX_HOLES);
151 //added 7/11/99 by adb to prevent memleaks
152 static void free_scanline(void)
154 if (scanline) d_free(scanline);
156 //end additions - adb
159 void gr_ibitblt_find_hole_size(grs_bitmap *mask_bmp, int *minx, int *miny, int *maxx, int *maxy)
164 Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
165 Assert( mask_bmp->bm_flags&BM_FLAG_TRANSPARENT );
167 *minx = mask_bmp->bm_w - 1;
169 *miny = mask_bmp->bm_h - 1;
172 //changed 7/11/99 by adb to prevent memleaks
173 if (scanline == NULL) {
174 scanline = (double *)d_malloc(sizeof(double) * (MAX_WIDTH / sizeof(double)));
175 atexit(free_scanline);
179 for (y = 0; y < mask_bmp->bm_h; y++) {
180 for (x = 0; x < mask_bmp->bm_w; x++) {
181 c = mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x];
182 if (c == TRANSPARENCY_COLOR) { // don't look for transparancy color here.
184 if (x < *minx) *minx = x;
185 if (y < *miny) *miny = y;
186 if (x > *maxx) *maxx = x;
187 if (y > *maxy) *maxy = y;