Fix macOS arm crash in scaling images with ffmpeg

Ref T78710
This commit is contained in:
Brecht Van Lommel 2021-04-29 14:57:23 +02:00
parent a5fdff26b1
commit db021ee2ea
Notes: blender-bot 2023-02-13 23:16:02 +01:00
Referenced by issue #93588, Imported video is wrong orientation on Mac OS Arm.
Referenced by issue #78710, macOS: Support arm64
1 changed files with 54 additions and 50 deletions

View File

@ -815,66 +815,70 @@ static void ffmpeg_postprocess(struct anim *anim)
anim->y);
}
if (ENDIAN_ORDER == B_ENDIAN) {
int *dstStride = anim->pFrameRGB->linesize;
uint8_t **dst = anim->pFrameRGB->data;
const int dstStride2[4] = {dstStride[0], 0, 0, 0};
uint8_t *dst2[4] = {dst[0], 0, 0, 0};
int x, y, h, w;
unsigned char *bottom;
unsigned char *top;
# if defined(__x86_64__) || defined(_M_X64)
/* Scale and flip image over Y axis in one go, using negative strides.
* This doesn't work with arm/powerpc though and may be misusing the API.
* Limit it x86_64 where it appears to work.
* http://trac.ffmpeg.org/ticket/9060 */
int *dstStride = anim->pFrameRGB->linesize;
uint8_t **dst = anim->pFrameRGB->data;
const int dstStride2[4] = {-dstStride[0], 0, 0, 0};
uint8_t *dst2[4] = {dst[0] + (anim->y - 1) * dstStride[0], 0, 0, 0};
sws_scale(anim->img_convert_ctx,
(const uint8_t *const *)input->data,
input->linesize,
0,
anim->y,
dst2,
dstStride2);
sws_scale(anim->img_convert_ctx,
(const uint8_t *const *)input->data,
input->linesize,
0,
anim->y,
dst2,
dstStride2);
# else
/* Scale with swscale then flip image over Y axis. */
int *dstStride = anim->pFrameRGB->linesize;
uint8_t **dst = anim->pFrameRGB->data;
const int dstStride2[4] = {dstStride[0], 0, 0, 0};
uint8_t *dst2[4] = {dst[0], 0, 0, 0};
int x, y, h, w;
unsigned char *bottom;
unsigned char *top;
bottom = (unsigned char *)ibuf->rect;
top = bottom + ibuf->x * (ibuf->y - 1) * 4;
sws_scale(anim->img_convert_ctx,
(const uint8_t *const *)input->data,
input->linesize,
0,
anim->y,
dst2,
dstStride2);
h = (ibuf->y + 1) / 2;
w = ibuf->x;
bottom = (unsigned char *)ibuf->rect;
top = bottom + ibuf->x * (ibuf->y - 1) * 4;
for (y = 0; y < h; y++) {
unsigned char tmp[4];
unsigned int *tmp_l = (unsigned int *)tmp;
h = (ibuf->y + 1) / 2;
w = ibuf->x;
for (x = 0; x < w; x++) {
tmp[0] = bottom[0];
tmp[1] = bottom[1];
tmp[2] = bottom[2];
tmp[3] = bottom[3];
for (y = 0; y < h; y++) {
unsigned char tmp[4];
unsigned int *tmp_l = (unsigned int *)tmp;
bottom[0] = top[0];
bottom[1] = top[1];
bottom[2] = top[2];
bottom[3] = top[3];
for (x = 0; x < w; x++) {
tmp[0] = bottom[0];
tmp[1] = bottom[1];
tmp[2] = bottom[2];
tmp[3] = bottom[3];
*(unsigned int *)top = *tmp_l;
bottom[0] = top[0];
bottom[1] = top[1];
bottom[2] = top[2];
bottom[3] = top[3];
bottom += 4;
top += 4;
}
top -= 8 * w;
*(unsigned int *)top = *tmp_l;
bottom += 4;
top += 4;
}
top -= 8 * w;
}
else {
int *dstStride = anim->pFrameRGB->linesize;
uint8_t **dst = anim->pFrameRGB->data;
const int dstStride2[4] = {-dstStride[0], 0, 0, 0};
uint8_t *dst2[4] = {dst[0] + (anim->y - 1) * dstStride[0], 0, 0, 0};
sws_scale(anim->img_convert_ctx,
(const uint8_t *const *)input->data,
input->linesize,
0,
anim->y,
dst2,
dstStride2);
}
# endif
if (need_aligned_ffmpeg_buffer(anim)) {
uint8_t *src = anim->pFrameRGB->data[0];