Reported pixel size of cell incorrect. #22800

Closed
opened 2026-01-31 08:23:54 +00:00 by claunia · 5 comments
Owner

Originally created by @salt-die on GitHub (Jan 25, 2025).

Windows Terminal version

1.22.3232.0

Windows build number

10.0.22631.0

Other Software

No response

Steps to reproduce

I can provide the sixel ansi to produce this image if needed, but otherwise output some sixel image and count the actual number of lines used in terminal.

Expected Behavior

Expect a 100 pixel tall sixel image to cover 5 lines in the terminal if pixel geometry is (20, 10)

Actual Behavior

Related to https://github.com/microsoft/terminal/pull/17504

Querying pixel size of cell returns (20, 10) as mentioned above (here, in python):

>>> print("\x1b[16t")

>>> ^[[6;20;10t

but printing an image that is 100 pixels high, say, uses 10 lines in terminal (expected 5 lines, or 20 pixels high per line):

Image

I've printed line numbers over the image to help show this.

Originally created by @salt-die on GitHub (Jan 25, 2025). ### Windows Terminal version 1.22.3232.0 ### Windows build number 10.0.22631.0 ### Other Software _No response_ ### Steps to reproduce I can provide the sixel ansi to produce this image if needed, but otherwise output some sixel image and count the actual number of lines used in terminal. ### Expected Behavior Expect a 100 pixel tall sixel image to cover 5 lines in the terminal if pixel geometry is (20, 10) ### Actual Behavior Related to https://github.com/microsoft/terminal/pull/17504 Querying pixel size of cell returns (20, 10) as mentioned above (here, in python): ```py >>> print("\x1b[16t") >>> ^[[6;20;10t ``` but printing an image that is 100 pixels high, say, uses 10 lines in terminal (expected 5 lines, or 20 pixels high per line): ![Image](https://github.com/user-attachments/assets/e8b7ca0f-6674-42e7-87ba-ba1ba33d2438) I've printed line numbers over the image to help show this.
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 08:23:54 +00:00
Author
Owner

@j4james commented on GitHub (Jan 25, 2025):

We'd need to see the source of test_sixel.py or the actual output that it produced to determine where the problem is, but the most likely explanation is that the pixel aspect ratio is set to 2:1, since that's what Sixel uses by default.

@j4james commented on GitHub (Jan 25, 2025): We'd need to see the source of test_sixel.py or the actual output that it produced to determine where the problem is, but the most likely explanation is that the pixel aspect ratio is set to 2:1, since that's what Sixel uses by default.
Author
Owner

@salt-die commented on GitHub (Jan 25, 2025):

Ok, I can provide the ansi that produced the image, but I'll use a smaller image for convenience (40 pixels high):

Image

P;0;;q";;40;80#0;2;14;17;21#1;2;22;26;31#2;2;25;29;36#3;2;18;21;25#4;2;16;20;24#5;2;21;24;30#6;2;19;22;27#7;2;21;25;30#0!42?!38~$#1!38?~!40?$#2!38~!41?$#4!41?~!37?$#5!39?I!39?$#6!40?~!38?$#7!39?t!39?-#0!42?!38~$#1!38?~!40?$#2!38~!41?$#4!41?~!37?$#5!39?d!39?$#6!40?~!38?$#7!39?Y!39?-#0!42?!38~$#1!38?~!40?$#2!38~!41?$#4!41?~!37?$#5!39?Q!39?$#6!40?~!38?$#7!39?l!39?-#0!38w!4?!38@$#1!38A@??w!38C$#2!38@!4?!38w$#3!38C!4?!38A$#4!38?w??@!37?$#5!39?Bk!38?$#6!38?C{BA!37?$#7!38?A?OC!37?-#0!38~!41?$#1!41?~!37?$#2!42?!38~$#4!38?~!40?$#5!40?S!38?$#6!39?~!39?$#7!40?j!38?-#0!38~!41?$#1!41?~!37?$#2!42?!38~$#4!38?~!40?$#5!40?I!38?$#6!39?~!39?$#7!40?t!38?-#0!38N!41?$#1!41?N!37?$#2!42?!38N$#4!38?N!40?$#5!40?D!38?$#6!39?N!39?$#7!40?I!38?-\

Uh, hopefully that pastes ok. (I think the beginning and ending control characters didn't paste actually)
Should one just always assume pixel aspect ratio of 2:1, or is there a query for that.

@salt-die commented on GitHub (Jan 25, 2025): Ok, I can provide the ansi that produced the image, but I'll use a smaller image for convenience (40 pixels high): ![Image](https://github.com/user-attachments/assets/38ca84c9-3e3c-4085-97c3-50da714a036a) ``` P;0;;q";;40;80#0;2;14;17;21#1;2;22;26;31#2;2;25;29;36#3;2;18;21;25#4;2;16;20;24#5;2;21;24;30#6;2;19;22;27#7;2;21;25;30#0!42?!38~$#1!38?~!40?$#2!38~!41?$#4!41?~!37?$#5!39?I!39?$#6!40?~!38?$#7!39?t!39?-#0!42?!38~$#1!38?~!40?$#2!38~!41?$#4!41?~!37?$#5!39?d!39?$#6!40?~!38?$#7!39?Y!39?-#0!42?!38~$#1!38?~!40?$#2!38~!41?$#4!41?~!37?$#5!39?Q!39?$#6!40?~!38?$#7!39?l!39?-#0!38w!4?!38@$#1!38A@??w!38C$#2!38@!4?!38w$#3!38C!4?!38A$#4!38?w??@!37?$#5!39?Bk!38?$#6!38?C{BA!37?$#7!38?A?OC!37?-#0!38~!41?$#1!41?~!37?$#2!42?!38~$#4!38?~!40?$#5!40?S!38?$#6!39?~!39?$#7!40?j!38?-#0!38~!41?$#1!41?~!37?$#2!42?!38~$#4!38?~!40?$#5!40?I!38?$#6!39?~!39?$#7!40?t!38?-#0!38N!41?$#1!41?N!37?$#2!42?!38N$#4!38?N!40?$#5!40?D!38?$#6!39?N!39?$#7!40?I!38?-\ ``` Uh, hopefully that pastes ok. (I think the beginning and ending control characters didn't paste actually) Should one just always assume pixel aspect ratio of 2:1, or is there a query for that.
Author
Owner

@j4james commented on GitHub (Jan 25, 2025):

The aspect ratio is declared as part of the image. One way of doing this is by using the raster attributes command (the part starting with "). So in your example, the start of the sequence would need to look like this:

P;0;;q"1;1;40;80

It can also be declared in the first parameter value, although that's less obvious - the value 9 indicates an aspect ratio of 1:1. So again using your example, the start of the sequence could be changed to something like this:

P9;0;;q";;40;80

If you don't set the aspect ratio in either of those places, it defaults to 2:1. That was the only aspect ratio supported by the first Sixel terminals, so later models kept that as the default for backwards compatibility.

Regardless of how you choose to set the aspect ratio, I would also recommend you set the second parameter to 1 rather than 0 (i.e. something like P9;1q), because otherwise it'll perform a background fill before rendering the image content, and the results of that can be unpredictable, and it's almost never what you want.

Also note that the dimensions you've declared for the background are 40 wide and 80 high, which I suspect is the reverse of what you intended.

@j4james commented on GitHub (Jan 25, 2025): The aspect ratio is declared as part of the image. One way of doing this is by using the raster attributes command (the part starting with `"`). So in your example, the start of the sequence would need to look like this: ``` P;0;;q"1;1;40;80 ``` It can also be declared in the first parameter value, although that's less obvious - the value `9` indicates an aspect ratio of 1:1. So again using your example, the start of the sequence could be changed to something like this: ``` P9;0;;q";;40;80 ``` If you don't set the aspect ratio in either of those places, it defaults to 2:1. That was the only aspect ratio supported by the first Sixel terminals, so later models kept that as the default for backwards compatibility. Regardless of how you choose to set the aspect ratio, I would also recommend you set the second parameter to `1` rather than `0` (i.e. something like `P9;1q`), because otherwise it'll perform a background fill before rendering the image content, and the results of that can be unpredictable, and it's almost never what you want. Also note that the dimensions you've declared for the background are 40 wide and 80 high, which I suspect is the reverse of what you intended.
Author
Owner

@salt-die commented on GitHub (Jan 25, 2025):

Thanks for the explanation! This does fix everything! The second parameter was determined by the image not having any transparent pixels. I've read somewhere that some terminals are much slower with P2=1, but maybe that's not true. Anyway, I'm satisfied and this can be closed.

@salt-die commented on GitHub (Jan 25, 2025): Thanks for the explanation! This does fix everything! The second parameter was determined by the image not having any transparent pixels. I've read somewhere that some terminals are much slower with P2=1, but maybe that's not true. Anyway, I'm satisfied and this can be closed.
Author
Owner

@DHowett commented on GitHub (Jan 25, 2025):

Thanks all!

@DHowett commented on GitHub (Jan 25, 2025): Thanks all!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#22800