2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2002-10-12 11:37:38 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
* rotate.c
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup imbuf
|
2011-02-27 20:23:21 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2010-08-16 05:46:10 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "imbuf.h"
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
void IMB_flipy(struct ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int x, y;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (ibuf == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ibuf->rect) {
|
|
|
|
unsigned int *top, *bottom, *line;
|
== Sequencer ==
Attention! Rather large sequencer rewrite:
* Implemented layer blending using implicit effects. (works like layers
in "The Gimp" or Photoshop.)
* Fixed Space-Bar start-stop in preview windows.
You can start playback using spacebar within a preview-window and it _works_!
* Fixed Flip Y (didn't work for float)
* Fixed premul (didn't work for float)
* Added IPOs to _all_ tracks. In blend-mode REPLACE it drives the
"mul"-parameter in all other blend modes it drives the effect.
* you can meta single tracks.
* moved "mute track" from "M" to "Shift-M"
* added "Shift-L" for "lock track"
* changed inner workings for Metas. Now all ImBufs have to use the
reference counting mechanism. (Only interesting for coders :)
!!! Really important change, that affects current files!
Since you can mute tracks and now there is real layer blending capabilities
in place, I changed the silly behaviour that chose the output track.
Old behaviour: if we have an effect track visible, use the uppermost effect
track. If there is _no_ effect track visible, use the lowest input track.
New behaviour: always use the uppermost track. With blend modes active:
work our way down starting from the uppermost track to the first
"replace"-mode track. This is the way the gimp, photoshop, basically _all_
other applications work...
So if this change ruins your day: please try to fix your files using
"mute". If this doesn't work out, I can still restore the old behaviour,
but I really hope, that this is _not_ necessary!
Rational: most people won't get affected by this change, since you can't
really do anything usefull with the (old) sequencer without at least one
effect track and then you are on the safe side...
2008-01-01 11:44:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
x = ibuf->x;
|
|
|
|
y = ibuf->y;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
top = ibuf->rect;
|
|
|
|
bottom = top + ((y - 1) * x);
|
|
|
|
line = MEM_mallocN(x * sizeof(int), "linebuf");
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
y >>= 1;
|
== Sequencer ==
Attention! Rather large sequencer rewrite:
* Implemented layer blending using implicit effects. (works like layers
in "The Gimp" or Photoshop.)
* Fixed Space-Bar start-stop in preview windows.
You can start playback using spacebar within a preview-window and it _works_!
* Fixed Flip Y (didn't work for float)
* Fixed premul (didn't work for float)
* Added IPOs to _all_ tracks. In blend-mode REPLACE it drives the
"mul"-parameter in all other blend modes it drives the effect.
* you can meta single tracks.
* moved "mute track" from "M" to "Shift-M"
* added "Shift-L" for "lock track"
* changed inner workings for Metas. Now all ImBufs have to use the
reference counting mechanism. (Only interesting for coders :)
!!! Really important change, that affects current files!
Since you can mute tracks and now there is real layer blending capabilities
in place, I changed the silly behaviour that chose the output track.
Old behaviour: if we have an effect track visible, use the uppermost effect
track. If there is _no_ effect track visible, use the lowest input track.
New behaviour: always use the uppermost track. With blend modes active:
work our way down starting from the uppermost track to the first
"replace"-mode track. This is the way the gimp, photoshop, basically _all_
other applications work...
So if this change ruins your day: please try to fix your files using
"mute". If this doesn't work out, I can still restore the old behaviour,
but I really hope, that this is _not_ necessary!
Rational: most people won't get affected by this change, since you can't
really do anything usefull with the (old) sequencer without at least one
effect track and then you are on the safe side...
2008-01-01 11:44:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (; y > 0; y--) {
|
|
|
|
memcpy(line, top, x * sizeof(int));
|
|
|
|
memcpy(top, bottom, x * sizeof(int));
|
|
|
|
memcpy(bottom, line, x * sizeof(int));
|
|
|
|
bottom -= x;
|
|
|
|
top += x;
|
|
|
|
}
|
== Sequencer ==
Attention! Rather large sequencer rewrite:
* Implemented layer blending using implicit effects. (works like layers
in "The Gimp" or Photoshop.)
* Fixed Space-Bar start-stop in preview windows.
You can start playback using spacebar within a preview-window and it _works_!
* Fixed Flip Y (didn't work for float)
* Fixed premul (didn't work for float)
* Added IPOs to _all_ tracks. In blend-mode REPLACE it drives the
"mul"-parameter in all other blend modes it drives the effect.
* you can meta single tracks.
* moved "mute track" from "M" to "Shift-M"
* added "Shift-L" for "lock track"
* changed inner workings for Metas. Now all ImBufs have to use the
reference counting mechanism. (Only interesting for coders :)
!!! Really important change, that affects current files!
Since you can mute tracks and now there is real layer blending capabilities
in place, I changed the silly behaviour that chose the output track.
Old behaviour: if we have an effect track visible, use the uppermost effect
track. If there is _no_ effect track visible, use the lowest input track.
New behaviour: always use the uppermost track. With blend modes active:
work our way down starting from the uppermost track to the first
"replace"-mode track. This is the way the gimp, photoshop, basically _all_
other applications work...
So if this change ruins your day: please try to fix your files using
"mute". If this doesn't work out, I can still restore the old behaviour,
but I really hope, that this is _not_ necessary!
Rational: most people won't get affected by this change, since you can't
really do anything usefull with the (old) sequencer without at least one
effect track and then you are on the safe side...
2008-01-01 11:44:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(line);
|
|
|
|
}
|
== Sequencer ==
Attention! Rather large sequencer rewrite:
* Implemented layer blending using implicit effects. (works like layers
in "The Gimp" or Photoshop.)
* Fixed Space-Bar start-stop in preview windows.
You can start playback using spacebar within a preview-window and it _works_!
* Fixed Flip Y (didn't work for float)
* Fixed premul (didn't work for float)
* Added IPOs to _all_ tracks. In blend-mode REPLACE it drives the
"mul"-parameter in all other blend modes it drives the effect.
* you can meta single tracks.
* moved "mute track" from "M" to "Shift-M"
* added "Shift-L" for "lock track"
* changed inner workings for Metas. Now all ImBufs have to use the
reference counting mechanism. (Only interesting for coders :)
!!! Really important change, that affects current files!
Since you can mute tracks and now there is real layer blending capabilities
in place, I changed the silly behaviour that chose the output track.
Old behaviour: if we have an effect track visible, use the uppermost effect
track. If there is _no_ effect track visible, use the lowest input track.
New behaviour: always use the uppermost track. With blend modes active:
work our way down starting from the uppermost track to the first
"replace"-mode track. This is the way the gimp, photoshop, basically _all_
other applications work...
So if this change ruins your day: please try to fix your files using
"mute". If this doesn't work out, I can still restore the old behaviour,
but I really hope, that this is _not_ necessary!
Rational: most people won't get affected by this change, since you can't
really do anything usefull with the (old) sequencer without at least one
effect track and then you are on the safe side...
2008-01-01 11:44:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ibuf->rect_float) {
|
|
|
|
float *topf = NULL, *bottomf = NULL, *linef = NULL;
|
== Sequencer ==
Attention! Rather large sequencer rewrite:
* Implemented layer blending using implicit effects. (works like layers
in "The Gimp" or Photoshop.)
* Fixed Space-Bar start-stop in preview windows.
You can start playback using spacebar within a preview-window and it _works_!
* Fixed Flip Y (didn't work for float)
* Fixed premul (didn't work for float)
* Added IPOs to _all_ tracks. In blend-mode REPLACE it drives the
"mul"-parameter in all other blend modes it drives the effect.
* you can meta single tracks.
* moved "mute track" from "M" to "Shift-M"
* added "Shift-L" for "lock track"
* changed inner workings for Metas. Now all ImBufs have to use the
reference counting mechanism. (Only interesting for coders :)
!!! Really important change, that affects current files!
Since you can mute tracks and now there is real layer blending capabilities
in place, I changed the silly behaviour that chose the output track.
Old behaviour: if we have an effect track visible, use the uppermost effect
track. If there is _no_ effect track visible, use the lowest input track.
New behaviour: always use the uppermost track. With blend modes active:
work our way down starting from the uppermost track to the first
"replace"-mode track. This is the way the gimp, photoshop, basically _all_
other applications work...
So if this change ruins your day: please try to fix your files using
"mute". If this doesn't work out, I can still restore the old behaviour,
but I really hope, that this is _not_ necessary!
Rational: most people won't get affected by this change, since you can't
really do anything usefull with the (old) sequencer without at least one
effect track and then you are on the safe side...
2008-01-01 11:44:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
x = ibuf->x;
|
|
|
|
y = ibuf->y;
|
== Sequencer ==
Attention! Rather large sequencer rewrite:
* Implemented layer blending using implicit effects. (works like layers
in "The Gimp" or Photoshop.)
* Fixed Space-Bar start-stop in preview windows.
You can start playback using spacebar within a preview-window and it _works_!
* Fixed Flip Y (didn't work for float)
* Fixed premul (didn't work for float)
* Added IPOs to _all_ tracks. In blend-mode REPLACE it drives the
"mul"-parameter in all other blend modes it drives the effect.
* you can meta single tracks.
* moved "mute track" from "M" to "Shift-M"
* added "Shift-L" for "lock track"
* changed inner workings for Metas. Now all ImBufs have to use the
reference counting mechanism. (Only interesting for coders :)
!!! Really important change, that affects current files!
Since you can mute tracks and now there is real layer blending capabilities
in place, I changed the silly behaviour that chose the output track.
Old behaviour: if we have an effect track visible, use the uppermost effect
track. If there is _no_ effect track visible, use the lowest input track.
New behaviour: always use the uppermost track. With blend modes active:
work our way down starting from the uppermost track to the first
"replace"-mode track. This is the way the gimp, photoshop, basically _all_
other applications work...
So if this change ruins your day: please try to fix your files using
"mute". If this doesn't work out, I can still restore the old behaviour,
but I really hope, that this is _not_ necessary!
Rational: most people won't get affected by this change, since you can't
really do anything usefull with the (old) sequencer without at least one
effect track and then you are on the safe side...
2008-01-01 11:44:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
topf = ibuf->rect_float;
|
|
|
|
bottomf = topf + 4 * ((y - 1) * x);
|
|
|
|
linef = MEM_mallocN(4 * x * sizeof(float), "linebuff");
|
== Sequencer ==
Attention! Rather large sequencer rewrite:
* Implemented layer blending using implicit effects. (works like layers
in "The Gimp" or Photoshop.)
* Fixed Space-Bar start-stop in preview windows.
You can start playback using spacebar within a preview-window and it _works_!
* Fixed Flip Y (didn't work for float)
* Fixed premul (didn't work for float)
* Added IPOs to _all_ tracks. In blend-mode REPLACE it drives the
"mul"-parameter in all other blend modes it drives the effect.
* you can meta single tracks.
* moved "mute track" from "M" to "Shift-M"
* added "Shift-L" for "lock track"
* changed inner workings for Metas. Now all ImBufs have to use the
reference counting mechanism. (Only interesting for coders :)
!!! Really important change, that affects current files!
Since you can mute tracks and now there is real layer blending capabilities
in place, I changed the silly behaviour that chose the output track.
Old behaviour: if we have an effect track visible, use the uppermost effect
track. If there is _no_ effect track visible, use the lowest input track.
New behaviour: always use the uppermost track. With blend modes active:
work our way down starting from the uppermost track to the first
"replace"-mode track. This is the way the gimp, photoshop, basically _all_
other applications work...
So if this change ruins your day: please try to fix your files using
"mute". If this doesn't work out, I can still restore the old behaviour,
but I really hope, that this is _not_ necessary!
Rational: most people won't get affected by this change, since you can't
really do anything usefull with the (old) sequencer without at least one
effect track and then you are on the safe side...
2008-01-01 11:44:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
y >>= 1;
|
== Sequencer ==
Attention! Rather large sequencer rewrite:
* Implemented layer blending using implicit effects. (works like layers
in "The Gimp" or Photoshop.)
* Fixed Space-Bar start-stop in preview windows.
You can start playback using spacebar within a preview-window and it _works_!
* Fixed Flip Y (didn't work for float)
* Fixed premul (didn't work for float)
* Added IPOs to _all_ tracks. In blend-mode REPLACE it drives the
"mul"-parameter in all other blend modes it drives the effect.
* you can meta single tracks.
* moved "mute track" from "M" to "Shift-M"
* added "Shift-L" for "lock track"
* changed inner workings for Metas. Now all ImBufs have to use the
reference counting mechanism. (Only interesting for coders :)
!!! Really important change, that affects current files!
Since you can mute tracks and now there is real layer blending capabilities
in place, I changed the silly behaviour that chose the output track.
Old behaviour: if we have an effect track visible, use the uppermost effect
track. If there is _no_ effect track visible, use the lowest input track.
New behaviour: always use the uppermost track. With blend modes active:
work our way down starting from the uppermost track to the first
"replace"-mode track. This is the way the gimp, photoshop, basically _all_
other applications work...
So if this change ruins your day: please try to fix your files using
"mute". If this doesn't work out, I can still restore the old behaviour,
but I really hope, that this is _not_ necessary!
Rational: most people won't get affected by this change, since you can't
really do anything usefull with the (old) sequencer without at least one
effect track and then you are on the safe side...
2008-01-01 11:44:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (; y > 0; y--) {
|
|
|
|
memcpy(linef, topf, 4 * x * sizeof(float));
|
|
|
|
memcpy(topf, bottomf, 4 * x * sizeof(float));
|
|
|
|
memcpy(bottomf, linef, 4 * x * sizeof(float));
|
|
|
|
bottomf -= 4 * x;
|
|
|
|
topf += 4 * x;
|
|
|
|
}
|
== Sequencer ==
Attention! Rather large sequencer rewrite:
* Implemented layer blending using implicit effects. (works like layers
in "The Gimp" or Photoshop.)
* Fixed Space-Bar start-stop in preview windows.
You can start playback using spacebar within a preview-window and it _works_!
* Fixed Flip Y (didn't work for float)
* Fixed premul (didn't work for float)
* Added IPOs to _all_ tracks. In blend-mode REPLACE it drives the
"mul"-parameter in all other blend modes it drives the effect.
* you can meta single tracks.
* moved "mute track" from "M" to "Shift-M"
* added "Shift-L" for "lock track"
* changed inner workings for Metas. Now all ImBufs have to use the
reference counting mechanism. (Only interesting for coders :)
!!! Really important change, that affects current files!
Since you can mute tracks and now there is real layer blending capabilities
in place, I changed the silly behaviour that chose the output track.
Old behaviour: if we have an effect track visible, use the uppermost effect
track. If there is _no_ effect track visible, use the lowest input track.
New behaviour: always use the uppermost track. With blend modes active:
work our way down starting from the uppermost track to the first
"replace"-mode track. This is the way the gimp, photoshop, basically _all_
other applications work...
So if this change ruins your day: please try to fix your files using
"mute". If this doesn't work out, I can still restore the old behaviour,
but I really hope, that this is _not_ necessary!
Rational: most people won't get affected by this change, since you can't
really do anything usefull with the (old) sequencer without at least one
effect track and then you are on the safe side...
2008-01-01 11:44:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(linef);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2007-10-10 23:34:40 +00:00
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
void IMB_flipx(struct ImBuf *ibuf)
|
2007-10-10 23:34:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int x, y, xr, xl, yi;
|
|
|
|
float px_f[4];
|
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (ibuf == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
x = ibuf->x;
|
|
|
|
y = ibuf->y;
|
|
|
|
|
|
|
|
if (ibuf->rect) {
|
|
|
|
for (yi = y - 1; yi >= 0; yi--) {
|
|
|
|
for (xr = x - 1, xl = 0; xr >= xl; xr--, xl++) {
|
|
|
|
SWAP(unsigned int, ibuf->rect[(x * yi) + xr], ibuf->rect[(x * yi) + xl]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ibuf->rect_float) {
|
|
|
|
for (yi = y - 1; yi >= 0; yi--) {
|
|
|
|
for (xr = x - 1, xl = 0; xr >= xl; xr--, xl++) {
|
|
|
|
memcpy(&px_f, &ibuf->rect_float[((x * yi) + xr) * 4], 4 * sizeof(float));
|
|
|
|
memcpy(&ibuf->rect_float[((x * yi) + xr) * 4],
|
|
|
|
&ibuf->rect_float[((x * yi) + xl) * 4],
|
|
|
|
4 * sizeof(float));
|
|
|
|
memcpy(&ibuf->rect_float[((x * yi) + xl) * 4], &px_f, 4 * sizeof(float));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-10 23:34:40 +00:00
|
|
|
}
|