Cleanup: UTF8 string functions for color-space & imbuf strings

Use UTF8 aware functions unless raw bytes are expected.
This commit is contained in:
Campbell Barton
2025-07-27 04:34:04 +00:00
parent 0d2b44e309
commit e93e9db6b7
26 changed files with 128 additions and 114 deletions

View File

@@ -20,7 +20,7 @@
#include "BLI_math_base.hh"
#include "BLI_math_vector.hh"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_task.h"
#include "BLI_utildefines.h"
@@ -1872,13 +1872,13 @@ void BKE_color_managed_display_settings_init(ColorManagedDisplaySettings *settin
{
const char *display_name = IMB_colormanagement_display_get_default_name();
STRNCPY(settings->display_device, display_name);
STRNCPY_UTF8(settings->display_device, display_name);
}
void BKE_color_managed_display_settings_copy(ColorManagedDisplaySettings *new_settings,
const ColorManagedDisplaySettings *settings)
{
STRNCPY(new_settings->display_device, settings->display_device);
STRNCPY_UTF8(new_settings->display_device, settings->display_device);
}
void BKE_color_managed_view_settings_init_render(
@@ -1896,8 +1896,8 @@ void BKE_color_managed_view_settings_init_render(
/* TODO(sergey): Find a way to make look query more reliable with non
* default configuration. */
STRNCPY(view_settings->view_transform, view_transform);
STRNCPY(view_settings->look, "None");
STRNCPY_UTF8(view_settings->view_transform, view_transform);
STRNCPY_UTF8(view_settings->look, "None");
view_settings->flag = 0;
view_settings->gamma = 1.0f;
@@ -1929,8 +1929,8 @@ void BKE_color_managed_view_settings_copy(ColorManagedViewSettings *new_settings
void BKE_color_managed_view_settings_copy_keep_curve_mapping(
ColorManagedViewSettings *new_settings, const ColorManagedViewSettings *settings)
{
STRNCPY(new_settings->look, settings->look);
STRNCPY(new_settings->view_transform, settings->view_transform);
STRNCPY_UTF8(new_settings->look, settings->look);
STRNCPY_UTF8(new_settings->view_transform, settings->view_transform);
new_settings->flag = settings->flag;
new_settings->exposure = settings->exposure;
@@ -1968,14 +1968,14 @@ void BKE_color_managed_view_settings_blend_read_data(BlendDataReader *reader,
void BKE_color_managed_colorspace_settings_init(
ColorManagedColorspaceSettings *colorspace_settings)
{
STRNCPY(colorspace_settings->name, "");
STRNCPY_UTF8(colorspace_settings->name, "");
}
void BKE_color_managed_colorspace_settings_copy(
ColorManagedColorspaceSettings *colorspace_settings,
const ColorManagedColorspaceSettings *settings)
{
STRNCPY(colorspace_settings->name, settings->name);
STRNCPY_UTF8(colorspace_settings->name, settings->name);
}
bool BKE_color_managed_colorspace_settings_equals(const ColorManagedColorspaceSettings *settings1,

View File

@@ -1180,7 +1180,7 @@ static ImBuf *add_ibuf_for_tile(Image *ima, ImageTile *tile)
const char *colorspace = IMB_colormanagement_role_colorspace_name_get(
COLOR_ROLE_DEFAULT_FLOAT);
STRNCPY(ima->colorspace_settings.name, colorspace);
STRNCPY_UTF8(ima->colorspace_settings.name, colorspace);
}
if (ibuf != nullptr) {
@@ -1204,7 +1204,7 @@ static ImBuf *add_ibuf_for_tile(Image *ima, ImageTile *tile)
const char *colorspace = IMB_colormanagement_role_colorspace_name_get(
COLOR_ROLE_DEFAULT_BYTE);
STRNCPY(ima->colorspace_settings.name, colorspace);
STRNCPY_UTF8(ima->colorspace_settings.name, colorspace);
}
if (ibuf != nullptr) {
@@ -1280,8 +1280,8 @@ Image *BKE_image_add_generated(Main *bmain,
copy_v4_v4(tile->gen_color, color);
if (is_data) {
STRNCPY(ima->colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DATA));
STRNCPY_UTF8(ima->colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DATA));
}
for (view_id = 0; view_id < 2; view_id++) {
@@ -1326,7 +1326,7 @@ static void image_colorspace_from_imbuf(Image *image, const ImBuf *ibuf)
}
if (colorspace_name) {
STRNCPY(image->colorspace_settings.name, colorspace_name);
STRNCPY_UTF8(image->colorspace_settings.name, colorspace_name);
}
}

View File

@@ -12,7 +12,7 @@
#include "DNA_scene_types.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
#include "IMB_colormanagement.hh"
@@ -76,7 +76,7 @@ void BKE_image_format_update_color_space_for_type(ImageFormatData *format)
if (format->linear_colorspace_settings.name[0] == '\0' || image_requires_linear != is_linear) {
const int role = image_requires_linear ? COLOR_ROLE_DEFAULT_FLOAT : COLOR_ROLE_DEFAULT_BYTE;
const char *default_color_space = IMB_colormanagement_role_colorspace_name_get(role);
STRNCPY(format->linear_colorspace_settings.name, default_color_space);
STRNCPY_UTF8(format->linear_colorspace_settings.name, default_color_space);
}
}
@@ -1125,8 +1125,8 @@ void BKE_image_format_color_management_copy_from_scene(ImageFormatData *imf, con
BKE_color_managed_display_settings_copy(&imf->display_settings, &scene->display_settings);
BKE_color_managed_view_settings_copy(&imf->view_settings, &scene->view_settings);
STRNCPY(imf->linear_colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR));
STRNCPY_UTF8(imf->linear_colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR));
}
/* Output */
@@ -1157,7 +1157,7 @@ void BKE_image_format_init_for_write(ImageFormatData *imf,
/* Use general scene settings also used for display. */
BKE_color_managed_display_settings_copy(&imf->display_settings, &scene_src->display_settings);
BKE_color_managed_view_settings_copy(&imf->view_settings, &scene_src->view_settings);
STRNCPY(imf->linear_colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR));
STRNCPY_UTF8(imf->linear_colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR));
}
}

