Commit cdc67a71 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Revert "BUG:318352"

This reverts commit c2a6cc79585d97760ffc8c7b74c9a702bb1eb84b.

Conflicts:
	krita/data/kritarc

Okay, it's official: no more commits until I am home and at my desk...
parent 9a00b556
This diff is collapsed.
/* brushlib - The MyPaint Brush Library
* Copyright (C) 2007-2008 Martin Renold <martinxyz@gmx.ch>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY. See the COPYING file for more details.
*/
#if 0
#include "Python.h"
#include "numpy/arrayobject.h"
#endif
#include <stdint.h>
#include <math.h>
#include "surface.hpp"
#include "brush.hpp"
#ifndef BRUSH_SETTINGS_H
#define BRUSH_SETTINGS_H
// DO NOT EDIT - autogenerated by generate.py
#define INPUT_PRESSURE 0
#define INPUT_SPEED1 1
#define INPUT_SPEED2 2
#define INPUT_RANDOM 3
#define INPUT_STROKE 4
#define INPUT_DIRECTION 5
#define INPUT_TILT_DECLINATION 6
#define INPUT_TILT_ASCENSION 7
#define INPUT_CUSTOM 8
#define INPUT_COUNT 9
#define BRUSH_OPAQUE 0
#define BRUSH_OPAQUE_MULTIPLY 1
#define BRUSH_OPAQUE_LINEARIZE 2
#define BRUSH_RADIUS_LOGARITHMIC 3
#define BRUSH_HARDNESS 4
#define BRUSH_DABS_PER_BASIC_RADIUS 5
#define BRUSH_DABS_PER_ACTUAL_RADIUS 6
#define BRUSH_DABS_PER_SECOND 7
#define BRUSH_RADIUS_BY_RANDOM 8
#define BRUSH_SPEED1_SLOWNESS 9
#define BRUSH_SPEED2_SLOWNESS 10
#define BRUSH_SPEED1_GAMMA 11
#define BRUSH_SPEED2_GAMMA 12
#define BRUSH_OFFSET_BY_RANDOM 13
#define BRUSH_OFFSET_BY_SPEED 14
#define BRUSH_OFFSET_BY_SPEED_SLOWNESS 15
#define BRUSH_SLOW_TRACKING 16
#define BRUSH_SLOW_TRACKING_PER_DAB 17
#define BRUSH_TRACKING_NOISE 18
#define BRUSH_COLOR_H 19
#define BRUSH_COLOR_S 20
#define BRUSH_COLOR_V 21
#define BRUSH_CHANGE_COLOR_H 22
#define BRUSH_CHANGE_COLOR_L 23
#define BRUSH_CHANGE_COLOR_HSL_S 24
#define BRUSH_CHANGE_COLOR_V 25
#define BRUSH_CHANGE_COLOR_HSV_S 26
#define BRUSH_SMUDGE 27
#define BRUSH_SMUDGE_LENGTH 28
#define BRUSH_SMUDGE_RADIUS_LOG 29
#define BRUSH_ERASER 30
#define BRUSH_STROKE_THRESHOLD 31
#define BRUSH_STROKE_DURATION_LOGARITHMIC 32
#define BRUSH_STROKE_HOLDTIME 33
#define BRUSH_CUSTOM_INPUT 34
#define BRUSH_CUSTOM_INPUT_SLOWNESS 35
#define BRUSH_ELLIPTICAL_DAB_RATIO 36
#define BRUSH_ELLIPTICAL_DAB_ANGLE 37
#define BRUSH_DIRECTION_FILTER 38
#define BRUSH_SETTINGS_COUNT 39
#define STATE_X 0
#define STATE_Y 1
#define STATE_PRESSURE 2
#define STATE_DIST 3
#define STATE_ACTUAL_RADIUS 4
#define STATE_SMUDGE_RA 5
#define STATE_SMUDGE_GA 6
#define STATE_SMUDGE_BA 7
#define STATE_SMUDGE_A 8
#define STATE_ACTUAL_X 9
#define STATE_ACTUAL_Y 10
#define STATE_NORM_DX_SLOW 11
#define STATE_NORM_DY_SLOW 12
#define STATE_NORM_SPEED1_SLOW 13
#define STATE_NORM_SPEED2_SLOW 14
#define STATE_STROKE 15
#define STATE_STROKE_STARTED 16
#define STATE_CUSTOM_INPUT 17
#define STATE_RNG_SEED 18
#define STATE_ACTUAL_ELLIPTICAL_DAB_RATIO 19
#define STATE_ACTUAL_ELLIPTICAL_DAB_ANGLE 20
#define STATE_DIRECTION_DX 21
#define STATE_DIRECTION_DY 22
#define STATE_DECLINATION 23
#define STATE_ASCENSION 24
#define STATE_COUNT 25
#endif
/* brushlib - The MyPaint Brush Library
* Copyright (C) 2007-2008 Martin Renold <martinxyz@gmx.ch>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY. See the COPYING file for more details.
*/
#ifndef HELPERS_H_
#define HELPERS_H_
#include <glib.h>
#include <assert.h>
// MAX, MIN, ABS, CLAMP are already available from gmacros.h
#define ROUND(x) ((int) ((x) + 0.5))
#define SIGN(x) ((x)>0?1:(-1))
#define SQR(x) ((x)*(x))
#define MAX3(a, b, c) ((a)>(b)?MAX((a),(c)):MAX((b),(c)))
#define MIN3(a, b, c) ((a)<(b)?MIN((a),(c)):MIN((b),(c)))
typedef struct { int x, y, w, h; } Rect;
// originally from my mass project (mass.sourceforge.net)
inline void ExpandRectToIncludePoint(Rect * r, int x, int y)
{
if (r->w == 0) {
r->w = 1; r->h = 1;
r->x = x; r->y = y;
} else {
if (x < r->x) { r->w += r->x-x; r->x = x; } else
if (x >= r->x+r->w) { r->w = x - r->x + 1; }
if (y < r->y) { r->h += r->y-y; r->y = y; } else
if (y >= r->y+r->h) { r->h = y - r->y + 1; }
}
}
// Optimized version from one in GIMP (noisify.c), where it was
// adapted from ppmforge.c, which is part of PBMPLUS. The algorithm
// comes from: 'The Science Of Fractal Images'. Peitgen, H.-O., and
// Saupe, D. eds. Springer Verlag, New York, 1988.
inline float rand_gauss (GRand * rng)
{
float sum = 0.0;
uint32_t rand1 = g_rand_int(rng);
uint32_t rand2 = g_rand_int(rng);
sum += rand1 & 0x7FFF;
sum += (rand1 >> 16) & 0x7FFF;
sum += rand2 & 0x7FFF;
sum += (rand2 >> 16) & 0x7FFF;
return sum * 5.28596089837e-5 - 3.46410161514;
}
// stolen from GIMP (gimpcolorspace.c)
// (from gimp_rgb_to_hsv)
inline void
rgb_to_hsv_float (float *r_ /*h*/, float *g_ /*s*/, float *b_ /*v*/)
{
float max, min, delta;
float h, s, v;
float r, g, b;
h = 0.0; // silence gcc warning
r = *r_;
g = *g_;
b = *b_;
r = CLAMP(r, 0.0, 1.0);
g = CLAMP(g, 0.0, 1.0);
b = CLAMP(b, 0.0, 1.0);
max = MAX3(r, g, b);
min = MIN3(r, g, b);
v = max;
delta = max - min;
if (delta > 0.0001)
{
s = delta / max;
if (r == max)
{
h = (g - b) / delta;
if (h < 0.0)
h += 6.0;
}
else if (g == max)
{
h = 2.0 + (b - r) / delta;
}
else if (b == max)
{
h = 4.0 + (r - g) / delta;
}
h /= 6.0;
}
else
{
s = 0.0;
h = 0.0;
}
*r_ = h;
*g_ = s;
*b_ = v;
}
// (from gimp_hsv_to_rgb)
inline void
hsv_to_rgb_float (float *h_, float *s_, float *v_)
{
gint i;
gdouble f, w, q, t;
float h, s, v;
float r, g, b;
r = g = b = 0.0; // silence gcc warning
h = *h_;
s = *s_;
v = *v_;
h = h - floor(h);
s = CLAMP(s, 0.0, 1.0);
v = CLAMP(v, 0.0, 1.0);
gdouble hue;
if (s == 0.0)
{
r = v;
g = v;
b = v;
}
else
{
hue = h;
if (hue == 1.0)
hue = 0.0;
hue *= 6.0;
i = (gint) hue;
f = hue - i;
w = v * (1.0 - s);
q = v * (1.0 - (s * f));
t = v * (1.0 - (s * (1.0 - f)));
switch (i)
{
case 0:
r = v;
g = t;
b = w;
break;
case 1:
r = q;
g = v;
b = w;
break;
case 2:
r = w;
g = v;
b = t;
break;
case 3:
r = w;
g = q;
b = v;
break;
case 4:
r = t;
g = w;
b = v;
break;
case 5:
r = v;
g = w;
b = q;
break;
}
}
*h_ = r;
*s_ = g;
*v_ = b;
}
// (from gimp_rgb_to_hsl)
inline void
rgb_to_hsl_float (float *r_, float *g_, float *b_)
{
gdouble max, min, delta;
float h, s, l;
float r, g, b;
// silence gcc warnings
h=0;
r = *r_;
g = *g_;
b = *b_;
r = CLAMP(r, 0.0, 1.0);
g = CLAMP(g, 0.0, 1.0);
b = CLAMP(b, 0.0, 1.0);
max = MAX3(r, g, b);
min = MIN3(r, g, b);
l = (max + min) / 2.0;
if (max == min)
{
s = 0.0;
h = 0.0; //GIMP_HSL_UNDEFINED;
}
else
{
if (l <= 0.5)
s = (max - min) / (max + min);
else
s = (max - min) / (2.0 - max - min);
delta = max - min;
if (delta == 0.0)
delta = 1.0;
if (r == max)
{
h = (g - b) / delta;
}
else if (g == max)
{
h = 2.0 + (b - r) / delta;
}
else if (b == max)
{
h = 4.0 + (r - g) / delta;
}
h /= 6.0;
if (h < 0.0)
h += 1.0;
}
*r_ = h;
*g_ = s;
*b_ = l;
}
static double
hsl_value (gdouble n1,
gdouble n2,
gdouble hue)
{
gdouble val;
if (hue > 6.0)
hue -= 6.0;
else if (hue < 0.0)
hue += 6.0;
if (hue < 1.0)
val = n1 + (n2 - n1) * hue;
else if (hue < 3.0)
val = n2;
else if (hue < 4.0)
val = n1 + (n2 - n1) * (4.0 - hue);
else
val = n1;
return val;
}
/**
* gimp_hsl_to_rgb:
* @hsl: A color value in the HSL colorspace
* @rgb: The value converted to a value in the RGB colorspace
*
* Convert a HSL color value to an RGB color value.
**/
inline void
hsl_to_rgb_float (float *h_, float *s_, float *l_)
{
float h, s, l;
float r, g, b;
h = *h_;
s = *s_;
l = *l_;
h = h - floor(h);
s = CLAMP(s, 0.0, 1.0);
l = CLAMP(l, 0.0, 1.0);
if (s == 0)
{
/* achromatic case */
r = l;
g = l;
b = l;
}
else
{
gdouble m1, m2;
if (l <= 0.5)
m2 = l * (1.0 + s);
else
m2 = l + s - l * s;
m1 = 2.0 * l - m2;
r = hsl_value (m1, m2, h * 6.0 + 2.0);
g = hsl_value (m1, m2, h * 6.0);
b = hsl_value (m1, m2, h * 6.0 - 2.0);
}
*h_ = r;
*s_ = g;
*l_ = b;
}
#endif
/* brushlib - The MyPaint Brush Library
* Copyright (C) 2007-2008 Martin Renold <martinxyz@gmx.ch>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY. See the COPYING file for more details.
*/
#ifndef __MAPPING_H__
#define __MAPPING_H__
#include "helpers.hpp"
// user-defined mappings
// (the curves you can edit in the brush settings)
class Mapping {
private:
typedef struct {
// a set of control points (stepwise linear)
float xvalues[8];
float yvalues[8];
int n;
} ControlPoints;
int inputs;
ControlPoints * pointsList; // one for each input
int inputs_used; // optimization
public:
float base_value;
Mapping(int inputs_) {
inputs = inputs_;
pointsList = new ControlPoints[inputs];
for (int i=0; i<inputs; i++) pointsList[i].n = 0;
inputs_used = 0;
base_value = 0;
}
~Mapping() {
delete[] pointsList;
}
void set_n (int input, int n)
{
assert (input >= 0 && input < inputs);
assert (n >= 0 && n <= 8);
assert (n != 1); // cannot build a linear mapping with only one point
ControlPoints * p = pointsList + input;
if (n != 0 && p->n == 0) inputs_used++;
if (n == 0 && p->n != 0) inputs_used--;
assert(inputs_used >= 0);
assert(inputs_used <= inputs);
p->n = n;
}
void set_point (int input, int index, float x, float y)
{
assert (input >= 0 && input < inputs);
assert (index >= 0 && index < 8);
ControlPoints * p = pointsList + input;
assert (index < p->n);
if (index > 0) {
assert (x >= p->xvalues[index-1]);
}
p->xvalues[index] = x;
p->yvalues[index] = y;
}
bool is_constant()
{
return inputs_used == 0;
}
float calculate (float * data)
{
int j;
float result;
result = base_value;
// constant mapping (common case)
if (inputs_used == 0) return result;
for (j=0; j<inputs; j++) {
ControlPoints * p = pointsList + j;
if (p->n) {
float x, y;
x = data[j];
// find the segment with the slope that we need to use
float x0, y0, x1, y1;
x0 = p->xvalues[0];
y0 = p->yvalues[0];
x1 = p->xvalues[1];
y1 = p->yvalues[1];
int i;
for (i=2; i<p->n && x>x1; i++) {
x0 = x1;
y0 = y1;
x1 = p->xvalues[i];
y1 = p->yvalues[i];
}
if (x0 == x1) {
y = y0;
} else {
// linear interpolation
y = (y1*(x - x0) + y0*(x1 - x)) / (x1 - x0);
}
result += y;
}
}
return result;
}
// used in python for the global pressure mapping
float calculate_single_input (float input)
{
assert(inputs == 1);
return calculate(&input);
}
};
#endif
/* brushlib - The MyPaint Brush Library
* Copyright (C) 2008 Martin Renold <martinxyz@gmx.ch>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY. See the COPYING file for more details.
*/
#ifndef SURFACE_H
#define SURFACE_H
// surface interface required by brush.hpp
class Surface {
public:
virtual ~Surface() {}
virtual bool draw_dab (float x, float y,
float radius,
float color_r, float color_g, float color_b,
float opaque, float hardness = 0.5,
float alpha_eraser = 1.0,
float aspect_ratio = 1.0, float angle = 0.0
) = 0;
virtual void get_color (float x, float y,
float radius,
float * color_r, float * color_g, float * color_b, float * color_a
) = 0;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment