add solution of lab 4

This commit is contained in:
2025-02-19 12:06:24 -05:00
parent e902f0662c
commit f4f4f7b138
6 changed files with 337 additions and 2 deletions

View File

@@ -67,6 +67,15 @@ std::vector<uint8_t> extractGifHeader(const std::vector<uint8_t>& fileData) {
// check point 2: complete this function, so as to reverse this std::list.
void reverseFrames(std::list<GifFrame>& frames) {
size_t n = frames.size();
if(n <= 1) return;
std::list<GifFrame>::iterator frontIt = frames.begin();
std::list<GifFrame>::reverse_iterator backIt = frames.rbegin();
for (size_t i = 0; i < n / 2; ++i) {
std::swap(*frontIt, *backIt);
++frontIt;
++backIt;
}
}
void writeGif(const std::string& outputFilename, const std::vector<uint8_t>& originalFileData,
@@ -274,7 +283,7 @@ std::vector<GifFrame> extractFrames(const std::string& filename, std::vector<uin
int main() {
// read the complete file into fileData, and extract frames.
std::vector<uint8_t> fileData;
std::vector<GifFrame> frames = extractFrames("input.gif", fileData, loopExtension);
std::vector<GifFrame> frames = extractFrames("brick_fake.gif", fileData, loopExtension);
if (frames.empty()) return 1;
// extract the complete header from fileData