Skip to content
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

Improves handling of Gcode Thumbnails #27947

Merged

Conversation

pedrolamas
Copy link
Contributor

@pedrolamas pedrolamas commented Aug 11, 2023

Summary of the Pull Request

This PR adds improved handling of Gcode Thumbnails that include JPG and QOI image formats , and also adds Gcode files support to Peek.

image

PR Checklist

Detailed Description of the Pull Request / Additional comments

PowerToys already had support to show PNG thumbnails found in Gcode files as File Explorer thumbnails or on the preview pane.

As Prusa Slicer recently added JPG and QOI image formats to the output Gcode, this PR adds support for those 2 new image formats.

The QOI image format support is added via QoiImage, a custom QOI decoder I wrote based on the reference code.

I've refactored the Gcode parsing related code and moved it to PreviewHandlerCommon.

Validation Steps Performed

Manual testing on my local machine mostly, but I also updated the UnitTests-GcodePreviewHandler and UnitTests-GcodeThumbnailProvider tests

@github-actions

This comment has been minimized.

@pedrolamas pedrolamas force-pushed the pedrolamas/gcode-thumbnails-extra branch 3 times, most recently from 0876339 to 24f6b87 Compare August 13, 2023 17:49
@pedrolamas pedrolamas force-pushed the pedrolamas/gcode-thumbnails-extra branch from 24f6b87 to 80254ff Compare August 14, 2023 10:23
@pedrolamas
Copy link
Contributor Author

pedrolamas commented Aug 14, 2023

I would argue that the Peek support doesn't bring that much value as these thumbnails are normally 128x128 or less, so we end up with a small image shown on Peek!

However, g-code files have a lot more metadata than just the thumbnails, so if Peek preview had a Property Grid of sorts, we could show that metadata as key value pairs... just a thought for further enhancement! 😉

@pedrolamas
Copy link
Contributor Author

Following up on my previous comment, I see I was incorrectly adding Peek support via ImagePreviewer in this is no image, so I have reverted and removed those changes from the PR.

@pedrolamas
Copy link
Contributor Author

I've just added #27979 to allow Peek to show not only Gcode thumbnails, but also any file that has a thumbnail!

Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the contribution!
Blocking until .74 while we figure out how to audit the new dependency ;)

@pedrolamas
Copy link
Contributor Author

pedrolamas commented Sep 1, 2023

Blocking until .74 while we figure out how to audit the new dependency ;)

@jaimecbernardo if the WTFPL license is an issue, there are a couple of other NuGet packages that are MIT based, maybe I should check those instead?

Alternatively, I can try pulling a QOI implementation into PowerToys...

@stefansjfw
Copy link
Collaborator

stefansjfw commented Sep 1, 2023

Blocking until .74 while we figure out how to audit the new dependency ;)

@jaimecbernardo if the WTFPL license is an issue, there are a couple of other NuGet packages that are MIT based, maybe I should check those instead?

Alternatively, I can try pulling a QOI implementation into PowerToys...

What alternate packages do you have in mind?

@pedrolamas
Copy link
Contributor Author

I found at least 2 potential candidates on NuGet:

I haven't tested any of these, but at least the license is MIT!

@stefansjfw
Copy link
Collaborator

Alternatively, I can try pulling a QOI implementation into PowerToys

How much code would this bring in? If not much, this might be the best option. The reason is that all of these packages have a small number of downloads, and not sure how stable are those

@jaimecbernardo
Copy link
Collaborator

With the WTFPL license, I'm thinking this could be a git submodule, so we can be sure of the code we are bringing in.
My biggest issue here is that it's low number of downloads so we might be bringing some risky code in that would be signed and running on end user machines.

@pedrolamas
Copy link
Contributor Author

I will take a look at one of the other MIT licensed QOI implementations and see if I can get my code to work with theirs; if so, I expect it to be one or two files tops to bring into PT, so might that be workable?

@jaimecbernardo
Copy link
Collaborator

That would be an interesting way of doing it, as well. I'm planning on making the current dependency into a git submodule after I do the current round of reviews :)

@pedrolamas
Copy link
Contributor Author

pedrolamas commented Sep 12, 2023

FWIW, I've now removed the QOI.Core dependency and replaced it with my very own custom implementation of a QOI decoder based on the (MIT licensed) reference code!

I've tested it against the sample images from https://qoiformat.org/ and worked fine (the "*.qoi.png" files on this screenshot are the output of my decoder):

image

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@pedrolamas pedrolamas force-pushed the pedrolamas/gcode-thumbnails-extra branch from 5f6389f to 537a726 Compare September 12, 2023 14:30
@jaimecbernardo
Copy link
Collaborator

Hi @pedrolamas , thanks for the changes :)
So this is based on https://github.com/phoboslab/qoi , right?

@pedrolamas
Copy link
Contributor Author

pedrolamas commented Sep 14, 2023

Hi @pedrolamas , thanks for the changes :) So this is based on phoboslab/qoi , right?

Correct, this is my own translation of the official reference code:

image

I added a small disclaimer on top of the QoiImage.cs file, pointing to the reference code file.


Side note: once this PR gets merged, I might look into adding support for QOI Explorer thumbnails and Peek Preview support!

@github-actions

This comment has been minimized.

@jaimecbernardo
Copy link
Collaborator

Thanks a lot for the implementation 😄
I've added the MIT notice to our NOTICE file.
@crutkas , I believe this should be enough to comply with the MIT license for the reference code that was translated and adapted?
3c9a047

@crutkas
Copy link
Member

crutkas commented Sep 14, 2023

Can you link me to their license md?

@pedrolamas
Copy link
Contributor Author

@crutkas
Copy link
Member

crutkas commented Sep 14, 2023

Lemme do the notice tweak and will call out it is a port too by Pedro

@jaimecbernardo
Copy link
Collaborator

Lemme do the notice tweak and will call out it is a port too by Pedro

FYI, This is what's already on the PR in NOTICE.md under "File Explorer add-ons":

### The Quite OK Image Format reference decoder

[@pedrolamas](https://github.com/pedrolamas) translated and adapted the reference decoder C++ code to C#.

**Source**: https://github.com/phoboslab/qoi

MIT License

Copyright (c) 2022 Dominic Szablewski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution!
Just waiting on @crutkas OK for the Notice.md changes and then we can merge 😉

tweaked notice a bit
@crutkas
Copy link
Member

crutkas commented Sep 19, 2023

i tweaked it a bit, @pedrolamas did great and on inspection, it would have been truthful.

@jaimecbernardo jaimecbernardo merged commit 4ba1d83 into microsoft:main Sep 19, 2023
@pedrolamas pedrolamas deleted the pedrolamas/gcode-thumbnails-extra branch November 7, 2023 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants