Cleanup: Remove non-working channels parameter of BLF_buffer
BLF_buffer was trying to accept "how many colors channels in output image?" argument and doing math with it, but in the lowest level code was always writing out full 4 channels for each pixel. All the call sites would ever call it with argument of 4 however, and that is why no one noticed the issue. Pull Request: https://projects.blender.org/blender/blender/pulls/121630
This commit is contained in:
committed by
Aras Pranckevicius
parent
30e3f14bcd
commit
008483fe8a
@@ -261,23 +261,12 @@ void BLF_shadow(int fontid, int level, const float rgba[4]) ATTR_NONNULL(3);
|
||||
void BLF_shadow_offset(int fontid, int x, int y);
|
||||
|
||||
/**
|
||||
* Set the buffer, size and number of channels to draw, one thing to take care is call
|
||||
* this function with NULL pointer when we finish, for example:
|
||||
* \code{.c}
|
||||
* BLF_buffer(my_fbuf, my_cbuf, 100, 100, 4, true, NULL);
|
||||
*
|
||||
* ... set color, position and draw ...
|
||||
*
|
||||
* BLF_buffer(NULL, NULL, NULL, 0, 0, false, NULL);
|
||||
* \endcode
|
||||
* Make font be rasterized into a given memory image/buffer.
|
||||
* The image is assumed to have 4 color channels (RGBA) per pixel.
|
||||
* When done, call this function with null buffer pointers.
|
||||
*/
|
||||
void BLF_buffer(int fontid,
|
||||
float *fbuf,
|
||||
unsigned char *cbuf,
|
||||
int w,
|
||||
int h,
|
||||
int nch,
|
||||
ColorManagedDisplay *display);
|
||||
void BLF_buffer(
|
||||
int fontid, float *fbuf, unsigned char *cbuf, int w, int h, ColorManagedDisplay *display);
|
||||
|
||||
/**
|
||||
* Set the color to be used for text.
|
||||
|
||||
@@ -843,8 +843,7 @@ void BLF_shadow_offset(int fontid, int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
void BLF_buffer(
|
||||
int fontid, float *fbuf, uchar *cbuf, int w, int h, int nch, ColorManagedDisplay *display)
|
||||
void BLF_buffer(int fontid, float *fbuf, uchar *cbuf, int w, int h, ColorManagedDisplay *display)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
@@ -853,7 +852,6 @@ void BLF_buffer(
|
||||
font->buf_info.cbuf = cbuf;
|
||||
font->buf_info.dims[0] = w;
|
||||
font->buf_info.dims[1] = h;
|
||||
font->buf_info.ch = nch;
|
||||
font->buf_info.display = display;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,14 +587,14 @@ static void blf_glyph_draw_buffer(FontBufInfoBLF *buf_info,
|
||||
if (buf_info->fbuf) {
|
||||
int yb = yb_start;
|
||||
for (int y = ((chy >= 0) ? 0 : -chy); y < height_clip; y++) {
|
||||
for (int x = ((chx >= 0) ? 0 : -chx); x < width_clip; x++) {
|
||||
const char a_byte = *(g->bitmap + x + (yb * g->pitch));
|
||||
const int x_start = (chx >= 0) ? 0 : -chx;
|
||||
const uchar *a_ptr = g->bitmap + x_start + (yb * g->pitch);
|
||||
const int64_t buf_ofs = (int64_t(buf_info->dims[0]) * (pen_y_px + y) + (chx + x_start)) * 4;
|
||||
float *fbuf = buf_info->fbuf + buf_ofs;
|
||||
for (int x = x_start; x < width_clip; x++, a_ptr++, fbuf += 4) {
|
||||
const char a_byte = *a_ptr;
|
||||
if (a_byte) {
|
||||
const float a = (a_byte / 255.0f) * b_col_float[3];
|
||||
const size_t buf_ofs = ((size_t(chx + x) +
|
||||
(size_t(pen_y_px + y) * size_t(buf_info->dims[0]))) *
|
||||
size_t(buf_info->ch));
|
||||
float *fbuf = buf_info->fbuf + buf_ofs;
|
||||
|
||||
float font_pixel[4];
|
||||
font_pixel[0] = b_col_float[0] * a;
|
||||
@@ -617,15 +617,15 @@ static void blf_glyph_draw_buffer(FontBufInfoBLF *buf_info,
|
||||
if (buf_info->cbuf) {
|
||||
int yb = yb_start;
|
||||
for (int y = ((chy >= 0) ? 0 : -chy); y < height_clip; y++) {
|
||||
for (int x = ((chx >= 0) ? 0 : -chx); x < width_clip; x++) {
|
||||
const char a_byte = *(g->bitmap + x + (yb * g->pitch));
|
||||
const int x_start = (chx >= 0) ? 0 : -chx;
|
||||
const uchar *a_ptr = g->bitmap + x_start + (yb * g->pitch);
|
||||
const int64_t buf_ofs = (int64_t(buf_info->dims[0]) * (pen_y_px + y) + (chx + x_start)) * 4;
|
||||
uchar *cbuf = buf_info->cbuf + buf_ofs;
|
||||
for (int x = x_start; x < width_clip; x++, a_ptr++, cbuf += 4) {
|
||||
const char a_byte = *a_ptr;
|
||||
|
||||
if (a_byte) {
|
||||
const float a = (a_byte / 255.0f) * b_col_float[3];
|
||||
const size_t buf_ofs = ((size_t(chx + x) +
|
||||
(size_t(pen_y_px + y) * size_t(buf_info->dims[0]))) *
|
||||
size_t(buf_info->ch));
|
||||
uchar *cbuf = buf_info->cbuf + buf_ofs;
|
||||
|
||||
uchar font_pixel[4];
|
||||
font_pixel[0] = b_col_char[0];
|
||||
@@ -1470,7 +1470,6 @@ static void blf_font_fill(FontBLF *font)
|
||||
font->buf_info.cbuf = nullptr;
|
||||
font->buf_info.dims[0] = 0;
|
||||
font->buf_info.dims[1] = 0;
|
||||
font->buf_info.ch = 0;
|
||||
font->buf_info.col_init[0] = 0;
|
||||
font->buf_info.col_init[1] = 0;
|
||||
font->buf_info.col_init[2] = 0;
|
||||
|
||||
@@ -219,9 +219,6 @@ struct FontBufInfoBLF {
|
||||
/** Buffer size, keep signed so comparisons with negative values work. */
|
||||
int dims[2];
|
||||
|
||||
/** Number of channels. */
|
||||
int ch;
|
||||
|
||||
/** Display device used for color management. */
|
||||
ColorManagedDisplay *display;
|
||||
|
||||
|
||||
@@ -84,8 +84,7 @@ void BKE_image_stamp_buf(struct Scene *scene,
|
||||
unsigned char *rect,
|
||||
float *rectf,
|
||||
int width,
|
||||
int height,
|
||||
int channels);
|
||||
int height);
|
||||
bool BKE_imbuf_alpha_test(struct ImBuf *ibuf);
|
||||
int BKE_imbuf_write_stamp(const struct Scene *scene,
|
||||
const struct RenderResult *rr,
|
||||
|
||||
@@ -1978,8 +1978,7 @@ void BKE_image_stamp_buf(Scene *scene,
|
||||
uchar *rect,
|
||||
float *rectf,
|
||||
int width,
|
||||
int height,
|
||||
int channels)
|
||||
int height)
|
||||
{
|
||||
StampData stamp_data;
|
||||
int w, h, pad;
|
||||
@@ -2034,7 +2033,7 @@ void BKE_image_stamp_buf(Scene *scene,
|
||||
BLF_size(mono, scene->r.stamp_font_id);
|
||||
BLF_wordwrap(mono, width - (BUFF_MARGIN_X * 2));
|
||||
|
||||
BLF_buffer(mono, rectf, rect, width, height, channels, display);
|
||||
BLF_buffer(mono, rectf, rect, width, height, display);
|
||||
BLF_buffer_col(mono, scene->r.fg_stamp);
|
||||
pad = BLF_width_max(mono);
|
||||
|
||||
@@ -2358,7 +2357,7 @@ void BKE_image_stamp_buf(Scene *scene,
|
||||
}
|
||||
|
||||
/* cleanup the buffer. */
|
||||
BLF_buffer(mono, nullptr, nullptr, 0, 0, 0, nullptr);
|
||||
BLF_buffer(mono, nullptr, nullptr, 0, 0, nullptr);
|
||||
BLF_wordwrap(mono, 0);
|
||||
|
||||
#undef TEXT_SIZE_CHECK
|
||||
|
||||
@@ -361,7 +361,7 @@ static void checker_board_text(
|
||||
* this is correct since currently generated images are assumed to be in sRGB space,
|
||||
* but this would probably needed to be fixed in some way
|
||||
*/
|
||||
BLF_buffer(mono, rect_float, rect, width, height, 4, nullptr);
|
||||
BLF_buffer(mono, rect_float, rect, width, height, nullptr);
|
||||
|
||||
const float text_color[4] = {0.0, 0.0, 0.0, 1.0};
|
||||
const float text_outline[4] = {1.0, 1.0, 1.0, 1.0};
|
||||
@@ -413,7 +413,7 @@ static void checker_board_text(
|
||||
}
|
||||
|
||||
/* cleanup the buffer. */
|
||||
BLF_buffer(mono, nullptr, nullptr, 0, 0, 0, nullptr);
|
||||
BLF_buffer(mono, nullptr, nullptr, 0, 0, nullptr);
|
||||
}
|
||||
|
||||
static void checker_board_color_prepare_slice(
|
||||
|
||||
@@ -393,7 +393,7 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R
|
||||
else {
|
||||
rect = ibuf_result->byte_buffer.data;
|
||||
}
|
||||
BKE_image_stamp_buf(scene, camera, nullptr, rect, rectf, rr->rectx, rr->recty, 4);
|
||||
BKE_image_stamp_buf(scene, camera, nullptr, rect, rectf, rr->rectx, rr->recty);
|
||||
}
|
||||
RE_render_result_rect_from_ibuf(rr, ibuf_result, oglrender->view_id);
|
||||
IMB_freeImBuf(ibuf_result);
|
||||
|
||||
@@ -1360,8 +1360,7 @@ static void renderresult_stampinfo(Render *re)
|
||||
rres.ibuf->byte_buffer.data,
|
||||
rres.ibuf->float_buffer.data,
|
||||
rres.rectx,
|
||||
rres.recty,
|
||||
4);
|
||||
rres.recty);
|
||||
RE_ReleaseResultImage(re);
|
||||
nr++;
|
||||
}
|
||||
|
||||
@@ -2798,7 +2798,7 @@ static void draw_text_shadow(const SeqRenderData *context,
|
||||
* not get blur. */
|
||||
tmp_out1 = prepare_effect_imbufs(context, nullptr, nullptr, nullptr, false);
|
||||
tmp_out2 = prepare_effect_imbufs(context, nullptr, nullptr, nullptr, false);
|
||||
BLF_buffer(font, nullptr, tmp_out1->byte_buffer.data, width, height, 4, display);
|
||||
BLF_buffer(font, nullptr, tmp_out1->byte_buffer.data, width, height, display);
|
||||
}
|
||||
|
||||
float offsetx = cosf(data->shadow_angle) * line_height * data->shadow_offset;
|
||||
@@ -2877,7 +2877,7 @@ static void draw_text_shadow(const SeqRenderData *context,
|
||||
});
|
||||
IMB_freeImBuf(tmp_out1);
|
||||
IMB_freeImBuf(tmp_out2);
|
||||
BLF_buffer(font, nullptr, out->byte_buffer.data, width, height, out->channels, display);
|
||||
BLF_buffer(font, nullptr, out->byte_buffer.data, width, height, display);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2960,7 +2960,7 @@ static void draw_text_outline(const SeqRenderData *context,
|
||||
/* Draw white text into temporary buffer. */
|
||||
const size_t pixel_count = size_t(size.x) * size.y;
|
||||
Array<uchar4> tmp_buf(pixel_count, uchar4(0));
|
||||
BLF_buffer(font, nullptr, (uchar *)tmp_buf.data(), size.x, size.y, 4, display);
|
||||
BLF_buffer(font, nullptr, (uchar *)tmp_buf.data(), size.x, size.y, display);
|
||||
BLF_position(font, x, y, 0.0f);
|
||||
BLF_buffer_col(font, float4(1.0f));
|
||||
BLF_draw_buffer(font, data->text, sizeof(data->text));
|
||||
@@ -3042,7 +3042,7 @@ static void draw_text_outline(const SeqRenderData *context,
|
||||
}
|
||||
}
|
||||
});
|
||||
BLF_buffer(font, nullptr, out->byte_buffer.data, size.x, size.y, out->channels, display);
|
||||
BLF_buffer(font, nullptr, out->byte_buffer.data, size.x, size.y, display);
|
||||
}
|
||||
|
||||
static ImBuf *do_text_effect(const SeqRenderData *context,
|
||||
@@ -3093,7 +3093,7 @@ static ImBuf *do_text_effect(const SeqRenderData *context,
|
||||
/* use max width to enable newlines only */
|
||||
BLF_wordwrap(font, (data->wrap_width != 0.0f) ? data->wrap_width * width : -1);
|
||||
|
||||
BLF_buffer(font, nullptr, out->byte_buffer.data, width, height, out->channels, display);
|
||||
BLF_buffer(font, nullptr, out->byte_buffer.data, width, height, display);
|
||||
|
||||
const int line_height = BLF_height_max(font);
|
||||
|
||||
@@ -3157,7 +3157,7 @@ static ImBuf *do_text_effect(const SeqRenderData *context,
|
||||
BLF_buffer_col(font, data->color);
|
||||
BLF_draw_buffer(font, data->text, sizeof(data->text));
|
||||
|
||||
BLF_buffer(font, nullptr, nullptr, 0, 0, 0, nullptr);
|
||||
BLF_buffer(font, nullptr, nullptr, 0, 0, nullptr);
|
||||
|
||||
BLF_disable(font, font_flags);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user