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 ){
23 lwListFree(clip->ifilter, (void (*)(void *)) lwFreePlugin);
24 lwListFree(clip->pfilter, (void (*)(void *)) lwFreePlugin);
26 switch ( clip->type ) {
28 _pico_free( clip->source.still.name );
32 _pico_free( clip->source.seq.prefix );
33 _pico_free( clip->source.seq.suffix );
37 _pico_free( clip->source.anim.name );
38 _pico_free( clip->source.anim.server );
39 _pico_free( clip->source.anim.data );
43 _pico_free( clip->source.xref.string );
47 _pico_free( clip->source.cycle.name );
60 ======================================================================
63 Read image references from a CLIP chunk in an LWO2 file.
64 ====================================================================== */
66 lwClip *lwGetClip( picoMemStream_t *fp, int cksize ){
74 /* allocate the Clip structure */
76 clip = _pico_calloc( 1, sizeof( lwClip ) );
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() ) {
106 switch ( clip->type ) {
108 clip->source.still.name = getS0( fp );
112 clip->source.seq.digits = getU1( fp );
113 clip->source.seq.flags = getU1( fp );
114 clip->source.seq.offset = getI2( fp );
115 getU2( fp ); /* not sure what this is yet */
116 clip->source.seq.start = getI2( fp );
117 clip->source.seq.end = getI2( fp );
118 clip->source.seq.prefix = getS0( fp );
119 clip->source.seq.suffix = getS0( fp );
123 clip->source.anim.name = getS0( fp );
124 clip->source.anim.server = getS0( fp );
126 clip->source.anim.data = getbytes( fp, sz - rlen );
130 clip->source.xref.index = getI4( fp );
131 clip->source.xref.string = getS0( fp );
135 clip->source.cycle.lo = getI2( fp );
136 clip->source.cycle.hi = getI2( fp );
137 clip->source.cycle.name = getS0( fp );
144 /* error while reading current subchunk? */
147 if ( rlen < 0 || rlen > sz ) {
151 /* skip unread parts of the current subchunk */
154 _pico_memstream_seek( fp, sz - rlen, PICO_SEEK_CUR );
157 /* end of the CLIP chunk? */
159 rlen = _pico_memstream_tell( fp ) - pos;
160 if ( cksize < rlen ) {
163 if ( cksize == rlen ) {
167 /* process subchunks as they're encountered */
171 if ( 0 > get_flen() ) {
181 clip->start_time = getF4( fp );
182 clip->duration = getF4( fp );
183 clip->frame_rate = getF4( fp );
187 clip->contrast.val = getF4( fp );
188 clip->contrast.eindex = getVX( fp );
192 clip->brightness.val = getF4( fp );
193 clip->brightness.eindex = getVX( fp );
197 clip->saturation.val = getF4( fp );
198 clip->saturation.eindex = getVX( fp );
202 clip->hue.val = getF4( fp );
203 clip->hue.eindex = getVX( fp );
207 clip->gamma.val = getF4( fp );
208 clip->gamma.eindex = getVX( fp );
212 clip->negative = getU2( fp );
217 filt = _pico_calloc( 1, sizeof( lwPlugin ) );
222 filt->name = getS0( fp );
223 filt->flags = getU2( fp );
225 filt->data = getbytes( fp, sz - rlen );
227 if ( id == ID_IFLT ) {
228 lwListAdd( (void *) &clip->ifilter, filt );
232 lwListAdd( (void *) &clip->pfilter, filt );
241 /* error while reading current subchunk? */
244 if ( rlen < 0 || rlen > sz ) {
248 /* skip unread parts of the current subchunk */
251 _pico_memstream_seek( fp, sz - rlen, PICO_SEEK_CUR );
254 /* end of the CLIP chunk? */
256 rlen = _pico_memstream_tell( fp ) - pos;
257 if ( cksize < rlen ) {
260 if ( cksize == rlen ) {
264 /* get the next chunk header */
269 if ( 6 != get_flen() ) {
283 ======================================================================
286 Returns an lwClip pointer, given a clip index.
287 ====================================================================== */
289 lwClip *lwFindClip( lwClip *list, int index ){
294 if ( clip->index == index ) {