- Restored "dither" option for conversion from float -> byte images.

This now is a post-process option only (used to be in render).
  It is only handled within the Imbuf/ module, on conversions from float
  to byte rect, which atm mostly happens on saving images.

- Small fix: when using Scene RenderLayer nodes, the speed vectors for
  these nodes were not created when that scene had "Do Composite" off.
This commit is contained in:
2006-02-18 14:35:43 +00:00
parent 7425a8fcaa
commit 1ea9099474
4 changed files with 42 additions and 10 deletions

View File

@@ -96,6 +96,7 @@ typedef struct ImBuf{
unsigned int encodedbuffersize; /**< Size of encodedbuffer */
float *rect_float; /**< floating point Rect equivilant */
float dither; /**< random dither value, for conversion from float -> byte rect */
struct MEM_CacheLimiterHandle_s * c_handle; /**< handle for cache limiter */
int refcounter; /**< Refcounter for multiple users */

View File

@@ -33,6 +33,7 @@
*/
#include "BLI_blenlib.h"
#include "BLI_rand.h"
#include "imbuf.h"
#include "imbuf_patch.h"
@@ -172,6 +173,7 @@ void IMB_rect_from_float(struct ImBuf *ibuf)
{
/* quick method to convert floatbuf to byte */
float *tof = ibuf->rect_float;
float dither= ibuf->dither;
int i;
unsigned char *to = (unsigned char *) ibuf->rect;
@@ -181,8 +183,8 @@ void IMB_rect_from_float(struct ImBuf *ibuf)
to = (unsigned char *) ibuf->rect;
}
for (i = ibuf->x * ibuf->y; i > 0; i--)
{
if(dither==0.0f) {
for (i = ibuf->x * ibuf->y; i > 0; i--) {
to[0] = FTOCHAR(tof[0]);
to[1] = FTOCHAR(tof[1]);
to[2] = FTOCHAR(tof[2]);
@@ -191,6 +193,25 @@ void IMB_rect_from_float(struct ImBuf *ibuf)
tof += 4;
}
}
else {
float dither_value, col;
dither= dither/255.0f;
for (i = ibuf->x * ibuf->y; i > 0; i--) {
dither_value = (BLI_frand()-0.5)*dither;
col= tof[0] + dither_value;
to[0] = FTOCHAR(col);
col= tof[1] + dither_value;
to[1] = FTOCHAR(col);
col= tof[2] + dither_value;
to[2] = FTOCHAR(col);
col= tof[3] + dither_value;
to[3] = FTOCHAR(col);
to += 4;
tof += 4;
}
}
}
void IMB_float_from_rect(struct ImBuf *ibuf)
{

View File

@@ -936,6 +936,9 @@ static void do_render_scene_node(Render *re, Scene *sce, int cfra)
/* makes render result etc */
RE_InitState(resc, &sce->r, re->winx, re->winy, &re->disprect);
/* this to enable this scene to create speed vectors */
resc->r.scemode |= R_DOCOMP;
/* now use renderdata and camera to set viewplane */
if(sce->camera==NULL) return;
RE_SetCamera(resc, sce->camera);
@@ -1222,10 +1225,14 @@ static void do_write_image_or_movie(Render *re, Scene *scene, bMovieHandle *mh)
/* if not exists, BKE_write_ibuf makes one */
ibuf->rect= rres.rect32;
ibuf->rect_float= rres.rectf;
ibuf->zbuf_float= rres.rectz;
/* float factor for random dither, imbuf takes care of it */
ibuf->dither= scene->r.dither_intensity;
ok= BKE_write_ibuf(ibuf, name, scene->r.imtype, scene->r.subimtype, scene->r.quality);
if(ok==0) {
printf("Render error: cannot save %s\n", name);
G.afbreek=1;

View File

@@ -136,6 +136,9 @@ static void save_rendered_image_cb_real(char *name, int zbuf)
ibuf->zbuf_float= rres.rectz;
}
/* float factor for random dither, imbuf takes care of it */
ibuf->dither= G.scene->r.dither_intensity;
BKE_write_ibuf(ibuf, str, G.scene->r.imtype, G.scene->r.subimtype, G.scene->r.quality);
IMB_freeImBuf(ibuf); /* imbuf knows rects are not part of ibuf */