gstreamer/gst/videoscale/vs_4tap.c

702 lines
18 KiB
C
Raw Normal View History

/*
* Image Scaling Functions (4 tap)
* Copyright (c) 2005 David A. Schleef <ds@schleef.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "vs_image.h"
#include "vs_scanline.h"
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static... Original commit message from CVS: * ext/alsa/gstalsamixertrack.c: (gst_alsa_mixer_track_get_type): * ext/alsa/gstalsasink.c: (set_hwparams): * ext/alsa/gstalsasrc.c: (set_hwparams): * ext/gio/gstgio.c: (gst_gio_uri_handler_get_uri): * ext/ogg/gstoggmux.h: * ext/ogg/gstogmparse.c: * gst-libs/gst/audio/audio.c: * gst-libs/gst/fft/kiss_fft_f64.c: (kiss_fft_f64_alloc): * gst-libs/gst/pbutils/missing-plugins.c: (gst_missing_uri_sink_message_new), (gst_missing_element_message_new), (gst_missing_decoder_message_new), (gst_missing_encoder_message_new): * gst-libs/gst/rtp/gstbasertppayload.c: * gst-libs/gst/rtp/gstrtcpbuffer.c: (gst_rtcp_packet_bye_get_reason): * gst/audioconvert/gstaudioconvert.c: * gst/audioresample/gstaudioresample.c: * gst/ffmpegcolorspace/imgconvert.c: * gst/playback/test.c: (gen_video_element), (gen_audio_element): * gst/typefind/gsttypefindfunctions.c: * gst/videoscale/vs_4tap.c: * gst/videoscale/vs_4tap.h: * sys/v4l/gstv4lelement.c: * sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get_any_caps): * sys/v4l/v4l_calls.c: * sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_capture_init), (gst_v4lsrc_try_capture): * sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls), (gst_ximagesink_ximage_new): * sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls), (gst_xvimagesink_xvimage_new): * tests/check/elements/audioconvert.c: * tests/check/elements/audioresample.c: (fail_unless_perfect_stream): * tests/check/elements/audiotestsrc.c: (setup_audiotestsrc): * tests/check/elements/decodebin.c: * tests/check/elements/gdpdepay.c: (setup_gdpdepay), (setup_gdpdepay_streamheader): * tests/check/elements/gdppay.c: (setup_gdppay), (GST_START_TEST), (setup_gdppay_streamheader): * tests/check/elements/gnomevfssink.c: (setup_gnomevfssink): * tests/check/elements/multifdsink.c: (setup_multifdsink): * tests/check/elements/textoverlay.c: * tests/check/elements/videorate.c: (setup_videorate): * tests/check/elements/videotestsrc.c: (setup_videotestsrc): * tests/check/elements/volume.c: (setup_volume): * tests/check/elements/vorbisdec.c: (setup_vorbisdec): * tests/check/elements/vorbistag.c: * tests/check/generic/clock-selection.c: * tests/check/generic/states.c: (setup), (teardown): * tests/check/libs/cddabasesrc.c: * tests/check/libs/video.c: * tests/check/pipelines/gio.c: * tests/check/pipelines/oggmux.c: * tests/check/pipelines/simple-launch-lines.c: (simple_launch_lines_suite): * tests/check/pipelines/streamheader.c: * tests/check/pipelines/theoraenc.c: * tests/check/pipelines/vorbisdec.c: * tests/check/pipelines/vorbisenc.c: * tests/examples/seek/scrubby.c: * tests/examples/seek/seek.c: (query_positions_elems), (query_positions_pads): * tests/icles/stress-xoverlay.c: (myclock): Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static, using NULL instead of 0 for pointers and using "foo (void)" instead of "foo ()" for declarations. * win32/common/libgstrtp.def: Add gst_rtp_buffer_set_extension_data to the symbol definition file.
2008-03-03 06:04:31 +00:00
#include "vs_4tap.h"
#include <liboil/liboil.h>
#include <math.h>
#define SHIFT 10
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define CLAMP(x,a,b) MAX(MIN((x),(b)),(a))
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifdef WIN32
#define rint(x) (floor((x)+0.5))
#endif
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static... Original commit message from CVS: * ext/alsa/gstalsamixertrack.c: (gst_alsa_mixer_track_get_type): * ext/alsa/gstalsasink.c: (set_hwparams): * ext/alsa/gstalsasrc.c: (set_hwparams): * ext/gio/gstgio.c: (gst_gio_uri_handler_get_uri): * ext/ogg/gstoggmux.h: * ext/ogg/gstogmparse.c: * gst-libs/gst/audio/audio.c: * gst-libs/gst/fft/kiss_fft_f64.c: (kiss_fft_f64_alloc): * gst-libs/gst/pbutils/missing-plugins.c: (gst_missing_uri_sink_message_new), (gst_missing_element_message_new), (gst_missing_decoder_message_new), (gst_missing_encoder_message_new): * gst-libs/gst/rtp/gstbasertppayload.c: * gst-libs/gst/rtp/gstrtcpbuffer.c: (gst_rtcp_packet_bye_get_reason): * gst/audioconvert/gstaudioconvert.c: * gst/audioresample/gstaudioresample.c: * gst/ffmpegcolorspace/imgconvert.c: * gst/playback/test.c: (gen_video_element), (gen_audio_element): * gst/typefind/gsttypefindfunctions.c: * gst/videoscale/vs_4tap.c: * gst/videoscale/vs_4tap.h: * sys/v4l/gstv4lelement.c: * sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get_any_caps): * sys/v4l/v4l_calls.c: * sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_capture_init), (gst_v4lsrc_try_capture): * sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls), (gst_ximagesink_ximage_new): * sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls), (gst_xvimagesink_xvimage_new): * tests/check/elements/audioconvert.c: * tests/check/elements/audioresample.c: (fail_unless_perfect_stream): * tests/check/elements/audiotestsrc.c: (setup_audiotestsrc): * tests/check/elements/decodebin.c: * tests/check/elements/gdpdepay.c: (setup_gdpdepay), (setup_gdpdepay_streamheader): * tests/check/elements/gdppay.c: (setup_gdppay), (GST_START_TEST), (setup_gdppay_streamheader): * tests/check/elements/gnomevfssink.c: (setup_gnomevfssink): * tests/check/elements/multifdsink.c: (setup_multifdsink): * tests/check/elements/textoverlay.c: * tests/check/elements/videorate.c: (setup_videorate): * tests/check/elements/videotestsrc.c: (setup_videotestsrc): * tests/check/elements/volume.c: (setup_volume): * tests/check/elements/vorbisdec.c: (setup_vorbisdec): * tests/check/elements/vorbistag.c: * tests/check/generic/clock-selection.c: * tests/check/generic/states.c: (setup), (teardown): * tests/check/libs/cddabasesrc.c: * tests/check/libs/video.c: * tests/check/pipelines/gio.c: * tests/check/pipelines/oggmux.c: * tests/check/pipelines/simple-launch-lines.c: (simple_launch_lines_suite): * tests/check/pipelines/streamheader.c: * tests/check/pipelines/theoraenc.c: * tests/check/pipelines/vorbisdec.c: * tests/check/pipelines/vorbisenc.c: * tests/examples/seek/scrubby.c: * tests/examples/seek/seek.c: (query_positions_elems), (query_positions_pads): * tests/icles/stress-xoverlay.c: (myclock): Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static, using NULL instead of 0 for pointers and using "foo (void)" instead of "foo ()" for declarations. * win32/common/libgstrtp.def: Add gst_rtp_buffer_set_extension_data to the symbol definition file.
2008-03-03 06:04:31 +00:00
static int16_t vs_4tap_taps[256][4];
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static... Original commit message from CVS: * ext/alsa/gstalsamixertrack.c: (gst_alsa_mixer_track_get_type): * ext/alsa/gstalsasink.c: (set_hwparams): * ext/alsa/gstalsasrc.c: (set_hwparams): * ext/gio/gstgio.c: (gst_gio_uri_handler_get_uri): * ext/ogg/gstoggmux.h: * ext/ogg/gstogmparse.c: * gst-libs/gst/audio/audio.c: * gst-libs/gst/fft/kiss_fft_f64.c: (kiss_fft_f64_alloc): * gst-libs/gst/pbutils/missing-plugins.c: (gst_missing_uri_sink_message_new), (gst_missing_element_message_new), (gst_missing_decoder_message_new), (gst_missing_encoder_message_new): * gst-libs/gst/rtp/gstbasertppayload.c: * gst-libs/gst/rtp/gstrtcpbuffer.c: (gst_rtcp_packet_bye_get_reason): * gst/audioconvert/gstaudioconvert.c: * gst/audioresample/gstaudioresample.c: * gst/ffmpegcolorspace/imgconvert.c: * gst/playback/test.c: (gen_video_element), (gen_audio_element): * gst/typefind/gsttypefindfunctions.c: * gst/videoscale/vs_4tap.c: * gst/videoscale/vs_4tap.h: * sys/v4l/gstv4lelement.c: * sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get_any_caps): * sys/v4l/v4l_calls.c: * sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_capture_init), (gst_v4lsrc_try_capture): * sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls), (gst_ximagesink_ximage_new): * sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls), (gst_xvimagesink_xvimage_new): * tests/check/elements/audioconvert.c: * tests/check/elements/audioresample.c: (fail_unless_perfect_stream): * tests/check/elements/audiotestsrc.c: (setup_audiotestsrc): * tests/check/elements/decodebin.c: * tests/check/elements/gdpdepay.c: (setup_gdpdepay), (setup_gdpdepay_streamheader): * tests/check/elements/gdppay.c: (setup_gdppay), (GST_START_TEST), (setup_gdppay_streamheader): * tests/check/elements/gnomevfssink.c: (setup_gnomevfssink): * tests/check/elements/multifdsink.c: (setup_multifdsink): * tests/check/elements/textoverlay.c: * tests/check/elements/videorate.c: (setup_videorate): * tests/check/elements/videotestsrc.c: (setup_videotestsrc): * tests/check/elements/volume.c: (setup_volume): * tests/check/elements/vorbisdec.c: (setup_vorbisdec): * tests/check/elements/vorbistag.c: * tests/check/generic/clock-selection.c: * tests/check/generic/states.c: (setup), (teardown): * tests/check/libs/cddabasesrc.c: * tests/check/libs/video.c: * tests/check/pipelines/gio.c: * tests/check/pipelines/oggmux.c: * tests/check/pipelines/simple-launch-lines.c: (simple_launch_lines_suite): * tests/check/pipelines/streamheader.c: * tests/check/pipelines/theoraenc.c: * tests/check/pipelines/vorbisdec.c: * tests/check/pipelines/vorbisenc.c: * tests/examples/seek/scrubby.c: * tests/examples/seek/seek.c: (query_positions_elems), (query_positions_pads): * tests/icles/stress-xoverlay.c: (myclock): Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static, using NULL instead of 0 for pointers and using "foo (void)" instead of "foo ()" for declarations. * win32/common/libgstrtp.def: Add gst_rtp_buffer_set_extension_data to the symbol definition file.
2008-03-03 06:04:31 +00:00
static double
vs_4tap_func (double x)
{
#if 0
if (x < -1)
return 0;
if (x > 1)
return 0;
if (x < 0)
return 1 + x;
return 1 - x;
#endif
#if 0
if (x == 0)
return 1;
return sin (M_PI * x) / (M_PI * x) * (1 - 0.25 * x * x);
#endif
#if 1
if (x == 0)
return 1;
return sin (M_PI * x) / (M_PI * x);
#endif
}
void
vs_4tap_init (void)
{
int i;
double a, b, c, d;
double sum;
for (i = 0; i < 256; i++) {
a = vs_4tap_func (-1 - i / 256.0);
b = vs_4tap_func (0 - i / 256.0);
c = vs_4tap_func (1 - i / 256.0);
d = vs_4tap_func (2 - i / 256.0);
sum = a + b + c + d;
vs_4tap_taps[i][0] = rint ((1 << SHIFT) * (a / sum));
vs_4tap_taps[i][1] = rint ((1 << SHIFT) * (b / sum));
vs_4tap_taps[i][2] = rint ((1 << SHIFT) * (c / sum));
vs_4tap_taps[i][3] = rint ((1 << SHIFT) * (d / sum));
}
}
void
vs_scanline_resample_4tap_Y (uint8_t * dest, uint8_t * src,
int n, int src_width, int *xacc, int increment)
{
int i;
int j;
int acc;
int x;
int y;
acc = *xacc;
for (i = 0; i < n; i++) {
j = acc >> 16;
x = (acc & 0xff00) >> 8;
if (j - 1 >= 0 && j + 2 < src_width) {
y = vs_4tap_taps[x][0] * src[MAX (j - 1, 0)];
y += vs_4tap_taps[x][1] * src[j];
y += vs_4tap_taps[x][2] * src[j + 1];
y += vs_4tap_taps[x][3] * src[j + 2];
} else {
y = vs_4tap_taps[x][0] * src[CLAMP (j - 1, 0, src_width - 1)];
y += vs_4tap_taps[x][1] * src[CLAMP (j, 0, src_width - 1)];
y += vs_4tap_taps[x][2] * src[CLAMP (j + 1, 0, src_width - 1)];
y += vs_4tap_taps[x][3] * src[CLAMP (j + 2, 0, src_width - 1)];
}
y += (1 << (SHIFT - 1));
dest[i] = CLAMP (y >> SHIFT, 0, 255);
acc += increment;
}
*xacc = acc;
}
void
vs_scanline_merge_4tap_Y (uint8_t * dest, uint8_t * src1, uint8_t * src2,
uint8_t * src3, uint8_t * src4, int n, int acc)
{
int i;
int y;
int a, b, c, d;
acc = (acc >> 8) & 0xff;
a = vs_4tap_taps[acc][0];
b = vs_4tap_taps[acc][1];
c = vs_4tap_taps[acc][2];
d = vs_4tap_taps[acc][3];
for (i = 0; i < n; i++) {
y = a * src1[i];
y += b * src2[i];
y += c * src3[i];
y += d * src4[i];
y += (1 << (SHIFT - 1));
dest[i] = CLAMP (y >> SHIFT, 0, 255);
}
}
void
vs_image_scale_4tap_Y (const VSImage * dest, const VSImage * src,
uint8_t * tmpbuf)
{
int yacc;
int y_increment;
int x_increment;
int i;
int j;
int xacc;
int k;
if (dest->height == 1)
y_increment = 0;
else
y_increment = ((src->height - 1) << 16) / (dest->height - 1);
if (dest->width == 1)
x_increment = 0;
else
x_increment = ((src->width - 1) << 16) / (dest->width - 1);
k = 0;
for (i = 0; i < 4; i++) {
xacc = 0;
vs_scanline_resample_4tap_Y (tmpbuf + i * dest->width,
src->pixels + i * src->stride, dest->width, src->width,
&xacc, x_increment);
}
yacc = 0;
for (i = 0; i < dest->height; i++) {
uint8_t *t0, *t1, *t2, *t3;
j = yacc >> 16;
while (j > k) {
k++;
if (k + 3 < src->height) {
xacc = 0;
vs_scanline_resample_4tap_Y (tmpbuf + ((k + 3) & 3) * dest->width,
src->pixels + (k + 3) * src->stride,
dest->width, src->width, &xacc, x_increment);
}
}
t0 = tmpbuf + (CLAMP (j - 1, 0, src->height - 1) & 3) * dest->width;
t1 = tmpbuf + (CLAMP (j, 0, src->height - 1) & 3) * dest->width;
t2 = tmpbuf + (CLAMP (j + 1, 0, src->height - 1) & 3) * dest->width;
t3 = tmpbuf + (CLAMP (j + 2, 0, src->height - 1) & 3) * dest->width;
vs_scanline_merge_4tap_Y (dest->pixels + i * dest->stride,
t0, t1, t2, t3, dest->width, yacc & 0xffff);
yacc += y_increment;
}
}
void
vs_scanline_resample_4tap_RGBA (uint8_t * dest, uint8_t * src,
int n, int src_width, int *xacc, int increment)
{
int i;
int j;
int acc;
int x;
int y;
int off;
acc = *xacc;
for (i = 0; i < n; i++) {
j = acc >> 16;
x = (acc & 0xffff) >> 8;
for (off = 0; off < 4; off++) {
if (j - 1 >= 0 && j + 2 < src_width) {
y = vs_4tap_taps[x][0] * src[MAX ((j - 1) * 4 + off, 0)];
y += vs_4tap_taps[x][1] * src[j * 4 + off];
y += vs_4tap_taps[x][2] * src[(j + 1) * 4 + off];
y += vs_4tap_taps[x][3] * src[(j + 2) * 4 + off];
} else {
y = vs_4tap_taps[x][0] * src[CLAMP ((j - 1) * 4 + off, 0,
4 * (src_width - 1) + off)];
y += vs_4tap_taps[x][1] * src[CLAMP (j * 4 + off, 0,
4 * (src_width - 1) + off)];
y += vs_4tap_taps[x][2] * src[CLAMP ((j + 1) * 4 + off, 0,
4 * (src_width - 1) + off)];
y += vs_4tap_taps[x][3] * src[CLAMP ((j + 2) * 4 + off, 0,
4 * (src_width - 1) + off)];
}
y += (1 << (SHIFT - 1));
dest[i * 4 + off] = CLAMP (y >> SHIFT, 0, 255);
}
acc += increment;
}
*xacc = acc;
}
void
vs_scanline_merge_4tap_RGBA (uint8_t * dest, uint8_t * src1, uint8_t * src2,
uint8_t * src3, uint8_t * src4, int n, int acc)
{
int i;
int y;
int off;
int a, b, c, d;
acc = (acc >> 8) & 0xff;
a = vs_4tap_taps[acc][0];
b = vs_4tap_taps[acc][1];
c = vs_4tap_taps[acc][2];
d = vs_4tap_taps[acc][3];
for (i = 0; i < n; i++) {
for (off = 0; off < 4; off++) {
y = a * src1[i * 4 + off];
y += b * src2[i * 4 + off];
y += c * src3[i * 4 + off];
y += d * src4[i * 4 + off];
y += (1 << (SHIFT - 1));
dest[i * 4 + off] = CLAMP (y >> SHIFT, 0, 255);
}
}
}
void
vs_image_scale_4tap_RGBA (const VSImage * dest, const VSImage * src,
uint8_t * tmpbuf)
{
int yacc;
int y_increment;
int x_increment;
int i;
int j;
int xacc;
int k;
if (dest->height == 1)
y_increment = 0;
else
y_increment = ((src->height - 1) << 16) / (dest->height - 1);
if (dest->width == 1)
x_increment = 0;
else
x_increment = ((src->width - 1) << 16) / (dest->width - 1);
k = 0;
for (i = 0; i < 4; i++) {
xacc = 0;
vs_scanline_resample_4tap_RGBA (tmpbuf + i * dest->stride,
src->pixels + i * src->stride, dest->width, src->width,
&xacc, x_increment);
}
yacc = 0;
for (i = 0; i < dest->height; i++) {
uint8_t *t0, *t1, *t2, *t3;
j = yacc >> 16;
while (j > k) {
k++;
if (k + 3 < src->height) {
xacc = 0;
vs_scanline_resample_4tap_RGBA (tmpbuf + ((k + 3) & 3) * dest->stride,
src->pixels + (k + 3) * src->stride,
dest->width, src->width, &xacc, x_increment);
}
}
t0 = tmpbuf + (CLAMP (j - 1, 0, src->height - 1) & 3) * dest->stride;
t1 = tmpbuf + (CLAMP (j, 0, src->height - 1) & 3) * dest->stride;
t2 = tmpbuf + (CLAMP (j + 1, 0, src->height - 1) & 3) * dest->stride;
t3 = tmpbuf + (CLAMP (j + 2, 0, src->height - 1) & 3) * dest->stride;
vs_scanline_merge_4tap_RGBA (dest->pixels + i * dest->stride,
t0, t1, t2, t3, dest->width, yacc & 0xffff);
yacc += y_increment;
}
}
void
vs_scanline_resample_4tap_RGB (uint8_t * dest, uint8_t * src,
int n, int src_width, int *xacc, int increment)
{
int i;
int j;
int acc;
int x;
int y;
int off;
acc = *xacc;
for (i = 0; i < n; i++) {
j = acc >> 16;
x = (acc & 0xffff) >> 8;
for (off = 0; off < 3; off++) {
if (j - 1 >= 0 && j + 2 < src_width) {
y = vs_4tap_taps[x][0] * src[MAX ((j - 1) * 3 + off, 0)];
y += vs_4tap_taps[x][1] * src[j * 3 + off];
y += vs_4tap_taps[x][2] * src[(j + 1) * 3 + off];
y += vs_4tap_taps[x][3] * src[(j + 2) * 3 + off];
} else {
y = vs_4tap_taps[x][0] * src[CLAMP ((j - 1) * 3 + off, 0,
3 * (src_width - 1) + off)];
y += vs_4tap_taps[x][1] * src[CLAMP (j * 3 + off, 0,
3 * (src_width - 1) + off)];
y += vs_4tap_taps[x][2] * src[CLAMP ((j + 1) * 3 + off, 0,
3 * (src_width - 1) + off)];
y += vs_4tap_taps[x][3] * src[CLAMP ((j + 2) * 3 + off, 0,
3 * (src_width - 1) + off)];
}
y += (1 << (SHIFT - 1));
dest[i * 3 + off] = CLAMP (y >> SHIFT, 0, 255);
}
acc += increment;
}
*xacc = acc;
}
void
vs_scanline_merge_4tap_RGB (uint8_t * dest, uint8_t * src1, uint8_t * src2,
uint8_t * src3, uint8_t * src4, int n, int acc)
{
int i;
int y;
int off;
int a, b, c, d;
acc = (acc >> 8) & 0xff;
a = vs_4tap_taps[acc][0];
b = vs_4tap_taps[acc][1];
c = vs_4tap_taps[acc][2];
d = vs_4tap_taps[acc][3];
for (i = 0; i < n; i++) {
for (off = 0; off < 3; off++) {
y = a * src1[i * 3 + off];
y += b * src2[i * 3 + off];
y += c * src3[i * 3 + off];
y += d * src4[i * 3 + off];
y += (1 << (SHIFT - 1));
dest[i * 3 + off] = CLAMP (y >> SHIFT, 0, 255);
}
}
}
void
vs_image_scale_4tap_RGB (const VSImage * dest, const VSImage * src,
uint8_t * tmpbuf)
{
int yacc;
int y_increment;
int x_increment;
int i;
int j;
int xacc;
int k;
if (dest->height == 1)
y_increment = 0;
else
y_increment = ((src->height - 1) << 16) / (dest->height - 1);
if (dest->width == 1)
x_increment = 0;
else
x_increment = ((src->width - 1) << 16) / (dest->width - 1);
k = 0;
for (i = 0; i < 4; i++) {
xacc = 0;
vs_scanline_resample_4tap_RGB (tmpbuf + i * dest->stride,
src->pixels + i * src->stride, dest->width, src->width,
&xacc, x_increment);
}
yacc = 0;
for (i = 0; i < dest->height; i++) {
uint8_t *t0, *t1, *t2, *t3;
j = yacc >> 16;
while (j > k) {
k++;
if (k + 3 < src->height) {
xacc = 0;
vs_scanline_resample_4tap_RGB (tmpbuf + ((k + 3) & 3) * dest->stride,
src->pixels + (k + 3) * src->stride,
dest->width, src->width, &xacc, x_increment);
}
}
t0 = tmpbuf + (CLAMP (j - 1, 0, src->height - 1) & 3) * dest->stride;
t1 = tmpbuf + (CLAMP (j, 0, src->height - 1) & 3) * dest->stride;
t2 = tmpbuf + (CLAMP (j + 1, 0, src->height - 1) & 3) * dest->stride;
t3 = tmpbuf + (CLAMP (j + 2, 0, src->height - 1) & 3) * dest->stride;
vs_scanline_merge_4tap_RGB (dest->pixels + i * dest->stride,
t0, t1, t2, t3, dest->width, yacc & 0xffff);
yacc += y_increment;
}
}
void
vs_scanline_resample_4tap_YUYV (uint8_t * dest, uint8_t * src,
int n, int src_width, int *xacc, int increment)
{
int i;
int j;
int acc;
int x;
int y;
int off;
acc = *xacc;
for (i = 0; i < n; i++) {
j = acc >> 16;
x = (acc & 0xffff) >> 8;
for (off = 0; off < 4; off++) {
if (j - 1 >= 0 && j + 2 < src_width) {
y = vs_4tap_taps[x][0] * src[MAX ((j - 1) * 4 + off, 0)];
y += vs_4tap_taps[x][1] * src[j * 4 + off];
y += vs_4tap_taps[x][2] * src[(j + 1) * 4 + off];
y += vs_4tap_taps[x][3] * src[(j + 2) * 4 + off];
} else {
y = vs_4tap_taps[x][0] * src[CLAMP ((j - 1) * 4 + off, 0,
4 * (src_width - 1) + off)];
y += vs_4tap_taps[x][1] * src[CLAMP (j * 4 + off, 0,
4 * (src_width - 1) + off)];
y += vs_4tap_taps[x][2] * src[CLAMP ((j + 1) * 4 + off, 0,
4 * (src_width - 1) + off)];
y += vs_4tap_taps[x][3] * src[CLAMP ((j + 2) * 4 + off, 0,
4 * (src_width - 1) + off)];
}
y += (1 << (SHIFT - 1));
dest[i * 4 + off] = CLAMP (y >> SHIFT, 0, 255);
}
acc += increment;
}
*xacc = acc;
}
void
vs_scanline_merge_4tap_YUYV (uint8_t * dest, uint8_t * src1, uint8_t * src2,
uint8_t * src3, uint8_t * src4, int n, int acc)
{
int i;
int y;
int off;
int a, b, c, d;
acc = (acc >> 8) & 0xff;
a = vs_4tap_taps[acc][0];
b = vs_4tap_taps[acc][1];
c = vs_4tap_taps[acc][2];
d = vs_4tap_taps[acc][3];
for (i = 0; i < n; i++) {
for (off = 0; off < 4; off++) {
y = a * src1[i * 4 + off];
y += b * src2[i * 4 + off];
y += c * src3[i * 4 + off];
y += d * src4[i * 4 + off];
y += (1 << (SHIFT - 1));
dest[i * 4 + off] = CLAMP (y >> SHIFT, 0, 255);
}
}
}
void
vs_image_scale_4tap_YUYV (const VSImage * dest, const VSImage * src,
uint8_t * tmpbuf)
{
int yacc;
int y_increment;
int x_increment;
int i;
int j;
int xacc;
int k;
if (dest->height == 1)
y_increment = 0;
else
y_increment = ((src->height - 1) << 16) / (dest->height - 1);
if (dest->width == 1)
x_increment = 0;
else
x_increment = ((src->width - 1) << 16) / (dest->width - 1);
k = 0;
for (i = 0; i < 4; i++) {
xacc = 0;
vs_scanline_resample_4tap_YUYV (tmpbuf + i * dest->stride,
src->pixels + i * src->stride, dest->stride / 4, src->stride / 4,
&xacc, x_increment);
}
yacc = 0;
for (i = 0; i < dest->height; i++) {
uint8_t *t0, *t1, *t2, *t3;
j = yacc >> 16;
while (j > k) {
k++;
if (k + 3 < src->height) {
xacc = 0;
vs_scanline_resample_4tap_YUYV (tmpbuf + ((k + 3) & 3) * dest->stride,
src->pixels + (k + 3) * src->stride,
dest->stride / 4, src->stride / 4, &xacc, x_increment);
}
}
t0 = tmpbuf + (CLAMP (j - 1, 0, src->height - 1) & 3) * dest->stride;
t1 = tmpbuf + (CLAMP (j, 0, src->height - 1) & 3) * dest->stride;
t2 = tmpbuf + (CLAMP (j + 1, 0, src->height - 1) & 3) * dest->stride;
t3 = tmpbuf + (CLAMP (j + 2, 0, src->height - 1) & 3) * dest->stride;
vs_scanline_merge_4tap_YUYV (dest->pixels + i * dest->stride,
t0, t1, t2, t3, dest->stride / 4, yacc & 0xffff);
yacc += y_increment;
}
}
void
vs_scanline_resample_4tap_UYVY (uint8_t * dest, uint8_t * src,
int n, int src_width, int *xacc, int increment)
{
int i;
int j;
int acc;
int x;
int y;
int off;
acc = *xacc;
for (i = 0; i < n; i++) {
j = acc >> 16;
x = (acc & 0xffff) >> 8;
for (off = 0; off < 4; off++) {
if (j - 1 >= 0 && j + 2 < src_width) {
y = vs_4tap_taps[x][0] * src[MAX ((j - 1) * 4 + off, 0)];
y += vs_4tap_taps[x][1] * src[j * 4 + off];
y += vs_4tap_taps[x][2] * src[(j + 1) * 4 + off];
y += vs_4tap_taps[x][3] * src[(j + 2) * 4 + off];
} else {
y = vs_4tap_taps[x][0] * src[CLAMP ((j - 1) * 4 + off, 0,
4 * (src_width - 1) + off)];
y += vs_4tap_taps[x][1] * src[CLAMP (j * 4 + off, 0,
4 * (src_width - 1) + off)];
y += vs_4tap_taps[x][2] * src[CLAMP ((j + 1) * 4 + off, 0,
4 * (src_width - 1) + off)];
y += vs_4tap_taps[x][3] * src[CLAMP ((j + 2) * 4 + off, 0,
4 * (src_width - 1) + off)];
}
y += (1 << (SHIFT - 1));
dest[i * 4 + off] = CLAMP (y >> SHIFT, 0, 255);
}
acc += increment;
}
*xacc = acc;
}
void
vs_scanline_merge_4tap_UYVY (uint8_t * dest, uint8_t * src1, uint8_t * src2,
uint8_t * src3, uint8_t * src4, int n, int acc)
{
int i;
int y;
int off;
int a, b, c, d;
acc = (acc >> 8) & 0xff;
a = vs_4tap_taps[acc][0];
b = vs_4tap_taps[acc][1];
c = vs_4tap_taps[acc][2];
d = vs_4tap_taps[acc][3];
for (i = 0; i < n; i++) {
for (off = 0; off < 4; off++) {
y = a * src1[i * 4 + off];
y += b * src2[i * 4 + off];
y += c * src3[i * 4 + off];
y += d * src4[i * 4 + off];
y += (1 << (SHIFT - 1));
dest[i * 4 + off] = CLAMP (y >> SHIFT, 0, 255);
}
}
}
void
vs_image_scale_4tap_UYVY (const VSImage * dest, const VSImage * src,
uint8_t * tmpbuf)
{
int yacc;
int y_increment;
int x_increment;
int i;
int j;
int xacc;
int k;
if (dest->height == 1)
y_increment = 0;
else
y_increment = ((src->height - 1) << 16) / (dest->height - 1);
if (dest->width == 1)
x_increment = 0;
else
x_increment = ((src->width - 1) << 16) / (dest->width - 1);
k = 0;
for (i = 0; i < 4; i++) {
xacc = 0;
vs_scanline_resample_4tap_UYVY (tmpbuf + i * dest->stride,
src->pixels + i * src->stride, dest->stride / 4, src->stride / 4,
&xacc, x_increment);
}
yacc = 0;
for (i = 0; i < dest->height; i++) {
uint8_t *t0, *t1, *t2, *t3;
j = yacc >> 16;
while (j > k) {
k++;
if (k + 3 < src->height) {
xacc = 0;
vs_scanline_resample_4tap_UYVY (tmpbuf + ((k + 3) & 3) * dest->stride,
src->pixels + (k + 3) * src->stride,
dest->stride / 4, src->stride / 4, &xacc, x_increment);
}
}
t0 = tmpbuf + (CLAMP (j - 1, 0, src->height - 1) & 3) * dest->stride;
t1 = tmpbuf + (CLAMP (j, 0, src->height - 1) & 3) * dest->stride;
t2 = tmpbuf + (CLAMP (j + 1, 0, src->height - 1) & 3) * dest->stride;
t3 = tmpbuf + (CLAMP (j + 2, 0, src->height - 1) & 3) * dest->stride;
vs_scanline_merge_4tap_UYVY (dest->pixels + i * dest->stride,
t0, t1, t2, t3, dest->stride / 4, yacc & 0xffff);
yacc += y_increment;
}
}