2 ======================================================================
5 Functions for LWO2 image references.
8 ====================================================================== */
10 #include "../picointernal.h"
15 ======================================================================
18 Free memory used by an lwClip.
19 ====================================================================== */
21 void lwFreeClip( lwClip *clip )
24 lwListFree( clip->ifilter, (void *) lwFreePlugin );
25 lwListFree( clip->pfilter, (void *) lwFreePlugin );
27 switch ( clip->type ) {
29 _pico_free( clip->source.still.name);
33 _pico_free( clip->source.seq.prefix );
34 _pico_free( clip->source.seq.suffix );
38 _pico_free( clip->source.anim.name );
39 _pico_free( clip->source.anim.server );
40 _pico_free( clip->source.anim.data );
44 _pico_free( clip->source.xref.string );
48 _pico_free( clip->source.cycle.name );
61 ======================================================================
64 Read image references from a CLIP chunk in an LWO2 file.
65 ====================================================================== */
67 lwClip *lwGetClip( picoMemStream_t *fp, int cksize )
76 /* allocate the Clip structure */
78 clip = _pico_calloc( 1, sizeof( lwClip ));
79 if ( !clip ) goto Fail;
81 clip->contrast.val = 1.0f;
82 clip->brightness.val = 1.0f;
83 clip->saturation.val = 1.0f;
84 clip->gamma.val = 1.0f;
86 /* remember where we started */
89 pos = _pico_memstream_tell( fp );
93 clip->index = getI4( fp );
95 /* first subchunk header */
97 clip->type = getU4( fp );
99 if ( 0 > get_flen() ) goto Fail;
104 switch ( clip->type ) {
106 clip->source.still.name = getS0( fp );
110 clip->source.seq.digits = getU1( fp );
111 clip->source.seq.flags = getU1( fp );
112 clip->source.seq.offset = getI2( fp );
113 getU2( fp ); /* not sure what this is yet */
114 clip->source.seq.start = getI2( fp );
115 clip->source.seq.end = getI2( fp );
116 clip->source.seq.prefix = getS0( fp );
117 clip->source.seq.suffix = getS0( fp );
121 clip->source.anim.name = getS0( fp );
122 clip->source.anim.server = getS0( fp );
124 clip->source.anim.data = getbytes( fp, sz - rlen );
128 clip->source.xref.index = getI4( fp );
129 clip->source.xref.string = getS0( fp );
133 clip->source.cycle.lo = getI2( fp );
134 clip->source.cycle.hi = getI2( fp );
135 clip->source.cycle.name = getS0( fp );
142 /* error while reading current subchunk? */
145 if ( rlen < 0 || rlen > sz ) goto Fail;
147 /* skip unread parts of the current subchunk */
150 _pico_memstream_seek( fp, sz - rlen, PICO_SEEK_CUR );
152 /* end of the CLIP chunk? */
154 rlen = _pico_memstream_tell( fp ) - pos;
155 if ( cksize < rlen ) goto Fail;
156 if ( cksize == rlen )
159 /* process subchunks as they're encountered */
163 if ( 0 > get_flen() ) goto Fail;
171 clip->start_time = getF4( fp );
172 clip->duration = getF4( fp );
173 clip->frame_rate = getF4( fp );
177 clip->contrast.val = getF4( fp );
178 clip->contrast.eindex = getVX( fp );
182 clip->brightness.val = getF4( fp );
183 clip->brightness.eindex = getVX( fp );
187 clip->saturation.val = getF4( fp );
188 clip->saturation.eindex = getVX( fp );
192 clip->hue.val = getF4( fp );
193 clip->hue.eindex = getVX( fp );
197 clip->gamma.val = getF4( fp );
198 clip->gamma.eindex = getVX( fp );
202 clip->negative = getU2( fp );
207 filt = _pico_calloc( 1, sizeof( lwPlugin ));
208 if ( !filt ) goto Fail;
210 filt->name = getS0( fp );
211 filt->flags = getU2( fp );
213 filt->data = getbytes( fp, sz - rlen );
215 if ( id == ID_IFLT ) {
216 lwListAdd( (void *) &clip->ifilter, filt );
220 lwListAdd( (void *) &clip->pfilter, filt );
229 /* error while reading current subchunk? */
232 if ( rlen < 0 || rlen > sz ) goto Fail;
234 /* skip unread parts of the current subchunk */
237 _pico_memstream_seek( fp, sz - rlen, PICO_SEEK_CUR );
239 /* end of the CLIP chunk? */
241 rlen = _pico_memstream_tell( fp ) - pos;
242 if ( cksize < rlen ) goto Fail;
243 if ( cksize == rlen ) break;
245 /* get the next chunk header */
250 if ( 6 != get_flen() ) goto Fail;
262 ======================================================================
265 Returns an lwClip pointer, given a clip index.
266 ====================================================================== */
268 lwClip *lwFindClip( lwClip *list, int index )
274 if ( clip->index == index ) break;