summaryrefslogtreecommitdiff
path: root/core/fxcodec/codec
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-08-24 19:45:09 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-24 19:45:09 +0000
commit16d18d935d055b74e05f615c0325318a329a7fe1 (patch)
treebce3c35b6db03cedd537a67a28cf91eb0b502b1c /core/fxcodec/codec
parent1cb4d6b14cc9375dc04f57d3f2149eccb9e327a8 (diff)
downloadpdfium-16d18d935d055b74e05f615c0325318a329a7fe1.tar.xz
Use span<uint8_t> in more fxcodec code.
There are also small tweaks in tests to ensure strict order of stack variable lifetimes. Change-Id: Ic9d5c6a2bdd378b517be627f8e29f725bafdc2ad Reviewed-on: https://pdfium-review.googlesource.com/41310 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcodec/codec')
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.cpp7
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.h3
-rw-r--r--core/fxcodec/codec/ccodec_gifmodule.cpp7
-rw-r--r--core/fxcodec/codec/ccodec_gifmodule.h3
-rw-r--r--core/fxcodec/codec/cfx_codec_memory.cpp8
-rw-r--r--core/fxcodec/codec/cfx_codec_memory.h12
-rw-r--r--core/fxcodec/codec/fx_codec_progress.cpp10
7 files changed, 23 insertions, 27 deletions
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.cpp b/core/fxcodec/codec/ccodec_bmpmodule.cpp
index f4bfa010dc..75e59edf2b 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.cpp
+++ b/core/fxcodec/codec/ccodec_bmpmodule.cpp
@@ -69,9 +69,6 @@ FX_FILESIZE CCodec_BmpModule::GetAvailInput(Context* pContext,
return ctx->m_Bmp.GetAvailInput(avail_buf_ptr);
}
-void CCodec_BmpModule::Input(Context* pContext,
- uint8_t* src_buf,
- uint32_t src_size) {
- auto* ctx = static_cast<CFX_BmpContext*>(pContext);
- ctx->m_Bmp.SetInputBuffer(src_buf, src_size);
+void CCodec_BmpModule::Input(Context* pContext, pdfium::span<uint8_t> src_buf) {
+ static_cast<CFX_BmpContext*>(pContext)->m_Bmp.SetInputBuffer(src_buf);
}
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.h b/core/fxcodec/codec/ccodec_bmpmodule.h
index ca2340d978..42d686e6f3 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.h
+++ b/core/fxcodec/codec/ccodec_bmpmodule.h
@@ -12,6 +12,7 @@
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/unowned_ptr.h"
+#include "third_party/base/span.h"
class CFX_DIBAttribute;
@@ -34,7 +35,7 @@ class CCodec_BmpModule {
std::unique_ptr<Context> Start(Delegate* pDelegate);
FX_FILESIZE GetAvailInput(Context* pContext, uint8_t** avail_buf_ptr);
- void Input(Context* pContext, uint8_t* src_buf, uint32_t src_size);
+ void Input(Context* pContext, pdfium::span<uint8_t> src_buf);
int32_t ReadHeader(Context* pContext,
int32_t* width,
int32_t* height,
diff --git a/core/fxcodec/codec/ccodec_gifmodule.cpp b/core/fxcodec/codec/ccodec_gifmodule.cpp
index 7bf216e393..872d90f770 100644
--- a/core/fxcodec/codec/ccodec_gifmodule.cpp
+++ b/core/fxcodec/codec/ccodec_gifmodule.cpp
@@ -72,9 +72,6 @@ uint32_t CCodec_GifModule::GetAvailInput(Context* pContext,
return context->GetAvailInput(avail_buf_ptr);
}
-void CCodec_GifModule::Input(Context* pContext,
- const uint8_t* src_buf,
- uint32_t src_size) {
- auto* context = static_cast<CFX_GifContext*>(pContext);
- context->SetInputBuffer((uint8_t*)src_buf, src_size);
+void CCodec_GifModule::Input(Context* pContext, pdfium::span<uint8_t> src_buf) {
+ static_cast<CFX_GifContext*>(pContext)->SetInputBuffer(src_buf);
}
diff --git a/core/fxcodec/codec/ccodec_gifmodule.h b/core/fxcodec/codec/ccodec_gifmodule.h
index cbc8fc6815..f14665ba2c 100644
--- a/core/fxcodec/codec/ccodec_gifmodule.h
+++ b/core/fxcodec/codec/ccodec_gifmodule.h
@@ -13,6 +13,7 @@
#include "core/fxcodec/gif/cfx_gif.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_system.h"
+#include "third_party/base/span.h"
class CFX_DIBAttribute;
@@ -43,7 +44,7 @@ class CCodec_GifModule {
std::unique_ptr<Context> Start(Delegate* pDelegate);
uint32_t GetAvailInput(Context* context, uint8_t** avail_buf_ptr);
- void Input(Context* context, const uint8_t* src_buf, uint32_t src_size);
+ void Input(Context* context, pdfium::span<uint8_t> src_buf);
CFX_GifDecodeStatus ReadHeader(Context* context,
int* width,
int* height,
diff --git a/core/fxcodec/codec/cfx_codec_memory.cpp b/core/fxcodec/codec/cfx_codec_memory.cpp
index 8eac02c9ee..b8cf97b098 100644
--- a/core/fxcodec/codec/cfx_codec_memory.cpp
+++ b/core/fxcodec/codec/cfx_codec_memory.cpp
@@ -6,13 +6,13 @@
#include <algorithm>
-CFX_CodecMemory::CFX_CodecMemory(uint8_t* buffer, size_t size)
- : buffer_(buffer), size_(size) {}
+CFX_CodecMemory::CFX_CodecMemory(pdfium::span<uint8_t> buffer)
+ : buffer_(buffer) {}
CFX_CodecMemory::~CFX_CodecMemory() = default;
bool CFX_CodecMemory::Seek(size_t pos) {
- if (pos > size_)
+ if (pos > buffer_.size())
return false;
pos_ = pos;
@@ -23,7 +23,7 @@ size_t CFX_CodecMemory::ReadBlock(void* buffer, size_t size) {
if (!buffer || !size || IsEOF())
return 0;
- size_t bytes_to_read = std::min(size, size_ - pos_);
+ size_t bytes_to_read = std::min(size, buffer_.size() - pos_);
memcpy(buffer, &buffer_[pos_], bytes_to_read);
pos_ += bytes_to_read;
return bytes_to_read;
diff --git a/core/fxcodec/codec/cfx_codec_memory.h b/core/fxcodec/codec/cfx_codec_memory.h
index 6eee72a32d..e726dc5320 100644
--- a/core/fxcodec/codec/cfx_codec_memory.h
+++ b/core/fxcodec/codec/cfx_codec_memory.h
@@ -6,27 +6,27 @@
#define CORE_FXCODEC_CODEC_CFX_CODEC_MEMORY_H_
#include "core/fxcrt/retain_ptr.h"
+#include "third_party/base/span.h"
class CFX_CodecMemory : public Retainable {
public:
template <typename T, typename... Args>
friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
- uint8_t* GetBuffer() { return buffer_; }
- size_t GetSize() const { return size_; }
+ uint8_t* GetBuffer() { return buffer_.data(); }
+ size_t GetSize() const { return buffer_.size(); }
size_t GetPosition() const { return pos_; }
- bool IsEOF() const { return pos_ >= size_; }
+ bool IsEOF() const { return pos_ >= buffer_.size(); }
size_t ReadBlock(void* buffer, size_t size);
// Sets the cursor position to |pos| if possible.
bool Seek(size_t pos);
private:
- CFX_CodecMemory(uint8_t* buffer, size_t size);
+ explicit CFX_CodecMemory(pdfium::span<uint8_t> buffer);
~CFX_CodecMemory() override;
- uint8_t* const buffer_;
- const size_t size_;
+ pdfium::span<uint8_t> const buffer_;
size_t pos_ = 0;
};
diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp
index 8ebb119dff..c5fb1e3a13 100644
--- a/core/fxcodec/codec/fx_codec_progress.cpp
+++ b/core/fxcodec/codec/fx_codec_progress.cpp
@@ -765,7 +765,7 @@ bool CCodec_ProgressiveDecoder::BmpDetectImageType(CFX_DIBAttribute* pAttribute,
}
m_offSet += size;
- pBmpModule->Input(m_pBmpContext.get(), m_pSrcBuf, size);
+ pBmpModule->Input(m_pBmpContext.get(), {m_pSrcBuf, size});
std::vector<uint32_t> palette;
int32_t readResult = pBmpModule->ReadHeader(
m_pBmpContext.get(), &m_SrcWidth, &m_SrcHeight, &m_BmpIsTopBottom,
@@ -873,7 +873,7 @@ bool CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule,
return false;
}
m_offSet += dwSize;
- pBmpModule->Input(m_pBmpContext.get(), m_pSrcBuf, dwSize + dwAvail);
+ pBmpModule->Input(m_pBmpContext.get(), {m_pSrcBuf, dwSize + dwAvail});
return true;
}
@@ -969,8 +969,8 @@ bool CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule,
}
m_offSet += dwAmountToFetchFromFile;
- pGifModule->Input(m_pGifContext.get(), m_pSrcBuf,
- dwAmountToFetchFromFile + dwUnusedBuffer);
+ pGifModule->Input(m_pGifContext.get(),
+ {m_pSrcBuf, dwAmountToFetchFromFile + dwUnusedBuffer});
m_InvalidateGifBuffer = false;
return true;
}
@@ -989,7 +989,7 @@ bool CCodec_ProgressiveDecoder::GifDetectImageType(CFX_DIBAttribute* pAttribute,
return false;
}
m_offSet += size;
- pGifModule->Input(m_pGifContext.get(), m_pSrcBuf, size);
+ pGifModule->Input(m_pGifContext.get(), {m_pSrcBuf, size});
m_SrcComponents = 1;
CFX_GifDecodeStatus readResult = pGifModule->ReadHeader(
m_pGifContext.get(), &m_SrcWidth, &m_SrcHeight, &m_GifPltNumber,