diff options
Diffstat (limited to 'source/blender/render/intern/source/imagetexture.c')
-rw-r--r-- | source/blender/render/intern/source/imagetexture.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index 23b5e597070..b9a2acb8b1c 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -32,6 +32,7 @@ #include <string.h> #include <fcntl.h> #include <math.h> +#include <float.h> #ifndef WIN32 #include <unistd.h> #else @@ -93,10 +94,10 @@ static void ibuf_get_color(float *col, struct ImBuf *ibuf, int x, int y) else { char *rect = (char *)( ibuf->rect+ ofs); - col[0] = ((float)rect[0])/255.0f; - col[1] = ((float)rect[1])/255.0f; - col[2] = ((float)rect[2])/255.0f; - col[3] = ((float)rect[3])/255.0f; + col[0] = ((float)rect[0])*(1.0f/255.0f); + col[1] = ((float)rect[1])*(1.0f/255.0f); + col[2] = ((float)rect[2])*(1.0f/255.0f); + col[3] = ((float)rect[3])*(1.0f/255.0f); } } @@ -245,7 +246,7 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, TexResult *texre if(tex->flag & TEX_NEGALPHA) texres->ta= 1.0f-texres->ta; /* de-premul, this is being premulled in shade_input_do_shade() */ - if(texres->ta!=1.0f && texres->ta!=0.0f) { + if(texres->ta!=1.0f && texres->ta>FLT_EPSILON) { fx= 1.0f/texres->ta; texres->tr*= fx; texres->tg*= fx; @@ -576,10 +577,10 @@ static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float max if(texres->talpha==0) texres->ta= 1.0; if(alphaclip!=1.0) { - /* this is for later investigation, premul or not? */ - /* texres->tr*= alphaclip; */ - /* texres->tg*= alphaclip; */ - /* texres->tb*= alphaclip; */ + /* premul it all */ + texres->tr*= alphaclip; + texres->tg*= alphaclip; + texres->tb*= alphaclip; texres->ta*= alphaclip; } } @@ -615,6 +616,7 @@ void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float *res return; } + memset(&texres, 0, sizeof(texres)); boxsample(ibuf, fx, fy, fx+dx, fy+dy, &texres, 0, 1); result[0]= texres.tr; result[1]= texres.tg; @@ -699,10 +701,22 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, float *dxt, f maxy= MAX3(dxt[1],dyt[1],dxt[1]+dyt[1] ); /* tex_sharper has been removed */ - minx= tex->filtersize*(maxx-minx)/2.0f; - miny= tex->filtersize*(maxy-miny)/2.0f; + minx= (maxx-minx)/2.0f; + miny= (maxy-miny)/2.0f; - if(tex->filtersize!=1.0f) { + if(tex->imaflag & TEX_FILTER_MIN) { + /* make sure the filtersize is minimal in pixels (normal, ref map can have miniature pixel dx/dy) */ + float addval= (0.5f * tex->filtersize) / (float) MIN2(ibuf->x, ibuf->y); + + if(addval > minx) + minx= addval; + if(addval > miny) + miny= addval; + } + else if(tex->filtersize!=1.0f) { + minx*= tex->filtersize; + miny*= tex->filtersize; + dxt[0]*= tex->filtersize; dxt[1]*= tex->filtersize; dyt[0]*= tex->filtersize; @@ -977,7 +991,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, float *texvec, float *dxt, f } /* de-premul, this is being premulled in shade_input_do_shade() */ - if(texres->ta!=1.0f && texres->ta!=0.0f) { + if(texres->ta!=1.0f && texres->ta>FLT_EPSILON) { fx= 1.0f/texres->ta; texres->tr*= fx; texres->tg*= fx; |