Skip to content

Commit 9f2b04e

Browse files
committed
update
1 parent 2466cf5 commit 9f2b04e

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/third_party/libnsgif/software_decoder.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void SoftwareGifDecoder::end() {
5757
currentFrameIndex_ = 0;
5858
endOfStream_ = false;
5959
errorMessage_.clear();
60+
dataBuffer_.clear();
6061
}
6162

6263
bool SoftwareGifDecoder::hasError(fl::string* msg) const {
@@ -234,7 +235,7 @@ bool SoftwareGifDecoder::loadMoreData() {
234235
return false;
235236
}
236237

237-
// Read available data from stream
238+
// Read available data from stream in chunks and accumulate
238239
const fl::size bufferSize = 4096; // Read in chunks
239240
fl::u8 buffer[bufferSize];
240241
fl::size bytesRead = stream_->read(buffer, bufferSize);
@@ -246,8 +247,14 @@ bool SoftwareGifDecoder::loadMoreData() {
246247
return false;
247248
}
248249

249-
// Feed data to libnsgif
250-
nsgif_error result = nsgif_data_scan(gif_, bytesRead, buffer);
250+
// Append new data to accumulated buffer
251+
// libnsgif requires ALL data to be provided in each call to nsgif_data_scan
252+
fl::size oldSize = dataBuffer_.size();
253+
dataBuffer_.resize(oldSize + bytesRead);
254+
memcpy(dataBuffer_.data() + oldSize, buffer, bytesRead);
255+
256+
// Feed ALL accumulated data to libnsgif
257+
nsgif_error result = nsgif_data_scan(gif_, dataBuffer_.size(), dataBuffer_.data());
251258

252259
// Check if we've read less than requested (likely end of stream)
253260
if (bytesRead < bufferSize) {

src/third_party/libnsgif/software_decoder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "fl/str.h"
88
#include "fl/stdint.h"
99
#include "fl/scoped_array.h"
10+
#include "fl/vector.h"
1011
#include "fx/frame.h"
1112

1213
// Include the actual nsgif header
@@ -48,6 +49,9 @@ namespace third_party {
4849
bool hasError_;
4950
bool dataComplete_;
5051

52+
// Data buffer - libnsgif requires all data to be contiguous
53+
fl::vector<fl::u8> dataBuffer_;
54+
5155
// Animation state
5256
fl::u32 currentFrameIndex_;
5357
bool endOfStream_;

0 commit comments

Comments
 (0)