[FEAT] remove some logs to execute faster

This commit is contained in:
Edouard DUPIN 2025-05-26 07:57:59 +02:00
parent e78439ef9e
commit 6c0af28ce3
4 changed files with 105 additions and 77 deletions

View File

@ -238,7 +238,7 @@ public class Base {
} else {
if (content.length() != 0) {
this.paint.stroke = parseColor(content);
LOGGER.error("Parse color : " + this.paint.stroke);
//LOGGER.trace("Parse color : " + this.paint.stroke);
}
content = element.getAttribute("stroke-width", "");
if (content.length() != 0) {
@ -332,9 +332,9 @@ public class Base {
if (inputString.length() == 0) {
return;
}
LOGGER.trace("indexOf transform : '" + inputString + "'");
//LOGGER.trace("indexOf transform : '" + inputString + "'");
inputString = inputString.replace(',', ' ');
LOGGER.trace("indexOf transform : '" + inputString + "'");
//LOGGER.trace("indexOf transform : '" + inputString + "'");
// need to indexOf elements in order ...
String data = Base.extractTransformData(inputString, "matrix");
if (data.length() != 0) {
@ -352,7 +352,7 @@ public class Base {
if (elements != null) {
this.transformMatrix = this.transformMatrix
.multiply(Matrix2x3f.createTranslate(new Vector2f(elements[0], elements[1])));
LOGGER.trace("Translate : " + elements[0] + ", " + elements[1]);
//LOGGER.trace("Translate : " + elements[0] + ", " + elements[1]);
} else {
final float elem = Float.parseFloat(data);
this.transformMatrix = this.transformMatrix.multiply(Matrix2x3f.createTranslate(new Vector2f(elem, 0)));
@ -364,7 +364,7 @@ public class Base {
if (elements != null) {
this.transformMatrix = this.transformMatrix
.multiply(Matrix2x3f.createScale(new Vector2f(elements[0], elements[1])));
LOGGER.trace("Translate : " + elements[0] + ", " + elements[1]);
//LOGGER.trace("Translate : " + elements[0] + ", " + elements[1]);
} else {
final float elem = Float.parseFloat(data);
this.transformMatrix = this.transformMatrix.multiply(Matrix2x3f.createScale(elem));

View File

@ -27,6 +27,7 @@ public class EsvgDocument extends Base {
private String title = ""; //!< sub-element list
private Uri uri = null; //!< reference elements ...
private String version = "0.0";
private static final boolean envDisplayRefs = "true".equals(System.getenv("ESQG_DISPLAY_REFS"));
public EsvgDocument() {
@ -380,7 +381,7 @@ public class EsvgDocument extends Base {
} else {
this.size = Vector2f.clipInt(this.size);
}
if (!isReference) {
if (envDisplayRefs && !isReference) {
displayDebug();
}
return true;

View File

@ -53,32 +53,33 @@ public class Renderer {
if (!this.visualDebug) {
return;
}
Vector2i dynamicSize = this.size.multiply(this.factor);
final Vector2i dynamicSize = this.size.multiply(this.factor);
// for each lines:
for (int yyy = 0; yyy < dynamicSize.y(); ++yyy) {
// Reduce the number of lines in the subsampling parsing:
List<Segment> availlableSegmentPixel = new ArrayList<>();
for (Segment it : listSegment.data) {
final List<Segment> availlableSegmentPixel = new ArrayList<>();
for (final Segment it : listSegment.data) {
if (it.p0.y() * this.factor <= yyy + 1 && it.p1.y() * this.factor >= (yyy)) {
availlableSegmentPixel.add(it);
}
}
//find all the segment that cross the middle of the line of the center of the pixel line:
float subSamplingCenterPos = yyy + 0.5f;
List<Segment> availlableSegment = new ArrayList<>();
final float subSamplingCenterPos = yyy + 0.5f;
final List<Segment> availlableSegment = new ArrayList<>();
// find in the subList ...
for (Segment it : availlableSegmentPixel) {
if (it.p0.y() * this.factor <= subSamplingCenterPos && it.p1.y() * this.factor >= subSamplingCenterPos) {
for (final Segment it : availlableSegmentPixel) {
if (it.p0.y() * this.factor <= subSamplingCenterPos
&& it.p1.y() * this.factor >= subSamplingCenterPos) {
availlableSegment.add(it);
}
}
// x position, angle
for (Segment it : availlableSegment) {
Vector2f delta = it.p0.multiply(this.factor).less(it.p1.multiply(this.factor));
for (final Segment it : availlableSegment) {
final Vector2f delta = it.p0.multiply(this.factor).less(it.p1.multiply(this.factor));
// x = coefficent*y+bbb;
float coefficient = delta.x() / delta.y();
float bbb = it.p0.x() * this.factor - coefficient * it.p0.y() * this.factor;
float xpos = coefficient * subSamplingCenterPos + bbb;
final float coefficient = delta.x() / delta.y();
final float bbb = it.p0.x() * this.factor - coefficient * it.p0.y() * this.factor;
final float xpos = coefficient * subSamplingCenterPos + bbb;
if (xpos >= 0 && xpos < dynamicSize.x() && yyy >= 0 && yyy < dynamicSize.y()) {
if (it.direction == 1.0f) {
this.buffer.setColor((int) xpos, yyy, Color.BLUE);
@ -91,32 +92,34 @@ public class Renderer {
// for each colomn:
for (int xxx = 0; xxx < dynamicSize.x(); ++xxx) {
// Reduce the number of lines in the subsampling parsing:
List<Segment> availlableSegmentPixel = new ArrayList<>();
for (Segment it : listSegment.data) {
if ((it.p0.x() * this.factor <= xxx + 1 && it.p1.x() * this.factor >= (xxx)) || (it.p0.x() * this.factor >= xxx + 1 && it.p1.x() * this.factor <= (xxx))) {
final List<Segment> availlableSegmentPixel = new ArrayList<>();
for (final Segment it : listSegment.data) {
if ((it.p0.x() * this.factor <= xxx + 1 && it.p1.x() * this.factor >= (xxx))
|| (it.p0.x() * this.factor >= xxx + 1 && it.p1.x() * this.factor <= (xxx))) {
availlableSegmentPixel.add(it);
}
}
//find all the segment that cross the middle of the line of the center of the pixel line:
float subSamplingCenterPos = xxx + 0.5f;
List<Segment> availlableSegment = new ArrayList<>();
final float subSamplingCenterPos = xxx + 0.5f;
final List<Segment> availlableSegment = new ArrayList<>();
// find in the subList ...
for (Segment it : availlableSegmentPixel) {
for (final Segment it : availlableSegmentPixel) {
if ((it.p0.x() * this.factor <= subSamplingCenterPos && it.p1.x() * this.factor >= subSamplingCenterPos)
|| (it.p0.x() * this.factor >= subSamplingCenterPos && it.p1.x() * this.factor <= subSamplingCenterPos)) {
|| (it.p0.x() * this.factor >= subSamplingCenterPos
&& it.p1.x() * this.factor <= subSamplingCenterPos)) {
availlableSegment.add(it);
}
}
// x position, angle
for (Segment it : availlableSegment) {
Vector2f delta = it.p0.multiply(this.factor).less(it.p1.multiply(this.factor));
for (final Segment it : availlableSegment) {
final Vector2f delta = it.p0.multiply(this.factor).less(it.p1.multiply(this.factor));
// x = coefficent*y+bbb;
if (delta.x() == 0) {
continue;
}
float coefficient = delta.y() / delta.x();
float bbb = it.p0.y() * this.factor - coefficient * it.p0.x() * this.factor;
float ypos = coefficient * subSamplingCenterPos + bbb;
final float coefficient = delta.y() / delta.x();
final float bbb = it.p0.y() * this.factor - coefficient * it.p0.x() * this.factor;
final float ypos = coefficient * subSamplingCenterPos + bbb;
if (ypos >= 0 && ypos < dynamicSize.y() && xxx >= 0 && xxx < dynamicSize.y()) {
if (it.direction == 1.0f) {
this.buffer.setColor(xxx, (int) ypos, Color.BLUE);
@ -160,6 +163,7 @@ public class Renderer {
base = result;
}
*/
/*
float r = (integration.a() * integration.r() + base.a() * (1.0f - integration.a()) * base.r());
float g = (integration.a() * integration.g() + base.a() * (1.0f - integration.a()) * base.g());
float b = (integration.a() * integration.b() + base.a() * (1.0f - integration.a()) * base.b());
@ -171,9 +175,26 @@ public class Renderer {
b *= reverse;
}
return new Color(r, g, b, a);
*/
final float a1 = integration.a(); // alpha over
final float a0 = base.a(); // alpha under
final float a = a1 + a0 * (1 - a1);
final float aCalc = a != 0 ? 1 / a : 1;
final float r = (integration.r() * a1 + base.r() * a0 * (1 - a1)) * aCalc;
final float g = (integration.g() * a1 + base.g() * a0 * (1 - a1)) * aCalc;
final float b = (integration.b() * a1 + base.b() * a0 * (1 - a1)) * aCalc;
return new Color(r, g, b, a);
}
public void print(final Weight weightFill, final DynamicColor colorFill, final Weight weightStroke, final DynamicColor colorStroke, final float opacity) {
public void print(
final Weight weightFill,
final DynamicColor colorFill,
final Weight weightStroke,
final DynamicColor colorStroke,
final float opacity) {
if (colorFill != null) {
//colorFill.setViewPort(Pair<Vector2f, Vector2f>(new Vector2f(0,0), Vector2f(sizeX, sizeY)));
colorFill.generate(this.document);
@ -186,9 +207,9 @@ public class Renderer {
for (int yyy = 0; yyy < this.size.y(); ++yyy) {
for (int xxx = 0; xxx < this.size.x(); ++xxx) {
Vector2i pos = new Vector2i(xxx, yyy);
float valueFill = weightFill.get(pos);
float valueStroke = weightStroke.get(pos);
final Vector2i pos = new Vector2i(xxx, yyy);
final float valueFill = weightFill.get(pos);
final float valueStroke = weightStroke.get(pos);
// calculate merge of stroke and fill value:
Color intermediateColorFill = Color.NONE;
@ -206,8 +227,8 @@ public class Renderer {
if (Renderer.DEBUG_MODE) {
for (int deltaY = 0; deltaY < this.factor; deltaY++) {
for (int deltaX = 0; deltaX < this.factor; deltaX++) {
int idx = xxx * this.factor + deltaX;
int idy = yyy * this.factor + deltaY;
final int idx = xxx * this.factor + deltaX;
final int idy = yyy * this.factor + deltaY;
this.buffer.mergeColor(idx, idy, intermediateColor);
}
}
@ -220,13 +241,19 @@ public class Renderer {
if (Renderer.DEBUG_MODE) {
// display the gradient position:
if (colorFill instanceof DynamicColorSpecial tmpColor) {
SegmentList listSegment = new SegmentList();
if (colorFill instanceof final DynamicColorSpecial tmpColor) {
final SegmentList listSegment = new SegmentList();
// Display bounding box
listSegment.addSegment(new Point(tmpColor.viewPort.first), new Point(new Vector2f(tmpColor.viewPort.first.x(), tmpColor.viewPort.second.y())), false);
listSegment.addSegment(new Point(new Vector2f(tmpColor.viewPort.first.x(), tmpColor.viewPort.second.y())), new Point(tmpColor.viewPort.second), false);
listSegment.addSegment(new Point(tmpColor.viewPort.second), new Point(new Vector2f(tmpColor.viewPort.second.x(), tmpColor.viewPort.first.y())), false);
listSegment.addSegment(new Point(new Vector2f(tmpColor.viewPort.second.x(), tmpColor.viewPort.first.y())), new Point(tmpColor.viewPort.first), false);
listSegment.addSegment(new Point(tmpColor.viewPort.first),
new Point(new Vector2f(tmpColor.viewPort.first.x(), tmpColor.viewPort.second.y())), false);
listSegment.addSegment(
new Point(new Vector2f(tmpColor.viewPort.first.x(), tmpColor.viewPort.second.y())),
new Point(tmpColor.viewPort.second), false);
listSegment.addSegment(new Point(tmpColor.viewPort.second),
new Point(new Vector2f(tmpColor.viewPort.second.x(), tmpColor.viewPort.first.y())), false);
listSegment.addSegment(
new Point(new Vector2f(tmpColor.viewPort.second.x(), tmpColor.viewPort.first.y())),
new Point(tmpColor.viewPort.first), false);
listSegment.applyMatrix(tmpColor.matrix);
// display the gradient axis
listSegment.addSegment(new Point(tmpColor.pos1), new Point(tmpColor.pos2), false);

View File

@ -108,12 +108,12 @@ public class PathModel {
}
public void display(final int spacing) {
LOGGER.warn(PathModel.spacingDist(spacing) + "Path");
//LOGGER.trace(PathModel.spacingDist(spacing) + "Path");
for (final Element it : this.listElement) {
if (it == null) {
continue;
}
LOGGER.warn(PathModel.spacingDist(spacing + 1) + it);
//LOGGER.trace(PathModel.spacingDist(spacing + 1) + it);
}
}