nr-filter-turbulence.cpp revision 7ec2a593a4a4046d6313fc868bd32ca1a5b2a119
/*
* feTurbulence filter primitive renderer
*
* Authors:
* Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
*
* Copyright (C) 2007 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "display/nr-arena-item.h"
#include "display/nr-filter.h"
#include "display/nr-filter-turbulence.h"
#include "display/nr-filter-units.h"
#include "display/nr-filter-utils.h"
#include "libnr/nr-rect-l.h"
#include <math.h>
namespace NR {
: XbaseFrequency(0),
YbaseFrequency(0),
numOctaves(1),
seed(0),
updated(false),
{
}
return new FilterTurbulence();
}
{
if (pix) {
delete pix;
}
}
}
}
void FilterTurbulence::set_seed(double s){
seed=s;
}
}
type=t;
}
void FilterTurbulence::set_updated(bool u){
updated=u;
}
//g_warning("update_pixbuf");
if (!pix){
pix = new NRPixBlock;
}
{
/* TODO: release-setup cycle not actually needed, if pixblock
* width and height don't change */
}
TurbulenceInit((long)seed);
double point[2];
if (type==TURBULENCE_TURBULENCE){
}
}
} else {
pix_data[4*(int(point[0]) + w*int(point[1]))] = CLAMP_D_TO_U8( ((turbulence(0,point)*255) +255)/2 );
pix_data[4*(int(point[0]) + w*int(point[1])) + 1] = CLAMP_D_TO_U8( ((turbulence(1,point)*255)+255)/2 );
pix_data[4*(int(point[0]) + w*int(point[1])) + 2] = CLAMP_D_TO_U8( ((turbulence(2,point)*255) +255)/2 );
pix_data[4*(int(point[0]) + w*int(point[1])) + 3] = CLAMP_D_TO_U8( ((turbulence(3,point)*255) +255)/2 );
}
}
}
updated=true;
updated_area = area;
}
//g_warning("render");
// TODO: could be faster - updated_area only has to be same size as area
int x,y;
}
}
return 0;
}
{
return lSeed;
}
{
long result;
return result;
}
{
//g_warning("init");
double s;
int i, j, k;
for(k = 0; k < 4; k++)
{
for(i = 0; i < BSize; i++)
{
uLatticeSelector[i] = i;
for (j = 0; j < 2; j++)
fGradient[k][i][j] = (double)(((lSeed = TurbulenceRandom(lSeed)) % (BSize + BSize)) - BSize) / BSize;
s = double(sqrt(fGradient[k][i][0] * fGradient[k][i][0] + fGradient[k][i][1] * fGradient[k][i][1]));
fGradient[k][i][0] /= s;
fGradient[k][i][1] /= s;
}
}
while(--i)
{
k = uLatticeSelector[i];
uLatticeSelector[j] = k;
}
for(i = 0; i < BSize + 2; i++)
{
for(k = 0; k < 4; k++)
for(j = 0; j < 2; j++)
}
}
double FilterTurbulence::TurbulenceNoise2(int nColorChannel, double vec[2], StitchInfo *pStitchInfo)
{
int i, j;
bx0 = (int)t;
rx0 = t - (int)t;
by0 = (int)t;
ry0 = t - (int)t;
// If stitching, adjust lattice points accordingly.
if(pStitchInfo != NULL)
{
}
i = uLatticeSelector[bx0];
j = uLatticeSelector[bx1];
}
{
//g_warning("turbulence");
// Adjust the base frequencies if necessary for stitching.
if(stitchTiles)
{
// When stitching tiled turbulence, the frequencies must be adjusted
// so that the tile borders will be continuous.
if(XbaseFrequency != 0.0)
{
else
}
if(YbaseFrequency != 0.0)
{
else
}
// Set up TurbulenceInitial stitch values.
pStitchInfo = &stitch;
}
double fSum = 0.0f;
double vec[2];
double ratio = 1;
{
else
vec[0] *= 2;
ratio *= 2;
if(pStitchInfo != NULL)
{
// Update stitch values. Subtracting PerlinN before the multiplication and
// adding it afterward simplifies to subtracting it once.
}
}
return fSum;
}
return TRAIT_PARALLER;
}
} /* namespace NR */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :