diff options
author | Lei Zhang <thestig@chromium.org> | 2015-10-08 12:32:46 -0700 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-10-08 12:32:46 -0700 |
commit | d1cb813d23df38a8e21df3314658995ded7c4b45 (patch) | |
tree | 121280512f7b23d2648b86f04840f5ecb4493226 | |
parent | 67fd5df1a378195ae3fb40c862a4e6e58731020a (diff) | |
download | pdfium-d1cb813d23df38a8e21df3314658995ded7c4b45.tar.xz |
Merge to XFA: Put CJBig2_SymbolDict's images in a CJBig2_List container.
Also mark it private.
TBR=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1395613003 .
(cherry picked from commit 8793b4a071fad51a770b93838e0752505b020e43)
Review URL: https://codereview.chromium.org/1397853002 .
-rw-r--r-- | core/src/fxcodec/jbig2/JBig2_Context.cpp | 19 | ||||
-rw-r--r-- | core/src/fxcodec/jbig2/JBig2_Context.h | 1 | ||||
-rw-r--r-- | core/src/fxcodec/jbig2/JBig2_List.h | 25 | ||||
-rw-r--r-- | core/src/fxcodec/jbig2/JBig2_SddProc.cpp | 22 | ||||
-rw-r--r-- | core/src/fxcodec/jbig2/JBig2_SymbolDict.cpp | 33 | ||||
-rw-r--r-- | core/src/fxcodec/jbig2/JBig2_SymbolDict.h | 14 |
6 files changed, 55 insertions, 59 deletions
diff --git a/core/src/fxcodec/jbig2/JBig2_Context.cpp b/core/src/fxcodec/jbig2/JBig2_Context.cpp index e8d4bb8cc8..7b11ca2e5e 100644 --- a/core/src/fxcodec/jbig2/JBig2_Context.cpp +++ b/core/src/fxcodec/jbig2/JBig2_Context.cpp @@ -8,6 +8,7 @@ #include <list> +#include "JBig2_ArithDecoder.h" #include "JBig2_GrdProc.h" #include "JBig2_GrrdProc.h" #include "JBig2_HtrdProc.h" @@ -478,7 +479,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, CJBig2_Segment* pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); if (pSeg->m_cFlags.s.type == 0) { - pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->SDNUMEXSYMS; + pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->NumImages(); pLRSeg = pSeg; } } @@ -491,9 +492,10 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, CJBig2_Segment* pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); if (pSeg->m_cFlags.s.type == 0) { - JBIG2_memcpy(SDINSYMS.get() + dwTemp, pSeg->m_Result.sd->SDEXSYMS, - pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); - dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; + const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd; + for (size_t j = 0; j < dict.NumImages(); ++j) + SDINSYMS.get()[dwTemp + j] = dict.GetImage(j); + dwTemp += dict.NumImages(); } } } @@ -721,7 +723,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { CJBig2_Segment* pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); if (pSeg->m_cFlags.s.type == 0) { - pTRD->SBNUMSYMS += pSeg->m_Result.sd->SDNUMEXSYMS; + pTRD->SBNUMSYMS += pSeg->m_Result.sd->NumImages(); } } @@ -733,9 +735,10 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { CJBig2_Segment* pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); if (pSeg->m_cFlags.s.type == 0) { - JBIG2_memcpy(SBSYMS.get() + dwTemp, pSeg->m_Result.sd->SDEXSYMS, - pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); - dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; + const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd; + for (size_t j = 0; j < dict.NumImages(); ++j) + SBSYMS.get()[dwTemp + j] = dict.GetImage(j); + dwTemp += dict.NumImages(); } } pTRD->SBSYMS = SBSYMS.get(); diff --git a/core/src/fxcodec/jbig2/JBig2_Context.h b/core/src/fxcodec/jbig2/JBig2_Context.h index 3c283d1d5b..4fcef810f6 100644 --- a/core/src/fxcodec/jbig2/JBig2_Context.h +++ b/core/src/fxcodec/jbig2/JBig2_Context.h @@ -16,6 +16,7 @@ #include "JBig2_Page.h" #include "JBig2_Segment.h" +class CJBig2_ArithDecoder; class CJBig2_GRDProc; class IFX_Pause; diff --git a/core/src/fxcodec/jbig2/JBig2_List.h b/core/src/fxcodec/jbig2/JBig2_List.h index e033eb23ea..ffdd22c3ca 100644 --- a/core/src/fxcodec/jbig2/JBig2_List.h +++ b/core/src/fxcodec/jbig2/JBig2_List.h @@ -4,11 +4,13 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef _JBIG2_LIST_H_ -#define _JBIG2_LIST_H_ +#ifndef CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ +#define CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ #include <vector> +// A poor man's ScopedVector for pointers of TYPE. +// Owns all the pointers contained within and deletes them on destruction. template <class TYPE> class CJBig2_List { public: @@ -18,23 +20,28 @@ class CJBig2_List { clear(); } + TYPE* get(size_t index) const { return m_vector[index]; } + TYPE* back() const { return m_vector.back(); } + size_t size() const { return m_vector.size(); } + + // Deletes all the pointers contained within. void clear() { for (size_t i = 0; i < m_vector.size(); ++i) delete m_vector[i]; m_vector.clear(); } + // Takes ownership of |pItem|. void push_back(TYPE* pItem) { m_vector.push_back(pItem); } - size_t size() const { return m_vector.size(); } - void resize(size_t count) { m_vector.resize(count); } - - TYPE* get(size_t index) { return m_vector[index]; } - - TYPE* back() { return m_vector.back(); } + void resize(size_t count) { + for (size_t i = count; i < size(); ++i) + delete m_vector[i]; + m_vector.resize(count); + } private: std::vector<TYPE*> m_vector; }; -#endif +#endif // CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ diff --git a/core/src/fxcodec/jbig2/JBig2_SddProc.cpp b/core/src/fxcodec/jbig2/JBig2_SddProc.cpp index 16f4a9024e..1d0393a7e3 100644 --- a/core/src/fxcodec/jbig2/JBig2_SddProc.cpp +++ b/core/src/fxcodec/jbig2/JBig2_SddProc.cpp @@ -258,24 +258,19 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( CUREXFLAG = !CUREXFLAG; } pDict.reset(new CJBig2_SymbolDict); - pDict->SDNUMEXSYMS = SDNUMEXSYMS; - pDict->SDEXSYMS = FX_Alloc(CJBig2_Image*, SDNUMEXSYMS); I = J = 0; for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) { if (EXFLAGS[I] && J < SDNUMEXSYMS) { if (I < SDNUMINSYMS) { - pDict->SDEXSYMS[J] = new CJBig2_Image(*SDINSYMS[I]); + pDict->AddImage(new CJBig2_Image(*SDINSYMS[I])); } else { - pDict->SDEXSYMS[J] = SDNEWSYMS[I - SDNUMINSYMS]; + pDict->AddImage(SDNEWSYMS[I - SDNUMINSYMS]); } - J = J + 1; + ++J; } else if (!EXFLAGS[I] && I >= SDNUMINSYMS) { delete SDNEWSYMS[I - SDNUMINSYMS]; } } - if (J < SDNUMEXSYMS) { - pDict->SDNUMEXSYMS = J; - } FX_Free(EXFLAGS); FX_Free(SDNEWSYMS); return pDict.release(); @@ -600,24 +595,19 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(CJBig2_BitStream* pStream, EXINDEX = EXINDEX + EXRUNLENGTH; CUREXFLAG = !CUREXFLAG; } - pDict->SDNUMEXSYMS = SDNUMEXSYMS; - pDict->SDEXSYMS = FX_Alloc(CJBig2_Image*, SDNUMEXSYMS); I = J = 0; for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) { if (EXFLAGS[I] && J < SDNUMEXSYMS) { if (I < SDNUMINSYMS) { - pDict->SDEXSYMS[J] = new CJBig2_Image(*SDINSYMS[I]); + pDict->AddImage(new CJBig2_Image(*SDINSYMS[I])); } else { - pDict->SDEXSYMS[J] = SDNEWSYMS[I - SDNUMINSYMS]; + pDict->AddImage(SDNEWSYMS[I - SDNUMINSYMS]); } - J = J + 1; + ++J; } else if (!EXFLAGS[I] && I >= SDNUMINSYMS) { delete SDNEWSYMS[I - SDNUMINSYMS]; } } - if (J < SDNUMEXSYMS) { - pDict->SDNUMEXSYMS = J; - } FX_Free(EXFLAGS); FX_Free(SDNEWSYMS); if (SDREFAGG == 0) { diff --git a/core/src/fxcodec/jbig2/JBig2_SymbolDict.cpp b/core/src/fxcodec/jbig2/JBig2_SymbolDict.cpp index 1ec56dfacc..a8f8a94529 100644 --- a/core/src/fxcodec/jbig2/JBig2_SymbolDict.cpp +++ b/core/src/fxcodec/jbig2/JBig2_SymbolDict.cpp @@ -10,12 +10,17 @@ #include "JBig2_Image.h" CJBig2_SymbolDict::CJBig2_SymbolDict() { - SDNUMEXSYMS = 0; - SDEXSYMS = NULL; m_bContextRetained = FALSE; m_gbContext = m_grContext = NULL; } +CJBig2_SymbolDict::~CJBig2_SymbolDict() { + if (m_bContextRetained) { + FX_Free(m_gbContext); + FX_Free(m_grContext); + } +} + nonstd::unique_ptr<CJBig2_SymbolDict> CJBig2_SymbolDict::DeepCopy() const { nonstd::unique_ptr<CJBig2_SymbolDict> dst; const CJBig2_SymbolDict* src = this; @@ -23,27 +28,9 @@ nonstd::unique_ptr<CJBig2_SymbolDict> CJBig2_SymbolDict::DeepCopy() const { return dst; dst.reset(new CJBig2_SymbolDict); - dst->SDNUMEXSYMS = src->SDNUMEXSYMS; - dst->SDEXSYMS = FX_Alloc(CJBig2_Image*, src->SDNUMEXSYMS); - for (FX_DWORD i = 0; i < src->SDNUMEXSYMS; ++i) { - if (src->SDEXSYMS[i]) { - dst->SDEXSYMS[i] = new CJBig2_Image(*(src->SDEXSYMS[i])); - } else { - dst->SDEXSYMS[i] = NULL; - } + for (size_t i = 0; i < src->m_SDEXSYMS.size(); ++i) { + CJBig2_Image* image = src->m_SDEXSYMS.get(i); + dst->m_SDEXSYMS.push_back(image ? new CJBig2_Image(*image) : nullptr); } return dst; } - -CJBig2_SymbolDict::~CJBig2_SymbolDict() { - if (SDEXSYMS) { - for (FX_DWORD i = 0; i < SDNUMEXSYMS; i++) { - delete SDEXSYMS[i]; - } - FX_Free(SDEXSYMS); - } - if (m_bContextRetained) { - FX_Free(m_gbContext); - FX_Free(m_grContext); - } -} diff --git a/core/src/fxcodec/jbig2/JBig2_SymbolDict.h b/core/src/fxcodec/jbig2/JBig2_SymbolDict.h index c8e39dc845..577bfbc2f2 100644 --- a/core/src/fxcodec/jbig2/JBig2_SymbolDict.h +++ b/core/src/fxcodec/jbig2/JBig2_SymbolDict.h @@ -9,9 +9,10 @@ #include "../../../../third_party/base/nonstd_unique_ptr.h" #include "../../../include/fxcrt/fx_basic.h" -#include "JBig2_ArithDecoder.h" +#include "JBig2_List.h" class CJBig2_Image; +struct JBig2ArithCtx; class CJBig2_SymbolDict { public: @@ -20,12 +21,19 @@ class CJBig2_SymbolDict { nonstd::unique_ptr<CJBig2_SymbolDict> DeepCopy() const; + // Takes ownership of |image|. + void AddImage(CJBig2_Image* image) { m_SDEXSYMS.push_back(image); } + + size_t NumImages() const { return m_SDEXSYMS.size(); } + CJBig2_Image* GetImage(size_t index) const { return m_SDEXSYMS.get(index); } + public: - FX_DWORD SDNUMEXSYMS; - CJBig2_Image** SDEXSYMS; FX_BOOL m_bContextRetained; JBig2ArithCtx* m_gbContext; JBig2ArithCtx* m_grContext; + + private: + CJBig2_List<CJBig2_Image> m_SDEXSYMS; }; #endif // CORE_SRC_FXCODEC_JBIG2_JBIG2_SYMBOLDICT_H_ |