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

Remove ImageMagick dependency #75

Merged
merged 2 commits into from
Apr 18, 2021
Merged

Remove ImageMagick dependency #75

merged 2 commits into from
Apr 18, 2021

Conversation

rashil2000
Copy link
Member

This PR introduces substantial quality improvements, with very little code change.

Highlights:

  • Speed. This one just blows ImageMagick out of the water. Testing on an extremely high res image (12000x6000), see below:

image

  • Image quality. Better color reproduction and sharper outlines. See below:

image

  • And of course, zero external dependencies from now on 🚀

@jcwillox
Copy link
Member

Fantastic, I knew there'd be a way to do this without an external tool just never got around to looking into it. I'll test out the changes tonight 👍

@rashil2000
Copy link
Member Author

Sure.

I'll list out one issue I found. It seems to print an extra black/white line at the bottom of the image in rare cases. I'll have to dig deeper into that.

@jcwillox
Copy link
Member

Gave it a try and it works pretty well, much faster compared to imagemagick. I did notice that issue you were talking about, but for me it's actually on every image, the bottom row of pixels is all white. Also, winfetch doesn't appear to work at all in PSv5, I get the following error,

+                 $currline += "$backVT$foreVTâ–„$e[0m"
+                                                ~~
Unexpected token '$e' in expression or statement.

@rashil2000
Copy link
Member Author

rashil2000 commented Apr 15, 2021

Wait, that's weird, I do all my testing on PSv5. I don't even have Core installed 😅

Can you try replacing $e with ${e} there?

Edit:
Editors are routinely known to mess up Unicode characters. I think I should replace with its hex value so that PS doesn't get confused. The hex value is 0x2584. Try replacing the character with [char]::ConvertFromUtf32(0x2584).

@jcwillox
Copy link
Member

Indeed replacing that character with $([char]0x2584) fixed it, which is basically what they did in the original version with the $CHAR variable.

I've also figured out what the issue was with the white line, basically the character your using means the topmost pixel uses the background color, and pixels are printed 2 at a time, if $ROWS is not a multiple of 2 then it needs to print a single pixel on the last line, to do this you set the background color correctly and set the foreground color to nothing, causing to it print a white pixel on the bottom row.

To fix that you need to rewrite your logic to use instead (which is what they used in the original method), this is pretty straightforward, just change the block character and swap your background and foreground colors.

@rashil2000
Copy link
Member Author

I made the change. Let me know if it works.

@jcwillox
Copy link
Member

Yep tested and it's working fine.

@rashil2000 rashil2000 merged commit 2d93065 into master Apr 18, 2021
@rashil2000 rashil2000 deleted the native-printing branch April 18, 2021 04:59
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.

2 participants