-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
179 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "GafArchive.h" | ||
#include <algorithm> | ||
#include <memory> | ||
#include <rwe/io/gaf/gaf_util.h> | ||
#include <rwe/io_utils.h> | ||
#include <rwe/rwe_string.h> | ||
|
||
namespace rwe | ||
{ | ||
GafArchive::Entry readEntry(std::istream& stream) | ||
{ | ||
auto entry = readRaw<GafEntry>(stream); | ||
|
||
auto nullPos = std::find(entry.name, entry.name + GafMaxNameLength, '\0'); | ||
auto nameLength = nullPos - entry.name; | ||
std::string name(reinterpret_cast<char*>(entry.name), nameLength); | ||
|
||
std::vector<GafFrameEntry> frames; | ||
frames.reserve(entry.frames); | ||
|
||
for (std::size_t i = 0; i < entry.frames; ++i) | ||
{ | ||
auto frameEntry = readRaw<GafFrameEntry>(stream); | ||
frames.emplace_back(frameEntry); | ||
} | ||
|
||
return GafArchive::Entry{std::move(name), entry.unknown1, entry.unknown2, std::move(frames)}; | ||
} | ||
|
||
const std::vector<GafArchive::Entry>& GafArchive::entries() const | ||
{ | ||
return _entries; | ||
} | ||
|
||
GafArchive::GafArchive(std::istream* stream) | ||
{ | ||
auto header = readRaw<GafHeader>(*stream); | ||
if (header.version != GafVersionNumber) | ||
{ | ||
throw GafException("Invalid GAF version number"); | ||
} | ||
|
||
_entries.reserve(header.entries); | ||
|
||
for (std::size_t i = 0; i < header.entries; ++i) | ||
{ | ||
auto pointer = readRaw<uint32_t>(*stream); | ||
auto previous = stream->tellg(); | ||
|
||
stream->seekg(pointer); | ||
_entries.push_back(readEntry(*stream)); | ||
stream->seekg(previous); | ||
} | ||
|
||
_stream = stream; | ||
} | ||
|
||
std::optional<std::reference_wrapper<const GafArchive::Entry>> GafArchive::findEntry(const std::string& name) const | ||
{ | ||
auto pos = std::find_if(_entries.begin(), _entries.end(), [&name](const Entry& e) { return toUpper(e.name) == toUpper(name); }); | ||
|
||
if (pos == _entries.end()) | ||
{ | ||
return std::nullopt; | ||
} | ||
|
||
return *pos; | ||
} | ||
|
||
void GafArchive::extract(const GafArchive::Entry& entry, GafReaderAdapter& adapter) | ||
{ | ||
extractGafEntry(_stream, entry.frameOffsets, adapter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <functional> | ||
#include <istream> | ||
#include <optional> | ||
#include <rwe/io/gaf/GafReaderAdapter.h> | ||
#include <rwe/io/gaf/gaf_headers.h> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace rwe | ||
{ | ||
class GafArchive | ||
{ | ||
public: | ||
struct Entry | ||
{ | ||
std::string name; | ||
uint16_t unknown1; | ||
uint32_t unknown2; | ||
std::vector<GafFrameEntry> frameOffsets; | ||
}; | ||
|
||
private: | ||
std::vector<Entry> _entries; | ||
std::istream* _stream; | ||
|
||
public: | ||
explicit GafArchive(std::istream* stream); | ||
|
||
const std::vector<Entry>& entries() const; | ||
|
||
std::optional<std::reference_wrapper<const Entry>> findEntry(const std::string& name) const; | ||
|
||
void extract(const Entry& entry, GafReaderAdapter& adapter); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include <rwe/io/gaf/gaf_headers.h> | ||
|
||
namespace rwe | ||
{ | ||
class GafReaderAdapter | ||
{ | ||
public: | ||
struct LayerData | ||
{ | ||
int x; | ||
int y; | ||
unsigned int width; | ||
unsigned int height; | ||
unsigned char transparencyKey; | ||
char* data; | ||
}; | ||
|
||
public: | ||
virtual void beginFrame(const GafFrameEntry& entry, const GafFrameData& header) = 0; | ||
virtual void frameLayer(const LayerData& data) = 0; | ||
virtual void endFrame() = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <rwe/io/gaf/GafReaderAdapter.h> | ||
#include <rwe/io/gaf/gaf_headers.h> | ||
#include <istream> | ||
#include <vector> | ||
|
||
namespace rwe | ||
{ | ||
class GafException : public std::runtime_error | ||
{ | ||
public: | ||
explicit GafException(const char* message); | ||
}; | ||
|
||
void decompressRow(std::istream& stream, char* buffer, std::size_t rowLength, char transparencyIndex); | ||
|
||
void decompressFrame(std::istream& stream, char* buffer, std::size_t width, std::size_t height, char transparencyIndex); | ||
|
||
void extractGafEntry(std::istream* _stream, const std::vector<GafFrameEntry>& frameEntries, GafReaderAdapter& adapter); | ||
} |
Oops, something went wrong.