aboutsummaryrefslogtreecommitdiff
path: root/image
diff options
context:
space:
mode:
authorEugene Sandulenko2016-05-19 00:03:07 +0200
committerEugene Sandulenko2016-05-19 00:03:51 +0200
commitd35cdf5009698b74a2d444dea508755a9f5e3cbc (patch)
tree82763c6a4354680f2aa06f467fae64789175d985 /image
parent64d4d02f484f8d0350bf893cd6d35bf9829188cd (diff)
downloadscummvm-rg350-d35cdf5009698b74a2d444dea508755a9f5e3cbc.tar.gz
scummvm-rg350-d35cdf5009698b74a2d444dea508755a9f5e3cbc.tar.bz2
scummvm-rg350-d35cdf5009698b74a2d444dea508755a9f5e3cbc.zip
IMAGE: Added BMP RLE4 decoder
Diffstat (limited to 'image')
-rw-r--r--image/codecs/codec.cpp3
-rw-r--r--image/codecs/msrle4.cpp140
-rw-r--r--image/codecs/msrle4.h53
-rw-r--r--image/module.mk1
4 files changed, 197 insertions, 0 deletions
diff --git a/image/codecs/codec.cpp b/image/codecs/codec.cpp
index 398e9c562c..910fcc18cb 100644
--- a/image/codecs/codec.cpp
+++ b/image/codecs/codec.cpp
@@ -34,6 +34,7 @@
#include "image/codecs/mpeg.h"
#include "image/codecs/msvideo1.h"
#include "image/codecs/msrle.h"
+#include "image/codecs/msrle4.h"
#include "image/codecs/qtrle.h"
#include "image/codecs/rpza.h"
#include "image/codecs/smc.h"
@@ -198,6 +199,8 @@ Codec *createBitmapCodec(uint32 tag, int width, int height, int bitsPerPixel) {
return new BitmapRawDecoder(width, height, bitsPerPixel);
case SWAP_CONSTANT_32(1):
return new MSRLEDecoder(width, height, bitsPerPixel);
+ case SWAP_CONSTANT_32(2):
+ return new MSRLE4Decoder(width, height, bitsPerPixel);
case MKTAG('C','R','A','M'):
case MKTAG('m','s','v','c'):
case MKTAG('W','H','A','M'):
diff --git a/image/codecs/msrle4.cpp b/image/codecs/msrle4.cpp
new file mode 100644
index 0000000000..cd9a8717bc
--- /dev/null
+++ b/image/codecs/msrle4.cpp
@@ -0,0 +1,140 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+// Based off ffmpeg's msrledec.c
+#include "common/debug.h"
+#include "image/codecs/msrle4.h"
+#include "common/stream.h"
+#include "common/textconsole.h"
+#include "common/util.h"
+namespace Image {
+
+MSRLE4Decoder::MSRLE4Decoder(uint16 width, uint16 height, byte bitsPerPixel) {
+ _surface = new Graphics::Surface();
+ _surface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
+ _bitsPerPixel = bitsPerPixel;
+}
+
+MSRLE4Decoder::~MSRLE4Decoder() {
+ _surface->free();
+ delete _surface;
+}
+
+const Graphics::Surface *MSRLE4Decoder::decodeFrame(Common::SeekableReadStream &stream) {
+ if (_bitsPerPixel == 4) {
+ decode4(stream);
+ } else
+ error("Unhandled %d bit Microsoft RLE encoding", _bitsPerPixel);
+
+ return _surface;
+}
+
+void MSRLE4Decoder::decode4(Common::SeekableReadStream &stream) {
+ int x = 0;
+ int y = _surface->h - 1;
+
+ byte *output = (byte *)_surface->getBasePtr(x, y);
+ byte *output_end = (byte *)_surface->getBasePtr(_surface->w, y);
+
+ while (!stream.eos()) {
+ byte count = stream.readByte();
+
+ if (count == 0) {
+ byte value = stream.readByte();
+
+ if (value == 0) {
+ // End of line
+
+ x = 0;
+ y--;
+ output = (byte *)_surface->getBasePtr(x, y);
+ } else if (value == 1) {
+ // End of image
+
+ return;
+ } else if (value == 2) {
+ // Skip
+
+ count = stream.readByte();
+ value = stream.readByte();
+
+ x += count;
+ y -= value;
+
+ if (y < 0) {
+ warning("MS RLE Codec: Skip beyond picture bounds");
+ return;
+ }
+
+ output = (byte *)_surface->getBasePtr(x, y);;
+
+ } else {
+ // Copy data
+
+ int odd_pixel = value & 1;
+ int rle_code = (value + 1) / 2;
+ int extra_byte = rle_code & 0x01;
+
+ if (output + value > output_end) {
+ stream.skip(rle_code + extra_byte);
+ continue;
+ }
+
+ for (int i = 0; i < rle_code; i++) {
+ byte color = stream.readByte();
+ *output++ = (color & 0xf0) >> 4;
+ if (i + 1 == rle_code && odd_pixel) {
+ break;
+ }
+ *output++ = color & 0x0f;
+ }
+
+ if (extra_byte)
+ stream.skip(1);
+
+ x += value;
+ }
+
+ } else {
+ // Run data
+
+ if (output + count > output_end)
+ continue;
+
+ byte color = stream.readByte();
+
+ for (int i = 0; i < count; i++, x++) {
+ *output++ = (color & 0xf0) >> 4;
+ i++;
+ x++;
+ if (i == count)
+ break;
+ *output++ = color & 0x0f;
+ }
+ }
+
+ }
+
+ warning("MS RLE Codec: No end-of-picture code");
+}
+
+} // End of namespace Image
diff --git a/image/codecs/msrle4.h b/image/codecs/msrle4.h
new file mode 100644
index 0000000000..26f52b651d
--- /dev/null
+++ b/image/codecs/msrle4.h
@@ -0,0 +1,53 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef IMAGE_CODECS_MSRLE4_H
+#define IMAGE_CODECS_MSRLE4_H
+
+#include "image/codecs/codec.h"
+
+namespace Image {
+
+/**
+ * Microsoft Run-Length Encoding decoder.
+ *
+ * Used by BMP/AVI.
+ */
+class MSRLE4Decoder : public Codec {
+public:
+ MSRLE4Decoder(uint16 width, uint16 height, byte bitsPerPixel);
+ ~MSRLE4Decoder();
+
+ const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream);
+ Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat::createFormatCLUT8(); }
+
+private:
+ byte _bitsPerPixel;
+
+ Graphics::Surface *_surface;
+
+ void decode4(Common::SeekableReadStream &stream);
+};
+
+} // End of namespace Image
+
+#endif
diff --git a/image/module.mk b/image/module.mk
index fdf52ec09f..3742fb909f 100644
--- a/image/module.mk
+++ b/image/module.mk
@@ -15,6 +15,7 @@ MODULE_OBJS := \
codecs/indeo3.o \
codecs/mjpeg.o \
codecs/msrle.o \
+ codecs/msrle4.o \
codecs/msvideo1.o \
codecs/qtrle.o \
codecs/rpza.o \