diff --git a/source/blender/blenfont/BLF_api.hh b/source/blender/blenfont/BLF_api.hh index 99853585e1d..3766986de52 100644 --- a/source/blender/blenfont/BLF_api.hh +++ b/source/blender/blenfont/BLF_api.hh @@ -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. diff --git a/source/blender/blenfont/intern/blf.cc b/source/blender/blenfont/intern/blf.cc index c72a1229730..8fc7eaa8cd2 100644 --- a/source/blender/blenfont/intern/blf.cc +++ b/source/blender/blenfont/intern/blf.cc @@ -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; } } diff --git a/source/blender/blenfont/intern/blf_font.cc b/source/blender/blenfont/intern/blf_font.cc index 06c9448d9d1..ce187623749 100644 --- a/source/blender/blenfont/intern/blf_font.cc +++ b/source/blender/blenfont/intern/blf_font.cc @@ -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; diff --git a/source/blender/blenfont/intern/blf_internal_types.hh b/source/blender/blenfont/intern/blf_internal_types.hh index 80d42fc6734..a941ba52976 100644 --- a/source/blender/blenfont/intern/blf_internal_types.hh +++ b/source/blender/blenfont/intern/blf_internal_types.hh @@ -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; diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 5252dfa7e7b..89ff47e70c3 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -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, diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index 8cbd42b601e..bab1f467920 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -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 diff --git a/source/blender/blenkernel/intern/image_gen.cc b/source/blender/blenkernel/intern/image_gen.cc index 1b22d1b44f8..68f1413d89f 100644 --- a/source/blender/blenkernel/intern/image_gen.cc +++ b/source/blender/blenkernel/intern/image_gen.cc @@ -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( diff --git a/source/blender/editors/render/render_opengl.cc b/source/blender/editors/render/render_opengl.cc index d143800e267..f6b77f6ac14 100644 --- a/source/blender/editors/render/render_opengl.cc +++ b/source/blender/editors/render/render_opengl.cc @@ -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); diff --git a/source/blender/render/intern/pipeline.cc b/source/blender/render/intern/pipeline.cc index 1a505b5349e..0ef845fd060 100644 --- a/source/blender/render/intern/pipeline.cc +++ b/source/blender/render/intern/pipeline.cc @@ -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++; } diff --git a/source/blender/sequencer/intern/effects.cc b/source/blender/sequencer/intern/effects.cc index 8e3ace93cf5..9f0ba8ab03b 100644 --- a/source/blender/sequencer/intern/effects.cc +++ b/source/blender/sequencer/intern/effects.cc @@ -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 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);