arm: remove duplicate functions
[libvpx.git] / vp8 / encoder / preproc.c
blobbd918fa3c0aad9f4c6c340f42b33d38848b5594b
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 /****************************************************************************
14 * Module Title : preproc.c
16 * Description : Simple pre-processor.
18 ****************************************************************************/
20 /****************************************************************************
21 * Header Files
22 ****************************************************************************/
24 #include "memory.h"
25 #include "preproc7.h"
26 #include "vpx_mem/vpx_mem.h"
28 /****************************************************************************
29 * Macros
30 ****************************************************************************/
31 #define FRAMECOUNT 7
32 #define ROUNDUP32(X) ( ( ( (unsigned long) X ) + 31 )&( 0xFFFFFFE0 ) )
34 /****************************************************************************
35 * Imports
36 ****************************************************************************/
37 extern void vp8_get_processor_flags(int *mmx_enabled, int *xmm_enabled, int *wmt_enabled);
39 /****************************************************************************
40 * Exported Global Variables
41 ****************************************************************************/
42 void (*temp_filter)(pre_proc_instance *ppi, unsigned char *s, unsigned char *d, int bytes, int strength);
43 void temp_filter_mmx
45 pre_proc_instance *ppi,
46 unsigned char *s,
47 unsigned char *d,
48 int bytes,
49 int strength
51 void temp_filter_wmt
53 pre_proc_instance *ppi,
54 unsigned char *s,
55 unsigned char *d,
56 int bytes,
57 int strength
60 /****************************************************************************
62 * ROUTINE : temp_filter_c
64 * INPUTS : pre_proc_instance *ppi : Pointer to pre-processor instance.
65 * unsigned char *s : Pointer to source frame.
66 * unsigned char *d : Pointer to destination frame.
67 * int bytes : Number of bytes to filter.
68 * int strength : Strength of filter to apply.
70 * OUTPUTS : None.
72 * RETURNS : void
74 * FUNCTION : Performs a closesness adjusted temporarl blur
76 * SPECIAL NOTES : Destination frame can be same as source frame.
78 ****************************************************************************/
79 void temp_filter_c
81 pre_proc_instance *ppi,
82 unsigned char *s,
83 unsigned char *d,
84 int bytes,
85 int strength
88 int byte = 0;
89 unsigned char *frameptr = ppi->frame_buffer;
91 if (ppi->frame == 0)
95 int frame = 0;
99 *frameptr = s[byte];
100 ++frameptr;
101 ++frame;
103 while (frame < FRAMECOUNT);
105 d[byte] = s[byte];
107 ++byte;
109 while (byte < bytes);
111 else
113 int modifier;
114 int offset = (ppi->frame % FRAMECOUNT);
118 int accumulator = 0;
119 int count = 0;
120 int frame = 0;
122 frameptr[offset] = s[byte];
126 int pixel_value = *frameptr;
128 modifier = s[byte];
129 modifier -= pixel_value;
130 modifier *= modifier;
131 modifier >>= strength;
132 modifier *= 3;
134 if (modifier > 16)
135 modifier = 16;
137 modifier = 16 - modifier;
139 accumulator += modifier * pixel_value;
141 count += modifier;
143 frameptr++;
145 ++frame;
147 while (frame < FRAMECOUNT);
149 accumulator += (count >> 1);
150 accumulator *= ppi->fixed_divide[count];
151 accumulator >>= 16;
153 d[byte] = accumulator;
155 ++byte;
157 while (byte < bytes);
160 ++ppi->frame;
162 /****************************************************************************
164 * ROUTINE : delete_pre_proc
166 * INPUTS : pre_proc_instance *ppi : Pointer to pre-processor instance.
168 * OUTPUTS : None.
170 * RETURNS : void
172 * FUNCTION : Deletes a pre-processing instance.
174 * SPECIAL NOTES : None.
176 ****************************************************************************/
177 void delete_pre_proc(pre_proc_instance *ppi)
179 if (ppi->frame_buffer_alloc)
180 vpx_free(ppi->frame_buffer_alloc);
182 ppi->frame_buffer_alloc = 0;
183 ppi->frame_buffer = 0;
185 if (ppi->fixed_divide_alloc)
186 vpx_free(ppi->fixed_divide_alloc);
188 ppi->fixed_divide_alloc = 0;
189 ppi->fixed_divide = 0;
192 /****************************************************************************
194 * ROUTINE : init_pre_proc
196 * INPUTS : pre_proc_instance *ppi : Pointer to pre-processor instance.
197 * int frame_size : Number of bytes in one frame.
199 * OUTPUTS : None.
201 * RETURNS : int: 1 if successful, 0 if failed.
203 * FUNCTION : Initializes prepprocessor instance.
205 * SPECIAL NOTES : None.
207 ****************************************************************************/
208 int init_pre_proc7(pre_proc_instance *ppi, int frame_size)
210 int i;
211 int mmx_enabled;
212 int xmm_enabled;
213 int wmt_enabled;
215 vp8_get_processor_flags(&mmx_enabled, &xmm_enabled, &wmt_enabled);
217 if (wmt_enabled)
218 temp_filter = temp_filter_wmt;
219 else if (mmx_enabled)
220 temp_filter = temp_filter_mmx;
221 else
222 temp_filter = temp_filter_c;
225 delete_pre_proc(ppi);
227 ppi->frame_buffer_alloc = vpx_malloc(32 + frame_size * FRAMECOUNT * sizeof(unsigned char));
229 if (!ppi->frame_buffer_alloc)
231 delete_pre_proc(ppi);
232 return 0;
235 ppi->frame_buffer = (unsigned char *) ROUNDUP32(ppi->frame_buffer_alloc);
237 ppi->fixed_divide_alloc = vpx_malloc(32 + 255 * sizeof(unsigned int));
239 if (!ppi->fixed_divide_alloc)
241 delete_pre_proc(ppi);
242 return 0;
245 ppi->fixed_divide = (unsigned int *) ROUNDUP32(ppi->fixed_divide_alloc);
247 for (i = 1; i < 255; i++)
248 ppi->fixed_divide[i] = 0x10000 / i;
250 return 1;