r665: Merged the official release 2.0.
[cinelerra_cv.git] / quicktime / dref.c
blob7d937815e1cb6abc1da28d028d3f771da8f92cbe
1 #include "funcprotos.h"
2 #include "quicktime.h"
4 void quicktime_dref_table_init(quicktime_dref_table_t *table)
6 table->size = 0;
7 table->type[0] = 'a';
8 table->type[1] = 'l';
9 table->type[2] = 'i';
10 table->type[3] = 's';
11 table->version = 0;
12 table->flags = 0x0001;
13 table->data_reference = malloc(256);
14 table->data_reference[0] = 0;
17 void quicktime_dref_table_delete(quicktime_dref_table_t *table)
19 if(table->data_reference) free(table->data_reference);
20 table->data_reference = 0;
23 void quicktime_read_dref_table(quicktime_t *file, quicktime_dref_table_t *table)
25 table->size = quicktime_read_int32(file);
26 quicktime_read_char32(file, table->type);
27 table->version = quicktime_read_char(file);
28 table->flags = quicktime_read_int24(file);
29 if(table->data_reference) free(table->data_reference);
31 table->data_reference = malloc(table->size);
32 if(table->size > 12)
33 quicktime_read_data(file, table->data_reference, table->size - 12);
34 table->data_reference[table->size - 12] = 0;
37 void quicktime_write_dref_table(quicktime_t *file, quicktime_dref_table_t *table)
39 int len = strlen(table->data_reference);
40 quicktime_write_int32(file, 12 + len);
41 quicktime_write_char32(file, table->type);
42 quicktime_write_char(file, table->version);
43 quicktime_write_int24(file, table->flags);
44 if(len)
45 quicktime_write_data(file, table->data_reference, len);
48 void quicktime_dref_table_dump(quicktime_dref_table_t *table)
50 printf(" data reference table (dref)\n");
51 printf(" type %c%c%c%c\n", table->type[0], table->type[1], table->type[2], table->type[3]);
52 printf(" version %d\n", table->version);
53 printf(" flags %d\n", table->flags);
54 printf(" data %s\n", table->data_reference);
58 void quicktime_dref_init(quicktime_dref_t *dref)
60 dref->version = 0;
61 dref->flags = 0;
62 dref->total_entries = 0;
63 dref->table = 0;
66 void quicktime_dref_init_all(quicktime_dref_t *dref)
68 if(!dref->total_entries)
70 dref->total_entries = 1;
71 dref->table = (quicktime_dref_table_t *)malloc(sizeof(quicktime_dref_table_t) * dref->total_entries);
72 quicktime_dref_table_init(&(dref->table[0]));
76 void quicktime_dref_delete(quicktime_dref_t *dref)
78 if(dref->table)
80 int i;
81 for(i = 0; i < dref->total_entries; i++)
82 quicktime_dref_table_delete(&(dref->table[i]));
83 free(dref->table);
85 dref->total_entries = 0;
88 void quicktime_dref_dump(quicktime_dref_t *dref)
90 int i;
92 printf(" data reference (dref)\n");
93 printf(" version %d\n", dref->version);
94 printf(" flags %d\n", dref->flags);
95 for(i = 0; i < dref->total_entries; i++)
97 quicktime_dref_table_dump(&(dref->table[i]));
101 void quicktime_read_dref(quicktime_t *file, quicktime_dref_t *dref)
103 int i;
105 dref->version = quicktime_read_char(file);
106 dref->flags = quicktime_read_int24(file);
107 dref->total_entries = quicktime_read_int32(file);
108 dref->table = (quicktime_dref_table_t*)malloc(sizeof(quicktime_dref_table_t) * dref->total_entries);
109 for(i = 0; i < dref->total_entries; i++)
111 quicktime_dref_table_init(&(dref->table[i]));
112 quicktime_read_dref_table(file, &(dref->table[i]));
116 void quicktime_write_dref(quicktime_t *file, quicktime_dref_t *dref)
118 int i;
119 quicktime_atom_t atom;
120 quicktime_atom_write_header(file, &atom, "dref");
122 quicktime_write_char(file, dref->version);
123 quicktime_write_int24(file, dref->flags);
124 quicktime_write_int32(file, dref->total_entries);
126 for(i = 0; i < dref->total_entries; i++)
128 quicktime_write_dref_table(file, &(dref->table[i]));
130 quicktime_atom_write_footer(file, &atom);