Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highly recommend a function to smooth the image. #243

Open
Pittow2 opened this issue Dec 8, 2023 · 0 comments
Open

Highly recommend a function to smooth the image. #243

Pittow2 opened this issue Dec 8, 2023 · 0 comments

Comments

@Pittow2
Copy link

Pittow2 commented Dec 8, 2023

The origin palette function does make a bad sence to human vision , the dark and cycled color let eyes go tired .

I'd like to recommend a new function to paint here .

It is based on the times of iteration . While the number of colors is much less than the times of iter , it is important to alloc a reasonable range of color to each iter time . The "number of pixels - iter times" function is just like y=1/x , less iter time means more area , while the larger iter time corresponds to the detail of fractal . So it can make the final image more beautiful by letting each color occupy the same area of the above function .

image image

It definitely makes a better view .

struct image{
	int *step;//iteration times
	byte *black;//it is 3 when the point goes to infinity
};
bool check(int n,int *cnt,int p,int *lim,int g){//(pixels*iter time range) should be equal to each color .
	u64 lc=0,lp=0,mul=1;
	int i,j,k,cc;
	for(i=0,k=0;i<n;++i){
		for(j=0,cc=0;j<cnt[i];++j){
			++lc;
			if(lc*((j+1)*mul+lp*cnt[i])>g*mul*cnt[i]){
				lc=0;lp=0;
				mul=cnt[i];
				lim[k++]=i;
				if(++cc>16)--k;//to limit each iter time up to 16 colors
				if(k>=p)return 0;
			}
		}
		if(lc>=cnt[i])lp+=mul;
		else lp+=lc;
	}return 1;
}
int splix(int n,int *cnt,int p,int *lim){
	int l=0,r=n*p,m;
	while(l+1!=r){
		m=(l+r)>>1;
		if(check(n,cnt,p,lim,m))r=m;
		else l=m;
	}check(n,cnt,p,lim,r);
	return r;
}
void smooth(image g){
	int max=0,min=1<<30,n=0,k=sx*sy,*cnt,*lim,i,j;
	for(i=0;i<k;++i)if(g.black[i]==3){
		if(max<g.step[i])max=g.step[i];
		if(min>g.step[i])min=g.step[i];
	}
	if(min==(1<<30))return;
	max=max-min+1;
	cnt=new int[max];
	for(i=0;i<max;++i)cnt[i]=0;
	for(i=0;i<k;++i)if(g.black[i]==3)++cnt[g.step[i]-min];
	lim=new int[512];//say we have 512 colors in total
	splix(max,cnt,512,lim);
	for(i=j=0;i<512;++i)for(;j<=lim[i]&&j<max;++j)cnt[j]=i;
	for(i=0;i<k;++i)if(g.black[i]==3)g.step[i]=cnt[g.step[i]-min];
	delete cnt;
	delete lim;
}

The colors should be picked up in the color ring . Bright colors refresh eyes .

rgb getrgb(double h){//h is in [0,1)
	while(h>=1)h-=1;
	double x=h*6,r=0,g=0,b=0;
	while(x>=2)x-=2;
	if(x>1)x=2-x;
	int a=h*6;
	if(a==0||a==5)r=1;
	else if(a==1||a==2)g=1;
	else b=1;
	if(a==1||a==4)r=x;
	else if(a==0||a==3)g=x;
	else b=x;
	byte r0=r*255,g0=g*255,b0=b*255;
	return (rgb){r0,g0,b0};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant