Fix #107493: Auto rotate videos fix #115661

Open
ErikHK wants to merge 7 commits from ErikHK/blender:auto_rotate_video into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 17 additions and 28 deletions
Showing only changes of commit 68f1246785 - Show all commits

View File

@ -886,9 +886,7 @@ static void ffmpeg_postprocess(anim *anim, AVFrame *input, ImBuf *ibuf)
if (displaymatrix == nullptr)
return;
double theta = 0;
theta = av_display_rotation_get((int32_t *)displaymatrix);
const double theta = av_display_rotation_get((int32_t *)displaymatrix);
ErikHK marked this conversation as resolved Outdated

const double theta = av_display_rotation_get((int32_t *)displaymatrix);

`const double theta = av_display_rotation_get((int32_t *)displaymatrix);`
/* perform rotation */
if (theta == -90) {

View File

@ -111,38 +111,29 @@ void IMB_flipx(ImBuf *ibuf)
void IMB_rotate90(ImBuf *ibuf)
{
ImBuf *tbuf;
int x, y;
uint *rect, *frect, *ibufrect;
int skip;
ibufrect = (uint *)ibuf->byte_buffer.data;
if (ibuf == 0)
return;
if (ibufrect == 0)
if (ibuf == nullptr)
return;
ErikHK marked this conversation as resolved
Review

Reduce the scope of variables. So instead of defining them in the beginning of the function define close to where you use htem. Examples:

  • ImBuf *tbuf = IMB_allocImBuf(ibuf->y, ibuf->x, 32, IB_rect);
  • for (int y = tbuf->y - 1; y >= 0; y--) {
Reduce the scope of variables. So instead of defining them in the beginning of the function define close to where you use htem. Examples: - `ImBuf *tbuf = IMB_allocImBuf(ibuf->y, ibuf->x, 32, IB_rect);` - `for (int y = tbuf->y - 1; y >= 0; y--) {`
tbuf = IMB_allocImBuf(ibuf->y, ibuf->x, 32, IB_rect);
if (tbuf == 0)
return;
/* create a temporary copy of the image */
uint8_t *imgdata = (uint8_t *)malloc(ibuf->x * ibuf->y * sizeof(uint));
memcpy(imgdata, ibuf->byte_buffer.data, ibuf->x * ibuf->y * sizeof(uint));
frect = (uint *)tbuf->byte_buffer.data;
uint *imgdatarect = (uint *)imgdata;
ErikHK marked this conversation as resolved Outdated

nullptr instead of 0.

`nullptr` instead of `0`.
uint *ibufrect = (uint *)ibuf->byte_buffer.data;
int skip = ibuf->x;
skip = tbuf->y;
for (y = tbuf->y - 1; y >= 0; y--) {
rect = ibufrect + y;
for (x = tbuf->x; x > 0; x--) {
*frect++ = *rect;
uint *rect;
for (int y = ibuf->x - 1; y >= 0; y--) {

You can duplicate just the data, and use that as a const-source , and write the rotated result directly to the ibuf->byte_buffer. This way you wouldn't need the extra memcpy after the loop.

You can duplicate just the data, and use that as a const-source , and write the rotated result directly to the `ibuf->byte_buffer`. This way you wouldn't need the extra `memcpy` after the loop.

Thanks for the tip! I think I solved it in the way you suggested, but since I'm not great at memory handling and stuff in C it would be nice if you could take a look at it :)

Thanks for the tip! I think I solved it in the way you suggested, but since I'm not great at memory handling and stuff in C it would be nice if you could take a look at it :)
rect = imgdatarect + y;
for (int x = ibuf->y; x > 0; x--) {
*ibufrect++ = *rect;
rect += skip;
}
}
memcpy(ibufrect, tbuf->byte_buffer.data, ibuf->x * ibuf->y * sizeof(uint));
x = ibuf->x;
ibuf->x = ibuf->y;
ibuf->y = x;
/* swap width and height of ibuf */
SWAP(int, ibuf->x, ibuf->y);
IMB_freeImBuf(tbuf);
/* free temporary copy of image */
free(imgdata);
}