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.
12 /****************************************************************************
14 * Module Title : preproc.c
16 * Description : Simple pre-processor.
18 ****************************************************************************/
20 /****************************************************************************
22 ****************************************************************************/
26 #include "vpx_mem/vpx_mem.h"
28 /****************************************************************************
30 ****************************************************************************/
32 #define ROUNDUP32(X) ( ( ( (unsigned long) X ) + 31 )&( 0xFFFFFFE0 ) )
34 /****************************************************************************
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);
45 pre_proc_instance *ppi,
53 pre_proc_instance *ppi,
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.
74 * FUNCTION : Performs a closesness adjusted temporarl blur
76 * SPECIAL NOTES : Destination frame can be same as source frame.
78 ****************************************************************************/
81 pre_proc_instance *ppi,
89 unsigned char *frameptr = ppi->frame_buffer;
103 while (frame < FRAMECOUNT);
109 while (byte < bytes);
114 int offset = (ppi->frame % FRAMECOUNT);
122 frameptr[offset] = s[byte];
126 int pixel_value = *frameptr;
129 modifier -= pixel_value;
130 modifier *= modifier;
131 modifier >>= strength;
137 modifier = 16 - modifier;
139 accumulator += modifier * pixel_value;
147 while (frame < FRAMECOUNT);
149 accumulator += (count >> 1);
150 accumulator *= ppi->fixed_divide[count];
153 d[byte] = accumulator;
157 while (byte < bytes);
162 /****************************************************************************
164 * ROUTINE : delete_pre_proc
166 * INPUTS : pre_proc_instance *ppi : Pointer to pre-processor instance.
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.
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)
215 vp8_get_processor_flags(&mmx_enabled, &xmm_enabled, &wmt_enabled);
218 temp_filter = temp_filter_wmt;
219 else if (mmx_enabled)
220 temp_filter = temp_filter_mmx;
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);
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);
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;