Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1671 tullio 1
/* #define DEBUG */
2
/* subspic.c, Frame buffer substitution routines */
3
 
4
/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
5
 
6
/*
7
 * Disclaimer of Warranty
8
 *
9
 * These software programs are available to the user without any license fee or
10
 * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
11
 * any and all warranties, whether express, implied, or statuary, including any
12
 * implied warranties or merchantability or of fitness for a particular
13
 * purpose.  In no event shall the copyright-holder be liable for any
14
 * incidental, punitive, or consequential damages of any kind whatsoever
15
 * arising from the use of these programs.
16
 *
17
 * This disclaimer of warranty extends to the user of these programs and user's
18
 * customers, employees, agents, transferees, successors, and assigns.
19
 *
20
 * The MPEG Software Simulation Group does not represent or warrant that the
21
 * programs furnished hereunder are free of infringement of any third-party
22
 * patents.
23
 *
24
 * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
25
 * are subject to royalty fees to patent holders.  Many of these patents are
26
 * general enough such that they are unavoidable regardless of implementation
27
 * design.
28
 *
29
 */
30
 
31
#include <stdlib.h>
32
 
33
#include "config.h"
34
#include "global.h"
35
 
36
/* private prototypes*/
37
static void Read_Frame(char *filename,
38
  unsigned char *frame_buffer[], int framenum);
39
static void Copy_Frame(unsigned char *src, unsigned char *dst,
40
  int width, int height, int parity, int incr);
41
static int Read_Components(char *filename,
42
  unsigned char *frame[3], int framenum);
43
static int Read_Component(char *fname, unsigned char *frame,
44
  int width, int height);
45
static int Extract_Components(char *filename,
46
  unsigned char *frame[3], int framenum);
47
 
48
extern int read(int Infile, void *Rdbfr, int rdsize);
49
 
50
/* substitute frame buffer routine */
51
void Substitute_Frame_Buffer (bitstream_framenum, sequence_framenum)
52
int bitstream_framenum;
53
int sequence_framenum;
54
{
55
  /* static tracking variables */
56
  static int previous_temporal_reference;
57
  static int previous_bitstream_framenum;
58
  static int previous_anchor_temporal_reference;
59
  static int previous_anchor_bitstream_framenum;
60
  static int previous_picture_coding_type;
61
  static int bgate;
62
 
63
  /* local temporary variables */
64
  int substitute_display_framenum;
65
 
66
 
67
#ifdef DEBUG
68
  cprintf("SUB: seq fn(%d) bitfn(%d) tempref(%d) picstr(%d) type(%d)\n",
69
    sequence_framenum, bitstream_framenum, temporal_reference,
70
    picture_structure, picture_coding_type);
71
#endif
72
 
73
  /* we don't substitute at the first picture of a sequence */
74
  if((sequence_framenum!=0)||(Second_Field))
75
  {
76
    /* only at the start of the frame */
77
    if ((picture_structure==FRAME_PICTURE)||(!Second_Field))
78
    {
79
      if(picture_coding_type==P_TYPE)
80
      {
81
        /* the most recently decoded reference frame needs substituting */
82
        substitute_display_framenum = bitstream_framenum - 1;
83
 
84
        Read_Frame(Substitute_Picture_Filename, forward_reference_frame,
85
          substitute_display_framenum);
86
      }
87
      /* only the first B frame in a consequitve set of B pictures
88
         loads a substitute backward_reference_frame since all subsequent
89
         B frames predict from the same reference pictures */
90
      else if((picture_coding_type==B_TYPE)&&(bgate!=1))
91
      {
92
        substitute_display_framenum =
93
          (previous_temporal_reference - temporal_reference)
94
            + bitstream_framenum - 1;
95
 
96
        Read_Frame(Substitute_Picture_Filename, backward_reference_frame,
97
          substitute_display_framenum);
98
      }
99
    } /* P fields can predict from the two most recently decoded fields, even
100
         from the first field of the same frame being decoded */
101
    else if(Second_Field && (picture_coding_type==P_TYPE))
102
    {
103
      /* our favourite case: the IP field picture pair */
104
      if((previous_picture_coding_type==I_TYPE)&&(picture_coding_type==P_TYPE))
105
      {
106
        substitute_display_framenum = bitstream_framenum;
107
      }
108
      else /* our more generic P field picture pair */
109
      {
110
        substitute_display_framenum =
111
          (temporal_reference - previous_anchor_temporal_reference)
112
113
114
 
115
116
117
118
119
120
121