mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Merge pull request 'fix/Tensor-luminosity-gradient' (#326) from fix/Tensor-luminosity-gradient into release/v9.0.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/326
This commit is contained in:
@ -416,6 +416,16 @@ namespace agg
|
||||
{
|
||||
return self_type(rgba::from_wavelength(wl, gamma));
|
||||
}
|
||||
|
||||
bool operator==(const self_type& other)
|
||||
{
|
||||
return a == other.a && r == other.r && g == other.g && b == other.b;
|
||||
}
|
||||
|
||||
bool operator!=(const self_type& other)
|
||||
{
|
||||
return !operator==(other);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1000,7 +1000,17 @@ namespace agg
|
||||
{
|
||||
if (i < RES && j < RES)
|
||||
{
|
||||
precalc[i][j] = c;
|
||||
if (m_oGradientInfo.luminocity)
|
||||
{
|
||||
ColorT fillC;
|
||||
fillC.r = m_oGradientInfo.shading.fill_color.r * c.r / 255 + 255 - c.r;
|
||||
fillC.g = m_oGradientInfo.shading.fill_color.g * c.g / 255 + 255 - c.g;
|
||||
fillC.b = m_oGradientInfo.shading.fill_color.b * c.b / 255 + 255 - c.b;
|
||||
fillC.a = 255;
|
||||
precalc[i][j] = fillC;
|
||||
}
|
||||
else
|
||||
precalc[i][j] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1020,22 +1020,39 @@ void CBooleanOperations::TracePaths()
|
||||
{
|
||||
size_t length = Segments1.size();
|
||||
Result.StartFigure();
|
||||
bool first_start = true;
|
||||
for (size_t i = 0; i < length + Segments2.size(); i++)
|
||||
{
|
||||
Segment s = i >= length ? Segments2[i - length] : Segments1[i];
|
||||
bool valid = s.IsValid(Op),
|
||||
start = true;
|
||||
start = true;
|
||||
PointD start_point;
|
||||
while (valid)
|
||||
{
|
||||
if (!start || (Op == Intersection && s.Inters && !GetNextSegment(s).Inters))
|
||||
SetVisited(s);
|
||||
|
||||
if (start)
|
||||
if (first_start)
|
||||
{
|
||||
Result.MoveTo(s.P.X, s.P.Y);
|
||||
start_point = s.P;
|
||||
}
|
||||
else if (start)
|
||||
{
|
||||
double x, y;
|
||||
Result.GetLastPoint(x, y);
|
||||
if (isZero(start_point.X - x) && isZero(start_point.Y - y))
|
||||
{
|
||||
Result.MoveTo(s.P.X, s.P.Y);
|
||||
start_point = s.P;
|
||||
}
|
||||
else
|
||||
Result.LineTo(s.P.X, s.P.Y);
|
||||
}
|
||||
else if (s.IsCurve)
|
||||
Result.CurveTo(s.HI.X + s.P.X, s.HI.Y + s.P.Y,
|
||||
s.HO.X + s.P.X, s.HO.Y + s.P.Y,
|
||||
s.P.X, s.P.Y);
|
||||
s.HO.X + s.P.X, s.HO.Y + s.P.Y,
|
||||
s.P.X, s.P.Y);
|
||||
else
|
||||
Result.LineTo(s.P.X, s.P.Y);
|
||||
|
||||
@ -1065,6 +1082,9 @@ void CBooleanOperations::TracePaths()
|
||||
|
||||
if (start)
|
||||
start = false;
|
||||
|
||||
if (first_start)
|
||||
first_start = false;
|
||||
}
|
||||
|
||||
if (!start && AllOverlap()) break;
|
||||
@ -1645,12 +1665,14 @@ int CBooleanOperations::CheckInters(const PointD& point, const Segment& segment,
|
||||
std::vector<double> roots = curve.GetCurveLineIntersection(segment.P.X,segment.P.Y, point.X - segment.P.X, point.Y - segment.P.Y);
|
||||
Curve line(segment, Segment(point));
|
||||
|
||||
int count = 0;
|
||||
for (const auto& r : roots)
|
||||
if (line.GetTimeOf(curve.GetPoint(r)) != -1)
|
||||
count++;
|
||||
return roots.size() % 2;
|
||||
|
||||
return count;
|
||||
// int count = 0;
|
||||
// for (const auto& r : roots)
|
||||
// if (line.GetTimeOf(curve.GetPoint(r)) != -1)
|
||||
// count++;
|
||||
|
||||
// return count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -863,20 +863,22 @@ namespace Aggplus
|
||||
|
||||
double CGraphicsPath::GetArea(unsigned idx, bool isCurve) const noexcept
|
||||
{
|
||||
float area;
|
||||
double area;
|
||||
if (isCurve)
|
||||
{
|
||||
std::vector<PointD> points = GetPoints(idx, 4);
|
||||
area = 3 * ((points[3].Y - points[0].Y) * (points[1].X + points[2].X)
|
||||
- (points[3].X - points[0].X) * (points[1].Y * points[2].Y)
|
||||
+ points[1].Y * (points[0].X - points[2].X)
|
||||
- points[1].X * (points[0].Y - points[2].Y)
|
||||
+ points[3].Y * (points[2].X + points[0].X / 3)
|
||||
- points[3].X * (points[2].Y - points[0].Y / 3)) / 20;
|
||||
area = (points[3].Y - points[0].Y) * (points[1].X + points[2].X)
|
||||
- (points[3].X - points[0].X) * (points[1].Y + points[2].Y)
|
||||
+ points[1].Y * (points[0].X - points[2].X)
|
||||
- points[1].X * (points[0].Y - points[2].Y)
|
||||
+ points[3].Y * (points[2].X + points[0].X / 3.0)
|
||||
- points[3].X * (points[2].Y + points[0].Y / 3.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<PointD> points = GetPoints(idx, 2);
|
||||
area = 4.0 * (points[1].Y * points[0].X - points[1].X * points[0].Y) / 3.0;
|
||||
}
|
||||
|
||||
std::vector<PointD> points = GetPoints(idx, 2);
|
||||
area = (points[1].Y * points[0].X - points[1].X * points[0].Y) / 20;
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
@ -371,6 +371,7 @@ namespace NSStructures
|
||||
*
|
||||
* Наверное напишу адаптор который переводит порядок точек из 6 типа в общий.
|
||||
*/
|
||||
agg::rgba8 fill_color;
|
||||
std::vector<std::vector<Point>> patch;
|
||||
std::vector<std::vector<agg::rgba8>> patch_colors; // 2 на 2 цвета по углам
|
||||
std::vector<std::vector<float>> patch_parameters; // 2 на 2 параметра
|
||||
@ -388,8 +389,8 @@ namespace NSStructures
|
||||
xsize(1.0f), ysize(1.0f),
|
||||
linstretch(1.0f), linoffset(0.0f),
|
||||
continue_shading_f(false),
|
||||
continue_shading_b(false)
|
||||
|
||||
continue_shading_b(false),
|
||||
luminocity(false)
|
||||
{
|
||||
}
|
||||
void setAngleDegrees(float deg)
|
||||
@ -404,6 +405,57 @@ namespace NSStructures
|
||||
{
|
||||
discrete_step = 1.0f / n;
|
||||
}
|
||||
bool checkLuminosity() const
|
||||
{
|
||||
if (shading.patch_colors.empty())
|
||||
return false;
|
||||
|
||||
for (const auto& ar : shading.patch_colors)
|
||||
for (const auto& c : ar)
|
||||
if (c.r != c.g || c.g != c.b)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
bool colorEqual(const agg::rgba8& c1, const agg::rgba8& c2) const
|
||||
{
|
||||
return c1.r == c2.r &&
|
||||
c1.g == c2.g &&
|
||||
c1.b == c2.b &&
|
||||
c1.a == c2.a;
|
||||
}
|
||||
bool isOneColor() const
|
||||
{
|
||||
switch (shading.shading_type)
|
||||
{
|
||||
case ShadingInfo::FunctionOnly:
|
||||
case ShadingInfo::Parametric:
|
||||
return false;
|
||||
case ShadingInfo::TriangleInterpolation:
|
||||
return colorEqual(shading.triangle_colors[0], shading.triangle_colors[1]) &&
|
||||
colorEqual(shading.triangle_colors[1], shading.triangle_colors[2]);
|
||||
case ShadingInfo::CurveInterpolation:
|
||||
case ShadingInfo::TensorCurveInterpolation:
|
||||
return colorEqual(shading.patch_colors[0][0], shading.patch_colors[0][1]) &&
|
||||
colorEqual(shading.patch_colors[0][1], shading.patch_colors[1][0]) &&
|
||||
colorEqual(shading.patch_colors[1][0], shading.patch_colors[1][1]);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
agg::rgba8 getFillColor() const
|
||||
{
|
||||
if (!shading.triangle_colors.empty())
|
||||
return shading.triangle_colors[0];
|
||||
if (!shading.patch_colors.empty())
|
||||
return shading.patch_colors[0][0];
|
||||
return agg::rgba8(0, 0, 0);
|
||||
}
|
||||
void setFillColor(const agg::rgba8& color)
|
||||
{
|
||||
shading.fill_color = color;
|
||||
luminocity = true;
|
||||
}
|
||||
void transform(const Aggplus::CMatrix& matrix)
|
||||
{
|
||||
// shading transform
|
||||
@ -502,6 +554,7 @@ namespace NSStructures
|
||||
float linstretch; // stretch linear gradient, can be negative (eq angle = 180) can not be zero
|
||||
float linoffset; // offset relative to image size
|
||||
float continue_shading_b, continue_shading_f;
|
||||
bool luminocity;
|
||||
ShadingInfo shading;
|
||||
};
|
||||
|
||||
@ -643,6 +696,7 @@ namespace NSStructures
|
||||
const std::vector<std::vector<float>> &curve_parametrs,
|
||||
const std::vector<std::vector<agg::rgba8>> &curve_colors,
|
||||
bool parametric,
|
||||
bool luminosity = false,
|
||||
float t0 = 0.0f, float t1 = 1.0f)
|
||||
{
|
||||
GradientInfo ginfo;
|
||||
@ -651,6 +705,7 @@ namespace NSStructures
|
||||
|
||||
ginfo.shading.f_type = ShadingInfo::UseNew;
|
||||
ginfo.shading.function = ColorFunction<agg::rgba8>(256, t0, t1);
|
||||
ginfo.luminocity = luminosity;
|
||||
ginfo.continue_shading_f = false;
|
||||
ginfo.continue_shading_b = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user