-
Notifications
You must be signed in to change notification settings - Fork 199
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
Adds support for loading parameters #166
Conversation
WDYT, @tonimelisma ? |
Looks sweet. However export parameters are called ExportParams and these are called LoadParams, should they be ImportParams? On the export side we also don't allow for generic export parameters, but we do have generic import parameters, is that cool? A small detail: FailOnError should probably be FailOnWarning |
I guess we could compromise, same as with export stuff, we could have a generic import function and format-specific ones? Perhaps we would need a function to identify the format of a file (or buffer?) so you could switch on it. If we also want to change the new export parameters and functions to align them with this import params function that would be fine as well as we haven't released a new version with them. I think generally it would be just easiest if the import and export params worked in a similar fashion. |
Good comments, let me share a few thoughts here:
OK, so my problem with this (and export) is our use of defaults. I don't like defining defaults in govips at all, and I don't like that we always pass these values through (e.g., scale=1.0) even when they're unset. I'd much prefer a model where we only set these parameters in vips if the user specifies them. To do that, we need to do two things:
So, I'm stuck right now between which direct to go. |
Hey David, good analysis. I think the root cause of the problem is the lack of proper undefined values / null safety in Go. Go is so much fun and nice to write, but some of the design choices are pretty horrible. For point 1), how would we accomplish this? How do we connect to the GObject API from Go, or to a C++ interface for that matter? On a quick browse, I couldn't find a good GObject library, and even if there is, I doubt it's very idiomatic Go. For point 2) regarding the ergonomics of the govips API, I think the current With* pattern is much more economical than separate Setters. Imagine having to set five different parameters for an export. That's at least 7 lines of code - create the ExportParams, set the five parameters and do the export. The cleanest option from a Go lang perspective would be to use variadic arguments for a list of Export Params. Define a generic export parameter type ExportParam, and create a set of methods which return these, which can be passed as a list for the Export function (or for the Import function similarly as well). Similar to imaging: https://github.com/disintegration/imaging/blob/v1.6.2/io.go#L174 |
Also, I hope you voted in the annual Go language survey and noted that the lack of null safety is a big problem for you 😉 |
Yeah, I agree with your points too. PS, don't upgrade to an M1 chip as your dev machine if you can help it, I sunk 2 hours into trying to get govips to build/run on my M1 Mac mini yesterday and still not out of the woods, about to just go back to my 16" MBP for that. I did manage to get one of my other projects (a Unity/Swift hybrid game) to run on my M1 last night though, so partial success. |
e9138bc
to
f2de139
Compare
OK, I mostly just posted what I'm thinking. If this works, then I'll probably change Export to use the same pattern. The ergonomics are a bit different, and we can still add variadic go constructors to make it easier, but basically you have to explicitly set parameters via its API. E.g., WDYT @tonimelisma? |
In #56 @toaster added |
d07c244
to
35b05f5
Compare
@thomasritz i can't recall why that was removed, but yes, if it makes sense we can certainly bring it back. I didn't do it in this PR since this didn't remove it, but should be easy to add. |
Inspired by: #155
However, this doesn't use libvips options yet. My intent is to likely switch to using VImage options (rather than C vararg functions) for import and export parameters, but I wanted to get this exposed and working first.