sammycage / lunasvg

SVG rendering and manipulation library in C++
MIT License
866 stars 124 forks source link

Cannot parse some SVG's tile by tile #55

Closed erentknn closed 2 years ago

erentknn commented 3 years ago

I have two SVG's. One is smaller (12k x 7k) other one is bigger (28k x 32k) I can parse the smaller one tile by tile with no problem. But with other one I get Access Violation error. I triple checked the code and cannot find any problem. Here is a sample code to reproduce it:

std::vector<std::vector<float>> tileParamList; // coordinates from the json file
const int width = 1024;
const int height = 1024;
auto svgImage = lunasvg::Document::loadFromData(svgStr);

for (int i = 0; i < tileParamList.size(); i++)
{
    lunasvg::Bitmap bitmap{ width, height };
    lunasvg::Matrix matrix{ 1, 0, 0, 1, -tileParamList[i][0], -tileParamList[i][1] };

    svgImage->render(bitmap, matrix); <----------- HERE

    auto res = cv::Mat(height, width, CV_8UC4);
    res.data = bitmap.data();
    cv::cvtColor(res, res, CV_RGBA2GRAY);
    res = res > 0;
}

SVG and tileList can be found here: broken.zip And other SVG can be found here (One that works correctly. Note: First few iterations might be blank image.): notbroken.zip

sammycage commented 3 years ago

short overflow in plutovg 🤯🤯🤯

sammycage commented 3 years ago

@erentknn Did you have access to cairo library?

erentknn commented 3 years ago

@sammycage No, I never used it before.

sammycage commented 3 years ago

@erentknn Are you using Linux or Windows?

erentknn commented 3 years ago

@sammycage Windows.

sammycage commented 3 years ago

OK.. I will try to replace plutovg with Blend2D. It is very fast compare to other renderer.

erentknn commented 3 years ago

Short overflow in plutovg 🤯🤯🤯

BTW, isn't it easier to fix the short overflow rather than replacing the all library?

sammycage commented 3 years ago

The problem is from freetype code inside PlutoVG... This makes it more difficult for me to fix.

sammycage commented 3 years ago

Let me explain the problem to you.

FT_Outline can only handle maximum of 32,767 points. But the svg file you provided has only just one path element that contains 175,537 points.

erentknn commented 3 years ago

Wow. That's a lot of points. Thank you for the explanation. Is there anything I can do for help?

sammycage commented 3 years ago

Is the SVG file manually generated?

Is there anything I can do for help?

Try decrease the number of points by increasing the number of path elements with less points.

erentknn commented 3 years ago

Yes, I am creating SVG from the contours found earlier.

Try decrease the number of points by increasing the number of path elements with less points.

I will try this.

sammycage commented 3 years ago

Yes, I am creating SVG from the contours found earlier.

If you need my help, please let me know.

erentknn commented 3 years ago

I split the path into multiple paths but result was not the same as before on both SVG's. Probably because of contours that are on multiple tiles breaks something. So I guess I have to wait your fix on issue 🤷‍♂️

sammycage commented 3 years ago

This is the blend2d binding lunasvg-blend2d.zip

I will fix this issue later