r730: Added italian translation
[cinelerra_cv/mob.git] / quicktime / avi_ix.c
blob6ce19c8e36379107a367ee89df8b6d55ab061313
1 #include "funcprotos.h"
2 #include "quicktime.h"
5 static char* make_tag(int number, char *tag)
7 tag[0] = 'i';
8 tag[1] = 'x';
9 tag[2] = '0' + (number / 10);
10 tag[3] = '0' + (number % 10);
11 return tag;
14 quicktime_ix_t* quicktime_new_ix(quicktime_t *file,
15 quicktime_trak_t *trak,
16 quicktime_strl_t *strl)
18 quicktime_ix_t *ix = calloc(1, sizeof(quicktime_ix_t));
19 ix->base_offset = quicktime_position(file);
20 make_tag(trak->tkhd.track_id - 1, ix->tag);
21 ix->longs_per_entry = 2;
22 ix->index_type = AVI_INDEX_OF_CHUNKS;
23 memcpy(ix->chunk_id, strl->tag, 4);
24 return ix;
28 void quicktime_delete_ix(quicktime_ix_t *ix)
30 if(ix->table) free(ix->table);
31 free(ix);
34 void quicktime_update_ixtable(quicktime_t *file,
35 quicktime_trak_t *trak,
36 int64_t offset,
37 int size)
39 quicktime_riff_t *riff = file->riff[file->total_riffs - 1];
40 quicktime_movi_t *movi = &riff->movi;
41 quicktime_ix_t *ix = movi->ix[trak->tkhd.track_id - 1];
42 quicktime_ixtable_t *ix_table;
44 /* Allocation */
45 if(ix->table_size >= ix->table_allocation)
47 quicktime_ixtable_t *old_table = ix->table;
48 int new_allocation = ix->table_allocation * 2;
49 if(new_allocation < 1) new_allocation = 1;
50 ix->table = calloc(1, sizeof(quicktime_ixtable_t) * new_allocation);
51 if(old_table)
53 memcpy(ix->table, old_table, sizeof(quicktime_ixtable_t) * ix->table_size);
54 free(old_table);
56 ix->table_allocation = new_allocation;
59 /* Appendage */
60 ix_table = &ix->table[ix->table_size++];
61 ix_table->relative_offset = offset - ix->base_offset;
62 ix_table->size = size;
66 void quicktime_write_ix(quicktime_t *file,
67 quicktime_ix_t *ix,
68 int track)
70 int i;
71 quicktime_atom_write_header(file, &ix->atom, ix->tag);
73 /* longs per entry */
74 quicktime_write_int16_le(file, ix->longs_per_entry);
75 /* index sub type */
76 quicktime_write_char(file, 0);
77 /* index type */
78 quicktime_write_char(file, ix->index_type);
79 /* entries in use */
80 quicktime_write_int32_le(file, ix->table_size);
81 /* chunk ID */
82 quicktime_write_char32(file, ix->chunk_id);
83 /* base offset */
84 quicktime_write_int64_le(file, ix->base_offset);
85 /* reserved */
86 quicktime_write_int32_le(file, 0);
88 /* table */
89 for(i = 0; i < ix->table_size; i++)
91 quicktime_ixtable_t *table = &ix->table[i];
92 quicktime_write_int32_le(file, table->relative_offset);
93 quicktime_write_int32_le(file, table->size);
96 quicktime_atom_write_footer(file, &ix->atom);
99 /* Update super index */
100 quicktime_riff_t *riff = file->riff[0];
101 quicktime_hdrl_t *hdrl = &riff->hdrl;
102 quicktime_strl_t *strl = hdrl->strl[track];
103 quicktime_indx_t *indx = &strl->indx;
105 quicktime_update_indx(file, indx, ix);
108 void quicktime_read_ix(quicktime_t *file,
109 quicktime_ix_t *ix)
111 int i;
112 quicktime_atom_t leaf_atom;
113 quicktime_atom_read_header(file, &leaf_atom);
115 ix->longs_per_entry = quicktime_read_int16_le(file);
116 /* sub type */
117 quicktime_read_char(file);
118 ix->index_type = quicktime_read_char(file);
119 ix->table_size = quicktime_read_int32_le(file);
120 quicktime_read_char32(file, ix->chunk_id);
121 ix->base_offset = quicktime_read_int64_le(file);
122 /* reserved */
123 quicktime_read_int32_le(file);
125 ix->table = calloc(ix->table_size, sizeof(quicktime_ixtable_t));
127 for(i = 0; i < ix->table_size; i++)
129 quicktime_ixtable_t *ixtable = &ix->table[i];
130 ixtable->relative_offset = quicktime_read_int32_le(file);
131 ixtable->size = quicktime_read_int32_le(file);