/ * DibOpenFile: Load the bitmaps in the file given by filename into the * given bitmap structure. Return TRUE on success. */
| 35 | * given bitmap structure. Return TRUE on success. |
| 36 | */ |
| 37 | Bool DibOpenFile(const char *szFile, Bitmaps *b) |
| 38 | { |
| 39 | file_node f; |
| 40 | DWORD dwLen, dwBits; |
| 41 | DWORD width, height, xoffset, yoffset; |
| 42 | BYTE num_hotspots, shrink; |
| 43 | int i, j, size, offset, num_indices; |
| 44 | |
| 45 | if (!MappedFileOpenRead(szFile, &f)) |
| 46 | return False; |
| 47 | |
| 48 | if (!DibReadHeader(&f, b, &shrink)) |
| 49 | return MappedFileClose(&f); |
| 50 | |
| 51 | // Allocate memory for bitmap pointers and indices |
| 52 | size = b->num_bitmaps * sizeof(PDIB) + b->num_groups * b->max_indices * sizeof(int); |
| 53 | b->pdibs = (PDIB *) SafeMalloc(size); |
| 54 | b->indices = (int *) ((BYTE *) b->pdibs + b->num_bitmaps * sizeof(PDIB)); |
| 55 | memset(b->pdibs, 0, size); |
| 56 | |
| 57 | // Read in bitmaps |
| 58 | for (i=0; i < b->num_bitmaps; i++) |
| 59 | { |
| 60 | // Switch width and height since walls are rotated 90 degrees |
| 61 | if (MappedFileRead(&f, &height, 4) != 4) |
| 62 | return MappedFileClose(&f); |
| 63 | |
| 64 | if (MappedFileRead(&f, &width, 4) != 4) |
| 65 | return MappedFileClose(&f); |
| 66 | |
| 67 | if (MappedFileRead(&f, &xoffset, 4) != 4) |
| 68 | return MappedFileClose(&f); |
| 69 | |
| 70 | if (MappedFileRead(&f, &yoffset, 4) != 4) |
| 71 | return MappedFileClose(&f); |
| 72 | |
| 73 | if (MappedFileRead(&f, &num_hotspots, 1) != 1) |
| 74 | return MappedFileClose(&f); |
| 75 | |
| 76 | /* How much memory do we need to hold the PDIB? */ |
| 77 | dwBits = width * height; |
| 78 | dwLen = dwBits + sizeof(DIBHEADER) + num_hotspots * (sizeof(POINT) + sizeof(BYTE)); |
| 79 | |
| 80 | // Arrangement of PDIB in memory: |
| 81 | // Header |
| 82 | // bytes of bitmap |
| 83 | // array of hotspot numbers |
| 84 | // array of hotspot positions |
| 85 | |
| 86 | b->pdibs[i] = (PDIB) SafeMalloc(dwLen); |
| 87 | |
| 88 | b->pdibs[i]->width = width; |
| 89 | b->pdibs[i]->height = height; |
| 90 | b->pdibs[i]->xoffset = xoffset; |
| 91 | b->pdibs[i]->yoffset = yoffset; |
| 92 | b->pdibs[i]->num_hotspots = num_hotspots; |
| 93 | b->pdibs[i]->numbers = (char *) (DibPtr(b->pdibs[i]) + dwBits); |
| 94 | b->pdibs[i]->hotspots = (POINT *) (b->pdibs[i]->numbers + num_hotspots * sizeof(BYTE)); |
no test coverage detected