aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorDenis Kasak2009-06-25 14:03:57 +0000
committerDenis Kasak2009-06-25 14:03:57 +0000
commitd6729f380409096c1e4a54d0a605169506a85ff4 (patch)
tree512cf86b830bce9a340e208346d02871ad44c6f9 /engines
parent02dadc70fce56be7bfb3704de13367c3142c6ff3 (diff)
downloadscummvm-rg350-d6729f380409096c1e4a54d0a605169506a85ff4.tar.gz
scummvm-rg350-d6729f380409096c1e4a54d0a605169506a85ff4.tar.bz2
scummvm-rg350-d6729f380409096c1e4a54d0a605169506a85ff4.zip
Added transformToRows() static method to Sprite. Modified Sprite constructors to use it.
svn-id: r41865
Diffstat (limited to 'engines')
-rw-r--r--engines/draci/sprite.cpp54
1 files changed, 31 insertions, 23 deletions
diff --git a/engines/draci/sprite.cpp b/engines/draci/sprite.cpp
index e54364bd44..6e4cb8b6b6 100644
--- a/engines/draci/sprite.cpp
+++ b/engines/draci/sprite.cpp
@@ -31,6 +31,26 @@
namespace Draci {
/**
+ * @brief Transforms an image from column-wise to row-wise
+ * @param img pointer to the buffer containing the image data
+ * width width of the image in the buffer
+ * height height of the image in the buffer
+ */
+static void transformToRows(byte *img, uint16 width, uint16 height) {
+ byte *buf = new byte[width * height];
+ byte *tmp = buf;
+ memcpy(buf, img, width * height);
+
+ for (uint16 i = 0; i < width; ++i) {
+ for (uint16 j = 0; j < height; ++j) {
+ img[j * width + i] = *tmp++;
+ }
+ }
+
+ delete[] buf;
+}
+
+/**
* Constructor for loading sprites from a raw data buffer, one byte per pixel.
*/
Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, uint16 x, uint16 y,
@@ -38,18 +58,12 @@ Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, uint16 x, uint16 y,
_data = new byte[width * height];
- // If the sprite is stored row-wise, just copy it to the internal buffer.
- // Otherwise, transform it and then copy.
-
- if (!columnwise) {
- memcpy(_data, raw_data, width * height);
- } else {
- for (uint16 i = 0; i < width; ++i) {
- for (uint16 j = 0; j < height; ++j) {
- _data[j * width + i] = *raw_data++;
- }
- }
- }
+ memcpy(_data, raw_data, width * height);
+
+ // If the sprite is stored column-wise, transform it to row-wise
+ if (columnwise) {
+ transformToRows(_data, width, height);
+ }
}
/**
@@ -66,17 +80,11 @@ Sprite::Sprite(byte *sprite_data, uint16 length, uint16 x, uint16 y,
_data = new byte[_width * _height];
- // If the sprite is stored row-wise, just copy it to the internal buffer.
- // Otherwise, transform it and then copy.
-
- if (!columnwise) {
- reader.read(_data, _width * _height);
- } else {
- for (uint16 i = 0; i < _width; ++i) {
- for (uint16 j = 0; j < _height; ++j) {
- _data[j * _width + i] = reader.readByte();
- }
- }
+ reader.read(_data, _width * _height);
+
+ // If the sprite is stored column-wise, transform it to row-wise
+ if (columnwise) {
+ transformToRows(_data, _width, _height);
}
}