-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Implement go's image and image/draw interfaces #365
Comments
Hi @akiross! I definitely agree that we should provide such interfaces if it means the binding feels more natural for the programming language. There is actually another branch where I was working on that but unfortunately hasn't been continued for awhile. Are you proposing to implement them yourself? If not, I can work on that. Thanks for the reminder either way! |
Hello @veeableful, I must say that I tried to work on it by myself, implementing a new First, I noticed that SDL_Surface must be locked before accessing raw data: this means there is a risk that data gets corrupted if surfaces are not properly locked when used. This could be a next step, but maybe it would be nice to warn the user if surfaces are not being used properly. Second, color models are of course a major issue here. I still did not understand if the existing Third, I am not really sure about how to access raw pixel data in a safe way, but I think an example of this is shown in the aforementioned branch :) If you can work on it, it's great. I'll play a little bit with it this morning, to see if I can use the branch code to come up with a new type implementing |
Hi @akiross, Yeah, it probably needs certain degree of SDL2 knowledge (which I got to admit: I'm not anywhere near an expert myself). I haven't worked on that code for awhile and probably need to set aside some time on Saturday to get into it again and properly work on this. For the Surface locking, maybe we can change the existing As an example: surface, _ := window.GetSurface()
pixels, _ := surface.Lock() // pixels is a type that implements image.Image
defer surface.Unlock()
// do something to the pixels instead of: surface, _ := window.GetSurface()
surface.Lock()
pixels := surface.Pixels() // pixels is an array of bytes
defer surface.Unlock()
// do something to the pixels |
Sorry I did not report earlier. I actually tried to implement those interfaces (as a new type), but I got stuck when using them for rendering with existing libraries. I was mistaken in thinking that it could just work out of the box with existing tools like draw2d or gg, because apparently the tool might depend on the specific interface implementation. For example, draw2d relies on truetype's render, and their code do not use The code is fairly simple and likely wrong, because I get correct results on the screen when drawing (colors are correct), but in the code channels seem inverted. About the locking, I ended up manually locking the interface just before the render and unlocking right after it, as you just shown. I don't fancy destructors, but something like a context manager could definitely be useful in this case. |
I think it's fine as long as we implement the interface correctly. It's up to the other libraries to make use of them. My guess is they did it that way for performance reasons. I think the code you did looks fine! Would you like to open a pull request to merge it? |
That's true and I suspect that as well. Regarding my code, I'm not really happy with it. If it is no rush, I will have time to work on it later this month and I plan to review it thoroughly and have it support other formats as well (e.g. palettes). |
Yes, definitely! Take as much time as you need @akiross. I really appreciate you working on this! |
I created a PR for this #369, although it does not include the support for palettes. |
Hello,
I would like to propose to implement the image.Image and https://golang.org/pkg/image/draw/#Image for sdl.Surface.
Actually, I am a bit surprised they are not already implemented: it is not so common among programming languages to have a standardized package for managing images and color, but go does and I think you should take advantage of it.
The reason for this proposal is that it should not take much effort, but it should instantly give benefit and access to a wide range of packages that already use such interfaces. For instance, the go packages themselves, as well as rendering libraries such as
https://github.com/llgcode/draw2d
(given that SDL rendering is quite limited).I think that one might object that this is not part of the original SDL, but I think that it is important for a library to be well integrated in the language's ecosystem.
The text was updated successfully, but these errors were encountered: