static ImBuf *loadblend_thumb(gzFile gzfile) { char buf[12]; int bhead[24/sizeof(int)]; /* max size on 64bit */ char endian, pointer_size; char endian_switch; int sizeof_bhead ; /* read the blend file header */ if(gzread(gzfile, buf, 12) != 12) return NULL; if(strncmp(buf, "BLENDER", 7)) return NULL; if(buf[7]=='-') pointer_size= 8; else if(buf[7]=='_') pointer_size= 4; else return NULL; sizeof_bhead = 16 + pointer_size; if(buf[8]=='V') endian= B_ENDIAN; /* big: PPC */ else if(buf[8]=='v') endian= L_ENDIAN; /* little: x86 */ else return NULL; endian_switch = ((ENDIAN_ORDER != endian)) ? 1 : 0; while(gzread(gzfile, bhead, sizeof_bhead) == sizeof_bhead) { if(endian_switch) SWITCH_INT(bhead[1]); /* length */ if (bhead[0]==REND) { gzseek(gzfile, bhead[1], SEEK_CUR); /* skip to the next */ } else { break; } } /* using 'TEST' since new names segfault when loading in old blenders */ if(bhead[0] == TEST) { ImBuf *img= NULL; int size[2]; if(gzread(gzfile, size, sizeof(size)) != sizeof(size)) return NULL; if(endian_switch) { SWITCH_INT(size[0]); SWITCH_INT(size[1]); } /* length */ bhead[1] -= sizeof(int) * 2; /* inconsistent image size, quit early */ if(bhead[1] != size[0] * size[1] * sizeof(int)) return NULL; /* finally malloc and read the data */ img= IMB_allocImBuf(size[0], size[1], 32, IB_rect | IB_metadata); if(gzread(gzfile, img->rect, bhead[1]) != bhead[1]) { IMB_freeImBuf(img); img= NULL; } return img; } return NULL; }
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++) { SWITCH_INT(idx->entries[i].frameno); SWITCH_INT64(idx->entries[i].seek_pos); SWITCH_INT64(idx->entries[i].seek_pos_dts); SWITCH_INT64(idx->entries[i].pts); } } fclose(fp); return idx; }