/**************************************************************************** * *ROUTINE:Scale2D * *INPUTS:constunsignedchar*source:Pointertodatatobe *scaled. *intsource_pitch:Strideofsourceimage. *unsignedintsource_width:Widthofinputimage. *unsignedintsource_height:Heightofinputimage. *unsignedchar*dest:Pointertooutputdata *array. *intdest_pitch:Strideofdestination *image. *unsignedintdest_width:Widthofdestinationimage. *unsignedintdest_height:Heightofdestination *image. *unsignedchar*temp_area:Pointertotempworkarea. *unsignedchartemp_area_height:Heightoftempworkarea. *unsignedinthscale:Horizontalscalefactor *numerator. *unsignedinthratio:Horizontalscalefactor *denominator. *unsignedintvscale:Verticalscalefactor *numerator. *unsignedintvratio:Verticalscalefactor *denominator. *unsignedintinterlaced:Interlaceflag. * *OUTPUTS:None. * *RETURNS:void * *FUNCTION:Performs2-taplinearinterpolationintwodimensions. * *SPECIALNOTES:Expansionisperformedonebandatatimetohelpwith *caching. *
****************************************************************************/ staticvoid Scale2D( /*const*/ unsigned char *source, int source_pitch, unsigned int source_width, unsigned int source_height, unsigned char *dest, int dest_pitch, unsigned int dest_width, unsigned int dest_height, unsigned char *temp_area, unsigned char temp_area_height, unsigned int hscale, unsigned int hratio, unsigned int vscale, unsigned int vratio, unsigned int interlaced) { /*unsigned*/
int i, j, k;
int bands;
int dest_band_height;
int source_band_height;
typedefvoid (*Scale1D)(constunsigned char *source, int source_step, unsigned int source_scale, unsigned int source_length, unsigned char *dest, int dest_step, unsigned int dest_scale, unsigned int dest_length);
/* find out the ratio for each direction */ switch (hratio * 10 / hscale) { case8: /* 4-5 Scale in Width direction */
horiz_line_scale = vp8_horizontal_line_5_4_scale; break; case6: /* 3-5 Scale in Width direction */
horiz_line_scale = vp8_horizontal_line_5_3_scale; break; case5: /* 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) { case8: /* 4-5 Scale in vertical direction */
vert_band_scale = vp8_vertical_band_5_4_scale;
source_band_height = 5;
dest_band_height = 4; break; case6: /* 3-5 Scale in vertical direction */
vert_band_scale = vp8_vertical_band_5_3_scale;
source_band_height = 5;
dest_band_height = 3; break; case5: /* 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 = (unsigned char *)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;
}
}
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.