Finished removing GPL'ed MMX code.
[platform/upstream/gstreamer.git] / gst-libs / gst / idct / idct.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <gst/gst.h>
25 #include <gst/idct/idct.h>
26 #include "dct.h"
27
28 static void gst_idct_int_sparse_idct (short *data);
29
30 GstIDCT *
31 gst_idct_new (GstIDCTMethod method)
32 {
33   GstIDCT *new = g_malloc (sizeof (GstIDCT));
34
35   new->need_transpose = FALSE;
36
37   if (method == GST_IDCT_DEFAULT) {
38     method = GST_IDCT_FAST_INT;
39   }
40
41   new->convert_sparse = gst_idct_int_sparse_idct;
42
43   switch (method) {
44     case GST_IDCT_FAST_INT:
45       GST_INFO ("using fast_int_idct");
46       gst_idct_init_fast_int_idct ();
47       new->convert = gst_idct_fast_int_idct;
48       break;
49     case GST_IDCT_INT:
50       GST_INFO ("using int_idct");
51       new->convert = gst_idct_int_idct;
52       break;
53     case GST_IDCT_FLOAT:
54       GST_INFO ("using float_idct");
55       gst_idct_init_float_idct ();
56       new->convert = gst_idct_float_idct;
57       break;
58     default:
59       GST_INFO ("method not supported");
60       g_free (new);
61       return NULL;
62   }
63   return new;
64 }
65
66 static void
67 gst_idct_int_sparse_idct (short *data)
68 {
69   short val;
70   gint32 v, *dp = (guint32 *) data;
71
72   v = *data;
73
74   if (v < 0) {
75     val = -v;
76     val += (8 >> 1);
77     val /= 8;
78     val = -val;
79   } else {
80     val = (v + (8 >> 1)) / 8;
81   }
82   v = ((val & 0xffff) | (val << 16));
83
84   dp[0] = v;
85   dp[1] = v;
86   dp[2] = v;
87   dp[3] = v;
88   dp[4] = v;
89   dp[5] = v;
90   dp[6] = v;
91   dp[7] = v;
92   dp[8] = v;
93   dp[9] = v;
94   dp[10] = v;
95   dp[11] = v;
96   dp[12] = v;
97   dp[13] = v;
98   dp[14] = v;
99   dp[15] = v;
100   dp[16] = v;
101   dp[17] = v;
102   dp[18] = v;
103   dp[19] = v;
104   dp[20] = v;
105   dp[21] = v;
106   dp[22] = v;
107   dp[23] = v;
108   dp[24] = v;
109   dp[25] = v;
110   dp[26] = v;
111   dp[27] = v;
112   dp[28] = v;
113   dp[29] = v;
114   dp[30] = v;
115   dp[31] = v;
116 }
117
118 void
119 gst_idct_destroy (GstIDCT * idct)
120 {
121   g_return_if_fail (idct != NULL);
122
123   g_free (idct);
124 }
125
126 static gboolean
127 plugin_init (GstPlugin * plugin)
128 {
129   return TRUE;
130 }
131
132 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
133     GST_VERSION_MINOR,
134     "gstidct",
135     "Accelerated IDCT routines",
136     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)