📄 fillfilter.cpp
字号:
#include "FillFilter.h"
#include "stdlib.h"
#include "TexturGenerator.h"
/*
long FFTab[65536];
long Marked[65536];
long MarkCnt[65536];
*/
long *FFTab;
long *Marked;
long *MarkCnt;
long TabLen;
tTC_FILLFILTER01 TempC3, C3;
tTC_FILLFILTER02 TempC4, C4;
void KillTabItem(long M)
{
TabLen--;
FFTab[M]=FFTab[TabLen];
}
void Mark(long W,long XT,long YT,long Val)
{
long addx,addy,tx,ty;
long X,Y;
X=W & 255;
Y=W >> 8;
for (addx = -XT;addx <= XT;addx++) {
for (addy = -YT;addy <= YT;addy++) {
tx = ((X + addx) + 256) % 256;
ty = ((Y + addy) + 256) % 256;
*(Marked+ty*256+tx)+=Val;
*(MarkCnt+ty*256+tx)+=1;
/*
Marked[ty*256+tx]+=Val;
MarkCnt[ty*256+tx]++;
*/
}
}
}
void FillbertFilter01(tImage *TempImage, tTC_FILLFILTER01 *Param) {
srand(Param->RandomStart);
char *Image;
unsigned long i;
signed long I,W;
signed long sammelwert;
signed long PixelSet = 0;
long Channel,TI;
Image = (char*) TempImage->Data;
Channel=Param->Channel%4;
Marked=(long*)malloc(65536*4);
MarkCnt=(long*)malloc(65536*4);
FFTab=(long*)malloc(65536*4);
memset(Marked,0,65536*4);
memset(MarkCnt,0,65536*4);
for(I=0;I<65536;I++)
*(FFTab+I)=I;
TabLen=65536;
for (i = 0;i < Param->StartPartikel;i++) {
TI=(rand()*TabLen)/(1 << 15);
W=*(FFTab+TI);
KillTabItem(TI);
PixelSet++;
Mark(W,Param->AusdehnungX,Param->AusdehnungY,Param->StartValue);
for(I=0;I<4;I++)
if((Channel==I)||(Param->Channel==4))
*(Image+W*4+I)=Param->StartValue;
}
do {
TI=(rand()*TabLen)/(1 << 15);
W=*(FFTab+TI);
if(*(Marked+W)!=0)
{
sammelwert = *(Marked+W) / *(MarkCnt+W);
sammelwert+= (rand() * Param->Change * 2) / (1 << 15) - Param->Change;
if(sammelwert<=0) sammelwert=1;
if(sammelwert>255) sammelwert=255;
for(I=0;I<4;I++)
if((Channel==I)||(Param->Channel==4))
*(Image+W*4+I)=sammelwert;
PixelSet++;
KillTabItem(TI);
Mark(W,Param->AusdehnungX,Param->AusdehnungY,sammelwert);
}
} while (PixelSet < 65536 );
free(Marked);
free(MarkCnt);
free(FFTab);
}
/*
void FillbertFilter01(tImage *TempImage, tTC_FILLFILTER01 *Param) {
srand(Param->RandomStart);
char *Image;
signed long x,y,I,K,M;
signed short addx, addy;
signed short tx,ty;
unsigned char sammelvalue;
signed long sammelwert;
unsigned long sammelcounter;
signed short randompart;
signed long PixelSet = 0;
long Channel;
Image = (char*) TempImage->Data;
Channel=Param->Channel%4;
M=Channel;
for(x=0;x<TempImage->XSize*TempImage->YSize;x++)
{
*(Image+M)=0;
M+=4;
}
for (unsigned long i = 0;i < Param->StartPartikel;i++) {
x = (rand() * TempImage->XSize) / (1 << 15);
y = (rand() * TempImage->YSize) / (1 << 15);
M=(x + y * TempImage->XSize) * 4;
if (*(Image+(M+Channel)) == 0)
PixelSet++;
for(I=0;I<4;I++)
if((Channel==I)||(Param->Channel==4))
*(Image+M+I)=Param->StartValue;
}
do {
x = (rand() * TempImage->XSize) / (1 << 15);
y = (rand() * TempImage->YSize) / (1 << 15);
M=(x + y * TempImage->XSize) * 4;
if (*(Image+M+Channel) == 0) {
sammelwert = 0;
sammelcounter = 0;
for (addx = -Param->AusdehnungX;addx <= Param->AusdehnungX;addx++) {
for (addy = -Param->AusdehnungY;addy <= Param->AusdehnungY;addy++) {
tx = ((x + addx) + TempImage->XSize) % TempImage->XSize;
ty = ((y + addy) + TempImage->YSize) % TempImage->YSize;
sammelvalue = *(Image+(tx + ty * TempImage->XSize) * 4 + Channel);
sammelwert += sammelvalue;
if (sammelvalue != 0)
sammelcounter++;
}
}
if (sammelcounter > 0) {
sammelwert = sammelwert / sammelcounter;
randompart = (rand() * Param->Change * 2) / (1 << 15) - Param->Change;
if (sammelwert + randompart <= 0)
sammelwert = 1;
else
if (sammelwert + randompart >= 255)
sammelwert = 255;
else
sammelwert += randompart;
for(I=0;I<4;I++)
if((Channel==I)||(Param->Channel==4))
*(Image+M+I)=sammelwert;
PixelSet++;
}
}
} while (PixelSet < (TempImage->XSize * TempImage->YSize) );
}
*/
void FillbertFilter02(tImage *TempImage, tTC_FILLFILTER02 *Param) {
signed long colorblue, colorred, colorgreen, coloralpha, tempcolor;
signed long addx, addy, actx, acty;
signed long divisor = 0;
for (actx=0;actx < 3;actx++)
for (acty=0;acty < 3;acty++)
divisor += Param->Faktor[actx][acty];
tImage *Old = CopyImage(TempImage);
long *ImageSource = (long*)Old->Data;
long *ImageDestination = (long*)TempImage->Data;
for (actx=0;actx < TempImage->XSize;actx++)
for (acty=0;acty < TempImage->YSize;acty++) {
colorblue = 0;
colorred = 0;
colorgreen = 0;
coloralpha = 0;
for (addx=-1;addx <= 1;addx++)
for (addy=-1;addy <=1;addy++) {
tempcolor = *(ImageSource + ((actx + addy + TempImage->XSize) % TempImage->XSize) + ((acty + addy + TempImage->YSize) % TempImage->YSize)* TempImage->XSize);
colorred += (tempcolor & 0x000000FF) * Param->Faktor[addx+1][addy+1];
colorgreen += ((tempcolor & 0x0000FF00) >> 8) * Param->Faktor[addx+1][addy+1];
colorblue += ((tempcolor & 0x00FF0000) >> 16) * Param->Faktor[addx+1][addy+1];
coloralpha += ((tempcolor & 0xFF000000) >> 24) * Param->Faktor[addx+1][addy+1];
}
// colorblue /= divisor;
// colorred /= divisor;
// colorgreen /= divisor;
// coloralpha /= divisor;
if (colorblue > 255)
colorblue = 255;
if (colorblue < 0)
colorblue = 0;
if (colorred > 255)
colorred = 255;
if (colorred < 0)
colorred = 0;
if (colorgreen > 255)
colorgreen = 255;
if (colorgreen < 0)
colorgreen = 0;
if (coloralpha > 255)
coloralpha = 255;
if (coloralpha < 0)
coloralpha = 0;
tempcolor = colorred + (colorgreen << 8) + (colorblue << 16) + (coloralpha << 24);
*(ImageDestination + actx + acty * TempImage->XSize) = tempcolor;
}
DestroyImage(Old);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -