fix [#27746] Black and White Render doesn't work and/or Saves as a Blank screen
convert to grayscale when saving renders rather then only writing the red channel.
This commit is contained in:
@@ -70,6 +70,7 @@ unsigned int rgb_to_cpack(float r, float g, float b);
|
||||
unsigned int hsv_to_cpack(float h, float s, float v);
|
||||
|
||||
float rgb_to_grayscale(float rgb[3]);
|
||||
unsigned char rgb_to_grayscale_byte(unsigned char rgb[3]);
|
||||
|
||||
/***************** Profile Transformations ********************/
|
||||
|
||||
|
||||
@@ -488,6 +488,11 @@ float rgb_to_grayscale(float rgb[3])
|
||||
return 0.3f*rgb[0] + 0.58f*rgb[1] + 0.12f*rgb[2];
|
||||
}
|
||||
|
||||
unsigned char rgb_to_grayscale_byte(unsigned char rgb[3])
|
||||
{
|
||||
return (76*(unsigned short)rgb[0] + 148*(unsigned short)rgb[1] + 31*(unsigned short)rgb[2]) / 255;
|
||||
}
|
||||
|
||||
/* ********************************* lift/gamma/gain / ASC-CDL conversion ********************************* */
|
||||
|
||||
void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power)
|
||||
|
||||
@@ -220,6 +220,11 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
|
||||
if(oglrender->write_still) {
|
||||
char name[FILE_MAX];
|
||||
int ok;
|
||||
|
||||
if(scene->r.planes == 8) {
|
||||
IMB_color_to_bw(ibuf);
|
||||
}
|
||||
|
||||
BKE_makepicstring(name, scene->r.pic, scene->r.cfra, scene->r.imtype, scene->r.scemode & R_EXTENSION, FALSE);
|
||||
ok= BKE_write_ibuf(ibuf, name, scene->r.imtype, scene->r.subimtype, scene->r.quality); /* no need to stamp here */
|
||||
if(ok) printf("OpenGL Render written to '%s'\n", name);
|
||||
@@ -433,6 +438,19 @@ static int screen_opengl_render_anim_step(bContext *C, wmOperator *op)
|
||||
ibuf= BKE_image_acquire_ibuf(oglrender->ima, &oglrender->iuser, &lock);
|
||||
|
||||
if(ibuf) {
|
||||
short ibuf_free= FALSE;
|
||||
|
||||
/* color -> greyscale */
|
||||
/* editing directly would alter the render view */
|
||||
if(scene->r.planes == 8) {
|
||||
ImBuf *ibuf_bw= IMB_dupImBuf(ibuf);
|
||||
IMB_color_to_bw(ibuf_bw);
|
||||
// IMB_freeImBuf(ibuf); /* owned by the image */
|
||||
ibuf= ibuf_bw;
|
||||
|
||||
ibuf_free= TRUE;
|
||||
}
|
||||
|
||||
if(BKE_imtype_is_movie(scene->r.imtype)) {
|
||||
ok= oglrender->mh->append_movie(&scene->r, CFRA, (int*)ibuf->rect, oglrender->sizex, oglrender->sizey, oglrender->reports);
|
||||
if(ok) {
|
||||
@@ -453,6 +471,10 @@ static int screen_opengl_render_anim_step(bContext *C, wmOperator *op)
|
||||
BKE_reportf(op->reports, RPT_INFO, "Saved file: %s", name);
|
||||
}
|
||||
}
|
||||
|
||||
if(ibuf_free) {
|
||||
IMB_freeImBuf(ibuf);
|
||||
}
|
||||
}
|
||||
|
||||
BKE_image_release_ibuf(oglrender->ima, lock);
|
||||
|
||||
@@ -338,6 +338,7 @@ void IMB_float_from_rect_simple(struct ImBuf *ibuf); /* no profile conversion */
|
||||
/* note, check that the conversion exists, only some are supported */
|
||||
void IMB_convert_profile(struct ImBuf *ibuf, int profile);
|
||||
float *IMB_float_profile_ensure(struct ImBuf *ibuf, int profile, int *alloc);
|
||||
void IMB_color_to_bw(struct ImBuf *ibuf);
|
||||
|
||||
/**
|
||||
* Change the ordering of the color bytes pointed to by rect from
|
||||
|
||||
@@ -490,3 +490,23 @@ float *IMB_float_profile_ensure(struct ImBuf *ibuf, int profile, int *alloc)
|
||||
return fbuf;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* no profile conversion */
|
||||
void IMB_color_to_bw(struct ImBuf *ibuf)
|
||||
{
|
||||
float *rctf= ibuf->rect_float;
|
||||
unsigned char *rct= (unsigned char *)ibuf->rect;
|
||||
int i;
|
||||
if(rctf) {
|
||||
for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4) {
|
||||
rctf[0]= rctf[1]= rctf[2]= rgb_to_grayscale(rctf);
|
||||
}
|
||||
}
|
||||
|
||||
if(rct) {
|
||||
for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) {
|
||||
rct[0]= rct[1]= rct[2]= rgb_to_grayscale_byte(rct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2995,6 +2995,15 @@ static int do_write_image_or_movie(Render *re, Scene *scene, bMovieHandle *mh, R
|
||||
}
|
||||
}
|
||||
|
||||
/* color -> greyscale */
|
||||
/* editing directly would alter the render view */
|
||||
if(scene->r.planes == 8) {
|
||||
ImBuf *ibuf_bw= IMB_dupImBuf(ibuf);
|
||||
IMB_color_to_bw(ibuf_bw);
|
||||
IMB_freeImBuf(ibuf);
|
||||
ibuf= ibuf_bw;
|
||||
}
|
||||
|
||||
ok= BKE_write_ibuf_stamp(scene, camera, ibuf, name, scene->r.imtype, scene->r.subimtype, scene->r.quality);
|
||||
|
||||
if(ok==0) {
|
||||
|
||||
Reference in New Issue
Block a user