Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2021-04-29 15:57:23 +0300
committerBrecht Van Lommel <brecht@blender.org>2021-04-29 16:58:51 +0300
commitdb021ee2ea0355f0c1733e51e3ee7c54e6ca2a3e (patch)
tree246f862d463e07621d68808232a232f0d31ae2ef /source/blender/imbuf/intern/anim_movie.c
parenta5fdff26b1f3d9765fc28be780c281e90402fe85 (diff)
Fix macOS arm crash in scaling images with ffmpeg
Ref T78710
Diffstat (limited to 'source/blender/imbuf/intern/anim_movie.c')
-rw-r--r--source/blender/imbuf/intern/anim_movie.c120
1 files changed, 62 insertions, 58 deletions
diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c
index 6c63c1a1b5b..9e8224f58b2 100644
--- a/source/blender/imbuf/intern/anim_movie.c
+++ b/source/blender/imbuf/intern/anim_movie.c
@@ -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;
-
- sws_scale(anim->img_convert_ctx,
- (const uint8_t *const *)input->data,
- input->linesize,
- 0,
- anim->y,
- dst2,
- dstStride2);
-
- bottom = (unsigned char *)ibuf->rect;
- top = bottom + ibuf->x * (ibuf->y - 1) * 4;
-
- h = (ibuf->y + 1) / 2;
- w = ibuf->x;
-
- for (y = 0; y < h; y++) {
- unsigned char tmp[4];
- unsigned int *tmp_l = (unsigned int *)tmp;
-
- for (x = 0; x < w; x++) {
- tmp[0] = bottom[0];
- tmp[1] = bottom[1];
- tmp[2] = bottom[2];
- tmp[3] = bottom[3];
-
- bottom[0] = top[0];
- bottom[1] = top[1];
- bottom[2] = top[2];
- bottom[3] = top[3];
-
- *(unsigned int *)top = *tmp_l;
-
- bottom += 4;
- top += 4;
- }
- top -= 8 * w;
+# 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);
+# 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;
+
+ sws_scale(anim->img_convert_ctx,
+ (const uint8_t *const *)input->data,
+ input->linesize,
+ 0,
+ anim->y,
+ dst2,
+ dstStride2);
+
+ bottom = (unsigned char *)ibuf->rect;
+ top = bottom + ibuf->x * (ibuf->y - 1) * 4;
+
+ h = (ibuf->y + 1) / 2;
+ w = ibuf->x;
+
+ for (y = 0; y < h; y++) {
+ unsigned char tmp[4];
+ unsigned int *tmp_l = (unsigned int *)tmp;
+
+ for (x = 0; x < w; x++) {
+ tmp[0] = bottom[0];
+ tmp[1] = bottom[1];
+ tmp[2] = bottom[2];
+ tmp[3] = bottom[3];
+
+ bottom[0] = top[0];
+ bottom[1] = top[1];
+ bottom[2] = top[2];
+ bottom[3] = top[3];
+
+ *(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];