-
-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Endianness problems? #43
Comments
Thank you for bringing this up! I am aware of the potential endianness issues you're mentioning. The challenge I’ve faced is finding a reliable and standard way to handle endianness in a cross-platform manner. If you know of a robust approach or have any suggestions, I would greatly appreciate your input! |
Thanks for your quick response. To detect endianness, you can simply do something like
Or, if
To swap words, you can use something like
Note that you don't need to worry about any specialized, architecture-dependent instructions to optimize these. The compiler already has patterns to detect these, and eg. on x86 will use Now for the example above, i still have to figure out where that happens. It is rendered from SVG source, so is not caused by the file loaders. I guess, somewhere the wrong byte of the pixel is used as alpha value. Any idea where to look? |
Thank you for the thoughtful explanation!
As you pointed out earlier, the issue might indeed arise from converting RGBA to the native format and vice versa. To avoid such issues, I recommend skipping the current PNG/JPG write functions for now. Instead, after rendering, you could try converting the By the way, which SVG library are you using? I'd like to understand more about the setup and see how it might relate to this behavior. |
The screenshot above is already from directly displaying the surface data, without writing out any file. I think that code is correct, if it would display the data in wrong order, i would get totally wrong colors. But currently there only seems to be an issue with blending the "knobs" at 3/6/9/12. I tried both plutosvg and LunaSVG, and get the same results. Basically, the code using plutosvg looks like:
The reason to do all the steps manually instead of just using Also note the call to plutovg_surface_clear(). This is because the window system (Atari) actually cannot handle alpha, and this should create a white background. Code using LunaSVG looks similar:
|
After further investigation, I discovered that the issue originates from converting RGBA image data from the stb image loader to To test if this resolves the problem, you can remove the embedded image by modifying the SVG processing code as follows: char *data;
(read svg document into data)
auto svg_image = Document::loadFromData(data, file_size);
svg_image->applyStyleSheet("image { display: none }"); // Hides embedded images
svg_image->updateLayout(); // Updates the layout after applying the style
int width = svg_image->width();
int height = svg_image->height();
size_t image_size = (size_t)width * height * 4;
uint8_t *bmap = (uint8_t *)malloc(image_size);
float xScale = 1.0f;
float yScale = 1.0f;
Matrix matrix(xScale, 0, 0, yScale, 0, 0);
Bitmap bitmap(bmap, width, height, (size_t)width * 4);
bitmap.clear(0xffffffff);
svg_image->render(bitmap, matrix); This code ensures that the embedded PNG image is ignored during rendering, which might help narrow down the problem. Let me know if the above changes fix the problem or if there’s something else you'd like me to look into for further debugging. |
Yes, thanks, that seems to work: I had to rebuild the library from current snapshot, because that applyStyleSheet function is not available in the v3.0.1 release. Is something similar possible using plutosvg? I would prefer using that, since the library is only used by a plugin, and the C++ code currently requires me to link a lot of libstdc++ in (on Atari there are no really shared libs). OTOH, plutosvg has some other limitations it seems, eg. the text is not rendered there. |
I've come up with the attached patch now. Still have to check whether it does the right for other images like jpeg (are those really used as embedded images in SVG documents?), but atleast it should not break anything on little-endian systems. |
Thank you for the patch! I really appreciate your effort. I'll take a closer look and try to implement it when I have time. |
for me it's a bit of a strange correction -- from my point of view it should just be used as a byte array:
|
@safocl Thanks for your input and suggestions! The approach you shared makes sense, but do you think it would actually address the endianness issue on big-endian systems? |
There seem to be some endianness problems. For example
plutovg/source/plutovg-surface.c
Line 47 in 3368ca4
Also, when trying to render
it renders as
On a big-endian machine.
The text was updated successfully, but these errors were encountered: