clang-format: Apply formatting

Code submissions have continually suffered from formatting
inconsistencies that constantly have to be addressed.  Using
clang-format simplifies this by making code formatting more consistent,
and allows automation of the code formatting so that maintainers can
focus more on the code itself instead of code formatting.
This commit is contained in:
jp9000
2019-06-22 22:13:45 -07:00
parent 53615ee10f
commit f53df7da64
567 changed files with 34068 additions and 32903 deletions

View File

@@ -6,6 +6,8 @@
#include <graphics/vec2.h>
#include <graphics/math-defs.h>
/* clang-format off */
#define S_RESOLUTION "resolution"
#define S_SAMPLING "sampling"
#define S_UNDISTORT "undistort"
@@ -27,25 +29,27 @@
#define S_SAMPLING_LANCZOS "lanczos"
#define S_SAMPLING_AREA "area"
/* clang-format on */
struct scale_filter_data {
obs_source_t *context;
gs_effect_t *effect;
gs_eparam_t *image_param;
gs_eparam_t *dimension_param;
gs_eparam_t *undistort_factor_param;
struct vec2 dimension_i;
double undistort_factor;
int cx_in;
int cy_in;
int cx_out;
int cy_out;
enum obs_scale_type sampling;
gs_samplerstate_t *point_sampler;
bool aspect_ratio_only;
bool target_valid;
bool valid;
bool undistort;
bool base_canvas_resolution;
obs_source_t *context;
gs_effect_t *effect;
gs_eparam_t *image_param;
gs_eparam_t *dimension_param;
gs_eparam_t *undistort_factor_param;
struct vec2 dimension_i;
double undistort_factor;
int cx_in;
int cy_in;
int cx_out;
int cy_out;
enum obs_scale_type sampling;
gs_samplerstate_t *point_sampler;
bool aspect_ratio_only;
bool target_valid;
bool valid;
bool undistort;
bool base_canvas_resolution;
};
static const char *scale_filter_name(void *unused)
@@ -78,7 +82,7 @@ static void scale_filter_update(void *data, obs_data_t *settings)
filter->aspect_ratio_only = false;
} else {
ret = sscanf(res_str, "%d:%d", &filter->cx_in,
&filter->cy_in);
&filter->cy_in);
if (ret != 2) {
filter->valid = false;
return;
@@ -179,8 +183,7 @@ static void scale_filter_tick(void *data, float seconds)
cy_f = (double)cy;
double old_aspect = cx_f / cy_f;
double new_aspect =
(double)filter->cx_in / (double)filter->cy_in;
double new_aspect = (double)filter->cx_in / (double)filter->cy_in;
if (filter->aspect_ratio_only) {
if (fabs(old_aspect - new_aspect) <= EPSILON) {
@@ -200,9 +203,7 @@ static void scale_filter_tick(void *data, float seconds)
filter->cy_out = filter->cy_in;
}
vec2_set(&filter->dimension_i,
1.0f / (float)cx,
1.0f / (float)cy);
vec2_set(&filter->dimension_i, 1.0f / (float)cx, 1.0f / (float)cy);
if (filter->undistort) {
filter->undistort_factor = new_aspect / old_aspect;
@@ -220,20 +221,28 @@ static void scale_filter_tick(void *data, float seconds)
switch (filter->sampling) {
default:
case OBS_SCALE_POINT:
case OBS_SCALE_BILINEAR: type = OBS_EFFECT_DEFAULT; break;
case OBS_SCALE_BICUBIC: type = OBS_EFFECT_BICUBIC; break;
case OBS_SCALE_LANCZOS: type = OBS_EFFECT_LANCZOS; break;
case OBS_SCALE_AREA: type = OBS_EFFECT_AREA; break;
case OBS_SCALE_BILINEAR:
type = OBS_EFFECT_DEFAULT;
break;
case OBS_SCALE_BICUBIC:
type = OBS_EFFECT_BICUBIC;
break;
case OBS_SCALE_LANCZOS:
type = OBS_EFFECT_LANCZOS;
break;
case OBS_SCALE_AREA:
type = OBS_EFFECT_AREA;
break;
}
}
filter->effect = obs_get_base_effect(type);
filter->image_param = gs_effect_get_param_by_name(filter->effect,
"image");
filter->image_param =
gs_effect_get_param_by_name(filter->effect, "image");
if (type != OBS_EFFECT_DEFAULT) {
filter->dimension_param = gs_effect_get_param_by_name(
filter->effect, "base_dimension_i");
filter->effect, "base_dimension_i");
} else {
filter->dimension_param = NULL;
}
@@ -241,8 +250,7 @@ static void scale_filter_tick(void *data, float seconds)
if (type == OBS_EFFECT_BICUBIC || type == OBS_EFFECT_LANCZOS) {
filter->undistort_factor_param = gs_effect_get_param_by_name(
filter->effect, "undistort_factor");
}
else {
} else {
filter->undistort_factor_param = NULL;
}
@@ -252,8 +260,7 @@ static void scale_filter_tick(void *data, float seconds)
static void scale_filter_render(void *data, gs_effect_t *effect)
{
struct scale_filter_data *filter = data;
const char *technique = filter->undistort ?
"DrawUndistort" : "Draw";
const char *technique = filter->undistort ? "DrawUndistort" : "Draw";
if (!filter->valid || !filter->target_valid) {
obs_source_skip_video_filter(filter->context);
@@ -261,75 +268,58 @@ static void scale_filter_render(void *data, gs_effect_t *effect)
}
if (!obs_source_process_filter_begin(filter->context, GS_RGBA,
OBS_NO_DIRECT_RENDERING))
OBS_NO_DIRECT_RENDERING))
return;
if (filter->dimension_param)
gs_effect_set_vec2(filter->dimension_param,
&filter->dimension_i);
&filter->dimension_i);
if (filter->undistort_factor_param)
gs_effect_set_float(filter->undistort_factor_param,
(float)filter->undistort_factor);
(float)filter->undistort_factor);
if (filter->sampling == OBS_SCALE_POINT)
gs_effect_set_next_sampler(filter->image_param,
filter->point_sampler);
filter->point_sampler);
obs_source_process_filter_tech_end(filter->context, filter->effect,
filter->cx_out, filter->cy_out, technique);
filter->cx_out, filter->cy_out,
technique);
UNUSED_PARAMETER(effect);
}
static const double downscale_vals[] = {
1.0,
1.25,
(1.0/0.75),
1.5,
(1.0/0.6),
1.75,
2.0,
2.25,
2.5,
2.75,
3.0
};
static const double downscale_vals[] = {1.0, 1.25, (1.0 / 0.75), 1.5,
(1.0 / 0.6), 1.75, 2.0, 2.25,
2.5, 2.75, 3.0};
#define NUM_DOWNSCALES (sizeof(downscale_vals) / sizeof(double))
static const char *aspects[] = {
"16:9",
"16:10",
"4:3",
"1:1"
};
static const char *aspects[] = {"16:9", "16:10", "4:3", "1:1"};
#define NUM_ASPECTS (sizeof(aspects) / sizeof(const char *))
static bool sampling_modified(obs_properties_t *props, obs_property_t *p,
obs_data_t *settings)
obs_data_t *settings)
{
const char *sampling = obs_data_get_string(settings, S_SAMPLING);
bool has_undistort;
if (astrcmpi(sampling, S_SAMPLING_POINT) == 0) {
has_undistort = false;
}
else if (astrcmpi(sampling, S_SAMPLING_BILINEAR) == 0) {
} else if (astrcmpi(sampling, S_SAMPLING_BILINEAR) == 0) {
has_undistort = false;
}
else if (astrcmpi(sampling, S_SAMPLING_LANCZOS) == 0) {
} else if (astrcmpi(sampling, S_SAMPLING_LANCZOS) == 0) {
has_undistort = true;
}
else if (astrcmpi(sampling, S_SAMPLING_AREA) == 0) {
} else if (astrcmpi(sampling, S_SAMPLING_AREA) == 0) {
has_undistort = false;
}
else { /* S_SAMPLING_BICUBIC */
} else { /* S_SAMPLING_BICUBIC */
has_undistort = true;
}
obs_property_set_visible(obs_properties_get(props, S_UNDISTORT), has_undistort);
obs_property_set_visible(obs_properties_get(props, S_UNDISTORT),
has_undistort);
UNUSED_PARAMETER(p);
return true;
@@ -360,18 +350,21 @@ static obs_properties_t *scale_filter_properties(void *data)
}
p = obs_properties_add_list(props, S_SAMPLING, T_SAMPLING,
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
OBS_COMBO_TYPE_LIST,
OBS_COMBO_FORMAT_STRING);
obs_property_set_modified_callback(p, sampling_modified);
obs_property_list_add_string(p, T_SAMPLING_POINT, S_SAMPLING_POINT);
obs_property_list_add_string(p, T_SAMPLING_BILINEAR, S_SAMPLING_BILINEAR);
obs_property_list_add_string(p, T_SAMPLING_BICUBIC, S_SAMPLING_BICUBIC);
obs_property_list_add_string(p, T_SAMPLING_LANCZOS, S_SAMPLING_LANCZOS);
obs_property_list_add_string(p, T_SAMPLING_AREA, S_SAMPLING_AREA);
obs_property_list_add_string(p, T_SAMPLING_POINT, S_SAMPLING_POINT);
obs_property_list_add_string(p, T_SAMPLING_BILINEAR,
S_SAMPLING_BILINEAR);
obs_property_list_add_string(p, T_SAMPLING_BICUBIC, S_SAMPLING_BICUBIC);
obs_property_list_add_string(p, T_SAMPLING_LANCZOS, S_SAMPLING_LANCZOS);
obs_property_list_add_string(p, T_SAMPLING_AREA, S_SAMPLING_AREA);
/* ----------------- */
p = obs_properties_add_list(props, S_RESOLUTION, T_RESOLUTION,
OBS_COMBO_TYPE_EDITABLE, OBS_COMBO_FORMAT_STRING);
OBS_COMBO_TYPE_EDITABLE,
OBS_COMBO_FORMAT_STRING);
obs_property_list_add_string(p, T_NONE, T_NONE);
obs_property_list_add_string(p, T_BASE, T_BASE);
@@ -413,17 +406,17 @@ static uint32_t scale_filter_height(void *data)
}
struct obs_source_info scale_filter = {
.id = "scale_filter",
.type = OBS_SOURCE_TYPE_FILTER,
.output_flags = OBS_SOURCE_VIDEO,
.get_name = scale_filter_name,
.create = scale_filter_create,
.destroy = scale_filter_destroy,
.video_tick = scale_filter_tick,
.video_render = scale_filter_render,
.update = scale_filter_update,
.get_properties = scale_filter_properties,
.get_defaults = scale_filter_defaults,
.get_width = scale_filter_width,
.get_height = scale_filter_height
.id = "scale_filter",
.type = OBS_SOURCE_TYPE_FILTER,
.output_flags = OBS_SOURCE_VIDEO,
.get_name = scale_filter_name,
.create = scale_filter_create,
.destroy = scale_filter_destroy,
.video_tick = scale_filter_tick,
.video_render = scale_filter_render,
.update = scale_filter_update,
.get_properties = scale_filter_properties,
.get_defaults = scale_filter_defaults,
.get_width = scale_filter_width,
.get_height = scale_filter_height,
};