View File

@@ -13,7 +13,7 @@
#include "BLI_index_range.hh"
#include "BLI_listbase.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_task.hh"
#include "BLI_vector.hh"
@@ -104,7 +104,7 @@ bool BKE_image_save_options_init(ImageSaveOptions *opts,
/* Default to saving in the same colorspace as the image setting. */
if (!opts->save_as_render) {
STRNCPY(opts->im_format.linear_colorspace_settings.name, ima_colorspace);
STRNCPY_UTF8(opts->im_format.linear_colorspace_settings.name, ima_colorspace);
}
opts->im_format.color_management = R_IMF_COLOR_MANAGEMENT_FOLLOW_SCENE;

View File

@@ -231,7 +231,7 @@ static void scene_init_data(ID *id)
BKE_color_managed_display_settings_init(&scene->display_settings);
BKE_color_managed_view_settings_init_render(
&scene->view_settings, &scene->display_settings, "AgX");
STRNCPY(scene->sequencer_colorspace_settings.name, colorspace_name);
STRNCPY_UTF8(scene->sequencer_colorspace_settings.name, colorspace_name);
BKE_image_format_init(&scene->r.im_format, true);
BKE_image_format_init(&scene->r.bake.im_format, true);
@@ -2901,12 +2901,12 @@ void BKE_scene_disable_color_management(Scene *scene)
none_display_name = IMB_colormanagement_display_get_none_name();
STRNCPY(display_settings->display_device, none_display_name);
STRNCPY_UTF8(display_settings->display_device, none_display_name);
view = IMB_colormanagement_view_get_raw_or_default_name(display_settings->display_device);
if (view) {
STRNCPY(view_settings->view_transform, view);
STRNCPY_UTF8(view_settings->view_transform, view);
}
}

View File

@@ -1913,7 +1913,7 @@ void blo_do_versions_260(FileData *fd, Library * /*lib*/, Main *bmain)
* crazy anyway and think it's fair enough to break compatibility in that cases.
*/
STRNCPY(ima->colorspace_settings.name, "Raw");
STRNCPY_UTF8(ima->colorspace_settings.name, "Raw");
}
}
}

View File

@@ -1194,8 +1194,8 @@ static void image_node_colorspace(bNode *node)
enum { SHD_COLORSPACE_NONE = 0 };
Image *image = (Image *)node->id;
if (color_space == SHD_COLORSPACE_NONE) {
STRNCPY(image->colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DATA));
STRNCPY_UTF8(image->colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DATA));
}
}
@@ -5260,17 +5260,17 @@ void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain)
view_settings = &scene->view_settings;
if (STREQ(view_settings->view_transform, "Default")) {
STRNCPY(view_settings->view_transform, "Standard");
STRNCPY_UTF8(view_settings->view_transform, "Standard");
}
else if (STR_ELEM(view_settings->view_transform, "RRT", "Film")) {
STRNCPY(view_settings->view_transform, "Filmic");
STRNCPY_UTF8(view_settings->view_transform, "Filmic");
}
else if (STREQ(view_settings->view_transform, "Log")) {
STRNCPY(view_settings->view_transform, "Filmic Log");
STRNCPY_UTF8(view_settings->view_transform, "Filmic Log");
}
if (STREQ(view_settings->look, "Filmic - Base Contrast")) {
STRNCPY(view_settings->look, "None");
STRNCPY_UTF8(view_settings->look, "None");
}
}
}

