summaryrefslogtreecommitdiff
path: root/core/fxcodec/lgif/cfx_lzwdecoder.h
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-09-26 15:39:10 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-26 19:58:33 +0000
commite2df5b7305df66efbd81232d911615af60624ae3 (patch)
tree5c5aff0ae260792790cfb1ed2f3f15863c0c0d63 /core/fxcodec/lgif/cfx_lzwdecoder.h
parent7d04f1b0ab4848f1d10983b7a7b1444ac93dec70 (diff)
downloadpdfium-e2df5b7305df66efbd81232d911615af60624ae3.tar.xz
Move LZW decoder out of fx_gif
CGifLZWDecoder has been moved out into its own file, name changed to CFX_LZWDecoder, member variable names updated, creation pattern changed, and unit tests added. Wrt the creation pattern, there is no longer a constructor and 2 initialization methods that need to be called. Instead all of the initialization is done as part of the constructor. A wrapper has been added for generating a std::unique_ptr<CFX_LZWDecoder>, so that params can be validated. BUG=pdfium:900,pdfium:901,pdfium:903,pdfium:904 Change-Id: Idcbe773f7fb18b08e64d5a89bfd87d4801332c53 Reviewed-on: https://pdfium-review.googlesource.com/14814 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fxcodec/lgif/cfx_lzwdecoder.h')
-rw-r--r--core/fxcodec/lgif/cfx_lzwdecoder.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/core/fxcodec/lgif/cfx_lzwdecoder.h b/core/fxcodec/lgif/cfx_lzwdecoder.h
new file mode 100644
index 0000000000..913df670c6
--- /dev/null
+++ b/core/fxcodec/lgif/cfx_lzwdecoder.h
@@ -0,0 +1,55 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FXCODEC_LGIF_CFX_LZWDECODER_H_
+#define CORE_FXCODEC_LGIF_CFX_LZWDECODER_H_
+
+#include <memory>
+#include <vector>
+
+#include "core/fxcodec/lgif/fx_gif.h"
+
+class CFX_LZWDecoder {
+ public:
+ struct tag_Table {
+ uint16_t prefix;
+ uint8_t suffix;
+ };
+
+ // Returns nullptr on error
+ static std::unique_ptr<CFX_LZWDecoder> Create(uint8_t color_exp,
+ uint8_t code_exp);
+ ~CFX_LZWDecoder();
+
+ GifDecodeStatus Decode(uint8_t* src_buf,
+ uint32_t src_size,
+ uint8_t* des_buf,
+ uint32_t* des_size);
+
+ private:
+ CFX_LZWDecoder(uint8_t color_exp, uint8_t code_exp);
+ void ClearTable();
+ void AddCode(uint16_t prefix_code, uint8_t append_char);
+ bool DecodeString(uint16_t code);
+
+ uint8_t code_size_;
+ uint8_t code_size_cur_;
+ uint16_t code_color_end_;
+ uint16_t code_clear_;
+ uint16_t code_end_;
+ uint16_t code_next_;
+ uint8_t code_first_;
+ uint8_t stack_[GIF_MAX_LZW_CODE];
+ size_t stack_size_;
+ tag_Table code_table_[GIF_MAX_LZW_CODE];
+ uint16_t code_old_;
+ uint8_t* next_in_;
+ uint32_t avail_in_;
+ uint8_t bits_left_;
+ uint32_t code_store_;
+};
+
+#endif // CORE_FXCODEC_LGIF_CFX_LZWDECODER_H_