-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[PNG] save_png() now works with std::vector and std::ostream #2873
Conversation
At the moment, since the implementation details are located in a .cpp file, the callback is stored in a |
I do. I sometimes use |
Ok. Can we add a test for that? Is there a way to ensure that the copy only happens when it's an expression not a matrix ? |
Yeah same. It's a convenient overload. Definitely don't want to remove it. Also be sure to update |
Totally keep it in a .cpp file too. It's to hide the ping header file. That way it doesn't come pollute caller code. But also so people's wacky build setups don't get more chance to screw up what And in the limit if everything is in every header build times of client code go up which is a bummer too. So the std::function is fine. |
Yeah just add an overload specifically for |
Ok cool. I was thinking of going in the same direction as the ffmpeg wrappers. Making everything header only eliminates problems associated with linking against the correct version of some library since nothing is compiled into libdlib.a |
Right. It does. But then you find out people have funky copies of png.h floating around that make things not compile. I don't know what the deal is with it. It seems to mostly be a png thing. Like someone did something naughty and broke a bunch of systems. I forget what all it was. Some of it was anaconda. Which is a perennial source of "someone changed something they shouldn't have and broke the system". |
It's why I hate dependencies. People can't help but make them broken or incompatible somehow with the official version of that dependency. And then there is complaining when down stream stuff doesn't work with their odd ball version of it. |
I think this is ready |
I've refactored load_png() to also support iostreams using a similar callback mechanism. I might put that in a separate PR if people are interested. The implementation also mirrors this one which is cool. But it's not necessary since load_png() supports reading from memory in some form. It also saves nearly 100 lines of code. |
…d, mirrors saving implementations details, and supports iostreams. We could make the callback API public, and we could support a ton of APIs...
I've pushed the refactored loading implementation details. I think it's nicer, supports iostreams and mirrors the saving implementations details. It's personal preference I know. I can always revert if people don't like. |
I can update docs for |
I think the |
@davisking do you mind restarting the macos runner? |
Ok, finally ready. I promise I won't touch anything. |
@davisking not a fan ? |
Ah no it's great. I was just traveling and in Texas the whole week. Just got back and looking at this now. |
Yeah that's great stuff :D Totally keep the |
Bugger. I'll revert the loading API changes. I don't quite see the use case for png_loader. It's not doing anything special except for RAII stuff. But ok |
It tells you what kind of image you have, which is sometimes useful. Like you might want to know definitively if the PNG has an alpha channel. That could just be some separate global function though. The real reason is I don't want to break user code. It doesn't cost anything to let the code just sit there and your most loyal users are the ones who have being using a tool the longest. And breaking old APIs selectively causes trouble for that group, which at some level is the group you least want to bother :) |
Fair enough I'll sort it out. |
@davisking If everything passes, then this is done. |
@davisking Can we merge this? |
Yeah, this is real nice :D |
save_png()
works withstd::vector<byte,alloc>
save_png()
works withstd::ostream
bgr_pixel
. No longer have to convert image toarray2d<rgb_pixel>
image.cpp
which checkssave_png()
works withmatrix
image.cpp
which checks the different ways of savingI've temporarily removed the overload forI've added an overload formatrix
which converts toarray2d
. The tests don't fail so I don't know why it's there. It unnecessarily incurs a huge allocation. I imagine it handles the case wherematrix_exp
is an expression not amatrix
. Who does that? Can we have an overload for that specifically?matrix
and formatrix_exp
. The latter does a copy. The former converts toconst_image_view
which is zero-copy.I've noticed the implementation ofDone itload_png()
supports buffers but it's really verbose. I managed to get everything working forsave_png
using a callback. I imagine the same can be done forload_png()
and reduce the code bloat. We could then also supportstd::istream