View File

@@ -642,12 +642,12 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
if (app_template && STR_ELEM(app_template, "Video_Editing", "2D_Animation")) {
/* Filmic is too slow, use standard until it is optimized. */
STRNCPY(scene->view_settings.view_transform, "Standard");
STRNCPY(scene->view_settings.look, "None");
STRNCPY_UTF8(scene->view_settings.view_transform, "Standard");
STRNCPY_UTF8(scene->view_settings.look, "None");
}
else {
/* Default to AgX view transform. */
STRNCPY(scene->view_settings.view_transform, "AgX");
STRNCPY_UTF8(scene->view_settings.view_transform, "AgX");
}
if (app_template && STREQ(app_template, "Video_Editing")) {

View File

@@ -8,7 +8,7 @@
#include "GPU_viewport.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "DRW_render.hh"
@@ -136,8 +136,8 @@ static void viewport_settings_apply(GPUViewport &viewport,
/* Use only view transform + look and nothing else for lookdev without
* scene lighting, as exposure depends on scene light intensity. */
BKE_color_managed_view_settings_init_render(&view_settings, display_settings, nullptr);
STRNCPY(view_settings.view_transform, scene.view_settings.view_transform);
STRNCPY(view_settings.look, scene.view_settings.look);
STRNCPY_UTF8(view_settings.view_transform, scene.view_settings.view_transform);
STRNCPY_UTF8(view_settings.look, scene.view_settings.look);
break;
}
case eDRWColorManagementType::UseRenderSettings: {

View File

@@ -3849,7 +3849,7 @@ uiBlock *UI_block_begin(const bContext *C,
* would slow down redraw, so only lookup for actual transform when it's indeed
* needed
*/
STRNCPY(block->display_device, scene->display_settings.display_device);
STRNCPY_UTF8(block->display_device, scene->display_settings.display_device);
/* Copy to avoid crash when scene gets deleted with UI still open. */
UnitSettings *unit = MEM_callocN<UnitSettings>(__func__);
@@ -3857,7 +3857,7 @@ uiBlock *UI_block_begin(const bContext *C,
block->unit = unit;
}
else {
STRNCPY(block->display_device, IMB_colormanagement_display_get_default_name());
STRNCPY_UTF8(block->display_device, IMB_colormanagement_display_get_default_name());
}
block->name = std::move(name);

View File

@@ -16,6 +16,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"
@@ -1224,7 +1225,7 @@ static wmOperatorStatus sequencer_add_movie_strip_exec(bContext *C, wmOperator *
RNA_struct_find_property(op->ptr, "files"));
char vt_old[64];
STRNCPY(vt_old, scene->view_settings.view_transform);
STRNCPY_UTF8(vt_old, scene->view_settings.view_transform);
float fps_old = scene->r.frs_sec / scene->r.frs_sec_base;
if (tot_files > 1) {
@@ -1671,7 +1672,7 @@ static wmOperatorStatus sequencer_add_image_strip_exec(bContext *C, wmOperator *
}
char vt_old[64];
STRNCPY(vt_old, scene->view_settings.view_transform);
STRNCPY_UTF8(vt_old, scene->view_settings.view_transform);
Strip *strip = seq::add_image_strip(CTX_data_main(C), scene, ed->seqbasep, &load_data);

View File

@@ -36,7 +36,7 @@
#include "BLI_math_vector_types.hh"
#include "BLI_path_utils.hh"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_task.hh"
#include "BLI_threads.h"
#include "BLI_vector_set.hh"
@@ -500,7 +500,7 @@ static bool colormanage_role_color_space_name_get(ocio::Config &config,
}
/* assume function was called with buffer properly allocated to MAX_COLORSPACE_NAME chars */
BLI_strncpy(colorspace_name, ociocs->name().c_str(), MAX_COLORSPACE_NAME);
BLI_strncpy_utf8(colorspace_name, ociocs->name().c_str(), MAX_COLORSPACE_NAME);
return true;
}
@@ -790,13 +790,13 @@ void IMB_colormanagement_init_default_view_settings(
default_view = display->get_default_view();
}
if (default_view != nullptr) {
STRNCPY(view_settings->view_transform, default_view->name().c_str());
STRNCPY_UTF8(view_settings->view_transform, default_view->name().c_str());
}
else {
view_settings->view_transform[0] = '\0';
}
/* TODO(sergey): Find a way to safely/reliable un-hardcode this. */
STRNCPY(view_settings->look, "None");
STRNCPY_UTF8(view_settings->look, "None");
/* Initialize rest of the settings. */
view_settings->flag = 0;
view_settings->gamma = 1.0f;
@@ -872,7 +872,7 @@ static void colormanage_check_display_settings(ColorManagedDisplaySettings *disp
const ocio::Display *default_display)
{
if (display_settings->display_device[0] == '\0') {
STRNCPY(display_settings->display_device, default_display->name().c_str());
STRNCPY_UTF8(display_settings->display_device, default_display->name().c_str());
}
else {
const ocio::Display *display = g_config->get_display_by_name(display_settings->display_device);
@@ -887,7 +887,7 @@ static void colormanage_check_display_settings(ColorManagedDisplaySettings *disp
default_display->name().c_str());
}
STRNCPY(display_settings->display_device, default_display->name().c_str());
STRNCPY_UTF8(display_settings->display_device, default_display->name().c_str());
}
}
}
@@ -905,7 +905,7 @@ static void colormanage_check_view_settings(ColorManagedDisplaySettings *display
if (view_settings->view_transform[0] == '\0') {
const ocio::View *default_view = display->get_default_view();
if (default_view) {
STRNCPY(view_settings->view_transform, default_view->name().c_str());
STRNCPY_UTF8(view_settings->view_transform, default_view->name().c_str());
}
}
else {
@@ -919,13 +919,13 @@ static void colormanage_check_view_settings(ColorManagedDisplaySettings *display
view_settings->view_transform,
default_view->name().c_str());
}
STRNCPY(view_settings->view_transform, default_view->name().c_str());
STRNCPY_UTF8(view_settings->view_transform, default_view->name().c_str());
}
}
}
if (view_settings->look[0] == '\0') {
STRNCPY(view_settings->look, default_look_name);
STRNCPY_UTF8(view_settings->look, default_look_name);
}
else {
const ocio::Look *look = g_config->get_look_by_name(view_settings->look);
@@ -937,7 +937,7 @@ static void colormanage_check_view_settings(ColorManagedDisplaySettings *display
default_look_name);
}
STRNCPY(view_settings->look, default_look_name);
STRNCPY_UTF8(view_settings->look, default_look_name);
}
else if (!colormanage_compatible_look(look, view_settings->view_transform)) {
if (!G.quiet) {
@@ -951,7 +951,7 @@ static void colormanage_check_view_settings(ColorManagedDisplaySettings *display
default_look_name);
}
STRNCPY(view_settings->look, default_look_name);
STRNCPY_UTF8(view_settings->look, default_look_name);
}
}
@@ -978,7 +978,7 @@ static void colormanage_check_colorspace_settings(
colorspace_settings->name);
}
STRNCPY(colorspace_settings->name, "");
STRNCPY_UTF8(colorspace_settings->name, "");
}
}
@@ -1013,7 +1013,7 @@ void IMB_colormanagement_check_file_config(Main *bmain)
colormanage_check_colorspace_settings(sequencer_colorspace_settings, "sequencer");
if (sequencer_colorspace_settings->name[0] == '\0') {
STRNCPY(sequencer_colorspace_settings->name, global_role_default_sequencer);
STRNCPY_UTF8(sequencer_colorspace_settings->name, global_role_default_sequencer);
}
/* check sequencer strip input color space settings */
@@ -1049,7 +1049,7 @@ void IMB_colormanagement_validate_settings(const ColorManagedDisplaySettings *di
}
if (!found && default_view) {
STRNCPY(view_settings->view_transform, default_view->name().c_str());
STRNCPY_UTF8(view_settings->view_transform, default_view->name().c_str());
}
}
@@ -2835,7 +2835,7 @@ void IMB_colormanagement_colorspace_from_ibuf_ftype(
if (type->save != nullptr) {
const char *role_colorspace = IMB_colormanagement_role_colorspace_name_get(
type->default_save_role);
STRNCPY(colorspace_settings->name, role_colorspace);
STRNCPY_UTF8(colorspace_settings->name, role_colorspace);
}
}
}

