summaryrefslogtreecommitdiff
path: root/src/j2k_transcode.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-04-16 22:07:10 +0200
committerCarl Hetherington <cth@carlh.net>2023-04-16 22:14:26 +0200
commitb0520d7a1bffaff1ca7161f5b7672f06b13808a1 (patch)
tree8b7777c6fc7fc6f2f36e85c60151031b8860a09b /src/j2k_transcode.cc
parent65d21ed2de3a76dc574c8ad111fc02d8f696fcd6 (diff)
Use a shared_ptr<vector> for ArrayData rather than a shared_array.
This is simpler and allows us to remove the hack of allocating some "maximum" buffer for incoming JPEG2000 data. It does mean that the buffer is zero-initialized before being written to, but hopefully that doesn't matter too much.
Diffstat (limited to 'src/j2k_transcode.cc')
-rw-r--r--src/j2k_transcode.cc21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/j2k_transcode.cc b/src/j2k_transcode.cc
index 686bc040..664d18a3 100644
--- a/src/j2k_transcode.cc
+++ b/src/j2k_transcode.cc
@@ -188,23 +188,14 @@ dcp::decompress_j2k (uint8_t const * data, int64_t size, int reduce)
class WriteBuffer
{
public:
-/* XXX: is there a better strategy for this? */
-#define MAX_J2K_SIZE (1024 * 1024 * 2)
- WriteBuffer ()
- : _data (shared_array<uint8_t>(new uint8_t[MAX_J2K_SIZE]), MAX_J2K_SIZE)
- , _offset (0)
- {
- _data.set_size (0);
- }
-
OPJ_SIZE_T write (void* buffer, OPJ_SIZE_T nb_bytes)
{
- DCP_ASSERT ((_offset + nb_bytes) < MAX_J2K_SIZE);
- memcpy (_data.data() + _offset, buffer, nb_bytes);
- _offset += nb_bytes;
- if (_offset > OPJ_SIZE_T(_data.size())) {
- _data.set_size (_offset);
+ auto const new_offset = _offset + nb_bytes;
+ if (new_offset > OPJ_SIZE_T(_data.size())) {
+ _data.set_size(new_offset);
}
+ memcpy(_data.data() + _offset, buffer, nb_bytes);
+ _offset = new_offset;
return nb_bytes;
}
@@ -221,7 +212,7 @@ public:
private:
ArrayData _data;
- OPJ_SIZE_T _offset;
+ OPJ_SIZE_T _offset = 0;
};