-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
screenshot: add screenshot-to-clipboard command #15568
base: master
Are you sure you want to change the base?
Conversation
3d5afcb
to
7caaf04
Compare
Download the artifacts for this pull request: |
7caaf04
to
d72d66b
Compare
osdep/mac/clipboard.swift
Outdated
|
||
dest.params.color = plcsp | ||
|
||
if mp_image_swscale(&dest, &image, SWS_FULL_CHR_H_INT | SWS_FULL_CHR_H_INP | SWS_ACCURATE_RND) < 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use the same pattern and options as other screenshot code. See 2c43d2b
I will remove mp_image_swscale
to avoid confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add more brittle boilerplate? Seems more reasonable to me to add global
and log
options to mp_image_swscale
and then remove the duplication in screenshot.c
, image_writer.c
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased with this change; the relevant changeset is net-red (+11 -20) so I think it's a reasonable reduction in duplication. Also improved one path through player/screenshot that wasn't using the global options (nor checking for errors).
f0df0fa
to
aac01fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the whole setImage
function is very convoluted. do you think we can split it into some logical parts/helper functions, format selection (format, colour space, bit depth, etc), compatibility test, fallback/conversion, etc? it's fine not doing it in this PR and we do it later.
osdep/mac/clipboard.swift
Outdated
withUnsafeMutableBytes(of: &dest.stride) { (stridePtr) in | ||
withUnsafeMutableBytes(of: &dest.planes) { (planesPtr) in | ||
let destStrides = stridePtr.baseAddress!.assumingMemoryBound(to: type(of: image.stride.0)) | ||
let destPlanes = planesPtr.baseAddress!.assumingMemoryBound(to: type(of: image.planes.0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to get rid of the forced unwrapping here. don't want mpv to completely fail because the clipboard code fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These pointers are the addresses of members of a stack object; they can't be null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't want to compromise even more on the force unwrappings than i already did on the previous occurrences. i also don't want to discuss the sense of it in any case.
please handle every unwrapping in an appropriate way and get rid of the force unwrappings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to use guard let
s here and added the extra handling for that, but also added an assert
for debug builds.
DOCS/man/input.rst
Outdated
@@ -447,6 +447,12 @@ Property Manipulation | |||
Playlist Manipulation | |||
~~~~~~~~~~~~~~~~~~~~~ | |||
|
|||
``screenshot-to-clipboard [<flags>]`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the documentation for this should be under Screenshot Commands
not Playlist Manipulation
.
also please correct me if i am wrong. this is raw bitmap data which we pass here or at least not compressed data (png, jpg, whatever is configured with our screenshot options)? so shouldn't this be screenshot-raw-to-clipboard
?
eg i would expect screenshot-to-clipboard
to write a screenshot to the clipboard in the same format screenshot
writes a screenshot to the file system. so it should be affected by 'all' the screenshot-*
options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
screenshot-to-file
also ignores the format option, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess the documentation mentions the screenshot-to-file
ignores at least the format option. my expectations were a bit betrayed then.
Take a screenshot and save it to a given file. The format of the file will be guessed by the extension (and --screenshot-format is ignored - the behaviour when the extension is missing or unknown is arbitrary).
though thinking a bit about the future. what if we want to actually add screenshot-to-clipboard
command that wants to add the aforementioned case (eg adding a screenshot as png, jpeg, etc)? would we add a new flag to this command? i am just wondering and trying to prevent a possible 'mess'.
though if we do what @na-na-hi proposed we don't need to think further about this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a conceptual difference between an "image on the clipboard" and a "file on the clipboard", and generally copying ephemeral image data does not result in you having a file on the clipboard. On macOS, images on the clipboard are commonly represented as PNG or TIFF data (sometimes both), but there is no eg JPEG clipboard format. There's also no concept of arbitrarily ephemeral file contents on the clipboard (only a file path). The same is true on Windows afaik, except that the image format is BMP instead of PNG/TIFF. I have no idea how this works on linux, apart from that apparently on X it's common for apps to expose several different types for a copied image.
Images copied out of mpv on this branch are PNG data (but that's an implementation detail, and it basically never matters to a user).
aac01fb
to
5e26514
Compare
Rebased with suggestions applied; split the function up to the extent that was possible without adding substantial duplication or major restructuring. |
I think there is no need for this to be a command. I designed the clipboard API with the ability for format conversion in mind: when the data formats in In this specific case, it is possible to make the Alternatively, writing a These approaches allow for more flexibility of setting image clipboard contents while not introducing a new command. |
I think supporting setting an I wouldn't object to having this be Also, it probably makes most sense for any magic-string |
tested the the mac parts and works as expected in programs that can handle those pastes. besides that one open point i am fine with he swift parts of the code. would be nice if we could resolve the rest of the open points in a timely manner:
|
This reverts commit d9eb9ed
5e26514
to
7fde240
Compare
Successor to #13837, post-#15355 and #15564.
Currently implemented only on macOS.