Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / quicktime / dref.c
blobf5982cae6df3e8a5c6797e352e031b7e1ded0181
1 #include "funcprotos.h"
2 #include "quicktime.h"
3 #include <string.h>
5 void quicktime_dref_table_init(quicktime_dref_table_t *table)
7 table->size = 0;
8 table->type[0] = 'a';
9 table->type[1] = 'l';
10 table->type[2] = 'i';
11 table->type[3] = 's';
12 table->version = 0;
13 table->flags = 0x0001;
14 table->data_reference = malloc(256);
15 table->data_reference[0] = 0;
18 void quicktime_dref_table_delete(quicktime_dref_table_t *table)
20 if(table->data_reference) free(table->data_reference);
21 table->data_reference = 0;
24 void quicktime_read_dref_table(quicktime_t *file, quicktime_dref_table_t *table)
26 table->size = quicktime_read_int32(file);
27 quicktime_read_char32(file, table->type);
28 table->version = quicktime_read_char(file);
29 table->flags = quicktime_read_int24(file);
30 if(table->data_reference) free(table->data_reference);
32 table->data_reference = malloc(table->size);
33 if(table->size > 12)
34 quicktime_read_data(file, table->data_reference, table->size - 12);
35 table->data_reference[table->size - 12] = 0;
38 void quicktime_write_dref_table(quicktime_t *file, quicktime_dref_table_t *table)
40 int len = strlen(table->data_reference);
41 quicktime_write_int32(file, 12 + len);
42 quicktime_write_char32(file, table->type);
43 quicktime_write_char(file, table->version);
44 quicktime_write_int24(file, table->flags);
45 if(len)
46 quicktime_write_data(file, table->data_reference, len);
49 void quicktime_dref_table_dump(quicktime_dref_table_t *table)
51 printf(" data reference table (dref)\n");
52 printf(" type %c%c%c%c\n", table->type[0], table->type[1], table->type[2], table->type[3]);
53 printf(" version %d\n", table->version);
54 printf(" flags %d\n", table->flags);
55 printf(" data %s\n", table->data_reference);
59 void quicktime_dref_init(quicktime_dref_t *dref)
61 dref->version = 0;
62 dref->flags = 0;
63 dref->total_entries = 0;
64 dref->table = 0;
67 void quicktime_dref_init_all(quicktime_dref_t *dref)
69 if(!dref->total_entries)
71 dref->total_entries = 1;
72 dref->table = (quicktime_dref_table_t *)malloc(sizeof(quicktime_dref_table_t) * dref->total_entries);
73 quicktime_dref_table_init(&(dref->table[0]));
77 void quicktime_dref_delete(quicktime_dref_t *dref)
79 if(dref->table)
81 int i;
82 for(i = 0; i < dref->total_entries; i++)
83 quicktime_dref_table_delete(&(dref->table[i]));
84 free(dref->table);
86 dref->total_entries = 0;
89 void quicktime_dref_dump(quicktime_dref_t *dref)
91 int i;
93 printf(" data reference (dref)\n");
94 printf(" version %d\n", dref->version);
95 printf(" flags %d\n", dref->flags);
96 for(i = 0; i < dref->total_entries; i++)
98 quicktime_dref_table_dump(&(dref->table[i]));
102 void quicktime_read_dref(quicktime_t *file, quicktime_dref_t *dref)
104 int i;
106 dref->version = quicktime_read_char(file);
107 dref->flags = quicktime_read_int24(file);
108 dref->total_entries = quicktime_read_int32(file);
109 dref->table = (quicktime_dref_table_t*)malloc(sizeof(quicktime_dref_table_t) * dref->total_entries);
110 for(i = 0; i < dref->total_entries; i++)
112 quicktime_dref_table_init(&(dref->table[i]));
113 quicktime_read_dref_table(file, &(dref->table[i]));
117 void quicktime_write_dref(quicktime_t *file, quicktime_dref_t *dref)
119 int i;
120 quicktime_atom_t atom;
121 quicktime_atom_write_header(file, &atom, "dref");
123 quicktime_write_char(file, dref->version);
124 quicktime_write_int24(file, dref->flags);
125 quicktime_write_int32(file, dref->total_entries);
127 for(i = 0; i < dref->total_entries; i++)
129 quicktime_write_dref_table(file, &(dref->table[i]));
131 quicktime_atom_write_footer(file, &atom);