Commit a527d250 authored by zhenfeng zhao's avatar zhenfeng zhao

Debug dynamics object files.

parent 997db31a
......@@ -60,6 +60,8 @@ libapppaint_a_sources = \
gimppaintcoreundo.h \
gimppaintoptions.c \
gimppaintoptions.h \
gimpdynamicsoptions.c \
gimpdynamicsoptions.h \
gimppencil.c \
gimppencil.h \
gimppenciloptions.c \
......
......@@ -32,10 +32,11 @@
#include "gimpdynamicsoptions.h"
#include "core/gimpdata.h"
#include "gimp-intl.h"
#define DEFAULT_DYNAMICS_EXPANDED FALSE
//#define DEFAULT_DYNAMICS_EXPANDED FALSE
#define DEFAULT_PRESSURE_OPACITY TRUE
#define DEFAULT_PRESSURE_HARDNESS FALSE
......@@ -168,6 +169,7 @@ enum
PROP_FADING_PRESCALE,
};
/*
static gdouble gimp_dynamics_options_get_dynamics_mix (gdouble mix1,
gdouble mix1_scale,
gdouble mix2,
......@@ -180,6 +182,7 @@ static gdouble gimp_dynamics_options_get_dynamics_mix (gdouble mix1,
gdouble mix5_scale,
gdouble mix6,
gdouble mix6_scale);
*/
static void gimp_dynamics_options_class_init (GimpDynamicsOptionsClass *klass)
......@@ -454,7 +457,7 @@ gimp_dynamics_options_class_init (GimpDynamicsOptionsClass *klass)
static void
gimp_dynamics_options_init (GimpDynamicsOptions *options)
{
options->application_mode_save = DEFAULT_APPLICATION_MODE;
//options->application_mode_save = DEFAULT_APPLICATION_MODE;
options->pressure_options = g_slice_new0 (GimpDynamicOptions);
options->velocity_options = g_slice_new0 (GimpDynamicOptions);
......@@ -1003,14 +1006,14 @@ gimp_dynamics_options_notify (GObject *object,
}
GimpDynamicsOptions *
GimpData *
gimp_dynamics_options_new (GimpPaintInfo *dynamics_info)
{
GimpDynamicsOptions *options;
g_return_val_if_fail (GIMP_IS_DYNAMICS_INFO (dynamics_info), NULL);
options = g_object_new (dynamics_info->dynamics_options_type,
options = g_object_new (dynamics_info->paint_options_type,
"gimp", dynamics_info->gimp,
"name", GIMP_OBJECT (dynamics_info)->name,
"paint-info", dynamics_info,
......@@ -1026,615 +1029,3 @@ gimp_dynamics_options_new (GimpPaintInfo *dynamics_info)
* Added one parameter: fading, the 6th driving factor.
* (velocity/pressure/direction/tilt/random/fading)
*/
static gdouble
gimp_dynamics_options_get_dynamics_mix (gdouble mix1,
gdouble mix1_scale,
gdouble mix2,
gdouble mix2_scale,
gdouble mix3,
gdouble mix3_scale,
gdouble mix4,
gdouble mix4_scale,
gdouble mix5,
gdouble mix5_scale,
gdouble mix6,
gdouble mix6_scale)
{
gdouble scale_sum = 0.0;
gdouble result = 1.0;
if (mix1 > -1.0)
{
scale_sum += fabs (mix1_scale);
}
else mix1 = 0.0;
if (mix2 > -1.0)
{
scale_sum += fabs (mix2_scale);
}
else mix2 = 0.0;
if (mix3 > -1.0)
{
scale_sum += fabs (mix3_scale);
}
else mix3 = 0.0;
if (mix4 > -1.0)
{
scale_sum += fabs (mix4_scale);
}
else mix4 = 0.0;
if (mix5 > -1.0)
{
scale_sum += fabs (mix5_scale);
}
else mix5 = 0.0;
if (mix6 > -1.0)
{
scale_sum += fabs (mix6_scale);
}
else mix6 = 0.0;
if (scale_sum > 0.0)
{
result = (mix1 * mix1_scale) / scale_sum +
(mix2 * mix2_scale) / scale_sum +
(mix3 * mix3_scale) / scale_sum +
(mix4 * mix4_scale) / scale_sum +
(mix5 * mix5_scale) / scale_sum +
(mix6 * mix6_scale) / scale_sum;
}
if (result < 0.0)
result = 1.0 + result;
return MAX (0.0, result);
}
gdouble
gimp_dynamics_options_get_dynamic_opacity (GimpDynamicsOptions *dynamics_options,
const GimpCoords *coords,
gdouble pixel_dist)
{
gdouble opacity = 1.0;
g_return_val_if_fail (GIMP_IS_DYNAMICS_OPTIONS (dynamics_options), 1.0);
g_return_val_if_fail (coords != NULL, 1.0);
if (dynamics_options->pressure_options->opacity ||
dynamics_options->velocity_options->opacity ||
dynamics_options->direction_options->opacity ||
dynamics_options->tilt_options->opacity ||
dynamics_options->random_options->opacity ||
dynamics_options->fading_options->opacity)
{
gdouble pressure = -1.0;
gdouble velocity = -1.0;
gdouble direction = -1.0;
gdouble tilt = -1.0;
gdouble random = -1.0;
gdouble fading = -1.0;
if (dynamics_options->pressure_options->opacity)
pressure = GIMP_PAINT_PRESSURE_SCALE * coords->pressure;
if (dynamics_options->velocity_options->opacity)
velocity = GIMP_PAINT_VELOCITY_SCALE * (1 - coords->velocity);
if (dynamics_options->random_options->opacity)
random = g_random_double_range (0.0, 1.0);
if (dynamics_options->tilt_options->opacity)
tilt = 1.0 - sqrt (SQR (coords->xtilt) + SQR (coords->ytilt));
if (dynamics_options->direction_options->opacity)
direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */
if (dynamics_options->fading_options->opacity)
{
gdouble p;
gdouble fade_out;
fade_out = DEFAULT_FADE_LENGTH;
p = pixel_dist / fade_out;
fading = exp (- p * p * 5.541);
}
/*
printf("pixel_dist: %f", pixel_dist);
*/
opacity = gimp_dynamics_options_get_dynamics_mix (pressure,
dynamics_options->pressure_options->prescale,
velocity,
dynamics_options->velocity_options->prescale,
random,
dynamics_options->random_options->prescale,
tilt,
dynamics_options->tilt_options->prescale,
direction,
dynamics_options->direction_options->prescale,
fading,
dynamics_options->fading_options->prescale);
}
return opacity;
}
gdouble
gimp_dynamics_options_get_dynamic_size (GimpDynamicsOptions *dynamics_options,
GimpPaintOptions *paint_options,
const GimpCoords *coords,
gboolean use_dynamics,
gdouble pixel_dist)
{
gdouble scale = 1.0;
if (use_dynamics)
{
gdouble pressure = -1.0;
gdouble velocity = -1.0;
gdouble direction = -1.0;
gdouble random = -1.0;
gdouble tilt = -1.0;
gdouble fading = -1.0;
if (dynamics_options->pressure_options->size)
{
pressure = coords->pressure;
}
else if (dynamics_options->pressure_options->inverse_size)
{
pressure = 1.0 - 0.9 * coords->pressure;
}
if (dynamics_options->velocity_options->size)
{
velocity = 1.0 - sqrt (coords->velocity);
}
else if (dynamics_options->velocity_options->inverse_size)
{
velocity = sqrt (coords->velocity);
}
if (dynamics_options->random_options->size)
{
random = 1.0 - g_random_double_range (0.0, 1.0);
}
else if (dynamics_options->random_options->inverse_size)
{
random = g_random_double_range (0.0, 1.0);
}
if (dynamics_options->tilt_options->size)
{
tilt = 1.0 - sqrt (SQR (coords->xtilt) + SQR (coords->ytilt));
}
else if (dynamics_options->tilt_options->inverse_size)
{
tilt = sqrt (SQR (coords->xtilt) + SQR (coords->ytilt));
}
if (dynamics_options->direction_options->size)
direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */
if (dynamics_options->fading_options->size ||
dynamics_options->fading_options->inverse_size)
{
gdouble p;
gdouble fade_out;
fade_out = DEFAULT_FADE_LENGTH;
p = pixel_dist / fade_out;
fading = exp (- p * p * 5.541);
}
scale = gimp_dynamics_options_get_dynamics_mix (pressure,
dynamics_options->pressure_options->prescale,
velocity,
dynamics_options->velocity_options->prescale,
random,
dynamics_options->random_options->prescale,
tilt,
dynamics_options->tilt_options->prescale,
direction,
dynamics_options->direction_options->prescale,
fading,
dynamics_options->fading_options->prescale);
if (scale < 1 / 64.0)
scale = 1 / 8.0;
else
scale = sqrt (scale);
}
scale *= paint_options->brush_scale;
return scale;
}
gdouble
gimp_dynamics_options_get_dynamic_aspect_ratio
(GimpDynamicsOptions *dynamics_options,
GimpPaintOptions *paint_options,
const GimpCoords *coords,
gdouble pixel_dist)
{
gdouble aspect_ratio = 1.0;
g_return_val_if_fail (GIMP_IS_DYNAMICS_OPTIONS (dynamics_options), 1.0);
g_return_val_if_fail (coords != NULL, 1.0);
if (dynamics_options->pressure_options->aspect_ratio ||
dynamics_options->velocity_options->aspect_ratio ||
dynamics_options->direction_options->aspect_ratio ||
dynamics_options->tilt_options->aspect_ratio ||
dynamics_options->random_options->aspect_ratio ||
dynamics_options->fading_options->aspect_ratio)
{
gdouble pressure = -1.0;
gdouble velocity = -1.0;
gdouble direction = -1.0;
gdouble tilt = -1.0;
gdouble random = -1.0;
gdouble fading = -1.0;
if (dynamics_options->pressure_options->aspect_ratio)
pressure = 2 * coords->pressure;
if (dynamics_options->velocity_options->aspect_ratio)
velocity = 2 * coords->velocity;
if (dynamics_options->random_options->aspect_ratio)
{
random = g_random_double_range (0.0, 1.0);
if (random <= 0.5)
{
random = 1 / (random / 0.5 * (2.0 - 1.0) + 1.0);
}
else
{
random = (random - 0.5) / (1.0 - 0.5) * (2.0 - 1.0) + 1.0;
}
}
if (dynamics_options->tilt_options->aspect_ratio)
{
tilt = sqrt ((1 - fabs (coords->xtilt)) / (1 - fabs (coords->ytilt)));
}
if (dynamics_options->direction_options->aspect_ratio)
{
direction = fmod (1 + coords->direction, 0.5) / 0.25;
if ((coords->direction > 0.0) && (coords->direction < 0.5))
direction = 1 / direction;
}
if (dynamics_options->fading_options->aspect_ratio)
{
gdouble p;
gdouble fade_out;
fade_out = DEFAULT_FADE_LENGTH;
p = pixel_dist / fade_out;
fading = exp (- p * p * 5.541);
}
aspect_ratio = gimp_dynamics_options_get_dynamics_mix (pressure,
dynamics_options->pressure_options->prescale,
velocity,
dynamics_options->velocity_options->prescale,
random,
dynamics_options->random_options->prescale,
tilt,
dynamics_options->tilt_options->prescale,
direction,
dynamics_options->direction_options->prescale,
fading,
dynamics_options->fading_options->prescale);
}
return paint_options->brush_aspect_ratio * aspect_ratio;
}
gdouble
gimp_dynamics_options_get_dynamic_rate (GimpDynamicsOptions *dynamics_options,
const GimpCoords *coords,
gdouble pixel_dist)
{
gdouble rate = 1.0;
g_return_val_if_fail (GIMP_IS_DYNAMICS_OPTIONS (dynamics_options), 1.0);
g_return_val_if_fail (coords != NULL, 1.0);
if (dynamics_options->pressure_options->rate ||
dynamics_options->velocity_options->rate ||
dynamics_options->direction_options->rate ||
dynamics_options->tilt_options->rate ||
dynamics_options->random_options->rate)
{
gdouble pressure = -1.0;
gdouble velocity = -1.0;
gdouble direction = -1.0;
gdouble random = -1.0;
gdouble tilt = -1.0;
gdouble fading = -1.0;
if (dynamics_options->pressure_options->rate)
pressure = GIMP_PAINT_PRESSURE_SCALE * coords->pressure;
if (dynamics_options->velocity_options->rate)
velocity = GIMP_PAINT_VELOCITY_SCALE * (1 - coords->velocity);
if (dynamics_options->random_options->rate)
random = g_random_double_range (0.0, 1.0);
if (dynamics_options->tilt_options->rate)
tilt = 1.0 - sqrt (SQR (coords->xtilt) + SQR (coords->ytilt));
if (dynamics_options->direction_options->rate)
direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */
if (dynamics_options->fading_options->rate)
{
gdouble p;
gdouble fade_out;
fade_out = DEFAULT_FADE_LENGTH;
p = pixel_dist / fade_out;
fading = exp (- p * p * 5.541);
}
rate = gimp_dynamics_options_get_dynamics_mix (pressure,
dynamics_options->pressure_options->prescale,
velocity,
dynamics_options->velocity_options->prescale,
random,
dynamics_options->random_options->prescale,
tilt,
dynamics_options->tilt_options->prescale,
direction,
dynamics_options->direction_options->prescale,
fading,
dynamics_options->fading_options->prescale);
}
return rate;
}
gdouble
gimp_dynamics_options_get_dynamic_color (GimpDynamicsOptions *dynamics_options,
const GimpCoords *coords,
gdouble pixel_dist)
{
gdouble color = 1.0;
g_return_val_if_fail (GIMP_IS_DYNAMICS_OPTIONS (dynamics_options), 1.0);
g_return_val_if_fail (coords != NULL, 1.0);
if (dynamics_options->pressure_options->color ||
dynamics_options->velocity_options->color ||
dynamics_options->direction_options->color ||
dynamics_options->tilt_options->color ||
dynamics_options->random_options->color ||
dynamics_options->fading_options->color)
{
gdouble pressure = -1.0;
gdouble velocity = -1.0;
gdouble direction = -1.0;
gdouble random = -1.0;
gdouble tilt = -1.0;
gdouble fading = -1.0;
if (dynamics_options->pressure_options->color)
pressure = GIMP_PAINT_PRESSURE_SCALE * coords->pressure;
if (dynamics_options->velocity_options->color)
velocity = GIMP_PAINT_VELOCITY_SCALE * coords->velocity;
if (dynamics_options->random_options->color)
random = g_random_double_range (0.0, 1.0);
if (dynamics_options->tilt_options->color)
tilt = 1.0 - sqrt (SQR (coords->xtilt) + SQR (coords->ytilt));
if (dynamics_options->direction_options->color)
direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */
if (dynamics_options->fading_options->color)
{
gdouble p;
gdouble fade_out;
fade_out = DEFAULT_FADE_LENGTH;
p = pixel_dist / fade_out;
fading = exp (- p * p * 5.541);
}
color = gimp_dynamics_options_get_dynamics_mix (pressure,
dynamics_options->pressure_options->prescale,
velocity,
dynamics_options->velocity_options->prescale,
random,
dynamics_options->random_options->prescale,
tilt,
dynamics_options->tilt_options->prescale,
direction,
dynamics_options->direction_options->prescale,
fading,
dynamics_options->fading_options->prescale);
}
return color;
}
gdouble
gimp_dynamics_options_get_dynamic_hardness (GimpDynamicsOptions *dynamics_options,
const GimpCoords *coords,
gdouble pixel_dist)
{
gdouble hardness = 1.0;
g_return_val_if_fail (GIMP_IS_DYNAMICS_OPTIONS (dynamics_options), 1.0);
g_return_val_if_fail (coords != NULL, 1.0);
if (dynamics_options->pressure_options->hardness ||
dynamics_options->velocity_options->hardness ||
dynamics_options->direction_options->hardness ||
dynamics_options->tilt_options->hardness ||
dynamics_options->random_options->hardness ||
dynamics_options->fading_options->hardness)
{
gdouble pressure = -1.0;
gdouble velocity = -1.0;
gdouble direction = -1.0;
gdouble random = -1.0;
gdouble tilt = -1.0;
gdouble fading = -1.0;
if (dynamics_options->pressure_options->hardness)
pressure = GIMP_PAINT_PRESSURE_SCALE * coords->pressure;
if (dynamics_options->velocity_options->hardness)
velocity = GIMP_PAINT_VELOCITY_SCALE * (1 - coords->velocity);
if (dynamics_options->random_options->hardness)
random = g_random_double_range (0.0, 1.0);
if (dynamics_options->tilt_options->hardness)
tilt = 1.0 - sqrt (SQR (coords->xtilt) + SQR (coords->ytilt));
if (dynamics_options->direction_options->hardness)
direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */
if (dynamics_options->fading_options->hardness)
{
gdouble p;
gdouble fade_out;
fade_out = DEFAULT_FADE_LENGTH;
p = pixel_dist / fade_out;
fading = exp (- p * p * 5.541);
}
hardness = gimp_dynamics_options_get_dynamics_mix (pressure,
dynamics_options->pressure_options->prescale,
velocity,
dynamics_options->velocity_options->prescale,
random,
dynamics_options->random_options->prescale,
tilt,
dynamics_options->tilt_options->prescale,
direction,
dynamics_options->direction_options->prescale,
fading,
dynamics_options->fading_options->prescale);
}
return hardness;
}
gdouble
gimp_dynamics_options_get_dynamic_angle (GimpDynamicsOptions *dynamics_options,
const GimpCoords *coords,
gdouble pixel_dist)
{
gdouble angle = 1.0;
g_return_val_if_fail (GIMP_IS_DYNAMICS_OPTIONS (dynamics_options), 1.0);
g_return_val_if_fail (coords != NULL, 1.0);
if (dynamics_options->pressure_options->angle ||
dynamics_options->velocity_options->angle ||
dynamics_options->direction_options->angle ||
dynamics_options->tilt_options->angle ||
dynamics_options->random_options->angle ||
dynamics_options->fading_options->angle)
{
gdouble pressure = -1.0;
gdouble velocity = -1.0;
gdouble direction = -1.0;
gdouble random = -1.0;
gdouble tilt = -1.0;
gdouble fading = -1.0;
if (dynamics_options->pressure_options->angle)
pressure = GIMP_PAINT_PRESSURE_SCALE * coords->pressure;
if (dynamics_options->velocity_options->angle)
velocity = GIMP_PAINT_VELOCITY_SCALE * (1 - coords->velocity);
if (dynamics_options->random_options->angle)
random = g_random_double_range (0.0, 1.0);
/* For tilt to make sense, it needs to be converted to an angle, not just vector */
if (dynamics_options->tilt_options->angle)
{
gdouble tilt_x = coords->xtilt;
gdouble tilt_y = coords->ytilt;
if (tilt_x == 0.0)
{
if (tilt_y >= 0.0)
tilt = 0.5;
else if (tilt_y < 0.0)
tilt = 0.0;
else tilt = -1.0;
}
else
{
tilt = atan ((- 1.0 * tilt_y) /
tilt_x) / (2 * G_PI);
if (tilt_x > 0.0)
tilt = tilt + 0.5;
}
tilt = tilt + 0.5; /* correct the angle, its wrong by 180 degrees */
while (tilt > 1.0)
tilt -= 1.0;
while (tilt < 0.0)
tilt += 1.0;
}
if (dynamics_options->direction_options->angle)
direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */
if (dynamics_options->fading_options->angle)
{
gdouble p;
gdouble fade_out;
fade_out = DEFAULT_FADE_LENGTH;
p = pixel_dist / fade_out;
fading = exp (- p * p * 5.541);
}
angle = gimp_dynamics_options_get_dynamics_mix (pressure,
dynamics_options->pressure_options->prescale,
velocity,
dynamics_options->velocity_options->prescale,
random,
dynamics_options->random_options->prescale,
tilt,
dynamics_options->tilt_options->prescale,
direction,
dynamics_options->direction_options->prescale,
fading,
dynamics_options->fading_options->prescale);
angle = angle - 0.5;
}
return angle + dynamics_options->brush_angle;
}
......@@ -19,7 +19,7 @@
#define __GIMP_DYNAMICS_OPTIONS_H__
#include "core/gimptooloptions.h"
//#include "core/gimptooloptions.h"
#include "gimppaintoptions.h"
#include "core/gimpdata.h"
......@@ -41,7 +41,7 @@ struct _GimpDynamicOptions
gdouble prescale;
};
struct _GimpDynamicsOutputOptions
struct _GimpDynamicOutputOptions
{
gboolean pressure;
gboolean velocity;
......@@ -76,7 +76,7 @@ typedef struct _GimpDynamicsOptionsClass GimpDynamicsOptionsClass;
struct _GimpDynamicsOptions
{
GimpData parent_instance;
GimpPaintOptions parent_instance;
GimpPaintInfo *dynamics_info;
......@@ -90,7 +90,7 @@ struct _GimpDynamicsOptions
struct _GimpDynamicsOptionsClass
{
GimpPaintOptionsClass parent_instance;
GimpDataClass parent_instance;
};
......@@ -98,38 +98,6 @@ GType gimp_dynamics_options_get_type (void) G_GNUC_CONST;
GimpData * gimp_dynamics_options_new (GimpPaintInfo *dynamics_info);
gdouble gimp_dynamics_options_get_dynamic_opacity (GimpDynamicsOptions *dynamics_options,
const GimpCoords *coords,