void BLI_endian_switch_int64_array(int64_t *val, const int size) { if (size > 0) { int i = size; val = val + (size - 1); while (i--) { BLI_endian_switch_int64(val--); } } }
struct anim_index *IMB_indexer_open(const char *name) { char header[13]; struct anim_index *idx; FILE *fp = BLI_fopen(name, "rb"); int i; if (!fp) { return NULL; } if (fread(header, 12, 1, fp) != 1) { fclose(fp); return NULL; } header[12] = 0; if (memcmp(header, magic, 8) != 0) { fclose(fp); return NULL; } if (atoi(header + 9) != INDEX_FILE_VERSION) { fclose(fp); return NULL; } idx = MEM_callocN(sizeof(struct anim_index), "anim_index"); BLI_strncpy(idx->name, name, sizeof(idx->name)); fseek(fp, 0, SEEK_END); idx->num_entries = (ftell(fp) - 12) / (sizeof(int) + /* framepos */ sizeof(unsigned long long) + /* seek_pos */ sizeof(unsigned long long) + /* seek_pos_dts */ sizeof(unsigned long long) /* pts */ ); fseek(fp, 12, SEEK_SET); idx->entries = MEM_callocN(sizeof(struct anim_index_entry) * idx->num_entries, "anim_index_entries"); for (i = 0; i < idx->num_entries; i++) { fread(&idx->entries[i].frameno, sizeof(int), 1, fp); fread(&idx->entries[i].seek_pos, sizeof(unsigned long long), 1, fp); fread(&idx->entries[i].seek_pos_dts, sizeof(unsigned long long), 1, fp); fread(&idx->entries[i].pts, sizeof(unsigned long long), 1, fp); } if (((ENDIAN_ORDER == B_ENDIAN) != (header[8] == 'V'))) { for (i = 0; i < idx->num_entries; i++) { BLI_endian_switch_int32(&idx->entries[i].frameno); BLI_endian_switch_int64((int64_t *)&idx->entries[i].seek_pos); BLI_endian_switch_int64((int64_t *)&idx->entries[i].seek_pos_dts); BLI_endian_switch_int64((int64_t *)&idx->entries[i].pts); } } fclose(fp); return idx; }