-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathitemdatabox.cpp
72 lines (60 loc) · 1.86 KB
/
itemdatabox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* This file is part of Nokia HEIF library
*
* Copyright (c) 2015-2025 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
*
* Contact: [email protected]
*
* This software, including documentation, is protected by copyright controlled by Nokia Corporation and/ or its
* subsidiaries. All rights are reserved.
*
* Copying, including reproducing, storing, adapting or translating, any or all of this material requires the prior
* written consent of Nokia.
*/
#include "itemdatabox.hpp"
#include <cstring>
ItemDataBox::ItemDataBox()
: Box("idat")
, mData()
{
}
bool ItemDataBox::read(Vector<std::uint8_t>& destination, const std::uint64_t offset, const std::uint64_t length) const
{
if ((offset + length) > mData.size())
{
return false;
}
destination.insert(destination.end(), mData.cbegin() + static_cast<int64_t>(offset),
mData.cbegin() + static_cast<int64_t>(offset + length));
return true;
}
bool ItemDataBox::read(uint8_t* destination, const std::uint64_t offset, const std::uint64_t length) const
{
if ((offset + length) > mData.size() || destination == nullptr)
{
return false;
}
std::memcpy(destination, mData.data() + static_cast<int64_t>(offset), length);
return true;
}
std::uint64_t ItemDataBox::addData(const Vector<std::uint8_t>& data)
{
const std::uint64_t offset = mData.size();
mData.insert(mData.end(), data.cbegin(), data.cend());
return offset;
}
void ItemDataBox::writeBox(ISOBMFF::BitStream& bitstr) const
{
// Do not write an empty box at all
if (mData.size() == 0)
{
return;
}
writeBoxHeader(bitstr);
bitstr.write8BitsArray(mData, mData.size());
updateSize(bitstr);
}
void ItemDataBox::parseBox(ISOBMFF::BitStream& bitstr)
{
parseBoxHeader(bitstr);
bitstr.read8BitsArray(mData, bitstr.numBytesLeft());
}