Skip to content

Commit e95dd76

Browse files
committed
Allocate the threadData array directly
The threadData array (formerly named tdArray) has a fixed size (i.e., the array does not grow or shrink while in use), so we can allocate the array directly. It is not necessary to define the array as avifArray. (cherry picked from commit c74189f)
1 parent d39a5de commit e95dd76

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/reformat.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,11 +1544,12 @@ avifResult avifImageYUVToRGB(const avifImage * image, avifRGBImage * rgb)
15441544
return avifImageYUVToRGBImpl(image, rgb, &state, alphaMultiplyMode);
15451545
}
15461546

1547-
AVIF_ARRAY_DECLARE(YUVToRGBThreadDataArray, YUVToRGBThreadData, threadData);
1548-
YUVToRGBThreadDataArray tdArray;
1549-
if (!avifArrayCreate(&tdArray, sizeof(YUVToRGBThreadData), jobs)) {
1547+
const size_t byteCount = sizeof(YUVToRGBThreadData) * jobs;
1548+
YUVToRGBThreadData * threadData = avifAlloc(byteCount);
1549+
if (!threadData) {
15501550
return AVIF_RESULT_OUT_OF_MEMORY;
15511551
}
1552+
memset(threadData, 0, byteCount);
15521553
int rowsPerJob = image->height / jobs;
15531554
if (rowsPerJob % 2) {
15541555
++rowsPerJob;
@@ -1557,7 +1558,7 @@ avifResult avifImageYUVToRGB(const avifImage * image, avifRGBImage * rgb)
15571558
int startRow = 0;
15581559
uint32_t i;
15591560
for (i = 0; i < jobs; ++i, startRow += rowsPerJob) {
1560-
YUVToRGBThreadData * tdata = &tdArray.threadData[i];
1561+
YUVToRGBThreadData * tdata = &threadData[i];
15611562
const avifCropRect rect = { .x = 0, .y = startRow, .width = image->width, .height = (i == jobs - 1) ? rowsForLastJob : rowsPerJob };
15621563
if (avifImageSetViewRect(&tdata->image, image, &rect) != AVIF_RESULT_OK) {
15631564
tdata->result = AVIF_RESULT_REFORMAT_FAILED;
@@ -1581,19 +1582,19 @@ avifResult avifImageYUVToRGB(const avifImage * image, avifRGBImage * rgb)
15811582
}
15821583
// If above loop ran successfully, Run the first job in the current thread.
15831584
if (i == jobs) {
1584-
avifImageYUVToRGBThreadWorker(&tdArray.threadData[0]);
1585+
avifImageYUVToRGBThreadWorker(&threadData[0]);
15851586
}
15861587
avifResult result = AVIF_RESULT_OK;
15871588
for (i = 0; i < jobs; ++i) {
1588-
YUVToRGBThreadData * tdata = &tdArray.threadData[i];
1589+
YUVToRGBThreadData * tdata = &threadData[i];
15891590
if (tdata->threadCreated && !avifJoinYUVToRGBThread(tdata)) {
15901591
result = AVIF_RESULT_REFORMAT_FAILED;
15911592
}
15921593
if (tdata->result != AVIF_RESULT_OK) {
15931594
result = tdata->result;
15941595
}
15951596
}
1596-
avifArrayDestroy(&tdArray);
1597+
avifFree(threadData);
15971598
return result;
15981599
}
15991600

0 commit comments

Comments
 (0)