Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2005-05-27 23:02:39 +0400
committerTon Roosendaal <ton@blender.org>2005-05-27 23:02:39 +0400
commit5dedd9306b4479fa32fc3a415fe5fb6563f2ab42 (patch)
treec81cb05f6c7655d98131213c5b8a51db2b8afcd8
parent9a2efcd64166ac3cb99e0c872dcc9c429535660d (diff)
Colorband didn't correctly compute with 2 entries being exactly on the
same spot. Was division by zero here... coded nice exception catching. BTW: worked before june 2004... was part of commit for Ramp Shading.
-rw-r--r--source/blender/blenkernel/intern/texture.c91
1 files changed, 53 insertions, 38 deletions
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index 847e101ea52..9fba11fd625 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -248,48 +248,63 @@ int do_colorband(ColorBand *coba, float in, float out[4])
out[3]= cbd1->a;
}
else {
- if(in < cbd1->pos) in= cbd1->pos;
-
- /* we're looking for first pos > in */
- for(a=0; a<coba->tot; a++, cbd1++) if(cbd1->pos > in) break;
-
- if(a==coba->tot) cbd1--;
- if(in > cbd1->pos) in= cbd1->pos;
-
- cbd2= cbd1-1;
- fac= (in-cbd1->pos)/(cbd2->pos-cbd1->pos);
-
- if(coba->ipotype==2) {
- /* ipo from right to left: 3 2 1 0 */
-
- if(a>=coba->tot-1) cbd0= cbd1;
- else cbd0= cbd1+1;
- if(a<2) cbd3= cbd2;
- else cbd3= cbd2-1;
-
- set_four_ipo(fac, t, KEY_BSPLINE);
-
- out[0]= t[3]*cbd3->r +t[2]*cbd2->r +t[1]*cbd1->r +t[0]*cbd0->r;
- out[1]= t[3]*cbd3->g +t[2]*cbd2->g +t[1]*cbd1->g +t[0]*cbd0->g;
- out[2]= t[3]*cbd3->b +t[2]*cbd2->b +t[1]*cbd1->b +t[0]*cbd0->b;
- out[3]= t[3]*cbd3->a +t[2]*cbd2->a +t[1]*cbd1->a +t[0]*cbd0->a;
- CLAMP(out[0], 0.0, 1.0);
- CLAMP(out[1], 0.0, 1.0);
- CLAMP(out[2], 0.0, 1.0);
- CLAMP(out[3], 0.0, 1.0);
+ if(in < cbd1->pos) {
+ out[0]= cbd1->r;
+ out[1]= cbd1->g;
+ out[2]= cbd1->b;
+ out[3]= cbd1->a;
}
else {
+
+ /* we're looking for first pos > in */
+ for(a=0; a<coba->tot; a++, cbd1++) if(cbd1->pos > in) break;
+
+ if(a==coba->tot) cbd1--;
+
+ if(in > cbd1->pos) {
+ out[0]= cbd1->r;
+ out[1]= cbd1->g;
+ out[2]= cbd1->b;
+ out[3]= cbd1->a;
+ }
+ else {
- if(coba->ipotype==1) { /* EASE */
- mfac= fac*fac;
- fac= 3.0f*mfac-2.0f*mfac*fac;
+ cbd2= cbd1-1;
+ fac= (in-cbd1->pos)/(cbd2->pos-cbd1->pos);
+
+ if(coba->ipotype==2) {
+ /* ipo from right to left: 3 2 1 0 */
+
+ if(a>=coba->tot-1) cbd0= cbd1;
+ else cbd0= cbd1+1;
+ if(a<2) cbd3= cbd2;
+ else cbd3= cbd2-1;
+
+ set_four_ipo(fac, t, KEY_BSPLINE);
+
+ out[0]= t[3]*cbd3->r +t[2]*cbd2->r +t[1]*cbd1->r +t[0]*cbd0->r;
+ out[1]= t[3]*cbd3->g +t[2]*cbd2->g +t[1]*cbd1->g +t[0]*cbd0->g;
+ out[2]= t[3]*cbd3->b +t[2]*cbd2->b +t[1]*cbd1->b +t[0]*cbd0->b;
+ out[3]= t[3]*cbd3->a +t[2]*cbd2->a +t[1]*cbd1->a +t[0]*cbd0->a;
+ CLAMP(out[0], 0.0, 1.0);
+ CLAMP(out[1], 0.0, 1.0);
+ CLAMP(out[2], 0.0, 1.0);
+ CLAMP(out[3], 0.0, 1.0);
+ }
+ else {
+
+ if(coba->ipotype==1) { /* EASE */
+ mfac= fac*fac;
+ fac= 3.0f*mfac-2.0f*mfac*fac;
+ }
+ mfac= 1.0f-fac;
+
+ out[0]= mfac*cbd1->r + fac*cbd2->r;
+ out[1]= mfac*cbd1->g + fac*cbd2->g;
+ out[2]= mfac*cbd1->b + fac*cbd2->b;
+ out[3]= mfac*cbd1->a + fac*cbd2->a;
+ }
}
- mfac= 1.0f-fac;
-
- out[0]= mfac*cbd1->r + fac*cbd2->r;
- out[1]= mfac*cbd1->g + fac*cbd2->g;
- out[2]= mfac*cbd1->b + fac*cbd2->b;
- out[3]= mfac*cbd1->a + fac*cbd2->a;
}
}
return 1; /* OK */