BKE_image: simplify UDIM tile label access, return string length
This commit is contained in:
parent
a79272a790
commit
e5598d067b
|
@ -345,11 +345,12 @@ bool BKE_image_has_opengl_texture(struct Image *ima);
|
|||
|
||||
/**
|
||||
* Get tile index for tiled images.
|
||||
* \return The string length.
|
||||
*/
|
||||
void BKE_image_get_tile_label(struct Image *ima,
|
||||
struct ImageTile *tile,
|
||||
char *label,
|
||||
int len_label);
|
||||
int BKE_image_get_tile_label(const struct Image *ima,
|
||||
const struct ImageTile *tile,
|
||||
char *label,
|
||||
int label_maxncpy);
|
||||
|
||||
/**
|
||||
* Checks whether the given filepath refers to a UDIM tiled texture.
|
||||
|
|
|
@ -3305,19 +3305,20 @@ static RenderPass *image_render_pass_get(RenderLayer *rl,
|
|||
return rpass_ret;
|
||||
}
|
||||
|
||||
void BKE_image_get_tile_label(Image *ima, ImageTile *tile, char *label, int len_label)
|
||||
int BKE_image_get_tile_label(const Image *ima,
|
||||
const ImageTile *tile,
|
||||
char *label,
|
||||
const int label_maxncpy)
|
||||
{
|
||||
label[0] = '\0';
|
||||
if (ima == nullptr || tile == nullptr) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tile->label[0]) {
|
||||
BLI_strncpy(label, tile->label, len_label);
|
||||
}
|
||||
else {
|
||||
BLI_snprintf(label, len_label, "%d", tile->tile_number);
|
||||
return BLI_strncpy_rlen(label, tile->label, label_maxncpy);
|
||||
}
|
||||
return BLI_snprintf_rlen(label, label_maxncpy, "%d", tile->tile_number);
|
||||
}
|
||||
|
||||
bool BKE_image_get_tile_info(char *filepath, ListBase *tiles, int *r_tile_start, int *r_tile_range)
|
||||
|
|
|
@ -386,8 +386,8 @@ static int rna_UDIMTile_channels_get(PointerRNA *ptr)
|
|||
|
||||
static void rna_UDIMTile_label_get(PointerRNA *ptr, char *value)
|
||||
{
|
||||
ImageTile *tile = (ImageTile *)ptr->data;
|
||||
Image *image = (Image *)ptr->owner_id;
|
||||
const ImageTile *tile = (ImageTile *)ptr->data;
|
||||
const Image *image = (Image *)ptr->owner_id;
|
||||
|
||||
/* We don't know the length of the target string here, so we assume
|
||||
* that it has been allocated according to what rna_UDIMTile_label_length returned. */
|
||||
|
@ -396,13 +396,11 @@ static void rna_UDIMTile_label_get(PointerRNA *ptr, char *value)
|
|||
|
||||
static int rna_UDIMTile_label_length(PointerRNA *ptr)
|
||||
{
|
||||
ImageTile *tile = (ImageTile *)ptr->data;
|
||||
Image *image = (Image *)ptr->owner_id;
|
||||
const ImageTile *tile = (ImageTile *)ptr->data;
|
||||
const Image *image = (Image *)ptr->owner_id;
|
||||
|
||||
char label[sizeof(tile->label)];
|
||||
BKE_image_get_tile_label(image, tile, label, sizeof(label));
|
||||
|
||||
return strlen(label);
|
||||
return BKE_image_get_tile_label(image, tile, label, sizeof(label));
|
||||
}
|
||||
|
||||
static void rna_UDIMTile_tile_number_set(PointerRNA *ptr, int value)
|
||||
|
|
Loading…
Reference in New Issue