MCPcopy Create free account
hub / github.com/ARM-software/astc-encoder / AddIntAttribute

Function AddIntAttribute

Source/ThirdParty/tinyexr.h:11215–11257  ·  view source on GitHub ↗

Helper to add an int attribute

Source from the content-addressed store, hash-verified

11213
11214// Helper to add an int attribute
11215static int AddIntAttribute(EXRHeader *exr_header, const char *name, int value) {
11216 if (!exr_header || !name) return TINYEXR_ERROR_INVALID_ARGUMENT;
11217
11218 int new_count = exr_header->num_custom_attributes + 1;
11219 if (new_count > TINYEXR_MAX_CUSTOM_ATTRIBUTES) {
11220 return TINYEXR_ERROR_DATA_TOO_LARGE;
11221 }
11222
11223 // Reallocate attributes array
11224 EXRAttribute *new_attrs = static_cast<EXRAttribute*>(
11225 realloc(exr_header->custom_attributes,
11226 sizeof(EXRAttribute) * static_cast<size_t>(new_count)));
11227 if (!new_attrs) {
11228 return TINYEXR_ERROR_INVALID_DATA;
11229 }
11230
11231 exr_header->custom_attributes = new_attrs;
11232 EXRAttribute *attr = &exr_header->custom_attributes[exr_header->num_custom_attributes];
11233
11234 // Initialize the new attribute
11235 memset(attr, 0, sizeof(EXRAttribute));
11236
11237#ifdef _MSC_VER
11238 strncpy_s(attr->name, sizeof(attr->name), name, 255);
11239 strncpy_s(attr->type, sizeof(attr->type), "int", 255);
11240#else
11241 strncpy(attr->name, name, 255);
11242 attr->name[255] = '\0';
11243 strncpy(attr->type, "int", 255);
11244 attr->type[255] = '\0';
11245#endif
11246
11247 attr->value = static_cast<unsigned char*>(malloc(sizeof(int)));
11248 if (!attr->value) {
11249 return TINYEXR_ERROR_INVALID_DATA;
11250 }
11251 memcpy(attr->value, &value, sizeof(int));
11252 attr->size = sizeof(int);
11253
11254 exr_header->num_custom_attributes = new_count;
11255
11256 return TINYEXR_SUCCESS;
11257}
11258
11259// Set spectral attributes on EXR header
11260int EXRSetSpectralAttributes(EXRHeader *exr_header,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected