Skip to content

Commit

Permalink
libsmackerdec: Replace most std::vector with GrowArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendricks266 committed Nov 3, 2023
1 parent 51d7c51 commit ab0d13f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions source/libsmackerdec/include/SmackerDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include <stdint.h>
#include "FileStream.h"
#include "BitReader.h"
#include <vector>
#include "collections.h"

// exportable interface
struct SmackerHandle
Expand Down Expand Up @@ -140,25 +140,25 @@ class SmackerDecoder
uint32_t treeSize;
uint32_t mMapSize, MClrSize, fullSize, typeSize;

std::vector<int> mmap_tbl;
std::vector<int> mclr_tbl;
std::vector<int> full_tbl;
std::vector<int> type_tbl;
GrowArray<int> mmap_tbl;
GrowArray<int> mclr_tbl;
GrowArray<int> full_tbl;
GrowArray<int> type_tbl;

int mmap_last[3], mclr_last[3], full_last[3], type_last[3];

std::vector<uint32_t> frameSizes;
std::vector<uint8_t> frameFlags;
GrowArray<uint32_t> frameSizes;
GrowArray<uint8_t> frameFlags;

uint32_t currentFrame;
int32_t nextPos;
int32_t firstFrameFilePos;

bool DecodeHeaderTrees();
int DecodeHeaderTree(SmackerCommon::BitReader &bits, std::vector<int> &recodes, int *last, int size);
int DecodeHeaderTree(SmackerCommon::BitReader &bits, GrowArray<int> &recodes, int *last, int size);
int DecodeTree(SmackerCommon::BitReader &bits, HuffContext *hc, uint32_t prefix, int length);
int DecodeBigTree(SmackerCommon::BitReader &bits, HuffContext *hc, DBCtx *ctx);
int GetCode(SmackerCommon::BitReader &bits, std::vector<int> &recode, int *last);
int GetCode(SmackerCommon::BitReader &bits, GrowArray<int> &recode, int *last);
int ReadPacket();
int DecodeFrame(uint32_t frameSize);
void GetFrameSize(uint32_t &width, uint32_t &height);
Expand Down
16 changes: 8 additions & 8 deletions source/libsmackerdec/src/SmackerDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include "compat.h"
#include "baselayer.h"

std::vector<class SmackerDecoder*> classInstances;
GrowArray<class SmackerDecoder*> classInstances;

SmackerHandle Smacker_Open(const char* fileName)
{
Expand Down Expand Up @@ -248,29 +248,29 @@ typedef struct HuffContext {
int maxlength;
int current;

std::vector<uint32_t> bits;
std::vector<int> lengths;
std::vector<int> values;
GrowArray<uint32_t> bits;
GrowArray<int> lengths;
GrowArray<int> values;

} HuffContext;

/* common parameters used for decode_bigtree */
typedef struct DBCtx {
SmackerCommon::VLCtable v1;
SmackerCommon::VLCtable v2;
std::vector<int> recode1, recode2;
GrowArray<int> recode1, recode2;
int escapes[3];
int *last;
int lcur;
} DBCtx;


static void last_reset(std::vector<int> &recode, int *last) {
static void last_reset(GrowArray<int> &recode, int *last) {
recode[last[0]] = recode[last[1]] = recode[last[2]] = 0;
}

/* get code and update history */
int SmackerDecoder::GetCode(SmackerCommon::BitReader &bits, std::vector<int> &recode, int *last)
int SmackerDecoder::GetCode(SmackerCommon::BitReader &bits, GrowArray<int> &recode, int *last)
{
int *table = &recode[0];

Expand Down Expand Up @@ -540,7 +540,7 @@ int SmackerDecoder::DecodeBigTree(SmackerCommon::BitReader &bits, HuffContext *h
/**
* Store large tree as Libav's vlc codes
*/
int SmackerDecoder::DecodeHeaderTree(SmackerCommon::BitReader &bits, std::vector<int> &recodes, int *last, int size)
int SmackerDecoder::DecodeHeaderTree(SmackerCommon::BitReader &bits, GrowArray<int> &recodes, int *last, int size)
{
HuffContext huff;
HuffContext tmp1, tmp2;
Expand Down

0 comments on commit ab0d13f

Please sign in to comment.