From: wavemist AT ix DOT netcom DOT com Newsgroups: comp.os.msdos.djgpp Subject: Allegro Bitmap Question 2 Date: Sun, 02 Aug 1998 15:49:11 GMT Organization: ICGNetcom Lines: 129 Message-ID: <35c48784.1351913@nntp.ix.netcom.com> NNTP-Posting-Host: prv-ri2-01.ix.netcom.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Argh! Ok, so I've learned that an 8 pixel by 8 pixel bitmap takes up 64 bytes in memory...great. Yet for some reason, even if I feed two identical tiles into memcmp, it claims that they are different. Could someone please look at the following code and tell me what I'm doing wrong? This is a program for ripping unique 8 by 8 tiles from a pcx file. /**************************** main ********************************/ void main(int argc, char *argv[]) { register int i; allegro_init(); /* check that an input file was specified */ if (argc < 2) { printf("Command syntax is: RIPPER infile1 ...\n"); exit(1); } /* initialize some globals */ tile_index = 0; level_index = 0; x2 = y2 = 0; tile_storage = create_bitmap(320, 240); clear(tile_storage); pcx_file = create_bitmap(320, 240); clear(pcx_file); fresh_tile = create_bitmap(8, 8); clear(fresh_tile); /* set all the tiles in the level map to 490 */ for (i = 0; i < MAXTILES; i++) level_map[i] = 490; /* rip all the files specified on the command line */ for (i = 1; i <= argc; i++) rip(argv[i]); /* write the level data and tiles out to disk */ write_level(); /* check your work -- reconstruct the pictures from the tiles */ display_level(); /* restore the text video mode and exit */ set_gfx_mode(GFX_TEXT, 24, 80, 0, 0); allegro_exit(); exit(0); } /***************************** rip ********************************/ int rip(char *filename) { unsigned int i,n; int x,y; int status; /* if you already have a full screen tiles, return an error */ if (tile_index >= TILELIMIT) return(-1); /* get the PCX file */ pcx_file = load_pcx(filename, desktop_palette); x = 0; y = 0; /* loop on the pcx file, starting at upper left corner, moving down the columns in sequence */ for (n = 0; n < TILELIMIT; n++) { /* get the new tile bitmap */ blit(pcx_file, fresh_tile, x, y, 0, 0, 8, 8); /* compare the new tile to all the ripper tiles */ for (i = 0; i < tile_index; i++) { status = memcmp(fresh_tile, stored_tile[i], 64); if(status == 0) { /* a duplicate tile is found, update the level map */ level_map[level_index] = i; break; } } /* no match was found, therefore the tile must be unique */ if (level_map[level_index] == 490) { /* hold the array in RAM for later comparisons */ stored_tile[i] = create_bitmap(8, 8); clear(stored_tile[i]); blit(fresh_tile, stored_tile[i], 0, 0, 0, 0, 8, 8); /* build the level map with the tile index */ level_map[level_index] = tile_index; /* we can't have more than 480 unique tiles */ tile_index++; if (tile_index >= TILELIMIT) break; } y = y + 8; if(y > 240) { y = 0; x = x + 8; } level_index++; } return (0); }