2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
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.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
* This file was moved here from the src/ directory. It is meant to
|
|
|
|
* deal with endianness. It resided in a general blending lib. The
|
|
|
|
* other functions were only used during rendering. This single
|
|
|
|
* function remained. It should probably move to imbuf/intern/util.c,
|
|
|
|
* but we'll keep it here for the time being. (nzc)*/
|
|
|
|
|
2011-02-27 20:23:21 +00:00
|
|
|
/** \file blender/imbuf/intern/imageprocess.c
|
|
|
|
* \ingroup imbuf
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* imageprocess.c MIXED MODEL
|
|
|
|
*
|
|
|
|
* april 95
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-03-08 14:23:34 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
#include "IMB_imbuf_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "IMB_imbuf.h"
|
2007-07-10 19:13:03 +00:00
|
|
|
#include "math.h"
|
|
|
|
|
|
|
|
/* This define should be relocated to a global header some where Kent Mein
|
2012-03-09 18:28:30 +00:00
|
|
|
* I stole it from util.h in the plugins api */
|
2007-07-10 19:13:03 +00:00
|
|
|
#define MAX2(x,y) ( (x)>(y) ? (x) : (y) )
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* Only this one is used liberally here, and in imbuf */
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
void IMB_convert_rgba_to_abgr(struct ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2008-01-20 18:55:56 +00:00
|
|
|
int size;
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
unsigned char rt, *cp = (unsigned char *)ibuf->rect;
|
|
|
|
float rtf, *cpf = ibuf->rect_float;
|
|
|
|
|
2008-01-20 18:55:56 +00:00
|
|
|
if (ibuf->rect) {
|
|
|
|
size = ibuf->x * ibuf->y;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
while (size-- > 0) {
|
2008-01-20 18:55:56 +00:00
|
|
|
rt= cp[0];
|
|
|
|
cp[0]= cp[3];
|
|
|
|
cp[3]= rt;
|
|
|
|
rt= cp[1];
|
|
|
|
cp[1]= cp[2];
|
|
|
|
cp[2]= rt;
|
|
|
|
cp+= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ibuf->rect_float) {
|
|
|
|
size = ibuf->x * ibuf->y;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
while (size-- > 0) {
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
rtf= cpf[0];
|
|
|
|
cpf[0]= cpf[3];
|
|
|
|
cpf[3]= rtf;
|
|
|
|
rtf= cpf[1];
|
|
|
|
cpf[1]= cpf[2];
|
|
|
|
cpf[2]= rtf;
|
|
|
|
cpf+= 4;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-20 00:34:24 +00:00
|
|
|
static void pixel_from_buffer(struct ImBuf *ibuf, unsigned char **outI, float **outF, int x, int y)
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
int offset = ibuf->x * y * 4 + 4*x;
|
|
|
|
|
|
|
|
if (ibuf->rect)
|
2008-11-20 00:34:24 +00:00
|
|
|
*outI= (unsigned char *)ibuf->rect + offset;
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
|
|
|
if (ibuf->rect_float)
|
2008-11-20 00:34:24 +00:00
|
|
|
*outF= (float *)ibuf->rect_float + offset;
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
}
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
|
2007-07-10 19:13:03 +00:00
|
|
|
/**************************************************************************
|
2012-03-09 18:28:30 +00:00
|
|
|
* INTERPOLATIONS
|
|
|
|
*
|
|
|
|
* Reference and docs:
|
|
|
|
* http://wiki.blender.org/index.php/User:Damiles#Interpolations_Algorithms
|
|
|
|
***************************************************************************/
|
2007-07-10 19:13:03 +00:00
|
|
|
|
2012-03-09 18:28:30 +00:00
|
|
|
/* BICUBIC Interpolation functions
|
|
|
|
* More info: http://wiki.blender.org/index.php/User:Damiles#Bicubic_pixel_interpolation
|
|
|
|
* function assumes out to be zero'ed, only does RGBA */
|
2008-11-19 02:07:23 +00:00
|
|
|
|
2011-09-28 05:53:40 +00:00
|
|
|
static float P(float k)
|
|
|
|
{
|
2008-11-19 02:07:23 +00:00
|
|
|
float p1, p2, p3, p4;
|
|
|
|
p1 = MAX2(k+2.0f,0);
|
|
|
|
p2 = MAX2(k+1.0f,0);
|
|
|
|
p3 = MAX2(k,0);
|
|
|
|
p4 = MAX2(k-1.0f,0);
|
|
|
|
return (float)(1.0f/6.0f)*( p1*p1*p1 - 4.0f * p2*p2*p2 + 6.0f * p3*p3*p3 - 4.0f * p4*p4*p4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* older, slower function, works the same as above */
|
2011-09-28 05:53:40 +00:00
|
|
|
static float P(float k)
|
|
|
|
{
|
2008-11-11 01:13:05 +00:00
|
|
|
return (float)(1.0f/6.0f)*( pow( MAX2(k+2.0f,0) , 3.0f ) - 4.0f * pow( MAX2(k+1.0f,0) , 3.0f ) + 6.0f * pow( MAX2(k,0) , 3.0f ) - 4.0f * pow( MAX2(k-1.0f,0) , 3.0f));
|
2007-07-10 19:13:03 +00:00
|
|
|
}
|
2008-11-19 02:07:23 +00:00
|
|
|
#endif
|
|
|
|
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *outI, float *outF, float u, float v)
|
2007-07-10 19:13:03 +00:00
|
|
|
{
|
|
|
|
int i,j,n,m,x1,y1;
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
unsigned char *dataI;
|
|
|
|
float a,b,w,wx,wy[4], outR,outG,outB,outA,*dataF;
|
2007-07-10 19:13:03 +00:00
|
|
|
|
2012-03-08 14:23:34 +00:00
|
|
|
/* sample area entirely outside image? */
|
|
|
|
if (ceil(u)<0 || floor(u)>in->x-1 || ceil(v)<0 || floor(v)>in->y-1)
|
|
|
|
return;
|
|
|
|
|
2010-07-17 18:08:14 +00:00
|
|
|
/* ImBuf in must have a valid rect or rect_float, assume this is already checked */
|
2007-07-10 19:13:03 +00:00
|
|
|
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
i= (int)floor(u);
|
|
|
|
j= (int)floor(v);
|
|
|
|
a= u - i;
|
|
|
|
b= v - j;
|
2007-07-10 19:13:03 +00:00
|
|
|
|
2008-11-19 02:07:23 +00:00
|
|
|
outR = outG = outB = outA = 0.0f;
|
|
|
|
|
|
|
|
/* Optimized and not so easy to read */
|
2008-11-11 01:13:05 +00:00
|
|
|
|
|
|
|
/* avoid calling multiple times */
|
|
|
|
wy[0] = P(b-(-1));
|
|
|
|
wy[1] = P(b- 0);
|
|
|
|
wy[2] = P(b- 1);
|
|
|
|
wy[3] = P(b- 2);
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
for (n= -1; n<= 2; n++) {
|
2008-11-11 01:13:05 +00:00
|
|
|
x1= i+n;
|
2012-03-08 14:23:34 +00:00
|
|
|
CLAMP(x1, 0, in->x-1);
|
|
|
|
wx = P(n-a);
|
2012-03-24 06:38:07 +00:00
|
|
|
for (m= -1; m<= 2; m++) {
|
2012-03-08 14:23:34 +00:00
|
|
|
y1= j+m;
|
|
|
|
CLAMP(y1, 0, in->y-1);
|
|
|
|
/* normally we could do this */
|
|
|
|
/* w = P(n-a) * P(b-m); */
|
|
|
|
/* except that would call P() 16 times per pixel therefor pow() 64 times, better precalc these */
|
|
|
|
w = wx * wy[m+1];
|
|
|
|
|
|
|
|
if (outF) {
|
|
|
|
dataF= in->rect_float + in->x * y1 * 4 + 4*x1;
|
|
|
|
outR+= dataF[0] * w;
|
|
|
|
outG+= dataF[1] * w;
|
|
|
|
outB+= dataF[2] * w;
|
|
|
|
outA+= dataF[3] * w;
|
|
|
|
}
|
|
|
|
if (outI) {
|
|
|
|
dataI= (unsigned char*)in->rect + in->x * y1 * 4 + 4*x1;
|
|
|
|
outR+= dataI[0] * w;
|
|
|
|
outG+= dataI[1] * w;
|
|
|
|
outB+= dataI[2] * w;
|
|
|
|
outA+= dataI[3] * w;
|
2007-07-10 19:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-19 02:07:23 +00:00
|
|
|
|
|
|
|
/* Done with optimized part */
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* older, slower function, works the same as above */
|
2012-03-24 06:38:07 +00:00
|
|
|
for (n= -1; n<= 2; n++) {
|
|
|
|
for (m= -1; m<= 2; m++) {
|
2008-11-19 02:07:23 +00:00
|
|
|
x1= i+n;
|
|
|
|
y1= j+m;
|
|
|
|
if (x1>0 && x1 < in->x && y1>0 && y1<in->y) {
|
|
|
|
if (do_float) {
|
|
|
|
dataF= in->rect_float + in->x * y1 * 4 + 4*x1;
|
|
|
|
outR+= dataF[0] * P(n-a) * P(b-m);
|
|
|
|
outG+= dataF[1] * P(n-a) * P(b-m);
|
|
|
|
outB+= dataF[2] * P(n-a) * P(b-m);
|
|
|
|
outA+= dataF[3] * P(n-a) * P(b-m);
|
|
|
|
}
|
|
|
|
if (do_rect) {
|
|
|
|
dataI= (unsigned char*)in->rect + in->x * y1 * 4 + 4*x1;
|
|
|
|
outR+= dataI[0] * P(n-a) * P(b-m);
|
|
|
|
outG+= dataI[1] * P(n-a) * P(b-m);
|
|
|
|
outB+= dataI[2] * P(n-a) * P(b-m);
|
|
|
|
outA+= dataI[3] * P(n-a) * P(b-m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
if (outI) {
|
2007-07-10 19:13:03 +00:00
|
|
|
outI[0]= (int)outR;
|
|
|
|
outI[1]= (int)outG;
|
|
|
|
outI[2]= (int)outB;
|
|
|
|
outI[3]= (int)outA;
|
|
|
|
}
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
if (outF) {
|
2007-07-10 19:13:03 +00:00
|
|
|
outF[0]= outR;
|
|
|
|
outF[1]= outG;
|
|
|
|
outF[2]= outB;
|
|
|
|
outF[3]= outA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
|
|
|
void bicubic_interpolation(ImBuf *in, ImBuf *out, float u, float v, int xout, int yout)
|
|
|
|
{
|
|
|
|
|
|
|
|
unsigned char *outI = NULL;
|
|
|
|
float *outF = NULL;
|
|
|
|
|
|
|
|
if (in == NULL || (in->rect == NULL && in->rect_float == NULL)) return;
|
|
|
|
|
2008-11-20 00:34:24 +00:00
|
|
|
pixel_from_buffer(out, &outI, &outF, xout, yout); /* gcc warns these could be uninitialized, but its ok */
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
|
|
|
bicubic_interpolation_color(in, outI, outF, u, v);
|
|
|
|
}
|
|
|
|
|
2007-07-10 19:13:03 +00:00
|
|
|
/* function assumes out to be zero'ed, only does RGBA */
|
|
|
|
/* BILINEAR INTERPOLATION */
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *outI, float *outF, float u, float v)
|
2007-07-10 19:13:03 +00:00
|
|
|
{
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
float *row1, *row2, *row3, *row4, a, b;
|
|
|
|
unsigned char *row1I, *row2I, *row3I, *row4I;
|
2007-07-10 19:13:03 +00:00
|
|
|
float a_b, ma_b, a_mb, ma_mb;
|
|
|
|
float empty[4]= {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
unsigned char emptyI[4]= {0, 0, 0, 0};
|
|
|
|
int y1, y2, x1, x2;
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
|
|
|
|
2010-07-17 18:08:14 +00:00
|
|
|
/* ImBuf in must have a valid rect or rect_float, assume this is already checked */
|
2007-07-10 19:13:03 +00:00
|
|
|
|
|
|
|
x1= (int)floor(u);
|
|
|
|
x2= (int)ceil(u);
|
|
|
|
y1= (int)floor(v);
|
|
|
|
y2= (int)ceil(v);
|
|
|
|
|
|
|
|
// sample area entirely outside image?
|
|
|
|
if (x2<0 || x1>in->x-1 || y2<0 || y1>in->y-1) return;
|
|
|
|
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
if (outF) {
|
2007-07-10 19:13:03 +00:00
|
|
|
// sample including outside of edges of image
|
|
|
|
if (x1<0 || y1<0) row1= empty;
|
|
|
|
else row1= (float *)in->rect_float + in->x * y1 * 4 + 4*x1;
|
|
|
|
|
|
|
|
if (x1<0 || y2>in->y-1) row2= empty;
|
|
|
|
else row2= (float *)in->rect_float + in->x * y2 * 4 + 4*x1;
|
|
|
|
|
|
|
|
if (x2>in->x-1 || y1<0) row3= empty;
|
|
|
|
else row3= (float *)in->rect_float + in->x * y1 * 4 + 4*x2;
|
|
|
|
|
|
|
|
if (x2>in->x-1 || y2>in->y-1) row4= empty;
|
|
|
|
else row4= (float *)in->rect_float + in->x * y2 * 4 + 4*x2;
|
|
|
|
|
2011-03-27 17:12:59 +00:00
|
|
|
a= u-floorf(u);
|
|
|
|
b= v-floorf(v);
|
2007-07-10 19:13:03 +00:00
|
|
|
a_b= a*b; ma_b= (1.0f-a)*b; a_mb= a*(1.0f-b); ma_mb= (1.0f-a)*(1.0f-b);
|
|
|
|
|
|
|
|
outF[0]= ma_mb*row1[0] + a_mb*row3[0] + ma_b*row2[0]+ a_b*row4[0];
|
|
|
|
outF[1]= ma_mb*row1[1] + a_mb*row3[1] + ma_b*row2[1]+ a_b*row4[1];
|
|
|
|
outF[2]= ma_mb*row1[2] + a_mb*row3[2] + ma_b*row2[2]+ a_b*row4[2];
|
|
|
|
outF[3]= ma_mb*row1[3] + a_mb*row3[3] + ma_b*row2[3]+ a_b*row4[3];
|
|
|
|
}
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
if (outI) {
|
2007-07-10 19:13:03 +00:00
|
|
|
// sample including outside of edges of image
|
|
|
|
if (x1<0 || y1<0) row1I= emptyI;
|
|
|
|
else row1I= (unsigned char *)in->rect + in->x * y1 * 4 + 4*x1;
|
|
|
|
|
|
|
|
if (x1<0 || y2>in->y-1) row2I= emptyI;
|
|
|
|
else row2I= (unsigned char *)in->rect + in->x * y2 * 4 + 4*x1;
|
|
|
|
|
|
|
|
if (x2>in->x-1 || y1<0) row3I= emptyI;
|
|
|
|
else row3I= (unsigned char *)in->rect + in->x * y1 * 4 + 4*x2;
|
|
|
|
|
|
|
|
if (x2>in->x-1 || y2>in->y-1) row4I= emptyI;
|
|
|
|
else row4I= (unsigned char *)in->rect + in->x * y2 * 4 + 4*x2;
|
|
|
|
|
2011-03-27 17:12:59 +00:00
|
|
|
a= u-floorf(u);
|
|
|
|
b= v-floorf(v);
|
2007-07-10 19:13:03 +00:00
|
|
|
a_b= a*b; ma_b= (1.0f-a)*b; a_mb= a*(1.0f-b); ma_mb= (1.0f-a)*(1.0f-b);
|
|
|
|
|
2009-05-07 14:53:40 +00:00
|
|
|
/* need to add 0.5 to avoid rounding down (causes darken with the smear brush)
|
|
|
|
* tested with white images and this should not wrap back to zero */
|
|
|
|
outI[0]= (ma_mb*row1I[0] + a_mb*row3I[0] + ma_b*row2I[0]+ a_b*row4I[0]) + 0.5f;
|
|
|
|
outI[1]= (ma_mb*row1I[1] + a_mb*row3I[1] + ma_b*row2I[1]+ a_b*row4I[1]) + 0.5f;
|
2009-05-28 06:13:56 +00:00
|
|
|
outI[2]= (ma_mb*row1I[2] + a_mb*row3I[2] + ma_b*row2I[2]+ a_b*row4I[2]) + 0.5f;
|
|
|
|
outI[3]= (ma_mb*row1I[3] + a_mb*row3I[3] + ma_b*row2I[3]+ a_b*row4I[3]) + 0.5f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* function assumes out to be zero'ed, only does RGBA */
|
|
|
|
/* BILINEAR INTERPOLATION */
|
|
|
|
|
|
|
|
/* Note about wrapping, the u/v still needs to be within the image bounds,
|
|
|
|
* just the interpolation is wrapped.
|
2011-05-28 13:11:24 +00:00
|
|
|
* This the same as bilinear_interpolation_color except it wraps rather than using empty and emptyI */
|
2009-05-28 06:13:56 +00:00
|
|
|
void bilinear_interpolation_color_wrap(struct ImBuf *in, unsigned char *outI, float *outF, float u, float v)
|
|
|
|
{
|
|
|
|
float *row1, *row2, *row3, *row4, a, b;
|
|
|
|
unsigned char *row1I, *row2I, *row3I, *row4I;
|
|
|
|
float a_b, ma_b, a_mb, ma_mb;
|
|
|
|
int y1, y2, x1, x2;
|
|
|
|
|
|
|
|
|
2010-07-17 18:08:14 +00:00
|
|
|
/* ImBuf in must have a valid rect or rect_float, assume this is already checked */
|
2009-05-28 06:13:56 +00:00
|
|
|
|
|
|
|
x1= (int)floor(u);
|
|
|
|
x2= (int)ceil(u);
|
|
|
|
y1= (int)floor(v);
|
|
|
|
y2= (int)ceil(v);
|
|
|
|
|
|
|
|
// sample area entirely outside image?
|
|
|
|
if (x2<0 || x1>in->x-1 || y2<0 || y1>in->y-1) return;
|
|
|
|
|
|
|
|
/* wrap interpolation pixels - main difference from bilinear_interpolation_color */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (x1<0)x1= in->x+x1;
|
|
|
|
if (y1<0)y1= in->y+y1;
|
2009-05-28 06:13:56 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (x2>=in->x)x2= x2-in->x;
|
|
|
|
if (y2>=in->y)y2= y2-in->y;
|
2009-05-28 06:13:56 +00:00
|
|
|
|
|
|
|
if (outF) {
|
|
|
|
// sample including outside of edges of image
|
|
|
|
row1= (float *)in->rect_float + in->x * y1 * 4 + 4*x1;
|
|
|
|
row2= (float *)in->rect_float + in->x * y2 * 4 + 4*x1;
|
|
|
|
row3= (float *)in->rect_float + in->x * y1 * 4 + 4*x2;
|
|
|
|
row4= (float *)in->rect_float + in->x * y2 * 4 + 4*x2;
|
|
|
|
|
2011-03-27 17:12:59 +00:00
|
|
|
a= u-floorf(u);
|
|
|
|
b= v-floorf(v);
|
2009-05-28 06:13:56 +00:00
|
|
|
a_b= a*b; ma_b= (1.0f-a)*b; a_mb= a*(1.0f-b); ma_mb= (1.0f-a)*(1.0f-b);
|
|
|
|
|
|
|
|
outF[0]= ma_mb*row1[0] + a_mb*row3[0] + ma_b*row2[0]+ a_b*row4[0];
|
|
|
|
outF[1]= ma_mb*row1[1] + a_mb*row3[1] + ma_b*row2[1]+ a_b*row4[1];
|
|
|
|
outF[2]= ma_mb*row1[2] + a_mb*row3[2] + ma_b*row2[2]+ a_b*row4[2];
|
|
|
|
outF[3]= ma_mb*row1[3] + a_mb*row3[3] + ma_b*row2[3]+ a_b*row4[3];
|
|
|
|
}
|
|
|
|
if (outI) {
|
|
|
|
// sample including outside of edges of image
|
|
|
|
row1I= (unsigned char *)in->rect + in->x * y1 * 4 + 4*x1;
|
|
|
|
row2I= (unsigned char *)in->rect + in->x * y2 * 4 + 4*x1;
|
|
|
|
row3I= (unsigned char *)in->rect + in->x * y1 * 4 + 4*x2;
|
|
|
|
row4I= (unsigned char *)in->rect + in->x * y2 * 4 + 4*x2;
|
|
|
|
|
2011-03-27 17:12:59 +00:00
|
|
|
a= u-floorf(u);
|
|
|
|
b= v-floorf(v);
|
2009-05-28 06:13:56 +00:00
|
|
|
a_b= a*b; ma_b= (1.0f-a)*b; a_mb= a*(1.0f-b); ma_mb= (1.0f-a)*(1.0f-b);
|
|
|
|
|
|
|
|
/* need to add 0.5 to avoid rounding down (causes darken with the smear brush)
|
|
|
|
* tested with white images and this should not wrap back to zero */
|
|
|
|
outI[0]= (ma_mb*row1I[0] + a_mb*row3I[0] + ma_b*row2I[0]+ a_b*row4I[0]) + 0.5f;
|
|
|
|
outI[1]= (ma_mb*row1I[1] + a_mb*row3I[1] + ma_b*row2I[1]+ a_b*row4I[1]) + 0.5f;
|
2009-05-07 14:53:40 +00:00
|
|
|
outI[2]= (ma_mb*row1I[2] + a_mb*row3I[2] + ma_b*row2I[2]+ a_b*row4I[2]) + 0.5f;
|
|
|
|
outI[3]= (ma_mb*row1I[3] + a_mb*row3I[3] + ma_b*row2I[3]+ a_b*row4I[3]) + 0.5f;
|
2007-07-10 19:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
void bilinear_interpolation(ImBuf *in, ImBuf *out, float u, float v, int xout, int yout)
|
|
|
|
{
|
|
|
|
|
|
|
|
unsigned char *outI = NULL;
|
|
|
|
float *outF = NULL;
|
|
|
|
|
|
|
|
if (in == NULL || (in->rect == NULL && in->rect_float == NULL)) return;
|
|
|
|
|
2008-11-20 00:34:24 +00:00
|
|
|
pixel_from_buffer(out, &outI, &outF, xout, yout); /* gcc warns these could be uninitialized, but its ok */
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
|
|
|
bilinear_interpolation_color(in, outI, outF, u, v);
|
|
|
|
}
|
|
|
|
|
2007-07-10 19:13:03 +00:00
|
|
|
/* function assumes out to be zero'ed, only does RGBA */
|
|
|
|
/* NEAREST INTERPOLATION */
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
void neareast_interpolation_color(struct ImBuf *in, unsigned char *outI, float *outF, float u, float v)
|
2007-07-10 19:13:03 +00:00
|
|
|
{
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
float *dataF;
|
|
|
|
unsigned char *dataI;
|
2007-07-10 19:13:03 +00:00
|
|
|
int y1, x1;
|
|
|
|
|
2010-07-17 18:08:14 +00:00
|
|
|
/* ImBuf in must have a valid rect or rect_float, assume this is already checked */
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
2007-07-10 19:13:03 +00:00
|
|
|
x1= (int)(u);
|
|
|
|
y1= (int)(v);
|
|
|
|
|
|
|
|
// sample area entirely outside image?
|
|
|
|
if (x1<0 || x1>in->x-1 || y1<0 || y1>in->y-1) return;
|
|
|
|
|
|
|
|
// sample including outside of edges of image
|
|
|
|
if (x1<0 || y1<0) {
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
if (outI) {
|
2007-07-10 19:13:03 +00:00
|
|
|
outI[0]= 0;
|
|
|
|
outI[1]= 0;
|
|
|
|
outI[2]= 0;
|
|
|
|
outI[3]= 0;
|
|
|
|
}
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
if (outF) {
|
2007-07-10 19:13:03 +00:00
|
|
|
outF[0]= 0.0f;
|
|
|
|
outF[1]= 0.0f;
|
|
|
|
outF[2]= 0.0f;
|
|
|
|
outF[3]= 0.0f;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-07-10 19:13:03 +00:00
|
|
|
dataI= (unsigned char *)in->rect + in->x * y1 * 4 + 4*x1;
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
if (outI) {
|
2007-07-10 19:13:03 +00:00
|
|
|
outI[0]= dataI[0];
|
|
|
|
outI[1]= dataI[1];
|
|
|
|
outI[2]= dataI[2];
|
|
|
|
outI[3]= dataI[3];
|
|
|
|
}
|
|
|
|
dataF= in->rect_float + in->x * y1 * 4 + 4*x1;
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
if (outF) {
|
2007-07-10 19:13:03 +00:00
|
|
|
outF[0]= dataF[0];
|
|
|
|
outF[1]= dataF[1];
|
|
|
|
outF[2]= dataF[2];
|
|
|
|
outF[3]= dataF[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
|
|
|
void neareast_interpolation(ImBuf *in, ImBuf *out, float x, float y, int xout, int yout)
|
|
|
|
{
|
|
|
|
|
|
|
|
unsigned char *outI = NULL;
|
|
|
|
float *outF = NULL;
|
|
|
|
|
|
|
|
if (in == NULL || (in->rect == NULL && in->rect_float == NULL)) return;
|
|
|
|
|
2008-11-20 00:34:24 +00:00
|
|
|
pixel_from_buffer(out, &outI, &outF, xout, yout); /* gcc warns these could be uninitialized, but its ok */
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
|
|
|
neareast_interpolation_color(in, outI, outF, x, y);
|
2008-11-20 00:34:24 +00:00
|
|
|
}
|