/* * Copyright (c) 2010 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
/**************************************************************************** * * ROUTINE : scale1d_2t1_i * * INPUTS : const unsigned char *source : Pointer to data to be scaled. * int source_step : Number of pixels to step on in * source. * unsigned int source_scale : Scale for source (UNUSED). * unsigned int source_length : Length of source (UNUSED). * unsigned char *dest : Pointer to output data array. * int dest_step : Number of pixels to step on in * destination. * unsigned int dest_scale : Scale for destination * (UNUSED). * unsigned int dest_length : Length of destination. * * OUTPUTS : None. * * RETURNS : void * * FUNCTION : Performs 2-to-1 interpolated scaling. * * SPECIAL NOTES : None. *
****************************************************************************/ staticvoid scale1d_2t1_i(constunsignedchar *source, int source_step, unsignedint source_scale, unsignedint source_length, unsignedchar *dest, int dest_step, unsignedint dest_scale, unsignedint dest_length) { unsignedint i, j; unsignedint temp; int source_pitch = source_step;
(void)source_length;
(void)source_scale;
(void)dest_scale;
/**************************************************************************** * * ROUTINE : scale1d_2t1_ps * * INPUTS : const unsigned char *source : Pointer to data to be scaled. * int source_step : Number of pixels to step on in * source. * unsigned int source_scale : Scale for source (UNUSED). * unsigned int source_length : Length of source (UNUSED). * unsigned char *dest : Pointer to output data array. * int dest_step : Number of pixels to step on in * destination. * unsigned int dest_scale : Scale for destination * (UNUSED). * unsigned int dest_length : Length of destination. * * OUTPUTS : None. * * RETURNS : void * * FUNCTION : Performs 2-to-1 point subsampled scaling. * * SPECIAL NOTES : None. *
****************************************************************************/ staticvoid scale1d_2t1_ps(constunsignedchar *source, int source_step, unsignedint source_scale, unsignedint source_length, unsignedchar *dest, int dest_step, unsignedint dest_scale, unsignedint dest_length) { unsignedint i, j;
for (i = 0; i < dest_length * dest_step; i += dest_step, j += source_step)
dest[i] = source[j];
} /**************************************************************************** * * ROUTINE : scale1d_c * * INPUTS : const unsigned char *source : Pointer to data to be scaled. * int source_step : Number of pixels to step on in * source. * unsigned int source_scale : Scale for source. * unsigned int source_length : Length of source (UNUSED). * unsigned char *dest : Pointer to output data array. * int dest_step : Number of pixels to step on in * destination. * unsigned int dest_scale : Scale for destination. * unsigned int dest_length : Length of destination. * * OUTPUTS : None. * * RETURNS : void * * FUNCTION : Performs linear interpolation in one dimension. * * SPECIAL NOTES : None. *
****************************************************************************/ staticvoid scale1d_c(constunsignedchar *source, int source_step, unsignedint source_scale, unsignedint source_length, unsignedchar *dest, int dest_step, unsignedint dest_scale, unsignedint dest_length) { unsignedint i; unsignedint round_value = dest_scale / 2; unsignedint left_modifier = dest_scale; unsignedint right_modifier = 0; unsignedchar left_pixel = *source; unsignedchar right_pixel = *(source + source_step);
(void)source_length;
/* These asserts are needed if there are boundary issues... */ /*assert ( dest_scale > source_scale );*/ /*assert ( (source_length-1) * dest_scale >= (dest_length-1) * source_scale
* );*/
assert(dest_scale != 0); for (i = 0; i < dest_length * dest_step; i += dest_step) {
dest[i] = (char)((left_modifier * left_pixel +
right_modifier * right_pixel + round_value) /
dest_scale);
/**************************************************************************** * * ROUTINE : Scale2D * * INPUTS : const unsigned char *source : Pointer to data to be * scaled. * int source_pitch : Stride of source image. * unsigned int source_width : Width of input image. * unsigned int source_height : Height of input image. * unsigned char *dest : Pointer to output data * array. * int dest_pitch : Stride of destination * image. * unsigned int dest_width : Width of destination image. * unsigned int dest_height : Height of destination * image. * unsigned char *temp_area : Pointer to temp work area. * unsigned char temp_area_height : Height of temp work area. * unsigned int hscale : Horizontal scale factor * numerator. * unsigned int hratio : Horizontal scale factor * denominator. * unsigned int vscale : Vertical scale factor * numerator. * unsigned int vratio : Vertical scale factor * denominator. * unsigned int interlaced : Interlace flag. * * OUTPUTS : None. * * RETURNS : void * * FUNCTION : Performs 2-tap linear interpolation in two dimensions. * * SPECIAL NOTES : Expansion is performed one band at a time to help with * caching. *
****************************************************************************/ staticvoid Scale2D( /*const*/ unsignedchar *source, int source_pitch, unsignedint source_width, unsignedint source_height, unsignedchar *dest, int dest_pitch, unsignedint dest_width, unsignedint dest_height, unsignedchar *temp_area, unsignedchar temp_area_height, unsignedint hscale, unsignedint hratio, unsignedint vscale, unsignedint vratio, unsignedint interlaced) { /*unsigned*/ int i, j, k; int bands; int dest_band_height; int source_band_height;
typedefvoid (*Scale1D)(constunsignedchar *source, int source_step, unsignedint source_scale, unsignedint source_length, unsignedchar *dest, int dest_step, unsignedint dest_scale, unsignedint dest_length);
/* find out the ratio for each direction */ switch (hratio * 10 / hscale) { case 8: /* 4-5 Scale in Width direction */
horiz_line_scale = vp8_horizontal_line_5_4_scale; break; case 6: /* 3-5 Scale in Width direction */
horiz_line_scale = vp8_horizontal_line_5_3_scale; break; case 5: /* 1-2 Scale in Width direction */
horiz_line_scale = vp8_horizontal_line_2_1_scale; break; default: /* The ratio is not acceptable now */ /* throw("The ratio is not acceptable for now!"); */
ratio_scalable = 0; break;
}
switch (vratio * 10 / vscale) { case 8: /* 4-5 Scale in vertical direction */
vert_band_scale = vp8_vertical_band_5_4_scale;
source_band_height = 5;
dest_band_height = 4; break; case 6: /* 3-5 Scale in vertical direction */
vert_band_scale = vp8_vertical_band_5_3_scale;
source_band_height = 5;
dest_band_height = 3; break; case 5: /* 1-2 Scale in vertical direction */
if (interlaced) { /* if the content is interlaced, point sampling is used */
vert_band_scale = vp8_vertical_band_2_1_scale;
} else {
interpolation = 1; /* if the content is progressive, interplo */
vert_band_scale = vp8_vertical_band_2_1_scale_i;
}
source_band_height = 2;
dest_band_height = 1; break; default: /* The ratio is not acceptable now */ /* throw("The ratio is not acceptable for now!"); */
ratio_scalable = 0; break;
}
if (ratio_scalable) { if (source_height == dest_height) { /* for each band of the image */ for (k = 0; k < (int)dest_height; k++) {
horiz_line_scale(source, source_width, dest, dest_width);
source += source_pitch;
dest += dest_pitch;
}
return;
}
if (interpolation) { if (source < source_base) source = source_base;
for (k = 0;
k < (int)(dest_height + dest_band_height - 1) / dest_band_height;
k++) { /* scale one band horizontally */ for (i = 0; i < source_band_height; i++) { /* Trap case where we could read off the base of the source buffer */
line_src = (unsignedchar *)source + i * source_pitch;
if (line_src < source_base) line_src = source_base;
if (vscale == 2 && vratio == 1) { if (interlaced)
Scale1Dv = scale1d_2t1_ps; else
Scale1Dv = scale1d_2t1_i;
}
if (source_height == dest_height) { /* for each band of the image */ for (k = 0; k < (int)dest_height; k++) {
Scale1Dh(source, 1, hscale, source_width + 1, dest, 1, hratio,
dest_width);
source += source_pitch;
dest += dest_pitch;
}
/* first row needs to be done so that we can stay one row ahead for vertical
* zoom */
Scale1Dh(source, 1, hscale, source_width + 1, temp_area, 1, hratio,
dest_width);
/* for each band of the image */
bands = (dest_height + dest_band_height - 1) / dest_band_height;
for (k = 0; k < bands; k++) { /* scale one band horizontally */ for (i = 1; i < source_band_height + 1; i++) { if (k * source_band_height + i < (int)source_height) {
Scale1Dh(source + i * source_pitch, 1, hscale, source_width + 1,
temp_area + i * dest_pitch, 1, hratio, dest_width);
} else { /* Duplicate the last row */ /* copy temp_area row 0 over from last row in the past */
memcpy(temp_area + i * dest_pitch, temp_area + (i - 1) * dest_pitch,
dest_pitch);
}
}
/* scale one band vertically */ for (j = 0; j < (int)dest_width; j++) {
Scale1Dv(&temp_area[j], dest_pitch, vscale, source_band_height + 1,
&dest[j], dest_pitch, vratio, dest_band_height);
}
/* copy temp_area row 0 over from last row in the past */
memcpy(temp_area, temp_area + source_band_height * dest_pitch, dest_pitch);
/* move to the next band */
source += source_band_height * source_pitch;
dest += dest_band_height * dest_pitch;
}
}
/**************************************************************************** * * ROUTINE : vpx_scale_frame * * INPUTS : YV12_BUFFER_CONFIG *src : Pointer to frame to be * scaled. * YV12_BUFFER_CONFIG *dst : Pointer to buffer to hold * scaled frame. * unsigned char *temp_area : Pointer to temp work area. * unsigned char temp_area_height : Height of temp work area. * unsigned int hscale : Horizontal scale factor * numerator. * unsigned int hratio : Horizontal scale factor * denominator. * unsigned int vscale : Vertical scale factor * numerator. * unsigned int vratio : Vertical scale factor * denominator. * unsigned int interlaced : Interlace flag. * * OUTPUTS : None. * * RETURNS : void * * FUNCTION : Performs 2-tap linear interpolation in two dimensions. * * SPECIAL NOTES : Expansion is performed one band at a time to help with * caching. *
****************************************************************************/ void vpx_scale_frame(YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst, unsignedchar *temp_area, unsignedchar temp_height, unsignedint hscale, unsignedint hratio, unsignedint vscale, unsignedint vratio, unsignedint interlaced) { int i; int dw = (hscale - 1 + src->y_width * hratio) / hscale; int dh = (vscale - 1 + src->y_height * vratio) / vscale;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.