aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/macresman.cpp128
-rw-r--r--common/macresman.h19
-rw-r--r--common/stream.cpp7
-rw-r--r--common/substream.h19
4 files changed, 26 insertions, 147 deletions
diff --git a/common/macresman.cpp b/common/macresman.cpp
index 489f8f93ce..0ecb430532 100644
--- a/common/macresman.cpp
+++ b/common/macresman.cpp
@@ -550,132 +550,4 @@ void MacResManager::readMap() {
}
}
-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 = 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 (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;
- }
-
- 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;
-
- data->readUint32BE(); // reserved
- data->readUint32BE(); // cursorID
-
- // Color version of cursor
- data->readUint32BE(); // baseAddr
-
- // Keep only lowbyte for now
- data->readByte();
- int iconRowBytes = data->readByte();
-
- if (!iconRowBytes)
- return;
-
- int iconBounds[4];
- iconBounds[0] = data->readUint16BE();
- iconBounds[1] = data->readUint16BE();
- iconBounds[2] = data->readUint16BE();
- iconBounds[3] = data->readUint16BE();
-
- data->readUint16BE(); // pmVersion
- data->readUint16BE(); // packType
- data->readUint32BE(); // packSize
-
- data->readUint32BE(); // hRes
- data->readUint32BE(); // vRes
-
- data->readUint16BE(); // pixelType
- data->readUint16BE(); // pixelSize
- data->readUint16BE(); // cmpCount
- data->readUint16BE(); // cmpSize
-
- data->readUint32BE(); // planeByte
- data->readUint32BE(); // pmTable
- data->readUint32BE(); // reserved
-
- // Pixel data for cursor
- int iconDataSize = iconRowBytes * (iconBounds[3] - iconBounds[1]);
- byte *iconData = new byte[iconDataSize];
-
- if (!iconData) {
- error("Cannot allocate iconData in macresman.cpp");
- }
-
- data->read(iconData, iconDataSize);
-
- // Color table
- data->readUint32BE(); // ctSeed
- data->readUint16BE(); // ctFlag
- uint16 ctSize = data->readUint16BE() + 1;
-
- *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
- data->readUint16BE(); // colorID[c]
-
- palette[0][c * 3 + 0] = data->readByte();
- data->readByte();
-
- palette[0][c * 3 + 1] = data->readByte();
- data->readByte();
-
- palette[0][c * 3 + 2] = data->readByte();
- data->readByte();
- }
-
- palSize = ctSize;
-
- int pixelsPerByte = (iconBounds[2] - iconBounds[0]) / iconRowBytes;
- int bpp = 8 / pixelsPerByte;
-
- // build a mask to make sure the pixels are properly shifted out
- int bitmask = 0;
- for (int m = 0; m < bpp; m++) {
- bitmask <<= 1;
- bitmask |= 1;
- }
-
- // Extract pixels from bytes
- for (int j = 0; j < iconDataSize; j++)
- 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);
- }
-
- delete[] iconData;
-
- assert(data->size() - data->pos() == 0);
-}
-
} // End of namespace Common
diff --git a/common/macresman.h b/common/macresman.h
index fdb3ce491d..f588d8f853 100644
--- a/common/macresman.h
+++ b/common/macresman.h
@@ -152,25 +152,6 @@ public:
String getBaseFileName() const { return _baseFileName; }
/**
- * Convert cursor from crsr format to format suitable for feeding to CursorMan
- * @param data Pointer to the cursor datax
- * @param cursor Pointer to memory where result cursor will be stored. The memory
- * block will be malloc()'ed
- * @param w Pointer to int where the cursor width will be stored
- * @param h Pointer to int where the cursor height will be stored
- * @param hotspotX Storage for cursor hotspot X coordinate
- * @param hotspotY Storage for cursor hotspot Y coordinate
- * @param keycolor Pointer to int where the transpared color value will be stored
- * @param colored If set to true then colored cursor will be returned (if any).
- * b/w version will be used otherwise
- * @param palette Pointer to memory where the cursor palette will be stored.
- * The memory will be malloc()'ed
- * @param palSize Pointer to integer where the palette size will be stored.
- */
- static void convertCrsrCursor(SeekableReadStream *data, byte **cursor, int &w, int &h, int &hotspotX,
- int &hotspotY, int &keycolor, bool colored, byte **palette, int &palSize);
-
- /**
* Return list of resource IDs with specified type ID
*/
MacResIDArray getResIDArray(uint32 typeID);
diff --git a/common/stream.cpp b/common/stream.cpp
index e870e68b2d..a785ac5164 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -242,6 +242,13 @@ bool SeekableSubReadStream::seek(int32 offset, int whence) {
return ret;
}
+uint32 SafeSubReadStream::read(void *dataPtr, uint32 dataSize) {
+ // Make sure the parent stream is at the right position
+ seek(0, SEEK_CUR);
+
+ return SeekableSubReadStream::read(dataPtr, dataSize);
+}
+
#pragma mark -
diff --git a/common/substream.h b/common/substream.h
index ecf11c54c9..8b83dbda2e 100644
--- a/common/substream.h
+++ b/common/substream.h
@@ -102,6 +102,25 @@ public:
}
};
+/**
+ * A seekable substream that removes the exclusivity demand required by the
+ * normal SeekableSubReadStream, at the cost of seek()ing the parent stream
+ * before each read().
+ *
+ * More than one SafeSubReadStream to the same parent stream can be used
+ * at the same time; they won't mess up each other. They will, however,
+ * reposition the parent stream, so don't depend on its position to be
+ * the same after a read() or seek() on one of its SafeSubReadStream.
+ */
+class SafeSubReadStream : public SeekableSubReadStream {
+public:
+ SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) :
+ SeekableSubReadStream(parentStream, begin, end, disposeParentStream) {
+ }
+
+ virtual uint32 read(void *dataPtr, uint32 dataSize);
+};
+
} // End of namespace Common