[Scummvm-git-logs] scummvm master -> 35b005bd2c7a03fc2f30152264ff1a6166db6e44
bluegr
noreply at scummvm.org
Sat Mar 8 18:18:44 UTC 2025
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
35b005bd2c IMAGE: Use palette class in more codecs
Commit: 35b005bd2c7a03fc2f30152264ff1a6166db6e44
https://github.com/scummvm/scummvm/commit/35b005bd2c7a03fc2f30152264ff1a6166db6e44
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2025-03-08T20:18:40+02:00
Commit Message:
IMAGE: Use palette class in more codecs
Changed paths:
image/codecs/cdtoons.cpp
image/codecs/cdtoons.h
image/codecs/qtrle.cpp
image/codecs/qtrle.h
image/codecs/rpza.cpp
image/codecs/rpza.h
diff --git a/image/codecs/cdtoons.cpp b/image/codecs/cdtoons.cpp
index f74e0839fc1..0037f67c7ae 100644
--- a/image/codecs/cdtoons.cpp
+++ b/image/codecs/cdtoons.cpp
@@ -47,14 +47,13 @@ static Common::Rect readRect(Common::SeekableReadStream &stream) {
return rect;
}
-CDToonsDecoder::CDToonsDecoder(uint16 width, uint16 height) {
+CDToonsDecoder::CDToonsDecoder(uint16 width, uint16 height) : _palette(256) {
debugN(5, "CDToons: width %d, height %d\n", width, height);
_surface = new Graphics::Surface();
_surface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
_currentPaletteId = 0;
- memset(_palette, 0, 256 * 3);
_dirtyPalette = false;
}
@@ -435,13 +434,11 @@ void CDToonsDecoder::setPalette(byte *data) {
// A lovely QuickTime palette
for (uint i = 0; i < 256; i++) {
- _palette[i * 3] = *data;
- _palette[i * 3 + 1] = *(data + 2);
- _palette[i * 3 + 2] = *(data + 4);
+ _palette.set(i, *data, *(data + 2), *(data + 4));
data += 6;
}
- _palette[0] = _palette[1] = _palette[2] = 0;
+ _palette.set(0, 0, 0, 0);
}
} // End of namespace Image
diff --git a/image/codecs/cdtoons.h b/image/codecs/cdtoons.h
index 4fbf699251e..2a3169a950c 100644
--- a/image/codecs/cdtoons.h
+++ b/image/codecs/cdtoons.h
@@ -25,6 +25,7 @@
#include "image/codecs/codec.h"
#include "common/hashmap.h"
+#include "graphics/palette.h"
namespace Image {
@@ -50,12 +51,12 @@ public:
Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
Graphics::PixelFormat getPixelFormat() const override { return Graphics::PixelFormat::createFormatCLUT8(); }
bool containsPalette() const override { return true; }
- const byte *getPalette() override { _dirtyPalette = false; return _palette; }
+ const byte *getPalette() override { _dirtyPalette = false; return _palette.data(); }
bool hasDirtyPalette() const override { return _dirtyPalette; }
private:
Graphics::Surface *_surface;
- byte _palette[256 * 3];
+ Graphics::Palette _palette;
bool _dirtyPalette;
uint16 _currentPaletteId;
diff --git a/image/codecs/qtrle.cpp b/image/codecs/qtrle.cpp
index 9c0d772681b..269fbe3be60 100644
--- a/image/codecs/qtrle.cpp
+++ b/image/codecs/qtrle.cpp
@@ -33,9 +33,8 @@
namespace Image {
-QTRLEDecoder::QTRLEDecoder(uint16 width, uint16 height, byte bitsPerPixel) : Codec() {
+QTRLEDecoder::QTRLEDecoder(uint16 width, uint16 height, byte bitsPerPixel) : Codec(), _ditherPalette(0) {
_bitsPerPixel = bitsPerPixel;
- _ditherPalette = 0;
_width = width;
_height = height;
_surface = 0;
@@ -56,7 +55,6 @@ QTRLEDecoder::~QTRLEDecoder() {
}
delete[] _colorMap;
- delete[] _ditherPalette;
}
#define CHECK_STREAM_PTR(n) \
@@ -472,7 +470,7 @@ const Graphics::Surface *QTRLEDecoder::decodeFrame(Common::SeekableReadStream &s
decode16(stream, rowPtr, height);
break;
case 24:
- if (_ditherPalette)
+ if (_ditherPalette.size() > 0)
dither24(stream, rowPtr, height);
else
decode24(stream, rowPtr, height);
@@ -488,7 +486,7 @@ const Graphics::Surface *QTRLEDecoder::decodeFrame(Common::SeekableReadStream &s
}
Graphics::PixelFormat QTRLEDecoder::getPixelFormat() const {
- if (_ditherPalette)
+ if (_ditherPalette.size() > 0)
return Graphics::PixelFormat::createFormatCLUT8();
switch (_bitsPerPixel) {
@@ -521,8 +519,8 @@ bool QTRLEDecoder::canDither(DitherType type) const {
void QTRLEDecoder::setDither(DitherType type, const byte *palette) {
assert(canDither(type));
- _ditherPalette = new byte[256 * 3];
- memcpy(_ditherPalette, palette, 256 * 3);
+ _ditherPalette.resize(256, false);
+ _ditherPalette.set(palette, 0, 256);
_dirtyPalette = true;
delete[] _colorMap;
diff --git a/image/codecs/qtrle.h b/image/codecs/qtrle.h
index 82aeaedaf15..12d37ab5e81 100644
--- a/image/codecs/qtrle.h
+++ b/image/codecs/qtrle.h
@@ -23,6 +23,7 @@
#define IMAGE_CODECS_QTRLE_H
#include "graphics/pixelformat.h"
+#include "graphics/palette.h"
#include "image/codecs/codec.h"
namespace Image {
@@ -41,7 +42,7 @@ public:
Graphics::PixelFormat getPixelFormat() const override;
bool containsPalette() const override { return _ditherPalette != 0; }
- const byte *getPalette() override { _dirtyPalette = false; return _ditherPalette; }
+ const byte *getPalette() override { _dirtyPalette = false; return _ditherPalette.data(); }
bool hasDirtyPalette() const override { return _dirtyPalette; }
bool canDither(DitherType type) const override;
void setDither(DitherType type, const byte *palette) override;
@@ -51,7 +52,7 @@ private:
Graphics::Surface *_surface;
uint16 _width, _height;
uint32 _paddedWidth;
- byte *_ditherPalette;
+ Graphics::Palette _ditherPalette;
bool _dirtyPalette;
byte *_colorMap;
diff --git a/image/codecs/rpza.cpp b/image/codecs/rpza.cpp
index 548d4ad4878..595cd2f8403 100644
--- a/image/codecs/rpza.cpp
+++ b/image/codecs/rpza.cpp
@@ -30,9 +30,8 @@
namespace Image {
-RPZADecoder::RPZADecoder(uint16 width, uint16 height) : Codec() {
+RPZADecoder::RPZADecoder(uint16 width, uint16 height) : Codec(), _ditherPalette(0) {
_format = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0);
- _ditherPalette = 0;
_dirtyPalette = false;
_colorMap = 0;
_width = width;
@@ -48,7 +47,6 @@ RPZADecoder::~RPZADecoder() {
delete _surface;
}
- delete[] _ditherPalette;
delete[] _colorMap;
}
@@ -353,8 +351,8 @@ bool RPZADecoder::canDither(DitherType type) const {
void RPZADecoder::setDither(DitherType type, const byte *palette) {
assert(canDither(type));
- _ditherPalette = new byte[256 * 3];
- memcpy(_ditherPalette, palette, 256 * 3);
+ _ditherPalette.resize(256, false);
+ _ditherPalette.set(palette, 0, 256);
_dirtyPalette = true;
_format = Graphics::PixelFormat::createFormatCLUT8();
diff --git a/image/codecs/rpza.h b/image/codecs/rpza.h
index 9adb3748a67..9d094644784 100644
--- a/image/codecs/rpza.h
+++ b/image/codecs/rpza.h
@@ -23,6 +23,7 @@
#define IMAGE_CODECS_RPZA_H
#include "graphics/pixelformat.h"
+#include "graphics/palette.h"
#include "image/codecs/codec.h"
namespace Image {
@@ -41,7 +42,7 @@ public:
Graphics::PixelFormat getPixelFormat() const override { return _format; }
bool containsPalette() const override { return _ditherPalette != 0; }
- const byte *getPalette() override { _dirtyPalette = false; return _ditherPalette; }
+ const byte *getPalette() override { _dirtyPalette = false; return _ditherPalette.data(); }
bool hasDirtyPalette() const override { return _dirtyPalette; }
bool canDither(DitherType type) const override;
void setDither(DitherType type, const byte *palette) override;
@@ -49,7 +50,7 @@ public:
private:
Graphics::PixelFormat _format;
Graphics::Surface *_surface;
- byte *_ditherPalette;
+ Graphics::Palette _ditherPalette;
bool _dirtyPalette;
byte *_colorMap;
uint16 _width, _height;
More information about the Scummvm-git-logs
mailing list