gst/videoscale/videoscale.c: Fix the scaling algorithm and avoid a buffer overflow. removed the while loop in the sca...

Original commit message from CVS:
* gst/videoscale/videoscale.c: (gst_videoscale_scale_nearest),
(gst_videoscale_scale_nearest_str2),
(gst_videoscale_scale_nearest_str4),
(gst_videoscale_scale_nearest_32bit),
(gst_videoscale_scale_nearest_24bit),
(gst_videoscale_scale_nearest_16bit):
Fix the scaling algorithm and avoid a buffer overflow.
removed the while loop in the scaling function as it
was used for point sampling only.
This commit is contained in:
Wim Taymans 2004-05-24 14:48:54 +00:00
parent 99ea03f95c
commit 30c85388fa
2 changed files with 72 additions and 61 deletions

View file

@ -1,3 +1,15 @@
2004-05-24 Wim Taymans <wim@fluendo.com>
* gst/videoscale/videoscale.c: (gst_videoscale_scale_nearest),
(gst_videoscale_scale_nearest_str2),
(gst_videoscale_scale_nearest_str4),
(gst_videoscale_scale_nearest_32bit),
(gst_videoscale_scale_nearest_24bit),
(gst_videoscale_scale_nearest_16bit):
Fix the scaling algorithm and avoid a buffer overflow.
removed the while loop in the scaling function as it
was used for point sampling only.
2004-05-24 Benjamin Otte <in7y118@public.uni-hamburg.de> 2004-05-24 Benjamin Otte <in7y118@public.uni-hamburg.de>
* ext/mad/gstid3tag.c: (gst_id3_tag_get_type), * ext/mad/gstid3tag.c: (gst_id3_tag_get_type),

View file

