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

Feature request: Add palette mapping for VT240 #169

Open
wohali opened this issue Aug 18, 2022 · 4 comments
Open

Feature request: Add palette mapping for VT240 #169

wohali opened this issue Aug 18, 2022 · 4 comments

Comments

@wohali
Copy link

wohali commented Aug 18, 2022

Currently, conversion for display of images on a real VT240 using -p 4 always displays the same 4 colours: red, green, blue, black. However, the sixel support on a VT240 actually can display 4 colours chosen from a palette of 64 colours. The fixed palette is documented on page 162 of this PDF:

http://bitsavers.org/pdf/dec/terminal/vt240/EK-VT240-RM-002_VT240_Programmer_Reference_Manual_Oct84.pdf

Could output matching these colours be achieved with a mapfile? And, if so, can a standard VT240 mapfile be added to the distribution?

Love your library. Thanks for your hard work.

@j4james
Copy link

j4james commented Aug 18, 2022

-p 4 should definitely be attempting to give you a representative palette. But if the images you are encoding contain a broad range of colors, then it may just be that red/green/blue/black is the best palette choice in many cases. As a test, try encoding something that's primary black and white, or some monochrome shade of color.

The other problem will be that libsixel doesn't take into account the limited range of the VT240 palette, so it may calculate something like RGB(12,83,41) as being the best palette value to use, but what the VT240 actually sees is RGB(0,100,33). I'm not sure the results would be that much better if it did account for those limits, but it's possible there's room for improvement there. Is that what you were suggesting regarding the VT240 map file?

I should also mention that this project is not actually active anymore - the maintainer hasn't been seen for several years now. Some libsixel users have created a fork at libsixel/libsixel which has a little more activity, so that may be the best place to follow up if you're hoping for new features to be developed.

@wohali
Copy link
Author

wohali commented Aug 20, 2022

Hey @j4james thanks for the info. I did try some B&W images and am still getting no change of the default palette. So, something's a bit off. Maybe RGB(12,83,41) would be ignored? I'm not really sure. That is indeed what I meant by the map file -- maybe it needs to output exactly the colours in the PDF, so if I can force it to only use those colours, maybe it'd work better. I could use a little hand-holding... I'm quite busy these days.

If I can't manage it with a map file, I'll go hit up the fork.

@j4james
Copy link

j4james commented Aug 20, 2022

I did try some B&W images and am still getting no change of the default palette. So, something's a bit off.

OK, that is strange. Can you perhaps try something like this with the B&W test image:

img2sixel -p 4 test.png > test.six

Then open up the test.six file in a text editor to see what is actually generated. It should start off looking something like this:

^[Pq"1;1;640;480#0;2;97;97;97#1;2;94;89;91#2;2;67;61;60#3;2;22;19;20

The 640;480 in the above example is just the size of the image, so that will depend on your particular image, but the VT240 will just ignore that anyway. The palette definition should follow immediately after that. In my example, you can see the four colors are:

#0;2;97;97;97
#1;2;94;89;91
#2;2;67;61;60
#3;2;22;19;20

The first number in each entry is just the color ID, the second value (the 2) indicates it's an RGB definition, and the remaining 3 values are the RGB components (with a range of 0 to 100).

My test image wasn't pure B&W, so the RGB components have a bit of variation to them, but you can clearly see they're not just red/green/blue. Otherwise you'd expect something like this:

#0;2;100;0;0
#1;2;0;100;0
#2;2;0;0;100
#3;2;0;0;0

So can you check the sixel that is generated for one of your B&W test cases and see whether it at least looks right. Then we'll know if there's a problem with img2sixel, or it's the VT240 that is ignoring the palette.

Maybe RGB(12,83,41) would be ignored?

If that's the case, you can try editing the palette in the generated file to something that more closely matches the VT240 color range, e.g. for B&W it could be something like this:

#0;2;99;99;99
#1;2;66;66;66
#2;2;33;33;33
#3;2;0;0;0

Or if you think it might require the colors to be HLS, the second value in the palette definitions should be changed to 1, and you could use something like this:

#0;1;0;99;0
#1;1;0;66;0
#2;1;0;33;0
#3;1;0;0;0

The image won't necessarily look correct if the order of the palette isn't right, but that should at least show whether it is making any difference at all, or your VT240 is simply not accepting palette changes.

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

No branches or pull requests

3 participants
@wohali @j4james and others