[svn] / trunk / xvidextra / src / apps / miniconvert / filters.h Repository:
ViewVC logotype

Diff of /trunk/xvidextra/src/apps/miniconvert/filters.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2048, Fri Oct 7 18:03:59 2011 UTC revision 2049, Thu Oct 13 14:36:24 2011 UTC
# Line 178  Line 178 
178    int m_Mpeg4SequenceSize;    int m_Mpeg4SequenceSize;
179  };  };
180    
181    
182    /*****************************************************************************
183     * Bitstream helper functions
184     ****************************************************************************/
185    
186    /* Copied from bitstream.h of xvidcore - TODO: BAD...
187    /* Copyright (C) 2001-2003 Peter Ross <pross@xvid.org> */
188    
189    /* Input buffer should be readable as full chunks of 8bytes, including
190    the end of the buffer. Padding might be appropriate. If only chunks
191    of 4bytes are applicable, define XVID_SAFE_BS_TAIL. Note that this will
192    slow decoding, so consider this as a last-resort solution */
193    
194    /* #define XVID_SAFE_BS_TAIL */
195    
196    #define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
197    
198    #define VIDOBJLAY_START_CODE_MASK       0x0000000f
199    #define VIDOBJLAY_START_CODE            0x00000120      /* ..0x0000012f */
200    #define VISOBJ_START_CODE                       0x000001b5
201    
202    #define VIDOBJLAY_SHAPE_RECTANGULAR                     0
203    #define VISOBJ_TYPE_VIDEO                                       1
204    #define VIDOBJLAY_AR_EXTPAR                                     15
205    
206    #define READ_MARKER()   BitstreamSkip(bs, 1)
207    
208    #define MAX(a, b) ((a > b) ? (a) : (b))
209    
210    
211    typedef struct
212    {
213            unsigned int bufa;
214            unsigned int bufb;
215            unsigned int buf;
216            unsigned int pos;
217            unsigned int *tail;
218            unsigned int *start;
219            unsigned int length;
220            unsigned int initpos;
221    }
222    Bitstream;
223    
224    
225    /* initialise bitstream structure */
226    
227    static void __inline
228    BitstreamInit(Bitstream * const bs,
229                              void *const bitstream,
230                              unsigned int length)
231    {
232            unsigned int tmp;
233            size_t bitpos;
234            unsigned int adjbitstream = (unsigned int)bitstream;
235    
236            /*
237             * Start the stream on a uint32_t boundary, by rounding down to the
238             * previous uint32_t and skipping the intervening bytes.
239             */
240            bitpos = ((sizeof(unsigned int)-1) & (size_t)bitstream);
241            adjbitstream = adjbitstream - bitpos;
242            bs->start = bs->tail = (unsigned int *) adjbitstream;
243    
244            tmp = *bs->start;
245    #ifndef ARCH_IS_BIG_ENDIAN
246            BSWAP(tmp);
247    #endif
248            bs->bufa = tmp;
249    
250            tmp = *(bs->start + 1);
251    #ifndef ARCH_IS_BIG_ENDIAN
252            BSWAP(tmp);
253    #endif
254            bs->bufb = tmp;
255    
256            bs->pos = bs->initpos = (unsigned int) bitpos*8;
257            /* preserve the intervening bytes */
258            if (bs->initpos > 0)
259                    bs->buf = bs->bufa & (0xffffffff << (32 - bs->initpos));
260            else
261                    bs->buf = 0;
262            bs->length = length;
263    }
264    
265    
266    /* reads n bits from bitstream without changing the stream pos */
267    
268    static unsigned int __inline
269    BitstreamShowBits(Bitstream * const bs,
270                                      const unsigned int bits)
271    {
272            int nbit = (bits + bs->pos) - 32;
273    
274            if (nbit > 0) {
275                    return ((bs->bufa & (0xffffffff >> bs->pos)) << nbit) | (bs->
276                                                                                                                                     bufb >> (32 -
277                                                                                                                                                      nbit));
278            } else {
279                    return (bs->bufa & (0xffffffff >> bs->pos)) >> (32 - bs->pos - bits);
280            }
281    }
282    
283    
284    /* skip n bits forward in bitstream */
285    
286    static __inline void
287    BitstreamSkip(Bitstream * const bs,
288                              const unsigned int bits)
289    {
290            bs->pos += bits;
291    
292            if (bs->pos >= 32) {
293                    unsigned int tmp;
294    
295                    bs->bufa = bs->bufb;
296    #if defined(XVID_SAFE_BS_TAIL)
297                    if (bs->tail<(bs->start+((bs->length+3)>>2)))
298    #endif
299                    {
300                            tmp = *((unsigned int *) bs->tail + 2);
301    #ifndef ARCH_IS_BIG_ENDIAN
302                            BSWAP(tmp);
303    #endif
304                            bs->bufb = tmp;
305                            bs->tail++;
306                    }
307    #if defined(XVID_SAFE_BS_TAIL)
308                    else {
309                            bs->bufb = 0;
310                    }
311    #endif
312                    bs->pos -= 32;
313            }
314    }
315    
316    
317    /* move forward to the next byte boundary */
318    
319    static __inline void
320    BitstreamByteAlign(Bitstream * const bs)
321    {
322            unsigned int remainder = bs->pos % 8;
323    
324            if (remainder) {
325                    BitstreamSkip(bs, 8 - remainder);
326            }
327    }
328    
329    
330    /* bitstream length (unit bits) */
331    
332    static unsigned int __inline
333    BitstreamPos(const Bitstream * const bs)
334    {
335            return((unsigned int)(8*((unsigned int)bs->tail - (unsigned int)bs->start) + bs->pos - bs->initpos));
336    }
337    
338    
339    /* read n bits from bitstream */
340    
341    static unsigned int __inline
342    BitstreamGetBits(Bitstream * const bs,
343                                     const unsigned int n)
344    {
345            unsigned int ret = BitstreamShowBits(bs, n);
346    
347            BitstreamSkip(bs, n);
348            return ret;
349    }
350    
351    
352    /* read single bit from bitstream */
353    
354    static unsigned int __inline
355    BitstreamGetBit(Bitstream * const bs)
356    {
357            return BitstreamGetBits(bs, 1);
358    }
359    
360    /*****************************************************************************/
361    
362  #endif                                                  /* _FILTERS_H_ */  #endif                                                  /* _FILTERS_H_ */

Legend:
Removed from v.2048  
changed lines
  Added in v.2049

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4