Skip to content

Commit

Permalink
Fix reading broken DC6 again
Browse files Browse the repository at this point in the history
See 811c452 for more details

Ref #158
  • Loading branch information
DarthGandalf committed Jan 21, 2024
1 parent 9c60255 commit dd88e6a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/Abyss/DataTypes/DC6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void DC6::setPalette(const Palette &palette) {

const auto &frameData = frame.getFrameData();
while (process) {
if (offset >= frameData.size()) {
throw std::runtime_error("Data overrun while decoding DC6 frame.");
}
const auto b = frameData[offset];
offset++;

Expand All @@ -102,6 +105,9 @@ void DC6::setPalette(const Palette &palette) {
}
case eScanlineType::RunOfOpaquePixels: {
for (auto i = 0; i < static_cast<int>(b); i++) {
if (offset >= frameData.size()) {
throw std::runtime_error("Data overrun while decoding DC6 frame.");
}
const auto paletteIndex = static_cast<int>(frameData[offset]);
const auto &paletteColor = palette.getEntries()[paletteIndex];
const auto pixel = static_cast<uint32_t>(paletteColor.getBlue() << 24 | paletteColor.getGreen() << 16 | paletteColor.getRed() << 8 | 0xFF);
Expand Down
9 changes: 2 additions & 7 deletions src/Abyss/DataTypes/DC6Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ DC6Frame::DC6Frame(Streams::StreamReader &stream) {
_nextBlock = stream.readUInt32();
_length = stream.readUInt32();

_frameData.resize(_length);
stream.readBytes(_frameData);

_terminator.resize(DC6TerminatorSize);
stream.readBytes(_terminator);
_frameData.resize(_length + DC6TerminatorSize);
stream.readBytes(_frameData);
}

uint32_t DC6Frame::getFlipped() const { return _flipped; }
Expand All @@ -39,6 +36,4 @@ uint32_t DC6Frame::getLength() const { return _length; }

const std::vector<std::byte>& DC6Frame::getFrameData() const { return _frameData; }

const std::vector<std::byte>& DC6Frame::getTerminator() const { return _terminator; }

} // namespace Abyss::DataTypes
2 changes: 0 additions & 2 deletions src/Abyss/DataTypes/DC6Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class DC6Frame {
uint32_t _nextBlock{};
uint32_t _length{};
std::vector<std::byte> _frameData{};
std::vector<std::byte> _terminator{};

public:
explicit DC6Frame(Streams::StreamReader& stream);
Expand All @@ -35,7 +34,6 @@ class DC6Frame {
[[nodiscard]] uint32_t getNextBlock() const;
[[nodiscard]] uint32_t getLength() const;
[[nodiscard]] const std::vector<std::byte>& getFrameData() const;
[[nodiscard]] const std::vector<std::byte>& getTerminator() const;
};

} // namespace Abyss::DataTypes

0 comments on commit dd88e6a

Please sign in to comment.