~ubuntu-branches/ubuntu/trusty/gavl/trusty

« back to all changes in this revision

Viewing changes to gavl/transform.c

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2009-01-17 20:38:33 UTC
  • mfrom: (1.1.3 upstream) (4.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090117203833-t8fq1e1jdquyelmy
Tags: 1.1.0-2
Fixed debian/copyright 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 * gavl - a general purpose audio/video processing library
 
3
 *
 
4
 * Copyright (c) 2001 - 2008 Members of the Gmerlin project
 
5
 * gmerlin-general@lists.sourceforge.net
 
6
 * http://gmerlin.sourceforge.net
 
7
 *
 
8
 * This program is free software: you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation, either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 * *****************************************************************/
 
21
 
 
22
#include <stdlib.h>
 
23
 
 
24
#include <gavl/gavl.h>
 
25
#include <video.h>
 
26
#include <transform.h>
 
27
 
 
28
gavl_image_transform_t * gavl_image_transform_create()
 
29
  {
 
30
  gavl_image_transform_t * ret;
 
31
  ret = calloc(1, sizeof(*ret));
 
32
  gavl_video_options_set_defaults(&ret->opt);
 
33
  return ret;
 
34
  }
 
35
 
 
36
void gavl_image_transform_destroy(gavl_image_transform_t * t)
 
37
  {
 
38
  int i, j;
 
39
  for(i = 0; i < 3; i++)
 
40
    {
 
41
    for(j = 0; j < GAVL_MAX_PLANES; j++)
 
42
      {
 
43
      gavl_transform_context_free(&t->contexts[i][j]);
 
44
      }
 
45
    }
 
46
  free(t);
 
47
  }
 
48
 
 
49
/** \brief Destroy a transformation engine
 
50
 *  \param A transformation engine
 
51
 *  \param Format (can be changed)
 
52
 *  \param func Coordinate transform function
 
53
 *  \param priv The priv argument for func
 
54
 */
 
55
 
 
56
void gavl_image_transform_init(gavl_image_transform_t * t,
 
57
                               gavl_video_format_t * format,
 
58
                               gavl_image_transform_func func, void * priv)
 
59
  {
 
60
  int i, j;
 
61
  gavl_video_options_t opt;
 
62
  gavl_video_options_copy(&opt, &t->opt);
 
63
 
 
64
  if(opt.scale_mode == GAVL_SCALE_AUTO)
 
65
    {
 
66
    if(opt.quality < 2)
 
67
      opt.scale_mode = GAVL_SCALE_NEAREST;
 
68
    else if(opt.quality < 3)
 
69
      opt.scale_mode = GAVL_SCALE_BILINEAR;
 
70
    else
 
71
      opt.scale_mode = GAVL_SCALE_CUBIC_BSPLINE;
 
72
    }
 
73
 
 
74
  /* Warning: Don't change this until you know what you
 
75
     are doing. The supported scale modes have a maximum of
 
76
     4 filter taps and *no* clipping */
 
77
  
 
78
  if(opt.scale_mode > GAVL_SCALE_CUBIC_BSPLINE)
 
79
    opt.scale_mode = GAVL_SCALE_CUBIC_BSPLINE;
 
80
  
 
81
  /* Count fields */
 
82
  gavl_video_format_copy(&t->format, format);
 
83
  
 
84
  switch(format->interlace_mode)
 
85
    {
 
86
    case GAVL_INTERLACE_NONE:
 
87
      t->num_fields = 1;
 
88
      break; 
 
89
    case GAVL_INTERLACE_TOP_FIRST:
 
90
    case GAVL_INTERLACE_BOTTOM_FIRST:
 
91
      t->num_fields = 2;
 
92
      break; 
 
93
    case GAVL_INTERLACE_MIXED:
 
94
      t->num_fields = 3;
 
95
      break;
 
96
    }
 
97
 
 
98
  if((t->format.pixelformat == GAVL_YUY2) ||
 
99
     (t->format.pixelformat == GAVL_UYVY))
 
100
    t->num_planes = 3;
 
101
  else
 
102
    t->num_planes =
 
103
      gavl_pixelformat_num_planes(t->format.pixelformat);
 
104
  
 
105
  /* Setup contexts */
 
106
  
 
107
  for(i = 0; i < t->num_fields; i++)
 
108
    for(j = 0; j < t->num_planes; j++)
 
109
      gavl_transform_context_init(t, &opt, i, j, func, priv);
 
110
  
 
111
  }
 
112
 
 
113
/** \brief Transform an image
 
114
 *  \param A transformation engine
 
115
 *  \param Input frame
 
116
 *  \param Output frame
 
117
 */
 
118
  
 
119
void gavl_image_transform_transform(gavl_image_transform_t * t,
 
120
                                    gavl_video_frame_t * in_frame,
 
121
                                    gavl_video_frame_t * out_frame)
 
122
  {
 
123
  int i, j;
 
124
  
 
125
  int num_fields, field;
 
126
 
 
127
  if(t->format.interlace_mode == GAVL_INTERLACE_NONE)
 
128
    {
 
129
    num_fields = 1;
 
130
    field = 0;
 
131
    }
 
132
  else if((t->format.interlace_mode == GAVL_INTERLACE_MIXED) &&
 
133
          (in_frame->interlace_mode == GAVL_INTERLACE_NONE))
 
134
    {
 
135
    num_fields = 1;
 
136
    field = 2;
 
137
    }
 
138
  else
 
139
    num_fields = 2;
 
140
 
 
141
  if(num_fields == 1)
 
142
    {
 
143
    for(j = 0; j < t->num_planes; j++)
 
144
      {
 
145
      //      fprintf(stderr, "Transform: %d\n", field);
 
146
      gavl_transform_context_transform(&t->contexts[field][j],
 
147
                                       in_frame, out_frame);
 
148
      }
 
149
    }
 
150
  else
 
151
    {
 
152
    for(i = 0; i < 2; i++)
 
153
      {
 
154
      for(j = 0; j < t->num_planes; j++)
 
155
        {
 
156
        gavl_transform_context_transform(&t->contexts[i][j],
 
157
                                         in_frame, out_frame);
 
158
        }
 
159
      }
 
160
    }
 
161
  
 
162
  }
 
163
 
 
164
gavl_video_options_t *
 
165
gavl_image_transform_get_options(gavl_image_transform_t * t)
 
166
  {
 
167
  return &t->opt;
 
168
  }