@ -561,32 +561,31 @@ gst_videoscale_scale_nearest (GstVideoscale * scale,
{ {
int ypos, yinc, y; int ypos, yinc, y;
int xpos, xinc, x; int xpos, xinc, x;
guchar *destp = dest; guchar *destp;
guchar *srcp = src; guchar *srcp;
GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw); GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw);
ypos = 0x10000; ypos = 0;
yinc = (sh << 16) / dh; yinc = (sh << 16) / dh;
xinc = (sw << 16) / dw; xinc = (sw << 16) / dw;
for (y = dh; y; y--) { for (y = dh; y; y--) {
if (ypos >= 0x10000) {
while (ypos > 0x10000) { src += (ypos >> 16) * sw;
ypos -= 0x10000; ypos &= 0xffff;
src += sw;
} }
xpos = 0x10000; xpos = 0;
srcp = src; srcp = src;
destp = dest; destp = dest;
for (x = dw; x; x--) { for (x = dw; x; x--) {
while (xpos >= 0x10000L) { if (xpos >= 0x10000) {
srcp++; srcp += (xpos >> 16);
xpos -= 0x10000L; xpos &= 0xffff;
} }
*destp++ = *srcp; *destp++ = *srcp;
xpos += xinc; xpos += xinc;
@ -603,32 +602,32 @@ gst_videoscale_scale_nearest_str2 (GstVideoscale * scale,
{ {
int ypos, yinc, y; int ypos, yinc, y;
int xpos, xinc, x; int xpos, xinc, x;
guchar *destp = dest; guchar *destp;
guchar *srcp = src; guchar *srcp;
GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw); GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw);
ypos = 0x10000; ypos = 0;
yinc = (sh << 16) / dh; yinc = (sh << 16) / dh;
xinc = (sw << 16) / dw; xinc = (sw << 16) / dw;
for (y = dh; y; y--) { for (y = dh; y; y--) {
while (ypos > 0x10000) { if (ypos >= 0x10000) {
ypos -= 0x10000; src += (ypos >> 16) * sw * 2;
src += sw * 2; ypos &= 0xffff;
} }
xpos = 0x10000; xpos = 0;
srcp = src; srcp = src;
destp = dest; destp = dest;
for (x = dw; x; x--) { for (x = dw; x; x--) {
while (xpos >= 0x10000L) { if (xpos >= 0x10000) {
srcp += 2; srcp += (xpos >> 16) * 2;
xpos -= 0x10000L; xpos &= 0xffff;
} }
*destp = *srcp; *destp = *srcp;
destp += 2; destp += 2;
@ -646,32 +645,32 @@ gst_videoscale_scale_nearest_str4 (GstVideoscale * scale,
{ {
int ypos, yinc, y; int ypos, yinc, y;
int xpos, xinc, x; int xpos, xinc, x;
guchar *destp = dest; guchar *destp;
guchar *srcp = src; guchar *srcp;
GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw); GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw);
ypos = 0x10000; ypos = 0;
yinc = (sh << 16) / dh; yinc = (sh << 16) / dh;
xinc = (sw << 16) / dw; xinc = (sw << 16) / dw;
for (y = dh; y; y--) { for (y = dh; y; y--) {
while (ypos > 0x10000) { if (ypos >= 0x10000) {
ypos -= 0x10000; src += (ypos >> 16) * sw * 4;
src += sw * 4; ypos &= 0xffff;
} }
xpos = 0x10000; xpos = 0;
srcp = src; srcp = src;
destp = dest; destp = dest;
for (x = dw; x; x--) { for (x = dw; x; x--) {
while (xpos >= 0x10000L) { if (xpos >= 0x10000) {
srcp += 4; srcp += (xpos >> 16) * 4;
xpos -= 0x10000L; xpos &= 0xffff;
} }
*destp = *srcp; *destp = *srcp;
destp += 4; destp += 4;
@ -689,32 +688,32 @@ gst_videoscale_scale_nearest_32bit (GstVideoscale * scale,
{ {
int ypos, yinc, y; int ypos, yinc, y;
int xpos, xinc, x; int xpos, xinc, x;
guchar *destp = dest; guchar *destp;
guchar *srcp = src; guchar *srcp;
GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw); GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw);
ypos = 0x10000; ypos = 0;
yinc = (sh << 16) / dh; yinc = (sh << 16) / dh;
xinc = (sw << 16) / dw; xinc = (sw << 16) / dw;
for (y = dh; y; y--) { for (y = dh; y; y--) {
while (ypos > 0x10000) { if (ypos >= 0x10000) {
ypos -= 0x10000; src += (ypos >> 16) * sw * 4;
src += sw * 4; ypos &= 0xffff;
} }
xpos = 0x10000; xpos = 0;
srcp = src; srcp = src;
destp = dest; destp = dest;
for (x = dw; x; x--) { for (x = dw; x; x--) {
while (xpos >= 0x10000L) { if (xpos >= 0x10000) {
srcp += 4; srcp += (xpos >> 16) * 4;
xpos -= 0x10000L; xpos &= 0xffff;
} }
*(guint32 *) destp = *(guint32 *) srcp; *(guint32 *) destp = *(guint32 *) srcp;
destp += 4; destp += 4;
@ -732,32 +731,32 @@ gst_videoscale_scale_nearest_24bit (GstVideoscale * scale,
{ {
int ypos, yinc, y; int ypos, yinc, y;
int xpos, xinc, x; int xpos, xinc, x;
guchar *destp = dest; guchar *destp;
guchar *srcp = src; guchar *srcp;
GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw); GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw);
ypos = 0x10000; ypos = 0;
yinc = (sh << 16) / dh; yinc = (sh << 16) / dh;
xinc = (sw << 16) / dw; xinc = (sw << 16) / dw;
for (y = dh; y; y--) { for (y = dh; y; y--) {
while (ypos > 0x10000) { if (ypos >= 0x10000) {
ypos -= 0x10000; src += (ypos >> 16) * sw * 3;
src += sw * 3; ypos &= 0xffff;
} }
xpos = 0x10000; xpos = 0;
srcp = src; srcp = src;
destp = dest; destp = dest;
for (x = dw; x; x--) { for (x = dw; x; x--) {
while (xpos >= 0x10000L) { if (xpos >= 0x10000) {
srcp += 3; srcp += (xpos >> 16) * 3;
xpos -= 0x10000L; xpos &= 0xffff;
} }
destp[0] = srcp[0]; destp[0] = srcp[0];
destp[1] = srcp[1]; destp[1] = srcp[1];
@ -777,32 +776,32 @@ gst_videoscale_scale_nearest_16bit (GstVideoscale * scale,
{ {
int ypos, yinc, y; int ypos, yinc, y;
int xpos, xinc, x; int xpos, xinc, x;
guchar *destp = dest; guchar *destp;
guchar *srcp = src; guchar *srcp;
GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw); GST_DEBUG_OBJECT (scale, "scaling nearest %p %p %d", src, dest, dw);
ypos = 0x10000; ypos = 0;
yinc = (sh << 16) / dh; yinc = (sh << 16) / dh;
xinc = (sw << 16) / dw; xinc = (sw << 16) / dw;
for (y = dh; y; y--) { for (y = dh; y; y--) {
while (ypos > 0x10000) { if (ypos >= 0x10000) {
ypos -= 0x10000; src += (ypos >> 16) * sw * 2;
src += sw * 2; ypos &= 0xffff;
} }
xpos = 0x10000; xpos = 0;
srcp = src; srcp = src;
destp = dest; destp = dest;
for (x = dw; x; x--) { for (x = dw; x; x--) {
while (xpos >= 0x10000L) { if (xpos >= 0x10000) {
srcp += 2; srcp += (xpos >> 16) * 2;
xpos -= 0x10000L; xpos &= 0xffff;
} }
destp[0] = srcp[0]; destp[0] = srcp[0];
destp[1] = srcp[1]; destp[1] = srcp[1];