diff options
Diffstat (limited to 'common/macresman.cpp')
-rw-r--r-- | common/macresman.cpp | 138 |
1 files changed, 65 insertions, 73 deletions
diff --git a/common/macresman.cpp b/common/macresman.cpp index 4fd4e72ee3..e7d4a30789 100644 --- a/common/macresman.cpp +++ b/common/macresman.cpp @@ -550,118 +550,110 @@ void MacResManager::readMap() { } } -void MacResManager::convertCrsrCursor(byte *data, int datasize, byte **cursor, int *w, int *h, - int *hotspot_x, int *hotspot_y, int *keycolor, bool colored, byte **palette, int *palSize) { - MemoryReadStream dis(data, datasize); - int i, b; - byte imageByte; - byte *iconData; - int pixelsPerByte, bpp; - int ctSize; - byte bitmask; - int iconRowBytes, iconBounds[4]; - int iconDataSize; - - dis.readUint16BE(); // type - dis.readUint32BE(); // offset to pixel map - dis.readUint32BE(); // offset to pixel data - dis.readUint32BE(); // expanded cursor data - dis.readUint16BE(); // expanded data depth - dis.readUint32BE(); // reserved +void MacResManager::convertCrsrCursor(SeekableReadStream *data, byte **cursor, int &w, int &h, int &hotspotX, + int &hotspotY, int &keycolor, bool colored, byte **palette, int &palSize) { + + data->readUint16BE(); // type + data->readUint32BE(); // offset to pixel map + data->readUint32BE(); // offset to pixel data + data->readUint32BE(); // expanded cursor data + data->readUint16BE(); // expanded data depth + data->readUint32BE(); // reserved // Grab B/W icon data - *cursor = (byte *)malloc(16 * 16); - for (i = 0; i < 32; i++) { - imageByte = dis.readByte(); - for (b = 0; b < 8; b++) - cursor[0][i*8+b] = (byte)((imageByte & (0x80 >> b)) > 0? 0x0F: 0x00); + *cursor = new byte[16 * 16]; + for (int i = 0; i < 32; i++) { + byte imageByte = data->readByte(); + for (int b = 0; b < 8; b++) + cursor[0][i * 8 + b] = (byte)((imageByte & (0x80 >> b)) > 0 ? 0x0F : 0x00); } // Apply mask data - for (i = 0; i < 32; i++) { - imageByte = dis.readByte(); - for (b = 0; b < 8; b++) + for (int i = 0; i < 32; i++) { + byte imageByte = data->readByte(); + for (int b = 0; b < 8; b++) if ((imageByte & (0x80 >> b)) == 0) - cursor[0][i*8+b] = 0xff; + cursor[0][i * 8 + b] = 0xff; } - *hotspot_y = dis.readUint16BE(); - *hotspot_x = dis.readUint16BE(); - *w = *h = 16; - *keycolor = 0xff; + hotspotY = data->readUint16BE(); + hotspotX = data->readUint16BE(); + w = h = 16; + keycolor = 0xff; // Use b/w cursor on backends which don't support cursor palettes if (!colored) return; - dis.readUint32BE(); // reserved - dis.readUint32BE(); // cursorID + data->readUint32BE(); // reserved + data->readUint32BE(); // cursorID // Color version of cursor - dis.readUint32BE(); // baseAddr + data->readUint32BE(); // baseAddr // Keep only lowbyte for now - dis.readByte(); - iconRowBytes = dis.readByte(); + data->readByte(); + int iconRowBytes = data->readByte(); if (!iconRowBytes) return; - iconBounds[0] = dis.readUint16BE(); - iconBounds[1] = dis.readUint16BE(); - iconBounds[2] = dis.readUint16BE(); - iconBounds[3] = dis.readUint16BE(); + int iconBounds[4]; + iconBounds[0] = data->readUint16BE(); + iconBounds[1] = data->readUint16BE(); + iconBounds[2] = data->readUint16BE(); + iconBounds[3] = data->readUint16BE(); - dis.readUint16BE(); // pmVersion - dis.readUint16BE(); // packType - dis.readUint32BE(); // packSize + data->readUint16BE(); // pmVersion + data->readUint16BE(); // packType + data->readUint32BE(); // packSize - dis.readUint32BE(); // hRes - dis.readUint32BE(); // vRes + data->readUint32BE(); // hRes + data->readUint32BE(); // vRes - dis.readUint16BE(); // pixelType - dis.readUint16BE(); // pixelSize - dis.readUint16BE(); // cmpCount - dis.readUint16BE(); // cmpSize + data->readUint16BE(); // pixelType + data->readUint16BE(); // pixelSize + data->readUint16BE(); // cmpCount + data->readUint16BE(); // cmpSize - dis.readUint32BE(); // planeByte - dis.readUint32BE(); // pmTable - dis.readUint32BE(); // reserved + data->readUint32BE(); // planeByte + data->readUint32BE(); // pmTable + data->readUint32BE(); // reserved // Pixel data for cursor - iconDataSize = iconRowBytes * (iconBounds[3] - iconBounds[1]); - iconData = (byte *)malloc(iconDataSize); - dis.read(iconData, iconDataSize); + int iconDataSize = iconRowBytes * (iconBounds[3] - iconBounds[1]); + byte *iconData = new byte[iconDataSize]; + data->read(iconData, iconDataSize); // Color table - dis.readUint32BE(); // ctSeed - dis.readUint16BE(); // ctFlag - ctSize = dis.readUint16BE() + 1; + data->readUint32BE(); // ctSeed + data->readUint16BE(); // ctFlag + uint16 ctSize = data->readUint16BE() + 1; - *palette = (byte *)malloc(ctSize * 3); + *palette = new byte[ctSize * 3]; // Read just high byte of 16-bit color for (int c = 0; c < ctSize; c++) { // We just use indices 0..ctSize, so ignore color ID - dis.readUint16BE(); // colorID[c] + data->readUint16BE(); // colorID[c] - palette[0][c * 3 + 0] = dis.readByte(); - dis.readByte(); + palette[0][c * 3 + 0] = data->readByte(); + data->readByte(); - palette[0][c * 3 + 1] = dis.readByte(); - dis.readByte(); + palette[0][c * 3 + 1] = data->readByte(); + data->readByte(); - palette[0][c * 3 + 2] = dis.readByte(); - dis.readByte(); + palette[0][c * 3 + 2] = data->readByte(); + data->readByte(); } - *palSize = ctSize; + palSize = ctSize; - pixelsPerByte = (iconBounds[2] - iconBounds[0]) / iconRowBytes; - bpp = 8 / pixelsPerByte; + int pixelsPerByte = (iconBounds[2] - iconBounds[0]) / iconRowBytes; + int bpp = 8 / pixelsPerByte; // build a mask to make sure the pixels are properly shifted out - bitmask = 0; + int bitmask = 0; for (int m = 0; m < bpp; m++) { bitmask <<= 1; bitmask |= 1; @@ -669,16 +661,16 @@ void MacResManager::convertCrsrCursor(byte *data, int datasize, byte **cursor, i // Extract pixels from bytes for (int j = 0; j < iconDataSize; j++) - for (b = 0; b < pixelsPerByte; b++) { + for (int b = 0; b < pixelsPerByte; b++) { int idx = j * pixelsPerByte + (pixelsPerByte - 1 - b); if (cursor[0][idx] != 0xff) // if mask is not there cursor[0][idx] = (byte)((iconData[j] >> (b * bpp)) & bitmask); } - free(iconData); + delete[] iconData; - assert(datasize - dis.pos() == 0); + assert(data->size() - data->pos() == 0); } } // End of namespace Common |