View File

@@ -9,7 +9,7 @@
#include <algorithm>
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BKE_idprop.hh"
@@ -151,7 +151,7 @@ static void set_file_colorspace(ImFileColorSpace &r_colorspace,
/* Override if necessary. */
if (ctx.use_metadata_colorspace) {
string ics = spec.get_string_attribute("oiio:ColorSpace");
STRNCPY(r_colorspace.metadata_colorspace, ics.c_str());
STRNCPY_UTF8(r_colorspace.metadata_colorspace, ics.c_str());
}
}

View File

@@ -85,6 +85,7 @@
#include "BLI_mmap.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_threads.h"
#include "BKE_idprop.hh"
@@ -2032,14 +2033,14 @@ static void imb_exr_set_known_colorspace(const Header &header, ImFileColorSpace
const char *known_colorspace = IMB_colormanagement_role_colorspace_name_get(
COLOR_ROLE_ACES_INTERCHANGE);
if (known_colorspace) {
STRNCPY(r_colorspace.metadata_colorspace, known_colorspace);
STRNCPY_UTF8(r_colorspace.metadata_colorspace, known_colorspace);
}
}
else if (header_chromaticities &&
(imb_check_chromaticity_matches(header_chromaticities->value(), CHROMATICITIES_XYZ_E)))
{
/* Only works for the Blender default configuration due to fixed name. */
STRNCPY(r_colorspace.metadata_colorspace, "Linear CIE-XYZ E");
STRNCPY_UTF8(r_colorspace.metadata_colorspace, "Linear CIE-XYZ E");
}
}

