| Index: source/libvpx/vpx_scale/generic/vpxscale.c
|
| ===================================================================
|
| --- source/libvpx/vpx_scale/generic/vpxscale.c (revision 172621)
|
| +++ source/libvpx/vpx_scale/generic/vpxscale.c (working copy)
|
| @@ -20,10 +20,9 @@
|
| /****************************************************************************
|
| * Header Files
|
| ****************************************************************************/
|
| -#include "./vpx_rtcd.h"
|
| +#include "./vpx_scale_rtcd.h"
|
| #include "vpx_mem/vpx_mem.h"
|
| #include "vpx_scale/yv12config.h"
|
| -#include "vpx_scale/scale_mode.h"
|
|
|
| typedef struct {
|
| int expanded_frame_width;
|
| @@ -41,66 +40,6 @@
|
|
|
| /****************************************************************************
|
| *
|
| - * ROUTINE : horizontal_line_copy
|
| - *
|
| - * INPUTS : None
|
| - *
|
| - *
|
| - * OUTPUTS : None.
|
| - *
|
| - * RETURNS : None
|
| - *
|
| - * FUNCTION : 1 to 1 scaling up for a horizontal line of pixles
|
| - *
|
| - * SPECIAL NOTES : None.
|
| - *
|
| - * ERRORS : None.
|
| - *
|
| - ****************************************************************************/
|
| -static
|
| -void horizontal_line_copy(
|
| - const unsigned char *source,
|
| - unsigned int source_width,
|
| - unsigned char *dest,
|
| - unsigned int dest_width
|
| -) {
|
| - (void) dest_width;
|
| -
|
| - duck_memcpy(dest, source, source_width);
|
| -}
|
| -/****************************************************************************
|
| - *
|
| - * ROUTINE : null_scale
|
| - *
|
| - * INPUTS : None
|
| - *
|
| - *
|
| - * OUTPUTS : None.
|
| - *
|
| - * RETURNS : None
|
| - *
|
| - * FUNCTION : 1 to 1 scaling up for a vertical band
|
| - *
|
| - * SPECIAL NOTES : None.
|
| - *
|
| - * ERRORS : None.
|
| - *
|
| - ****************************************************************************/
|
| -static
|
| -void null_scale(
|
| - unsigned char *dest,
|
| - unsigned int dest_pitch,
|
| - unsigned int dest_width
|
| -) {
|
| - (void) dest;
|
| - (void) dest_pitch;
|
| - (void) dest_width;
|
| -
|
| - return;
|
| -}
|
| -
|
| -/****************************************************************************
|
| - *
|
| * ROUTINE : scale1d_2t1_i
|
| *
|
| * INPUTS : const unsigned char *source : Pointer to data to be scaled.
|
| @@ -589,422 +528,3 @@
|
| for (i = dh / 2 - 1; i < (int)dst->y_height / 2; i++)
|
| duck_memcpy(dst->v_buffer + i * dst->uv_stride, dst->v_buffer + (dh / 2 - 2)*dst->uv_stride, dst->uv_width);
|
| }
|
| -/****************************************************************************
|
| - *
|
| - * ROUTINE : any_ratio_2d_scale
|
| - *
|
| - * INPUTS : SCALE_INSTANCE *si : Pointer to post-processor instance (NOT USED).
|
| - * const unsigned char *source : Pointer to source image.
|
| - * unsigned int source_pitch : Stride of source image.
|
| - * unsigned int source_width : Width of source image.
|
| - * unsigned int source_height : Height of source image (NOT USED).
|
| - * unsigned char *dest : Pointer to destination image.
|
| - * unsigned int dest_pitch : Stride of destination image.
|
| - * unsigned int dest_width : Width of destination image.
|
| - * unsigned int dest_height : Height of destination image.
|
| - *
|
| - * OUTPUTS : None.
|
| - *
|
| - * RETURNS : int: 1 if image scaled, 0 if image could not be scaled.
|
| - *
|
| - * FUNCTION : Scale the image with changing apect ratio.
|
| - *
|
| - * SPECIAL NOTES : This scaling is a bi-linear scaling. Need to re-work the
|
| - * whole function for new scaling algorithm.
|
| - *
|
| - ****************************************************************************/
|
| -static
|
| -int any_ratio_2d_scale
|
| -(
|
| - SCALE_VARS *si,
|
| - const unsigned char *source,
|
| - int source_pitch,
|
| - unsigned int source_width,
|
| - unsigned int source_height,
|
| - unsigned char *dest,
|
| - unsigned int dest_pitch,
|
| - unsigned int dest_width,
|
| - unsigned int dest_height
|
| -) {
|
| - unsigned int i, k;
|
| - unsigned int src_band_height = 0;
|
| - unsigned int dest_band_height = 0;
|
| -
|
| - /* suggested scale factors */
|
| - int hs = si->HScale;
|
| - int hr = si->HRatio;
|
| - int vs = si->VScale;
|
| - int vr = si->VRatio;
|
| -
|
| - /* assume the ratios are scalable instead of should be centered */
|
| - int ratio_scalable = 1;
|
| -
|
| - const unsigned char *source_base = ((source_pitch >= 0) ? source : (source + ((source_height - 1) * source_pitch)));
|
| - const unsigned char *line_src;
|
| -
|
| - void (*horiz_line_scale)(const unsigned char *, unsigned int, unsigned char *, unsigned int) = NULL;
|
| - void (*vert_band_scale)(unsigned char *, unsigned int, unsigned int) = NULL;
|
| - void (*last_vert_band_scale)(unsigned char *, unsigned int, unsigned int) = NULL;
|
| -
|
| - (void) si;
|
| -
|
| - /* find out the ratio for each direction */
|
| - switch (hr * 30 / hs) {
|
| - case 24:
|
| - /* 4-5 Scale in Width direction */
|
| - horiz_line_scale = vp8_horizontal_line_4_5_scale;
|
| - break;
|
| - case 22:
|
| - /* 3-4 Scale in Width direction */
|
| - horiz_line_scale = vp8_horizontal_line_3_4_scale;
|
| - break;
|
| -
|
| - case 20:
|
| - /* 4-5 Scale in Width direction */
|
| - horiz_line_scale = vp8_horizontal_line_2_3_scale;
|
| - break;
|
| - case 18:
|
| - /* 3-5 Scale in Width direction */
|
| - horiz_line_scale = vp8_horizontal_line_3_5_scale;
|
| - break;
|
| - case 15:
|
| - /* 1-2 Scale in Width direction */
|
| - horiz_line_scale = vp8_horizontal_line_1_2_scale;
|
| - break;
|
| - case 30:
|
| - /* no scale in Width direction */
|
| - horiz_line_scale = horizontal_line_copy;
|
| - break;
|
| - default:
|
| - /* The ratio is not acceptable now */
|
| - /* throw("The ratio is not acceptable for now!"); */
|
| - ratio_scalable = 0;
|
| - break;
|
| - }
|
| -
|
| - switch (vr * 30 / vs) {
|
| - case 24:
|
| - /* 4-5 Scale in vertical direction */
|
| - vert_band_scale = vp8_vertical_band_4_5_scale;
|
| - last_vert_band_scale = vp8_last_vertical_band_4_5_scale;
|
| - src_band_height = 4;
|
| - dest_band_height = 5;
|
| - break;
|
| - case 22:
|
| - /* 3-4 Scale in vertical direction */
|
| - vert_band_scale = vp8_vertical_band_3_4_scale;
|
| - last_vert_band_scale = vp8_last_vertical_band_3_4_scale;
|
| - src_band_height = 3;
|
| - dest_band_height = 4;
|
| - break;
|
| - case 20:
|
| - /* 2-3 Scale in vertical direction */
|
| - vert_band_scale = vp8_vertical_band_2_3_scale;
|
| - last_vert_band_scale = vp8_last_vertical_band_2_3_scale;
|
| - src_band_height = 2;
|
| - dest_band_height = 3;
|
| - break;
|
| - case 18:
|
| - /* 3-5 Scale in vertical direction */
|
| - vert_band_scale = vp8_vertical_band_3_5_scale;
|
| - last_vert_band_scale = vp8_last_vertical_band_3_5_scale;
|
| - src_band_height = 3;
|
| - dest_band_height = 5;
|
| - break;
|
| - case 15:
|
| - /* 1-2 Scale in vertical direction */
|
| - vert_band_scale = vp8_vertical_band_1_2_scale;
|
| - last_vert_band_scale = vp8_last_vertical_band_1_2_scale;
|
| - src_band_height = 1;
|
| - dest_band_height = 2;
|
| - break;
|
| - case 30:
|
| - /* no scale in Width direction */
|
| - vert_band_scale = null_scale;
|
| - last_vert_band_scale = null_scale;
|
| - src_band_height = 4;
|
| - dest_band_height = 4;
|
| - break;
|
| - default:
|
| - /* The ratio is not acceptable now */
|
| - /* throw("The ratio is not acceptable for now!"); */
|
| - ratio_scalable = 0;
|
| - break;
|
| - }
|
| -
|
| - if (ratio_scalable == 0)
|
| - return ratio_scalable;
|
| -
|
| - horiz_line_scale(source, source_width, dest, dest_width);
|
| -
|
| - /* except last band */
|
| - for (k = 0; k < (dest_height + dest_band_height - 1) / dest_band_height - 1; k++) {
|
| - /* scale one band horizontally */
|
| - for (i = 1; i < src_band_height; i++) {
|
| - /* Trap case where we could read off the base of the source buffer */
|
| - line_src = source + i * source_pitch;
|
| -
|
| - if (line_src < source_base)
|
| - line_src = source_base;
|
| -
|
| - horiz_line_scale(line_src, source_width,
|
| - dest + i * dest_pitch, dest_width);
|
| - }
|
| -
|
| - /* first line of next band */
|
| - /* Trap case where we could read off the base of the source buffer */
|
| - line_src = source + src_band_height * source_pitch;
|
| -
|
| - if (line_src < source_base)
|
| - line_src = source_base;
|
| -
|
| - horiz_line_scale(line_src, source_width,
|
| - dest + dest_band_height * dest_pitch,
|
| - dest_width);
|
| -
|
| - /* Vertical scaling is in place */
|
| - vert_band_scale(dest, dest_pitch, dest_width);
|
| -
|
| - /* Next band... */
|
| - source += src_band_height * source_pitch;
|
| - dest += dest_band_height * dest_pitch;
|
| - }
|
| -
|
| - /* scale one band horizontally */
|
| - for (i = 1; i < src_band_height; i++) {
|
| - /* Trap case where we could read off the base of the source buffer */
|
| - line_src = source + i * source_pitch;
|
| -
|
| - if (line_src < source_base)
|
| - line_src = source_base;
|
| -
|
| - horiz_line_scale(line_src, source_width,
|
| - dest + i * dest_pitch,
|
| - dest_width);
|
| - }
|
| -
|
| - /* Vertical scaling is in place */
|
| - last_vert_band_scale(dest, dest_pitch, dest_width);
|
| -
|
| - return ratio_scalable;
|
| -}
|
| -
|
| -/****************************************************************************
|
| - *
|
| - * ROUTINE : any_ratio_frame_scale
|
| - *
|
| - * INPUTS : SCALE_INSTANCE *si : Pointer to post-processor instance (NOT USED).
|
| - * unsigned char *frame_buffer : Pointer to source image.
|
| - * int YOffset : Offset from start of buffer to Y samples.
|
| - * int UVOffset : Offset from start of buffer to UV samples.
|
| - *
|
| - * OUTPUTS : None.
|
| - *
|
| - * RETURNS : int: 1 if image scaled, 0 if image could not be scaled.
|
| - *
|
| - * FUNCTION : Scale the image with changing apect ratio.
|
| - *
|
| - * SPECIAL NOTES : None.
|
| - *
|
| - ****************************************************************************/
|
| -static
|
| -int any_ratio_frame_scale(SCALE_VARS *scale_vars, int YOffset, int UVOffset) {
|
| - int i;
|
| - int ew;
|
| - int eh;
|
| -
|
| - /* suggested scale factors */
|
| - int hs = scale_vars->HScale;
|
| - int hr = scale_vars->HRatio;
|
| - int vs = scale_vars->VScale;
|
| - int vr = scale_vars->VRatio;
|
| -
|
| - int ratio_scalable = 1;
|
| -
|
| - int sw = (scale_vars->expanded_frame_width * hr + hs - 1) / hs;
|
| - int sh = (scale_vars->expanded_frame_height * vr + vs - 1) / vs;
|
| - int dw = scale_vars->expanded_frame_width;
|
| - int dh = scale_vars->expanded_frame_height;
|
| - YV12_BUFFER_CONFIG *src_yuv_config = scale_vars->src_yuv_config;
|
| - YV12_BUFFER_CONFIG *dst_yuv_config = scale_vars->dst_yuv_config;
|
| -
|
| - if (hr == 3)
|
| - ew = (sw + 2) / 3 * 3 * hs / hr;
|
| - else
|
| - ew = (sw + 7) / 8 * 8 * hs / hr;
|
| -
|
| - if (vr == 3)
|
| - eh = (sh + 2) / 3 * 3 * vs / vr;
|
| - else
|
| - eh = (sh + 7) / 8 * 8 * vs / vr;
|
| -
|
| - ratio_scalable = any_ratio_2d_scale(scale_vars,
|
| - (const unsigned char *)src_yuv_config->y_buffer,
|
| - src_yuv_config->y_stride, sw, sh,
|
| - (unsigned char *) dst_yuv_config->y_buffer + YOffset,
|
| - dst_yuv_config->y_stride, dw, dh);
|
| -
|
| - for (i = 0; i < eh; i++)
|
| - duck_memset(dst_yuv_config->y_buffer + YOffset + i * dst_yuv_config->y_stride + dw, 0, ew - dw);
|
| -
|
| - for (i = dh; i < eh; i++)
|
| - duck_memset(dst_yuv_config->y_buffer + YOffset + i * dst_yuv_config->y_stride, 0, ew);
|
| -
|
| - if (ratio_scalable == 0)
|
| - return ratio_scalable;
|
| -
|
| - sw = (sw + 1) >> 1;
|
| - sh = (sh + 1) >> 1;
|
| - dw = (dw + 1) >> 1;
|
| - dh = (dh + 1) >> 1;
|
| -
|
| - any_ratio_2d_scale(scale_vars,
|
| - (const unsigned char *)src_yuv_config->u_buffer,
|
| - src_yuv_config->y_stride / 2, sw, sh,
|
| - (unsigned char *)dst_yuv_config->u_buffer + UVOffset,
|
| - dst_yuv_config->uv_stride, dw, dh);
|
| -
|
| - any_ratio_2d_scale(scale_vars,
|
| - (const unsigned char *)src_yuv_config->v_buffer,
|
| - src_yuv_config->y_stride / 2, sw, sh,
|
| - (unsigned char *)dst_yuv_config->v_buffer + UVOffset,
|
| - dst_yuv_config->uv_stride, dw, dh);
|
| -
|
| - return ratio_scalable;
|
| -}
|
| -
|
| -/****************************************************************************
|
| - *
|
| - * ROUTINE : center_image
|
| - *
|
| - * INPUTS : SCALE_INSTANCE *si : Pointer to post-processor instance.
|
| - *
|
| - * OUTPUTS : None.
|
| - *
|
| - * RETURNS : void
|
| - *
|
| - * FUNCTION : Centers the image without scaling in the output buffer.
|
| - *
|
| - * SPECIAL NOTES : None.
|
| - *
|
| - ****************************************************************************/
|
| -static void
|
| -center_image(YV12_BUFFER_CONFIG *src_yuv_config, YV12_BUFFER_CONFIG *dst_yuv_config) {
|
| - int i;
|
| - int row_offset, col_offset;
|
| - unsigned char *src_data_pointer;
|
| - unsigned char *dst_data_pointer;
|
| -
|
| - /* center values */
|
| - row_offset = (dst_yuv_config->y_height - src_yuv_config->y_height) / 2;
|
| - col_offset = (dst_yuv_config->y_width - src_yuv_config->y_width) / 2;
|
| -
|
| - /* Y's */
|
| - src_data_pointer = src_yuv_config->y_buffer;
|
| - dst_data_pointer = (unsigned char *)dst_yuv_config->y_buffer + (row_offset * dst_yuv_config->y_stride) + col_offset;
|
| -
|
| - for (i = 0; i < src_yuv_config->y_height; i++) {
|
| - duck_memcpy(dst_data_pointer, src_data_pointer, src_yuv_config->y_width);
|
| - dst_data_pointer += dst_yuv_config->y_stride;
|
| - src_data_pointer += src_yuv_config->y_stride;
|
| - }
|
| -
|
| - row_offset /= 2;
|
| - col_offset /= 2;
|
| -
|
| - /* U's */
|
| - src_data_pointer = src_yuv_config->u_buffer;
|
| - dst_data_pointer = (unsigned char *)dst_yuv_config->u_buffer + (row_offset * dst_yuv_config->uv_stride) + col_offset;
|
| -
|
| - for (i = 0; i < src_yuv_config->uv_height; i++) {
|
| - duck_memcpy(dst_data_pointer, src_data_pointer, src_yuv_config->uv_width);
|
| - dst_data_pointer += dst_yuv_config->uv_stride;
|
| - src_data_pointer += src_yuv_config->uv_stride;
|
| - }
|
| -
|
| - /* V's */
|
| - src_data_pointer = src_yuv_config->v_buffer;
|
| - dst_data_pointer = (unsigned char *)dst_yuv_config->v_buffer + (row_offset * dst_yuv_config->uv_stride) + col_offset;
|
| -
|
| - for (i = 0; i < src_yuv_config->uv_height; i++) {
|
| - duck_memcpy(dst_data_pointer, src_data_pointer, src_yuv_config->uv_width);
|
| - dst_data_pointer += dst_yuv_config->uv_stride;
|
| - src_data_pointer += src_yuv_config->uv_stride;
|
| - }
|
| -}
|
| -
|
| -/****************************************************************************
|
| - *
|
| - * ROUTINE : scale_or_center
|
| - *
|
| - * INPUTS : SCALE_INSTANCE *si : Pointer to post-processor instance.
|
| - *
|
| - *
|
| - *
|
| - * OUTPUTS : None.
|
| - *
|
| - * RETURNS : void
|
| - *
|
| - * FUNCTION : Decides to scale or center image in scale buffer for blit
|
| - *
|
| - * SPECIAL NOTES : None.
|
| - *
|
| - ****************************************************************************/
|
| -void
|
| -vp8_yv12_scale_or_center
|
| -(
|
| - YV12_BUFFER_CONFIG *src_yuv_config,
|
| - YV12_BUFFER_CONFIG *dst_yuv_config,
|
| - int expanded_frame_width,
|
| - int expanded_frame_height,
|
| - int scaling_mode,
|
| - int HScale,
|
| - int HRatio,
|
| - int VScale,
|
| - int VRatio
|
| -) {
|
| - /*if ( ppi->post_processing_level )
|
| - update_umvborder ( ppi, frame_buffer );*/
|
| -
|
| -
|
| - switch (scaling_mode) {
|
| - case SCALE_TO_FIT:
|
| - case MAINTAIN_ASPECT_RATIO: {
|
| - SCALE_VARS scale_vars;
|
| - /* center values */
|
| -#if 1
|
| - int row = (dst_yuv_config->y_height - expanded_frame_height) / 2;
|
| - int col = (dst_yuv_config->y_width - expanded_frame_width) / 2;
|
| - /*int YOffset = row * dst_yuv_config->y_width + col;
|
| - int UVOffset = (row>>1) * dst_yuv_config->uv_width + (col>>1);*/
|
| - int YOffset = row * dst_yuv_config->y_stride + col;
|
| - int UVOffset = (row >> 1) * dst_yuv_config->uv_stride + (col >> 1);
|
| -#else
|
| - int row = (src_yuv_config->y_height - expanded_frame_height) / 2;
|
| - int col = (src_yuv_config->y_width - expanded_frame_width) / 2;
|
| - int YOffset = row * src_yuv_config->y_width + col;
|
| - int UVOffset = (row >> 1) * src_yuv_config->uv_width + (col >> 1);
|
| -#endif
|
| -
|
| - scale_vars.dst_yuv_config = dst_yuv_config;
|
| - scale_vars.src_yuv_config = src_yuv_config;
|
| - scale_vars.HScale = HScale;
|
| - scale_vars.HRatio = HRatio;
|
| - scale_vars.VScale = VScale;
|
| - scale_vars.VRatio = VRatio;
|
| - scale_vars.expanded_frame_width = expanded_frame_width;
|
| - scale_vars.expanded_frame_height = expanded_frame_height;
|
| -
|
| - /* perform center and scale */
|
| - any_ratio_frame_scale(&scale_vars, YOffset, UVOffset);
|
| -
|
| - break;
|
| - }
|
| - case CENTER:
|
| - center_image(src_yuv_config, dst_yuv_config);
|
| - break;
|
| -
|
| - default:
|
| - break;
|
| - }
|
| -}
|
|
|