diff options
author | Lei Zhang <thestig@chromium.org> | 2018-08-13 20:36:16 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-08-13 20:36:16 +0000 |
commit | d801c9c9caddf3941f6844fab58b19261d7d3cad (patch) | |
tree | 745db126f620e06dadab32fd71ead7bc8ca2dede /core/fxcodec/codec/cfx_codec_memory.cpp | |
parent | 30029419ad4b9e5cd382767a8645677afbeff7fd (diff) | |
download | pdfium-d801c9c9caddf3941f6844fab58b19261d7d3cad.tar.xz |
Implement CFX_CodecMemory.
This class is much simpler than CFX_MemoryStream and does only what
CFX_BmpDecompressor and CFX_GifContext needs. Swap out CFX_MemoryStream
and remove CFX_MemoryStream::Seek().
BUG=pdfium:263
Change-Id: Ifd8ce4d2b6c9fedd6ec842d46f54fc8e654fbca7
Reviewed-on: https://pdfium-review.googlesource.com/39880
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fxcodec/codec/cfx_codec_memory.cpp')
-rw-r--r-- | core/fxcodec/codec/cfx_codec_memory.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/core/fxcodec/codec/cfx_codec_memory.cpp b/core/fxcodec/codec/cfx_codec_memory.cpp new file mode 100644 index 0000000000..8eac02c9ee --- /dev/null +++ b/core/fxcodec/codec/cfx_codec_memory.cpp @@ -0,0 +1,30 @@ +// Copyright 2018 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. + +#include "core/fxcodec/codec/cfx_codec_memory.h" + +#include <algorithm> + +CFX_CodecMemory::CFX_CodecMemory(uint8_t* buffer, size_t size) + : buffer_(buffer), size_(size) {} + +CFX_CodecMemory::~CFX_CodecMemory() = default; + +bool CFX_CodecMemory::Seek(size_t pos) { + if (pos > size_) + return false; + + pos_ = pos; + return true; +} + +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_); + memcpy(buffer, &buffer_[pos_], bytes_to_read); + pos_ += bytes_to_read; + return bytes_to_read; +} |