gaudieffects: Avoid divide by 0 in burn element

This commit is contained in:
Jan Schmidt 2010-12-12 02:24:00 +11:00 committed by Jan Schmidt
parent 7e3472d772
commit a4f2ab78ff
2 changed files with 34 additions and 20 deletions

View file

@ -0,0 +1,23 @@
#!/usr/bin/python
import gobject; gobject.threads_init()
import pygst; pygst.require("0.10")
import gst
p = gst.parse_launch ("""
v4l2src !
ffmpegcolorspace ! queue ! video/x-raw-rgb,width=320,height=240,framerate=30/1 ! burn qos=true name=vf ! ffmpegcolorspace !
timeoverlay ! xvimagesink
""")
m = p.get_by_name ("vf")
m.set_property ("adjustment", 128)
control = gst.Controller(m, "adjustment")
control.set_interpolation_mode("adjustment", gst.INTERPOLATE_LINEAR)
control.set("adjustment", 0 * gst.SECOND, 128)
control.set("adjustment", 5 * gst.SECOND, 256)
control.set("adjustment", 25 * gst.SECOND, 0)
p.set_state (gst.STATE_PLAYING)
gobject.MainLoop().run()

View file

@ -96,7 +96,6 @@ enum
#define DEFAULT_ADJUSTMENT 175
static gint gate_int (gint value, gint min, gint max);
static void transform (guint32 * src, guint32 * dest, gint video_area,
gint adjustment);
@ -289,24 +288,13 @@ gst_burn_plugin_init (GstPlugin * burn)
}
/*** Now the image processing work.... ***/
/* Keep the values inbounds. */
static gint
gate_int (gint value, gint min, gint max)
{
if (value < min) {
return min;
} else if (value > max) {
return max;
} else {
return value;
}
}
/* Transform processes each frame. */
static void
transform (guint32 * src, guint32 * dest, gint video_area, gint adjustment)
{
guint32 in, red, green, blue;
guint32 in;
gint red, green, blue, c;
gint x;
for (x = 0; x < video_area; x++) {
@ -316,13 +304,16 @@ transform (guint32 * src, guint32 * dest, gint video_area, gint adjustment)
green = (in >> 8) & 0xff;
blue = (in) & 0xff;
red = 256 - ((256 * (255 - red)) / (red + adjustment));
green = 256 - ((256 * (255 - green)) / (green + adjustment));
blue = 256 - ((256 * (255 - blue)) / (blue + adjustment));
c = (red + adjustment);
red = c ? (256 - (256 * (255 - red) / c)) : 0;
c = (green + adjustment);
green = c ? (256 - (256 * (255 - green) / c)) : 0;
c = (blue + adjustment);
blue = c ? (256 - (256 * (255 - blue) / c)) : 0;
red = gate_int (red, 0, 255);
green = gate_int (green, 0, 255);
blue = gate_int (blue, 0, 255);
red = CLAMP (red, 0, 255);
green = CLAMP (green, 0, 255);
blue = CLAMP (blue, 0, 255);
*dest++ = (red << 16) | (green << 8) | blue;
}