diff options
Diffstat (limited to 'core/fxcodec/gif')
-rw-r--r-- | core/fxcodec/gif/cfx_gifcontext.cpp | 8 | ||||
-rw-r--r-- | core/fxcodec/gif/cfx_gifcontext.h | 2 | ||||
-rw-r--r-- | core/fxcodec/gif/cfx_lzwdecompressor.cpp | 33 | ||||
-rw-r--r-- | core/fxcodec/gif/cfx_lzwdecompressor.h | 10 | ||||
-rw-r--r-- | core/fxcodec/gif/cfx_lzwdecompressor_unittest.cpp | 36 |
5 files changed, 45 insertions, 44 deletions
diff --git a/core/fxcodec/gif/cfx_gifcontext.cpp b/core/fxcodec/gif/cfx_gifcontext.cpp index 6159e56c13..3e09489f64 100644 --- a/core/fxcodec/gif/cfx_gifcontext.cpp +++ b/core/fxcodec/gif/cfx_gifcontext.cpp @@ -348,21 +348,21 @@ uint32_t CFX_GifContext::GetAvailInput(uint8_t** avail_buf) const { return avail_in_; } -uint8_t* CFX_GifContext::ReadData(uint8_t** des_buf_pp, uint32_t data_size) { +uint8_t* CFX_GifContext::ReadData(uint8_t** dest_buf_pp, uint32_t data_size) { if (!next_in_) return nullptr; if (avail_in_ <= skip_size_) return nullptr; - if (!des_buf_pp) + if (!dest_buf_pp) return nullptr; if (data_size == 0) return nullptr; if (avail_in_ - skip_size_ < data_size) return nullptr; - *des_buf_pp = next_in_ + skip_size_; + *dest_buf_pp = next_in_ + skip_size_; skip_size_ += data_size; - return *des_buf_pp; + return *dest_buf_pp; } CFX_GifDecodeStatus CFX_GifContext::ReadGifSignature() { diff --git a/core/fxcodec/gif/cfx_gifcontext.h b/core/fxcodec/gif/cfx_gifcontext.h index 3a367bd361..ba23522b79 100644 --- a/core/fxcodec/gif/cfx_gifcontext.h +++ b/core/fxcodec/gif/cfx_gifcontext.h @@ -66,7 +66,7 @@ class CFX_GifContext : public CCodec_GifModule::Context { uint8_t img_pass_num_; protected: - uint8_t* ReadData(uint8_t** des_buf_pp, uint32_t data_size); + uint8_t* ReadData(uint8_t** dest_buf_pp, uint32_t data_size); CFX_GifDecodeStatus ReadGifSignature(); CFX_GifDecodeStatus ReadLogicalScreenDescriptor(); diff --git a/core/fxcodec/gif/cfx_lzwdecompressor.cpp b/core/fxcodec/gif/cfx_lzwdecompressor.cpp index 09df6e767b..d4fd43d321 100644 --- a/core/fxcodec/gif/cfx_lzwdecompressor.cpp +++ b/core/fxcodec/gif/cfx_lzwdecompressor.cpp @@ -44,12 +44,12 @@ CFX_LZWDecompressor::~CFX_LZWDecompressor() {} CFX_GifDecodeStatus CFX_LZWDecompressor::Decode(uint8_t* src_buf, uint32_t src_size, - uint8_t* des_buf, - uint32_t* des_size) { - if (!src_buf || src_size == 0 || !des_buf || !des_size) + uint8_t* dest_buf, + uint32_t* dest_size) { + if (!src_buf || src_size == 0 || !dest_buf || !dest_size) return CFX_GifDecodeStatus::Error; - if (*des_size == 0) + if (*dest_size == 0) return CFX_GifDecodeStatus::InsufficientDestSize; next_in_ = src_buf; @@ -59,15 +59,15 @@ CFX_GifDecodeStatus CFX_LZWDecompressor::Decode(uint8_t* src_buf, uint32_t i = 0; if (decompressed_next_ != 0) { - uint32_t extracted_size = ExtractData(des_buf, *des_size); + uint32_t extracted_size = ExtractData(dest_buf, *dest_size); if (decompressed_next_ != 0) return CFX_GifDecodeStatus::InsufficientDestSize; - des_buf += extracted_size; + dest_buf += extracted_size; i += extracted_size; } - while (i <= *des_size && (avail_in_ > 0 || bits_left_ >= code_size_cur_)) { + while (i <= *dest_size && (avail_in_ > 0 || bits_left_ >= code_size_cur_)) { if (code_size_cur_ > GIF_MAX_LZW_EXP) return CFX_GifDecodeStatus::Error; @@ -96,7 +96,7 @@ CFX_GifDecodeStatus CFX_LZWDecompressor::Decode(uint8_t* src_buf, continue; } if (code == code_end_) { - *des_size = i; + *dest_size = i; return CFX_GifDecodeStatus::Success; } @@ -122,11 +122,11 @@ CFX_GifDecodeStatus CFX_LZWDecompressor::Decode(uint8_t* src_buf, } code_old_ = code; - uint32_t extracted_size = ExtractData(des_buf, *des_size - i); + uint32_t extracted_size = ExtractData(dest_buf, *dest_size - i); if (decompressed_next_ != 0) return CFX_GifDecodeStatus::InsufficientDestSize; - des_buf += extracted_size; + dest_buf += extracted_size; i += extracted_size; } } @@ -134,7 +134,7 @@ CFX_GifDecodeStatus CFX_LZWDecompressor::Decode(uint8_t* src_buf, if (avail_in_ != 0) return CFX_GifDecodeStatus::Error; - *des_size = i; + *dest_size = i; return CFX_GifDecodeStatus::Unfinished; } @@ -182,15 +182,16 @@ bool CFX_LZWDecompressor::DecodeString(uint16_t code) { return true; } -uint32_t CFX_LZWDecompressor::ExtractData(uint8_t* des_buf, uint32_t des_size) { - if (des_size == 0) +uint32_t CFX_LZWDecompressor::ExtractData(uint8_t* dest_buf, + uint32_t dest_size) { + if (dest_size == 0) return 0; - uint32_t copy_size = des_size <= decompressed_next_ - ? des_size + uint32_t copy_size = dest_size <= decompressed_next_ + ? dest_size : static_cast<uint32_t>(decompressed_next_); std::reverse_copy(decompressed_.data() + decompressed_next_ - copy_size, - decompressed_.data() + decompressed_next_, des_buf); + decompressed_.data() + decompressed_next_, dest_buf); decompressed_next_ -= copy_size; return copy_size; } diff --git a/core/fxcodec/gif/cfx_lzwdecompressor.h b/core/fxcodec/gif/cfx_lzwdecompressor.h index 717c055973..e6e0634b10 100644 --- a/core/fxcodec/gif/cfx_lzwdecompressor.h +++ b/core/fxcodec/gif/cfx_lzwdecompressor.h @@ -26,12 +26,12 @@ class CFX_LZWDecompressor { CFX_GifDecodeStatus Decode(uint8_t* src_buf, uint32_t src_size, - uint8_t* des_buf, - uint32_t* des_size); + uint8_t* dest_buf, + uint32_t* dest_size); // Used by unittests, should not be called in production code. - uint32_t ExtractDataForTest(uint8_t* des_buf, uint32_t des_size) { - return ExtractData(des_buf, des_size); + uint32_t ExtractDataForTest(uint8_t* dest_buf, uint32_t dest_size) { + return ExtractData(dest_buf, dest_size); } std::vector<uint8_t>* DecompressedForTest() { return &decompressed_; } @@ -43,7 +43,7 @@ class CFX_LZWDecompressor { void ClearTable(); void AddCode(uint16_t prefix_code, uint8_t append_char); bool DecodeString(uint16_t code); - uint32_t ExtractData(uint8_t* des_buf, uint32_t des_size); + uint32_t ExtractData(uint8_t* dest_buf, uint32_t dest_size); uint8_t code_size_; uint8_t code_size_cur_; diff --git a/core/fxcodec/gif/cfx_lzwdecompressor_unittest.cpp b/core/fxcodec/gif/cfx_lzwdecompressor_unittest.cpp index 0d0906eb10..551bc1e23e 100644 --- a/core/fxcodec/gif/cfx_lzwdecompressor_unittest.cpp +++ b/core/fxcodec/gif/cfx_lzwdecompressor_unittest.cpp @@ -24,12 +24,12 @@ TEST(CFX_LZWDecompressor, ExtractData) { std::vector<uint8_t>* decompressed = decompressor->DecompressedForTest(); *decompressed = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; *(decompressor->DecompressedNextForTest()) = decompressed->size(); - uint8_t des_buf[20]; - memset(des_buf, static_cast<uint8_t>(-1), sizeof(des_buf)); + uint8_t dest_buf[20]; + memset(dest_buf, static_cast<uint8_t>(-1), sizeof(dest_buf)); - EXPECT_EQ(0u, decompressor->ExtractDataForTest(des_buf, 0)); - for (size_t i = 0; i < FX_ArraySize(des_buf); ++i) - EXPECT_EQ(static_cast<uint8_t>(-1), des_buf[i]); + EXPECT_EQ(0u, decompressor->ExtractDataForTest(dest_buf, 0)); + for (size_t i = 0; i < FX_ArraySize(dest_buf); ++i) + EXPECT_EQ(static_cast<uint8_t>(-1), dest_buf[i]); EXPECT_EQ(10u, *(decompressor->DecompressedNextForTest())); for (size_t i = 0; i < *(decompressor->DecompressedNextForTest()); ++i) @@ -41,15 +41,15 @@ TEST(CFX_LZWDecompressor, ExtractData) { std::vector<uint8_t>* decompressed = decompressor->DecompressedForTest(); *decompressed = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; *(decompressor->DecompressedNextForTest()) = decompressed->size(); - uint8_t des_buf[20]; - memset(des_buf, static_cast<uint8_t>(-1), sizeof(des_buf)); + uint8_t dest_buf[20]; + memset(dest_buf, static_cast<uint8_t>(-1), sizeof(dest_buf)); - EXPECT_EQ(5u, decompressor->ExtractDataForTest(des_buf, 5)); + EXPECT_EQ(5u, decompressor->ExtractDataForTest(dest_buf, 5)); size_t i = 0; for (; i < 5; ++i) - EXPECT_EQ(9 - i, des_buf[i]); - for (; i < FX_ArraySize(des_buf); ++i) - EXPECT_EQ(static_cast<uint8_t>(-1), des_buf[i]); + EXPECT_EQ(9 - i, dest_buf[i]); + for (; i < FX_ArraySize(dest_buf); ++i) + EXPECT_EQ(static_cast<uint8_t>(-1), dest_buf[i]); EXPECT_EQ(5u, *(decompressor->DecompressedNextForTest())); for (i = 0; i < *(decompressor->DecompressedNextForTest()); ++i) @@ -61,16 +61,16 @@ TEST(CFX_LZWDecompressor, ExtractData) { std::vector<uint8_t>* decompressed = decompressor->DecompressedForTest(); *decompressed = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; *(decompressor->DecompressedNextForTest()) = decompressed->size(); - uint8_t des_buf[20]; - memset(des_buf, static_cast<uint8_t>(-1), sizeof(des_buf)); + uint8_t dest_buf[20]; + memset(dest_buf, static_cast<uint8_t>(-1), sizeof(dest_buf)); - EXPECT_EQ(10u, - decompressor->ExtractDataForTest(des_buf, FX_ArraySize(des_buf))); + EXPECT_EQ(10u, decompressor->ExtractDataForTest(dest_buf, + FX_ArraySize(dest_buf))); size_t i = 0; for (; i < 10; ++i) - EXPECT_EQ(9 - i, des_buf[i]); - for (; i < FX_ArraySize(des_buf); ++i) - EXPECT_EQ(static_cast<uint8_t>(-1), des_buf[i]); + EXPECT_EQ(9 - i, dest_buf[i]); + for (; i < FX_ArraySize(dest_buf); ++i) + EXPECT_EQ(static_cast<uint8_t>(-1), dest_buf[i]); EXPECT_EQ(0u, *(decompressor->DecompressedNextForTest())); } |