Core: use UTF8 string formatting for BKE_image

Also use UTF8 string functions elsewhere for RenderSlot::name &
RenderView::name.
This commit is contained in:
Campbell Barton
2025-07-22 16:41:13 +10:00
parent 0501555dcc
commit 4d4f518d80
5 changed files with 78 additions and 74 deletions

View File

@@ -527,7 +527,7 @@ static void imagecache_put(Image *image, int index, ImBuf *ibuf)
if (image->cache == nullptr) {
// char cache_name[64];
// SNPRINTF(cache_name, "Image Datablock %s", image->id.name);
// SNPRINTF_UTF8(cache_name, "Image Datablock %s", image->id.name);
image->cache = IMB_moviecache_create(
"Image Datablock Cache", sizeof(ImageCacheKey), imagecache_hashhash, imagecache_hashcmp);
@@ -1725,9 +1725,9 @@ static void stampdata(
if (scene->r.stamp & R_STAMP_FILENAME) {
const char *blendfile_path = BKE_main_blendfile_path_from_global();
SNPRINTF(stamp_data->file,
do_prefix ? "File %s" : "%s",
(blendfile_path[0] != '\0') ? blendfile_path : "<untitled>");
SNPRINTF_UTF8(stamp_data->file,
do_prefix ? "File %s" : "%s",
(blendfile_path[0] != '\0') ? blendfile_path : "<untitled>");
}
else {
stamp_data->file[0] = '\0';
@@ -1735,7 +1735,7 @@ static void stampdata(
if (scene->r.stamp & R_STAMP_NOTE) {
/* Never do prefix for Note */
STRNCPY(stamp_data->note, scene->r.stamp_udata);
STRNCPY_UTF8(stamp_data->note, scene->r.stamp_udata);
}
else {
stamp_data->note[0] = '\0';
@@ -1744,15 +1744,15 @@ static void stampdata(
if (scene->r.stamp & R_STAMP_DATE) {
t = time(nullptr);
tl = localtime(&t);
SNPRINTF(text,
"%04d/%02d/%02d %02d:%02d:%02d",
tl->tm_year + 1900,
tl->tm_mon + 1,
tl->tm_mday,
tl->tm_hour,
tl->tm_min,
tl->tm_sec);
SNPRINTF(stamp_data->date, do_prefix ? "Date %s" : "%s", text);
SNPRINTF_UTF8(text,
"%04d/%02d/%02d %02d:%02d:%02d",
tl->tm_year + 1900,
tl->tm_mon + 1,
tl->tm_mday,
tl->tm_hour,
tl->tm_min,
tl->tm_sec);
SNPRINTF_UTF8(stamp_data->date, do_prefix ? "Date %s" : "%s", text);
}
else {
stamp_data->date[0] = '\0';
@@ -1762,13 +1762,13 @@ static void stampdata(
const char *name = BKE_scene_find_last_marker_name(scene, scene->r.cfra);
if (name) {
STRNCPY(text, name);
STRNCPY_UTF8(text, name);
}
else {
STRNCPY(text, "<none>");
STRNCPY_UTF8(text, "<none>");
}
SNPRINTF(stamp_data->marker, do_prefix ? "Marker %s" : "%s", text);
SNPRINTF_UTF8(stamp_data->marker, do_prefix ? "Marker %s" : "%s", text);
}
else {
stamp_data->marker[0] = '\0';
@@ -1778,7 +1778,7 @@ static void stampdata(
const short timecode_style = USER_TIMECODE_SMPTE_FULL;
BLI_timecode_string_from_time(
text, sizeof(text), 0, FRA2TIME(scene->r.cfra), FPS, timecode_style);
SNPRINTF(stamp_data->time, do_prefix ? "Timecode %s" : "%s", text);
SNPRINTF_UTF8(stamp_data->time, do_prefix ? "Timecode %s" : "%s", text);
}
else {
stamp_data->time[0] = '\0';
@@ -1792,27 +1792,27 @@ static void stampdata(
digits = integer_digits_i(scene->r.efra);
}
SNPRINTF(fmtstr, do_prefix ? "Frame %%0%di" : "%%0%di", digits);
SNPRINTF(stamp_data->frame, fmtstr, scene->r.cfra);
SNPRINTF_UTF8(fmtstr, do_prefix ? "Frame %%0%di" : "%%0%di", digits);
SNPRINTF_UTF8(stamp_data->frame, fmtstr, scene->r.cfra);
}
else {
stamp_data->frame[0] = '\0';
}
if (scene->r.stamp & R_STAMP_FRAME_RANGE) {
SNPRINTF(stamp_data->frame_range,
do_prefix ? "Frame Range %d:%d" : "%d:%d",
scene->r.sfra,
scene->r.efra);
SNPRINTF_UTF8(stamp_data->frame_range,
do_prefix ? "Frame Range %d:%d" : "%d:%d",
scene->r.sfra,
scene->r.efra);
}
else {
stamp_data->frame_range[0] = '\0';
}
if (use_dynamic && scene->r.stamp & R_STAMP_CAMERA) {
SNPRINTF(stamp_data->camera,
do_prefix ? "Camera %s" : "%s",
camera ? camera->id.name + 2 : "<none>");
SNPRINTF_UTF8(stamp_data->camera,
do_prefix ? "Camera %s" : "%s",
camera ? camera->id.name + 2 : "<none>");
}
else {
stamp_data->camera[0] = '\0';
@@ -1820,20 +1820,20 @@ static void stampdata(
if (use_dynamic && scene->r.stamp & R_STAMP_CAMERALENS) {
if (camera && camera->type == OB_CAMERA) {
SNPRINTF(text, "%.2f", ((Camera *)camera->data)->lens);
SNPRINTF_UTF8(text, "%.2f", ((Camera *)camera->data)->lens);
}
else {
STRNCPY(text, "<none>");
STRNCPY_UTF8(text, "<none>");
}
SNPRINTF(stamp_data->cameralens, do_prefix ? "Lens %s" : "%s", text);
SNPRINTF_UTF8(stamp_data->cameralens, do_prefix ? "Lens %s" : "%s", text);
}
else {
stamp_data->cameralens[0] = '\0';
}
if (scene->r.stamp & R_STAMP_SCENE) {
SNPRINTF(stamp_data->scene, do_prefix ? "Scene %s" : "%s", scene->id.name + 2);
SNPRINTF_UTF8(stamp_data->scene, do_prefix ? "Scene %s" : "%s", scene->id.name + 2);
}
else {
stamp_data->scene[0] = '\0';
@@ -1843,13 +1843,13 @@ static void stampdata(
const Strip *strip = blender::seq::strip_topmost_get(scene, scene->r.cfra);
if (strip) {
STRNCPY(text, strip->name + 2);
STRNCPY_UTF8(text, strip->name + 2);
}
else {
STRNCPY(text, "<none>");
STRNCPY_UTF8(text, "<none>");
}
SNPRINTF(stamp_data->strip, do_prefix ? "Strip %s" : "%s", text);
SNPRINTF_UTF8(stamp_data->strip, do_prefix ? "Strip %s" : "%s", text);
}
else {
stamp_data->strip[0] = '\0';
@@ -1862,24 +1862,24 @@ static void stampdata(
if (use_dynamic && stats && (scene->r.stamp & R_STAMP_RENDERTIME)) {
BLI_timecode_string_from_time_simple(text, sizeof(text), stats->lastframetime);
SNPRINTF(stamp_data->rendertime, do_prefix ? "RenderTime %s" : "%s", text);
SNPRINTF_UTF8(stamp_data->rendertime, do_prefix ? "RenderTime %s" : "%s", text);
}
else {
stamp_data->rendertime[0] = '\0';
}
if (use_dynamic && stats && (scene->r.stamp & R_STAMP_MEMORY)) {
SNPRINTF(stamp_data->memory, do_prefix ? "Peak Memory ddM" : "%dM", stats->mem_peak);
SNPRINTF_UTF8(stamp_data->memory, do_prefix ? "Peak Memory ddM" : "%dM", stats->mem_peak);
}
else {
stamp_data->memory[0] = '\0';
}
}
if (scene->r.stamp & R_STAMP_FRAME_RANGE) {
SNPRINTF(stamp_data->frame_range,
do_prefix ? "Frame Range %d:%d" : "%d:%d",
scene->r.sfra,
scene->r.efra);
SNPRINTF_UTF8(stamp_data->frame_range,
do_prefix ? "Frame Range %d:%d" : "%d:%d",
scene->r.sfra,
scene->r.efra);
}
else {
stamp_data->frame_range[0] = '\0';
@@ -1888,7 +1888,7 @@ static void stampdata(
if (scene->r.stamp & R_STAMP_HOSTNAME) {
char hostname[500]; /* sizeof(stamp_data->hostname) minus some bytes for a label. */
BLI_hostname_get(hostname, sizeof(hostname));
SNPRINTF(stamp_data->hostname, do_prefix ? "Hostname %s" : "%s", hostname);
SNPRINTF_UTF8(stamp_data->hostname, do_prefix ? "Hostname %s" : "%s", hostname);
}
else {
stamp_data->hostname[0] = '\0';
@@ -1901,90 +1901,91 @@ static void stampdata_from_template(StampData *stamp_data,
bool do_prefix)
{
if (scene->r.stamp & R_STAMP_FILENAME) {
SNPRINTF(stamp_data->file, do_prefix ? "File %s" : "%s", stamp_data_template->file);
SNPRINTF_UTF8(stamp_data->file, do_prefix ? "File %s" : "%s", stamp_data_template->file);
}
else {
stamp_data->file[0] = '\0';
}
if (scene->r.stamp & R_STAMP_NOTE) {
STRNCPY(stamp_data->note, stamp_data_template->note);
STRNCPY_UTF8(stamp_data->note, stamp_data_template->note);
}
else {
stamp_data->note[0] = '\0';
}
if (scene->r.stamp & R_STAMP_DATE) {
SNPRINTF(stamp_data->date, do_prefix ? "Date %s" : "%s", stamp_data_template->date);
SNPRINTF_UTF8(stamp_data->date, do_prefix ? "Date %s" : "%s", stamp_data_template->date);
}
else {
stamp_data->date[0] = '\0';
}
if (scene->r.stamp & R_STAMP_MARKER) {
SNPRINTF(stamp_data->marker, do_prefix ? "Marker %s" : "%s", stamp_data_template->marker);
SNPRINTF_UTF8(stamp_data->marker, do_prefix ? "Marker %s" : "%s", stamp_data_template->marker);
}
else {
stamp_data->marker[0] = '\0';
}
if (scene->r.stamp & R_STAMP_TIME) {
SNPRINTF(stamp_data->time, do_prefix ? "Timecode %s" : "%s", stamp_data_template->time);
SNPRINTF_UTF8(stamp_data->time, do_prefix ? "Timecode %s" : "%s", stamp_data_template->time);
}
else {
stamp_data->time[0] = '\0';
}
if (scene->r.stamp & R_STAMP_FRAME) {
SNPRINTF(stamp_data->frame, do_prefix ? "Frame %s" : "%s", stamp_data_template->frame);
SNPRINTF_UTF8(stamp_data->frame, do_prefix ? "Frame %s" : "%s", stamp_data_template->frame);
}
else {
stamp_data->frame[0] = '\0';
}
if (scene->r.stamp & R_STAMP_FRAME_RANGE) {
SNPRINTF(stamp_data->frame_range,
do_prefix ? "Frame Range %s" : "%s",
stamp_data_template->frame_range);
SNPRINTF_UTF8(stamp_data->frame_range,
do_prefix ? "Frame Range %s" : "%s",
stamp_data_template->frame_range);
}
else {
stamp_data->frame_range[0] = '\0';
}
if (scene->r.stamp & R_STAMP_CAMERA) {
SNPRINTF(stamp_data->camera, do_prefix ? "Camera %s" : "%s", stamp_data_template->camera);
SNPRINTF_UTF8(stamp_data->camera, do_prefix ? "Camera %s" : "%s", stamp_data_template->camera);
}
else {
stamp_data->camera[0] = '\0';
}
if (scene->r.stamp & R_STAMP_CAMERALENS) {
SNPRINTF(
SNPRINTF_UTF8(
stamp_data->cameralens, do_prefix ? "Lens %s" : "%s", stamp_data_template->cameralens);
}
else {
stamp_data->cameralens[0] = '\0';
}
if (scene->r.stamp & R_STAMP_SCENE) {
SNPRINTF(stamp_data->scene, do_prefix ? "Scene %s" : "%s", stamp_data_template->scene);
SNPRINTF_UTF8(stamp_data->scene, do_prefix ? "Scene %s" : "%s", stamp_data_template->scene);
}
else {
stamp_data->scene[0] = '\0';
}
if (scene->r.stamp & R_STAMP_SEQSTRIP) {
SNPRINTF(stamp_data->strip, do_prefix ? "Strip %s" : "%s", stamp_data_template->strip);
SNPRINTF_UTF8(stamp_data->strip, do_prefix ? "Strip %s" : "%s", stamp_data_template->strip);
}
else {
stamp_data->strip[0] = '\0';
}
if (scene->r.stamp & R_STAMP_RENDERTIME) {
SNPRINTF(stamp_data->rendertime,
do_prefix ? "RenderTime %s" : "%s",
stamp_data_template->rendertime);
SNPRINTF_UTF8(stamp_data->rendertime,
do_prefix ? "RenderTime %s" : "%s",
stamp_data_template->rendertime);
}
else {
stamp_data->rendertime[0] = '\0';
}
if (scene->r.stamp & R_STAMP_MEMORY) {
SNPRINTF(stamp_data->memory, do_prefix ? "Peak Memory %s" : "%s", stamp_data_template->memory);
SNPRINTF_UTF8(
stamp_data->memory, do_prefix ? "Peak Memory %s" : "%s", stamp_data_template->memory);
}
else {
stamp_data->memory[0] = '\0';
}
if (scene->r.stamp & R_STAMP_HOSTNAME) {
SNPRINTF(
SNPRINTF_UTF8(
stamp_data->hostname, do_prefix ? "Hostname %s" : "%s", stamp_data_template->hostname);
}
else {
@@ -2522,7 +2523,7 @@ void BKE_render_result_stamp_data(RenderResult *rr, const char *key, const char
}
stamp_data = rr->stamp_data;
StampDataCustomField *field = MEM_mallocN<StampDataCustomField>("StampData Custom Field");
STRNCPY(field->key, key);
STRNCPY_UTF8(field->key, key);
field->value = BLI_strdup(value);
BLI_addtail(&stamp_data->custom_fields, field);
}
@@ -2561,7 +2562,7 @@ static void metadata_set_field(void *data,
char *propvalue,
int /*propvalue_maxncpy*/)
{
/* We know it is an ImBuf* because that's what we pass to BKE_stamp_info_callback. */
/* We know it is an `ImBuf *` because that's what we pass to #BKE_stamp_info_callback. */
ImBuf *imbuf = static_cast<ImBuf *>(data);
IMB_metadata_set_field(imbuf->metadata, propname, propvalue);
}
@@ -2571,7 +2572,7 @@ static void metadata_get_field(void *data,
char *propvalue,
int propvalue_maxncpy)
{
/* We know it is an ImBuf* because that's what we pass to BKE_stamp_info_callback. */
/* We know it is an `ImBuf *` because that's what we pass to #BKE_stamp_info_callback. */
ImBuf *imbuf = static_cast<ImBuf *>(data);
IMB_metadata_get_field(imbuf->metadata, propname, propvalue, propvalue_maxncpy);
}
@@ -3502,7 +3503,7 @@ ImageTile *BKE_image_add_tile(Image *ima, int tile_number, const char *label)
}
if (label) {
STRNCPY(tile->label, label);
STRNCPY_UTF8(tile->label, label);
}
for (int eye = 0; eye < 2; eye++) {
@@ -3860,7 +3861,7 @@ static void image_init_multilayer_multiview(Image *ima, RenderResult *rr)
if (rr) {
LISTBASE_FOREACH (RenderView *, rv, &rr->views) {
ImageView *iv = MEM_callocN<ImageView>("Viewer Image View");
STRNCPY(iv->name, rv->name);
STRNCPY_UTF8(iv->name, rv->name);
BLI_addtail(&ima->views, iv);
}
}
@@ -3973,7 +3974,7 @@ static void image_add_view(Image *ima, const char *viewname, const char *filepat
ImageView *iv;
iv = MEM_mallocN<ImageView>("Viewer Image View");
STRNCPY(iv->name, viewname);
STRNCPY_UTF8(iv->name, viewname);
STRNCPY(iv->filepath, filepath);
/* For stereo drawing we need to ensure:
@@ -5666,7 +5667,7 @@ RenderSlot *BKE_image_add_renderslot(Image *ima, const char *name)
}
else {
int n = BLI_listbase_count(&ima->renderslots) + 1;
SNPRINTF(slot->name, DATA_("Slot %d"), n);
SNPRINTF_UTF8(slot->name, DATA_("Slot %d"), n);
}
BLI_addtail(&ima->renderslots, slot);
return slot;

View File

@@ -17,6 +17,7 @@
#include "BLI_math_rotation.h"
#include "BLI_mempool.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
/* Define macros in `DNA_genfile.h`. */
@@ -3770,7 +3771,7 @@ void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain)
if (ima->type == IMA_TYPE_R_RESULT) {
for (int i = 0; i < 8; i++) {
RenderSlot *slot = MEM_callocN<RenderSlot>("Image Render Slot Init");
SNPRINTF(slot->name, "Slot %d", i + 1);
SNPRINTF_UTF8(slot->name, "Slot %d", i + 1);
BLI_addtail(&ima->renderslots, slot);
}
}

View File

@@ -11,6 +11,7 @@
#include "BLI_math_vector.h"
#include "BLI_math_vector_types.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
@@ -85,7 +86,7 @@ void FileOutput::add_view(const char *view_name, int channels, float *buffer)
{
RenderView *render_view = MEM_callocN<RenderView>("Render View For File Output.");
BLI_addtail(&render_result_->views, render_view);
STRNCPY(render_view->name, view_name);
STRNCPY_UTF8(render_view->name, view_name);
render_view->ibuf = IMB_allocImBuf(
render_result_->rectx, render_result_->recty, channels * 8, 0);

View File

@@ -17,6 +17,7 @@
#include "BLI_listbase.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
#include "BLT_translation.hh"
@@ -85,10 +86,10 @@ static void ui_imageuser_slot_menu(bContext *C, uiLayout *layout, void *image_p)
LISTBASE_FOREACH_INDEX (RenderSlot *, slot, &image->renderslots, slot_id) {
char str[64];
if (slot->name[0] != '\0') {
STRNCPY(str, slot->name);
STRNCPY_UTF8(str, slot->name);
}
else {
SNPRINTF(str, IFACE_("Slot %d"), slot_id + 1);
SNPRINTF_UTF8(str, IFACE_("Slot %d"), slot_id + 1);
}
/* Default to "blank" for nicer alignment. */
int icon = ICON_BLANK1;
@@ -595,13 +596,13 @@ static void uiblock_layer_pass_buttons(uiLayout *layout,
/* menu buts */
if (render_slot) {
char str[64];
RenderSlot *slot = BKE_image_get_renderslot(image, *render_slot);
char str[sizeof(slot->name)];
if (slot && slot->name[0] != '\0') {
STRNCPY(str, slot->name);
STRNCPY_UTF8(str, slot->name);
}
else {
SNPRINTF(str, IFACE_("Slot %d"), *render_slot + 1);
SNPRINTF_UTF8(str, IFACE_("Slot %d"), *render_slot + 1);
}
rnd_pt = ui_imageuser_data_copy(&rnd_pt_local);

View File

@@ -394,7 +394,7 @@ class Context : public compositor::Context {
BKE_stamp_info_callback(
&callback_data,
render_result->stamp_data,
[](void *user_data, const char *key, char *value, int /*value_length*/) {
[](void *user_data, const char *key, char *value, int /*value_maxncpy*/) {
StampCallbackData *data = static_cast<StampCallbackData *>(user_data);
const std::string manifest_key = bke::cryptomatte::BKE_cryptomatte_meta_data_key(