View File

@@ -18,6 +18,8 @@
#include "BLI_mmap.h"
#include "BLI_path_utils.hh" /* For assertions. */
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include <cstdlib>
#include "IMB_allocimbuf.hh"
@@ -42,32 +44,33 @@ static void imb_handle_colorspace_and_alpha(ImBuf *ibuf,
if (r_colorspace && r_colorspace[0]) {
/* Existing configured colorspace has priority. */
STRNCPY(new_colorspace, r_colorspace);
STRNCPY_UTF8(new_colorspace, r_colorspace);
}
else if (file_colorspace.metadata_colorspace[0] &&
colormanage_colorspace_get_named(file_colorspace.metadata_colorspace))
{
/* Use colorspace from file metadata if provided. */
STRNCPY(new_colorspace, file_colorspace.metadata_colorspace);
STRNCPY_UTF8(new_colorspace, file_colorspace.metadata_colorspace);
}
else {
/* The color-space from the file-path (not a file-path). */
const char *filepath_colorspace = (filepath) ?
IMB_colormanagement_space_from_filepath_rules(filepath) :
nullptr;
if (filepath_colorspace) {
/* Use colorspace from OpenColorIO file rules. */
STRNCPY(new_colorspace, filepath_colorspace);
STRNCPY_UTF8(new_colorspace, filepath_colorspace);
}
else {
/* Use float colorspace if the image may contain HDR colors, byte otherwise. */
const char *role_colorspace = IMB_colormanagement_role_colorspace_name_get(
file_colorspace.is_hdr_float ? COLOR_ROLE_DEFAULT_FLOAT : COLOR_ROLE_DEFAULT_BYTE);
STRNCPY(new_colorspace, role_colorspace);
STRNCPY_UTF8(new_colorspace, role_colorspace);
}
}
if (r_colorspace) {
BLI_strncpy(r_colorspace, new_colorspace, IM_MAX_SPACE);
BLI_strncpy_utf8(r_colorspace, new_colorspace, IM_MAX_SPACE);
}
if (r_colorspace) {
@@ -270,8 +273,8 @@ ImBuf *IMB_thumb_load_image(const char *filepath,
/* Save dimensions of original image into the thumbnail metadata. */
char cwidth[40];
char cheight[40];
SNPRINTF(cwidth, "%zu", width);
SNPRINTF(cheight, "%zu", height);
SNPRINTF_UTF8(cwidth, "%zu", width);
SNPRINTF_UTF8(cheight, "%zu", height);
IMB_metadata_ensure(&ibuf->metadata);
IMB_metadata_set_field(ibuf->metadata, "Thumb::Image::Width", cwidth);
IMB_metadata_set_field(ibuf->metadata, "Thumb::Image::Height", cheight);

View File

@@ -18,6 +18,7 @@
#include "BLI_hash_md5.hh"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_string_utils.hh"
#include "BLI_system.h"
#include "BLI_threads.h"
@@ -387,7 +388,7 @@ static ImBuf *thumb_create_ex(const char *file_path,
if (img != nullptr) {
if (BLI_stat(file_path, &info) != -1) {
SNPRINTF(mtime, "%ld", (long int)info.st_mtime);
SNPRINTF_UTF8(mtime, "%ld", (long int)info.st_mtime);
}
}
}
@@ -409,7 +410,7 @@ static ImBuf *thumb_create_ex(const char *file_path,
MOV_close(anim);
}
if (BLI_stat(file_path, &info) != -1) {
SNPRINTF(mtime, "%ld", (long int)info.st_mtime);
SNPRINTF_UTF8(mtime, "%ld", (long int)info.st_mtime);
}
}
if (!img) {
@@ -431,7 +432,7 @@ static ImBuf *thumb_create_ex(const char *file_path,
IMB_scale(img, ex, ey, IMBScaleFilter::Box, false);
}
}
SNPRINTF(desc, "Thumbnail for %s", uri);
SNPRINTF_UTF8(desc, "Thumbnail for %s", uri);
IMB_metadata_ensure(&img->metadata);
IMB_metadata_set_field(img->metadata, "Software", "Blender");
IMB_metadata_set_field(img->metadata, "Thumb::URI", uri);

View File

@@ -18,6 +18,7 @@
#include "BLI_path_utils.hh"
#include "BLI_span.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_task.hh"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
@@ -105,9 +106,9 @@ static void probe_video_colorspace(MovieReader *anim, char r_colorspace_name[IM_
{
/* Use default role as fallback (i.e. it is an unknown combination of colorspace and primaries)
*/
BLI_strncpy(r_colorspace_name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE),
IM_MAX_SPACE);
BLI_strncpy_utf8(r_colorspace_name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE),
IM_MAX_SPACE);
if (anim->state == MovieReader::State::Uninitialized) {
if (!anim_getnew(anim)) {
@@ -125,7 +126,7 @@ static void probe_video_colorspace(MovieReader *anim, char r_colorspace_name[IM_
{
const char *hlg_name = IMB_colormanagement_get_rec2100_hlg_display_colorspace();
if (hlg_name) {
BLI_strncpy(r_colorspace_name, hlg_name, IM_MAX_SPACE);
BLI_strncpy_utf8(r_colorspace_name, hlg_name, IM_MAX_SPACE);
}
return;
}
@@ -135,7 +136,7 @@ static void probe_video_colorspace(MovieReader *anim, char r_colorspace_name[IM_
{
const char *pq_name = IMB_colormanagement_get_rec2100_pq_display_colorspace();
if (pq_name) {
BLI_strncpy(r_colorspace_name, pq_name, IM_MAX_SPACE);
BLI_strncpy_utf8(r_colorspace_name, pq_name, IM_MAX_SPACE);
}
return;
}
@@ -162,17 +163,17 @@ MovieReader *MOV_open_file(const char *filepath,
if (colorspace && colorspace[0] != '\0') {
/* Use colorspace from argument, if provided. */
STRNCPY(anim->colorspace, colorspace);
STRNCPY_UTF8(anim->colorspace, colorspace);
}
else {
/* Try to initialize colorspace from the FFmpeg stream by interpreting color information from
* it. */
char file_colorspace[IM_MAX_SPACE];
probe_video_colorspace(anim, file_colorspace);
STRNCPY(anim->colorspace, file_colorspace);
STRNCPY_UTF8(anim->colorspace, file_colorspace);
if (colorspace) {
/* Copy the used colorspace into output argument. */
BLI_strncpy(colorspace, file_colorspace, IM_MAX_SPACE);
BLI_strncpy_utf8(colorspace, file_colorspace, IM_MAX_SPACE);
}
}
}
@@ -1410,11 +1411,11 @@ ImBuf *MOV_decode_preview_frame(MovieReader *anim)
char value[128];
IMB_metadata_ensure(&ibuf->metadata);
SNPRINTF(value, "%i", anim->x);
SNPRINTF_UTF8(value, "%i", anim->x);
IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::Width", value);
SNPRINTF(value, "%i", anim->y);
SNPRINTF_UTF8(value, "%i", anim->y);
IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::Height", value);
SNPRINTF(value, "%i", anim->duration_in_frames);
SNPRINTF_UTF8(value, "%i", anim->duration_in_frames);
IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::Frames", value);
#ifdef WITH_FFMPEG
@@ -1423,9 +1424,9 @@ ImBuf *MOV_decode_preview_frame(MovieReader *anim)
AVRational frame_rate = av_guess_frame_rate(anim->pFormatCtx, v_st, nullptr);
if (frame_rate.num != 0) {
double duration = anim->duration_in_frames / av_q2d(frame_rate);
SNPRINTF(value, "%g", av_q2d(frame_rate));
SNPRINTF_UTF8(value, "%g", av_q2d(frame_rate));
IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::FPS", value);
SNPRINTF(value, "%g", duration);
SNPRINTF_UTF8(value, "%g", duration);
IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::Duration", value);
IMB_metadata_set_field(ibuf->metadata, "Thumb::Video::Codec", anim->pCodec->long_name);
}

View File

@@ -26,6 +26,7 @@
# include "BLI_math_color.h"
# include "BLI_path_utils.hh"
# include "BLI_string.h"
# include "BLI_string_utf8.h"
# include "BLI_threads.h"
# include "BLI_utildefines.h"
@@ -554,7 +555,7 @@ static const AVCodec *get_av1_encoder(
}
/* Set gop_size as rav1e's "--keyint". */
char buffer[64];
SNPRINTF(buffer, "keyint=%d", context->ffmpeg_gop_size);
SNPRINTF_UTF8(buffer, "keyint=%d", context->ffmpeg_gop_size);
av_dict_set(opts, "rav1e-params", buffer, 0);
}
else if (STREQ(codec->name, "libsvtav1")) {
@@ -594,7 +595,7 @@ static const AVCodec *get_av1_encoder(
}
/* A char array need only an alignment of 1. */
char *tiles_string_mut = (char *)calloc(digits * 2 + 2, 1);
BLI_snprintf(tiles_string_mut, digits * 2 + 2, "%dx%d", threads_sqrt, threads_sqrt);
BLI_snprintf_utf8(tiles_string_mut, digits * 2 + 2, "%dx%d", threads_sqrt, threads_sqrt);
tiles_string_is_dynamic = true;
tiles_string = tiles_string_mut;
}
@@ -626,13 +627,15 @@ static const AVCodec *get_av1_encoder(
/* A char array need only an alignment of 1. */
char *tiles_string_mut = (char *)calloc(combined_digits + 2, 1);
if (rectx > recty) {
BLI_snprintf(tiles_string_mut, combined_digits + 2, "%dx%d", sqrt_p2_next, sqrt_p2);
BLI_snprintf_utf8(
tiles_string_mut, combined_digits + 2, "%dx%d", sqrt_p2_next, sqrt_p2);
}
else if (rectx < recty) {
BLI_snprintf(tiles_string_mut, combined_digits + 2, "%dx%d", sqrt_p2, sqrt_p2_next);
BLI_snprintf_utf8(
tiles_string_mut, combined_digits + 2, "%dx%d", sqrt_p2, sqrt_p2_next);
}
else {
BLI_snprintf(tiles_string_mut, combined_digits + 2, "%dx%d", sqrt_p2, sqrt_p2);
BLI_snprintf_utf8(tiles_string_mut, combined_digits + 2, "%dx%d", sqrt_p2, sqrt_p2);
}
tiles_string_is_dynamic = true;
tiles_string = tiles_string_mut;

View File

@@ -16,6 +16,7 @@
#include "BLI_math_vector.hh"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "DNA_material_types.h"
@@ -305,8 +306,8 @@ static void add_image_texture(Main *bmain,
if (!STR_ELEM(
socket_name, "Base Color", "Specular Tint", "Sheen Tint", "Coat Tint", "Emission Color"))
{
STRNCPY(image->colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DATA));
STRNCPY_UTF8(image->colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DATA));
}
/* Add texture node and any UV transformations if needed. */

View File

@@ -26,6 +26,7 @@
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_ref.hh"
#include "BLI_string_utf8.h"
#include "BLI_vector.hh"
#include "DNA_material_types.h"
@@ -1376,13 +1377,13 @@ void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader &usd_shader,
if (color_space == usdtokens::auto_) {
/* If it's auto, determine whether to apply color correction based
* on incoming connection (passed in from outer functions). */
STRNCPY(image->colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(
extra.is_color_corrected ? COLOR_ROLE_DEFAULT_BYTE : COLOR_ROLE_DATA));
STRNCPY_UTF8(image->colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(
extra.is_color_corrected ? COLOR_ROLE_DEFAULT_BYTE : COLOR_ROLE_DATA));
}
else if (color_space == usdtokens::sRGB) {
STRNCPY(image->colorspace_settings.name, IMB_colormanagement_srgb_colorspace_name_get());
STRNCPY_UTF8(image->colorspace_settings.name, IMB_colormanagement_srgb_colorspace_name_get());
}
/*
@@ -1391,8 +1392,8 @@ void USDMaterialReader::load_tex_image(const pxr::UsdShadeShader &usd_shader,
* On write, we are *only* using the correct, lower-case "raw" token.
*/
else if (ELEM(color_space, usdtokens::RAW, usdtokens::raw)) {
STRNCPY(image->colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DATA));
STRNCPY_UTF8(image->colorspace_settings.name,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DATA));
}
NodeTexImage *storage = static_cast<NodeTexImage *>(tex_image->storage);

View File

@@ -448,7 +448,7 @@ static void rna_ColorManagedDisplaySettings_display_device_set(PointerRNA *ptr,
const char *name = IMB_colormanagement_display_get_indexed_name(value);
if (name) {
STRNCPY(display->display_device, name);
STRNCPY_UTF8(display->display_device, name);
}
}
@@ -508,11 +508,11 @@ static void rna_ColorManagedViewSettings_view_transform_set(PointerRNA *ptr, int
return;
}
STRNCPY(view->view_transform, view_name);
STRNCPY_UTF8(view->view_transform, view_name);
const char *look_name = IMB_colormanagement_look_validate_for_view(view_name, view->look);
if (look_name) {
STRNCPY(view->look, look_name);
STRNCPY_UTF8(view->look, look_name);
}
}
@@ -545,7 +545,7 @@ static void rna_ColorManagedViewSettings_look_set(PointerRNA *ptr, int value)
const char *name = IMB_colormanagement_look_get_indexed_name(value);
if (name) {
STRNCPY(view->look, name);
STRNCPY_UTF8(view->look, name);
}
}
@@ -605,7 +605,7 @@ static void rna_ColorManagedColorspaceSettings_is_data_set(PointerRNA *ptr, bool
ColorManagedColorspaceSettings *colorspace = (ColorManagedColorspaceSettings *)ptr->data;
if (value) {
const char *data_name = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DATA);
STRNCPY(colorspace->name, data_name);
STRNCPY_UTF8(colorspace->name, data_name);
}
}
@@ -622,7 +622,7 @@ static void rna_ColorManagedColorspaceSettings_colorspace_set(PointerRNA *ptr, i
const char *name = IMB_colormanagement_colorspace_get_indexed_name(value);
if (name && name[0]) {
STRNCPY(colorspace->name, name);
STRNCPY_UTF8(colorspace->name, name);
}
}

View File

@@ -4247,7 +4247,7 @@ static void rna_NodeConvertColorSpace_from_color_space_set(PointerRNA *ptr, int
const char *name = IMB_colormanagement_colorspace_get_indexed_name(value);
if (name && name[0]) {
STRNCPY(node_storage->from_color_space, name);
STRNCPY_UTF8(node_storage->from_color_space, name);
}
}
static int rna_NodeConvertColorSpace_to_color_space_get(PointerRNA *ptr)
@@ -4264,7 +4264,7 @@ static void rna_NodeConvertColorSpace_to_color_space_set(PointerRNA *ptr, int va
const char *name = IMB_colormanagement_colorspace_get_indexed_name(value);
if (name && name[0]) {
STRNCPY(node_storage->to_color_space, name);
STRNCPY_UTF8(node_storage->to_color_space, name);
}
}

View File

@@ -251,7 +251,7 @@ static Strip *rna_Strips_new_image(ID *id,
load_data.fit_method = eSeqImageFitMethod(fit_method);
char vt_old[64];
STRNCPY(vt_old, scene->view_settings.view_transform);
STRNCPY_UTF8(vt_old, scene->view_settings.view_transform);
Strip *strip = blender::seq::add_image_strip(bmain, scene, seqbase, &load_data);
@@ -321,7 +321,7 @@ static Strip *rna_Strips_new_movie(ID *id,
load_data.allow_invalid_file = true;
char vt_old[64];
STRNCPY(vt_old, scene->view_settings.view_transform);
STRNCPY_UTF8(vt_old, scene->view_settings.view_transform);
float fps_old = scene->r.frs_sec / scene->r.frs_sec_base;
Strip *strip = blender::seq::add_movie_strip(bmain, scene, seqbase, &load_data);

View File

@@ -6,7 +6,7 @@
* \ingroup cmpnodes
*/
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "UI_interface_layout.hh"
#include "UI_resources.hh"
@@ -40,8 +40,8 @@ static void node_composit_init_convert_colorspace(bNodeTree * /*ntree*/, bNode *
const char *first_colorspace = IMB_colormanagement_role_colorspace_name_get(
COLOR_ROLE_SCENE_LINEAR);
if (first_colorspace && first_colorspace[0]) {
STRNCPY(ncs->from_color_space, first_colorspace);
STRNCPY(ncs->to_color_space, first_colorspace);
STRNCPY_UTF8(ncs->from_color_space, first_colorspace);
STRNCPY_UTF8(ncs->to_color_space, first_colorspace);
}
else {
ncs->from_color_space[0] = 0;

View File

@@ -23,6 +23,7 @@
#include "BLI_listbase.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BKE_image.hh"
#include "BKE_lib_id.hh"
@@ -122,7 +123,7 @@ static void strip_add_set_view_transform(Scene *scene, Strip *strip, LoadData *l
scene->display_settings.display_device);
const char *default_view_transform =
IMB_colormanagement_display_get_default_view_transform_name(display);
STRNCPY(scene->view_settings.view_transform, default_view_transform);
STRNCPY_UTF8(scene->view_settings.view_transform, default_view_transform);
}
}
}
@@ -508,7 +509,7 @@ Strip *add_movie_strip(Main *bmain, Scene *scene, ListBase *seqbase, LoadData *l
strip->flag |= SEQ_AUTO_PLAYBACK_RATE;
}
STRNCPY(strip->data->colorspace_settings.name, colorspace);
STRNCPY_UTF8(strip->data->colorspace_settings.name, colorspace);
StripData *data = strip->data;
/* We only need 1 element for MOVIE strips. */

View File

@@ -36,6 +36,7 @@
#include "BLI_path_utils.hh"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_system.h"
#include "BLI_time.h"
#include "BLI_utildefines.h"
@@ -1729,8 +1730,8 @@ static std::optional<int> wm_main_playanim_intern(int argc, const char **argv, P
IMB_init();
MOV_init();
STRNCPY(ps.display_ctx.display_settings.display_device,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE));
STRNCPY_UTF8(ps.display_ctx.display_settings.display_device,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE));
IMB_colormanagement_init_default_view_settings(&ps.display_ctx.view_settings,
&ps.display_ctx.display_settings);
ps.display_ctx.ui_scale = 1.0f;