radial fix

This commit is contained in:
danya
2021-04-22 15:37:50 +03:00
parent 9f7f51fc82
commit 72d9418fd5
3 changed files with 57 additions and 17 deletions

View File

@ -2,6 +2,7 @@
#include <time.h>
#include <math.h>
#include "../../../graphics/AggPlusEnums.h"
#include "../../../graphics/structures.h"
#ifndef M_1_PI
#define M_1_PI 0.318309886183790671538
#endif
@ -81,15 +82,41 @@ namespace agg
class calcRadial : public calcBase
{
public:
calcRadial(const NSStructures::GradientInfo &_gi)
calcRadial(const NSStructures::GradientInfo &_gi) : extend_to_inf_constant(10)
{
r0 = _gi.r0;
r1 = _gi.r1;
p0 = _gi.p0;
p1 = _gi.p1;
ginfo = _gi;
extend_back_coef = extend_front_coef = 0;
if (ginfo.continue_shading_b)
{
if (r0 < r1)
{
extend_back_coef = r0 / (r1 - r0);
}
else
{
extend_back_coef = extend_to_inf_constant;
}
}
if (ginfo.continue_shading_f)
{
if (r1 < r0)
{
extend_front_coef = r1 / (r0 - r1);
}
else
{
extend_front_coef = extend_to_inf_constant;
}
}
var_segment = 1 / (1 + extend_back_coef + extend_front_coef);
}
virtual float eval(float x, float y) override
@ -117,12 +144,13 @@ namespace agg
{
return NAN_FLOAT;
}
float x1 = (-b + sqrtf(D)) / 2 / a;
float x2 = (-b - sqrtf(D)) / 2 / a;
float x2 = (-b + sqrtf(D)) / 2 / a;
float x1 = (-b - sqrtf(D)) / 2 / a;
if (abs(a) < FLT_EPSILON)
x1 = -c / b;
if (0 <= x1 && x1 <= 1)
{
return ginfo.shading.function.get_x_min() +
@ -133,18 +161,22 @@ namespace agg
return ginfo.shading.function.get_x_min() +
(ginfo.shading.function.get_x_max() - ginfo.shading.function.get_x_min()) * x2;
}
if (ginfo.continue_shading_b)
if (ginfo.continue_shading_b &&
(0 >= x1 && x1 >= -extend_back_coef ||
0 >= x2 && x2 >= -extend_back_coef))
{
if (x1 <= 0 || x2 <= 0)
return ginfo.shading.function.get_x_min();
return ginfo.shading.function.get_x_min();
}
if (ginfo.continue_shading_f)
if (ginfo.continue_shading_f &&
(1 <= x1 && x1 <= 1 + extend_front_coef ||
1 <= x2 && x2 <= 1 + extend_front_coef))
{
if (x1 >= 1 || x2 >= 1)
return ginfo.shading.function.get_x_max();
return ginfo.shading.function.get_x_max();
}
return NAN_FLOAT;
}
virtual ~calcRadial() {}
@ -153,6 +185,10 @@ namespace agg
float r0, r1;
NSStructures::Point p0,p1;
NSStructures::GradientInfo ginfo;
float extend_front_coef, extend_back_coef;
float var_segment;
float extend_to_inf_constant;
};
/**
@ -218,6 +254,8 @@ namespace agg
float cx, cy, factor;
float inverseFactor;
float invXsize, invYsize;
};
/**

View File

@ -2813,7 +2813,7 @@ namespace PdfReader
double dT1 = pShading->GetDomain1();
int nComponentsCount = pShading->GetColorSpace()->GetComponentsCount();
if (0) // Графический тип рендера todo
if (true) // Графический тип рендера todo
{
double xmin, ymin, xmax, ymax;
m_pGState->GetUserClipBBox(&xmin, &ymin, &xmax, &ymax);

View File

@ -102,7 +102,7 @@ void GenerateImg(QImage &img, std::vector<Point> &points, Info &info) {
void MainWindow::on_RenderPic_clicked()
{
/*
CApplicationFontsWorker oWorker;
oWorker.m_sDirectory = NSFile::GetProcessDirectory() + L"/fonts_cache";
oWorker.m_bIsNeedThumbnails = false;
@ -114,9 +114,11 @@ void MainWindow::on_RenderPic_clicked()
PDFREADER.LoadFromFile(L"test.pdf");
int page = ui->lineEdit->text().toInt();
PDFREADER.ConvertToRaster(page + 1, L"testpdf.bmp", 1);
QImage pm("testpdf.bmp");
// QImage pm(400, 400, QImage::Format_RGB888);
// GenerateImg(pm, points, info);
*/
// QImage pm("testpdf.bmp");
QImage pm(400, 400, QImage::Format_RGB888);
GenerateImg(pm, points, info);
//setColor2(pm, 0x0000FF);
//pm.invertPixels();
ui->lable_test->setPixmap(QPixmap::fromImage(pm));