forked from AOMediaCodec/libavif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrawdata.c
38 lines (33 loc) · 880 Bytes
/
rawdata.c
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
// Copyright 2019 Joe Drago. All rights reserved.
// SPDX-License-Identifier: BSD-2-Clause
#include "avif/avif.h"
#include <string.h>
void avifRWDataRealloc(avifRWData * raw, size_t newSize)
{
if (raw->size != newSize) {
uint8_t * old = raw->data;
size_t oldSize = raw->size;
raw->data = avifAlloc(newSize);
raw->size = newSize;
if (oldSize) {
size_t bytesToCopy = (oldSize < raw->size) ? oldSize : raw->size;
memcpy(raw->data, old, bytesToCopy);
avifFree(old);
}
}
}
void avifRWDataSet(avifRWData * raw, const uint8_t * data, size_t len)
{
if (len) {
avifRWDataRealloc(raw, len);
memcpy(raw->data, data, len);
} else {
avifFree(raw);
}
}
void avifRWDataFree(avifRWData * raw)
{
avifFree(raw->data);
raw->data = NULL;
raw->size = 0;
}