Skip to content
Permalink
Browse files

Switch GifDecoder to using malloc in case it helps ESP32.

  • Loading branch information...
marcmerlin committed Mar 9, 2019
1 parent 29b155d commit 0c6191181ec3a6b7061afcb9acf1512a7a19a358
Showing with 22 additions and 4 deletions.
  1. +4 −0 GifAnim_Impl.h
  2. +3 −3 GifDecoder.h
  3. +13 −0 LzwDecoder_Impl.h
  4. +2 −1 SimpleGifAnimViewer2/SimpleGifAnimViewer2.ino
@@ -123,7 +123,11 @@ void sav_setup(const char *pathname) {
}

void sav_loop() {
static int frame = 0;
Serial.print("Decoding Frame Start:");
Serial.println(frame++);
decoder.decodeFrame();
Serial.println("Decoding Frame End");
}

// vim:sts=4:sw=4
@@ -132,9 +132,9 @@ class GifDecoder {
uint8_t *sp;
uint8_t * temp_buffer;

uint8_t stack [LZW_SIZTABLE];
uint8_t suffix [LZW_SIZTABLE];
uint16_t prefix [LZW_SIZTABLE];
uint8_t *stack;
uint8_t *suffix;
uint16_t *prefix;

// Masks for 0 .. 16 bits
unsigned int mask[17] = {
@@ -42,6 +42,15 @@ void GifDecoder<maxGifWidth, maxGifHeight, lzwMaxBits>::lzw_setTempBuffer(uint8_
temp_buffer = tempBuffer;
}

void mallocdie(uint8_t seq, uint16_t req) {
Serial.print("Failed to malloc #");
Serial.print(seq);
Serial.print(" in lzw_decode_init. Requested bytes: ");
Serial.println(req);
while(1);
return;
}

// Initialize LZW decoder
// csize initial code size in bits
// buf input data
@@ -54,6 +63,10 @@ void GifDecoder<maxGifWidth, maxGifHeight, lzwMaxBits>::lzw_decode_init (int csi
bs = 0;
bcnt = 0;

if (!stack && !(stack = (uint8_t *) malloc(LZW_SIZTABLE))) mallocdie(1, LZW_SIZTABLE);
if (!prefix && !(prefix = (uint16_t *) malloc(LZW_SIZTABLE))) mallocdie(2, LZW_SIZTABLE);
if (!suffix && !(suffix = (uint8_t *) malloc(LZW_SIZTABLE*2))) mallocdie(3, LZW_SIZTABLE*2);

// Initialize decoder variables
codesize = csize;
cursize = codesize + 1;
@@ -7,7 +7,8 @@ int OFFSETX = 0;
int OFFSETY = 0;

File file;
const char *pathname = "/gifs64/200_circlesmoke.gif";
//const char *pathname = "/gifs64/200_circlesmoke.gif";
const char *pathname = "/gifs64/257_mesh.gif";

// Setup method runs once, when the sketch starts
void setup() {

0 comments on commit 0c61911

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.