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( (void*) clip->ifilter, lwFreePlugin );
25 lwListFree( (void*) clip->pfilter, lwFreePlugin );
32 ======================================================================
35 Read image references from a CLIP chunk in an LWO2 file.
36 ====================================================================== */
38 lwClip *lwGetClip( picoMemStream_t *fp, int cksize )
47 /* allocate the Clip structure */
49 clip = _pico_calloc( 1, sizeof( lwClip ));
50 if ( !clip ) goto Fail;
52 clip->contrast.val = 1.0f;
53 clip->brightness.val = 1.0f;
54 clip->saturation.val = 1.0f;
55 clip->gamma.val = 1.0f;
57 /* remember where we started */
60 pos = _pico_memstream_tell( fp );
64 clip->index = getI4( fp );
66 /* first subchunk header */
68 clip->type = getU4( fp );
70 if ( 0 > get_flen() ) goto Fail;
75 switch ( clip->type ) {
77 clip->source.still.name = getS0( fp );
81 clip->source.seq.digits = getU1( fp );
82 clip->source.seq.flags = getU1( fp );
83 clip->source.seq.offset = getI2( fp );
84 getU2( fp ); /* not sure what this is yet */
85 clip->source.seq.start = getI2( fp );
86 clip->source.seq.end = getI2( fp );
87 clip->source.seq.prefix = getS0( fp );
88 clip->source.seq.suffix = getS0( fp );
92 clip->source.anim.name = getS0( fp );
93 clip->source.anim.server = getS0( fp );
95 clip->source.anim.data = getbytes( fp, sz - rlen );
99 clip->source.xref.index = getI4( fp );
100 clip->source.xref.string = getS0( fp );
104 clip->source.cycle.lo = getI2( fp );
105 clip->source.cycle.hi = getI2( fp );
106 clip->source.cycle.name = getS0( fp );
113 /* error while reading current subchunk? */
116 if ( rlen < 0 || rlen > sz ) goto Fail;
118 /* skip unread parts of the current subchunk */
121 _pico_memstream_seek( fp, sz - rlen, PICO_SEEK_CUR );
123 /* end of the CLIP chunk? */
125 rlen = _pico_memstream_tell( fp ) - pos;
126 if ( cksize < rlen ) goto Fail;
127 if ( cksize == rlen )
130 /* process subchunks as they're encountered */
134 if ( 0 > get_flen() ) goto Fail;
142 clip->start_time = getF4( fp );
143 clip->duration = getF4( fp );
144 clip->frame_rate = getF4( fp );
148 clip->contrast.val = getF4( fp );
149 clip->contrast.eindex = getVX( fp );
153 clip->brightness.val = getF4( fp );
154 clip->brightness.eindex = getVX( fp );
158 clip->saturation.val = getF4( fp );
159 clip->saturation.eindex = getVX( fp );
163 clip->hue.val = getF4( fp );
164 clip->hue.eindex = getVX( fp );
168 clip->gamma.val = getF4( fp );
169 clip->gamma.eindex = getVX( fp );
173 clip->negative = getU2( fp );
178 filt = _pico_calloc( 1, sizeof( lwPlugin ));
179 if ( !filt ) goto Fail;
181 filt->name = getS0( fp );
182 filt->flags = getU2( fp );
184 filt->data = getbytes( fp, sz - rlen );
186 if ( id == ID_IFLT ) {
187 lwListAdd( &clip->ifilter, filt );
191 lwListAdd( &clip->pfilter, filt );
200 /* error while reading current subchunk? */
203 if ( rlen < 0 || rlen > sz ) goto Fail;
205 /* skip unread parts of the current subchunk */
208 _pico_memstream_seek( fp, sz - rlen, PICO_SEEK_CUR );
210 /* end of the CLIP chunk? */
212 rlen = _pico_memstream_tell( fp ) - pos;
213 if ( cksize < rlen ) goto Fail;
214 if ( cksize == rlen ) break;
216 /* get the next chunk header */
221 if ( 6 != get_flen() ) goto Fail;
233 ======================================================================
236 Returns an lwClip pointer, given a clip index.
237 ====================================================================== */
239 lwClip *lwFindClip( lwClip *list, int index )
245 if ( clip->index == index ) break;