fix videoscale for stride

Original commit message from CVS:
fix videoscale for stride
This commit is contained in:
Thomas Vander Stichele 2004-07-22 18:07:14 +00:00
parent bf097276b9
commit 769c94e3af
3 changed files with 49 additions and 14 deletions

View file

@ -1,3 +1,12 @@
2004-07-22 Thomas Vander Stichele <thomas at apestaart dot org>
* gst/videoscale/videoscale.c: (gst_videoscale_setup),
(gst_videoscale_planar411), (gst_videoscale_scale_nearest_32bit),
(gst_videoscale_scale_nearest_24bit),
(gst_videoscale_scale_nearest_16bit):
fix 16bit and 24bit for stride (24bit might need testing)
don't pretend we do more than one algorithm
2004-07-22 Zaheer Abbas Merali <zaheerabbas at merali dot org> 2004-07-22 Zaheer Abbas Merali <zaheerabbas at merali dot org>
* configure.ac: * configure.ac:

View file

@ -55,10 +55,10 @@ gst_videoscale_method_get_type (void)
{ {
static GType videoscale_method_type = 0; static GType videoscale_method_type = 0;
static GEnumValue videoscale_methods[] = { static GEnumValue videoscale_methods[] = {
{GST_VIDEOSCALE_POINT_SAMPLE, "0", "Point Sample"}, {GST_VIDEOSCALE_POINT_SAMPLE, "0", "Point Sample (not implemented)"},
{GST_VIDEOSCALE_NEAREST, "1", "Nearest"}, {GST_VIDEOSCALE_NEAREST, "1", "Nearest"},
{GST_VIDEOSCALE_BILINEAR, "2", "Bilinear"}, {GST_VIDEOSCALE_BILINEAR, "2", "Bilinear (not implemented)"},
{GST_VIDEOSCALE_BICUBIC, "3", "Bicubic"}, {GST_VIDEOSCALE_BICUBIC, "3", "Bicubic (not implemented)"},
{0, NULL, NULL}, {0, NULL, NULL},
}; };

View file

@ -34,6 +34,9 @@
#include "videoscale_x86.h" #include "videoscale_x86.h"
#endif #endif
#define ROUND_UP_4(x) (((x) + 3) & ~3)
#define ROUND_UP_8(x) (((x) + 7) & ~7)
/* scalers */ /* scalers */
static void gst_videoscale_scale_nearest (GstVideoscale * scale, static void gst_videoscale_scale_nearest (GstVideoscale * scale,
unsigned char *dest, unsigned char *src, int sw, int sh, int dw, int dh); unsigned char *dest, unsigned char *src, int sw, int sh, int dw, int dh);
@ -205,13 +208,14 @@ gst_videoscale_setup (GstVideoscale * videoscale)
{ {
g_return_if_fail (GST_IS_VIDEOSCALE (videoscale)); g_return_if_fail (GST_IS_VIDEOSCALE (videoscale));
g_return_if_fail (videoscale->format != NULL); g_return_if_fail (videoscale->format != NULL);
gint from_stride, to_stride;
GST_DEBUG_OBJECT (videoscale, "format=%p " GST_FOURCC_FORMAT GST_DEBUG_OBJECT (videoscale, "format=%p " GST_FOURCC_FORMAT
" from %dx%d to %dx%d", " from %dx%d to %dx%d, %d bpp",
videoscale->format, videoscale->format,
GST_FOURCC_ARGS (videoscale->format->fourcc), GST_FOURCC_ARGS (videoscale->format->fourcc),
videoscale->from_width, videoscale->from_height, videoscale->from_width, videoscale->from_height,
videoscale->to_width, videoscale->to_height); videoscale->to_width, videoscale->to_height, videoscale->format->bpp);
if (videoscale->to_width == 0 || videoscale->to_height == 0 || if (videoscale->to_width == 0 || videoscale->to_height == 0 ||
videoscale->from_width == 0 || videoscale->from_height == 0) { videoscale->from_width == 0 || videoscale->from_height == 0) {
@ -231,10 +235,17 @@ gst_videoscale_setup (GstVideoscale * videoscale)
GST_DEBUG_OBJECT (videoscale, "scaling method POINT_SAMPLE"); GST_DEBUG_OBJECT (videoscale, "scaling method POINT_SAMPLE");
videoscale->from_buf_size = (videoscale->from_width * videoscale->from_height /* FIXME: we should get from and to strides from caps. For now we conform
* videoscale->format->bpp) / 8; * to videotestsrc's idea of it, which is to round w * bytespp to nearest
videoscale->to_buf_size = (videoscale->to_width * videoscale->to_height * multiple of 4 */
* videoscale->format->bpp) / 8; from_stride = ROUND_UP_4 (videoscale->from_width *
(ROUND_UP_8 (videoscale->format->bpp) / 8));
to_stride = ROUND_UP_4 (videoscale->to_width *
(ROUND_UP_8 (videoscale->format->bpp) / 8));
GST_DEBUG_OBJECT (videoscale, "from_stride %d to_stride %d",
from_stride, to_stride);
videoscale->from_buf_size = from_stride * videoscale->from_height;
videoscale->to_buf_size = to_stride * videoscale->to_height;
videoscale->passthru = FALSE; videoscale->passthru = FALSE;
videoscale->inited = TRUE; videoscale->inited = TRUE;
@ -692,7 +703,8 @@ gst_videoscale_scale_nearest_32bit (GstVideoscale * scale,
GST_LOG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw); GST_LOG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw);
/* given how videoscale rounds off stride to nearest multiple of 4,
* we don't have stride issues for 32 bit */
ypos = 0; ypos = 0;
yinc = (sh << 16) / dh; yinc = (sh << 16) / dh;
xinc = (sw << 16) / dw; xinc = (sw << 16) / dw;
@ -732,9 +744,14 @@ gst_videoscale_scale_nearest_24bit (GstVideoscale * scale,
int xpos, xinc, x; int xpos, xinc, x;
guchar *destp; guchar *destp;
guchar *srcp; guchar *srcp;
int sstride, dstride; /* row strides in bytes */
GST_LOG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw); GST_LOG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw);
/* FIXME: strides should be gotten from caps; for now we do it Just Like
videotestsrc, which means round off to next multiple of 4 bytes */
sstride = ROUND_UP_4 (sw * 3);
dstride = ROUND_UP_4 (dw * 3);
ypos = 0; ypos = 0;
yinc = (sh << 16) / dh; yinc = (sh << 16) / dh;
@ -743,7 +760,7 @@ gst_videoscale_scale_nearest_24bit (GstVideoscale * scale,
for (y = dh; y; y--) { for (y = dh; y; y--) {
if (ypos >= 0x10000) { if (ypos >= 0x10000) {
src += (ypos >> 16) * sw * 3; src += (ypos >> 16) * sstride;
ypos &= 0xffff; ypos &= 0xffff;
} }
@ -763,7 +780,7 @@ gst_videoscale_scale_nearest_24bit (GstVideoscale * scale,
destp += 3; destp += 3;
xpos += xinc; xpos += xinc;
} }
dest += dw * 3; dest += dstride;
ypos += yinc; ypos += yinc;
} }
@ -777,10 +794,19 @@ gst_videoscale_scale_nearest_16bit (GstVideoscale * scale,
int xpos, xinc, x; int xpos, xinc, x;
guchar *destp; guchar *destp;
guchar *srcp; guchar *srcp;
int sstride, dstride; /* row strides in bytes */
GST_LOG_OBJECT (scale, "scaling nearest from %p to %p, destination width %d", GST_LOG_OBJECT (scale, "scaling nearest from %p to %p, destination width %d",
src, dest, dw); src, dest, dw);
/* FIXME: strides should be gotten from caps; for now we do it Just Like
videotestsrc, which means round off to next multiple of 4 bytes */
sstride = sw * 2;
if (sw % 2 == 1)
sstride += 2;
dstride = dw * 2;
if (dw % 2 == 1)
dstride += 2;
ypos = 0; ypos = 0;
yinc = (sh << 16) / dh; /* 16 bit fixed point arithmetic */ yinc = (sh << 16) / dh; /* 16 bit fixed point arithmetic */
@ -790,7 +816,7 @@ gst_videoscale_scale_nearest_16bit (GstVideoscale * scale,
for (y = dh; y; y--) { /* faster than 0 .. dh */ for (y = dh; y; y--) { /* faster than 0 .. dh */
if (ypos >= 0x10000) { /* ypos >= 1 ? */ if (ypos >= 0x10000) { /* ypos >= 1 ? */
src += (ypos >> 16) * sw * 2; /* go down round(ypos) src lines */ src += (ypos >> 16) * sstride; /* go down round(ypos) src lines */
ypos &= 0xffff; /* ypos %= 1 */ ypos &= 0xffff; /* ypos %= 1 */
} }
@ -810,7 +836,7 @@ gst_videoscale_scale_nearest_16bit (GstVideoscale * scale,
destp += 2; /* go right one destination pixel */ destp += 2; /* go right one destination pixel */
xpos += xinc; xpos += xinc;
} }
dest += dw * 2; /* go down one destination line */ dest += dstride; /* go down one destination line */
ypos += yinc; ypos += yinc;
} }