Fix #107493: Auto rotate videos fix #115661
|
@ -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
|
||||
|
||||
/* perform rotation */
|
||||
if (theta == -90) {
|
||||
|
|
|
@ -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
Sergey Sharybin
commented
Reduce the scope of variables. So instead of defining them in the beginning of the function define close to where you use htem. Examples:
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
Sergey Sharybin
commented
`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--) {
|
||||
Sergey Sharybin
commented
You can duplicate just the data, and use that as a const-source , and write the rotated result directly to the 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.
ErikHK
commented
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
const double theta = av_display_rotation_get((int32_t *)displaymatrix);