c64 Extended Color Mode: last character 63 = 191 to use background 2?? ($D022) - basic

In extended colour mode:
For characters 32 to 63 on background 1 (53281/$D021 value), I can add 192 to get the same on background 2 (53282/$D022 value). For characters 64 to 95 on bg1, I can add 128 to get the same on bg2
...at least that's the theory. But I'm finding that character chr$(63) is falling in to the second set: so 63 + 128 = chr$(191) prints correctly, but chr$(255) doesn't? Not a biggy, I can workaround, but i'm reluctant to believe that the documentation is wrong especially as 64 seems to be a more sensible cutoff point than 63. This may be a Vice bug?

It looks like you're confusing the PETSCII values (CHR$()) for the screen codes that are used in display.
Screen codes 0-63 use background 0, 64-127 use background 1, 128-191 use background 2, and 192-255 use background 3.
There is not a 1:1 mapping between screen codes and PETSCII values. You can't take the ASC() value of a character and do something like CHR$(ASC("X")+64) to reliably get a screen code that happens to be 64 more, even though you may find some cases in which that might be true.

Related

How to add padding to title in `matplotlib.animation`?

I created an animation using python matplotlib.animation library and I'm quite happy with it. The output is
The only part I'm unhappy with is the title. As you can see it "jiggles" around. The update function in the animation looks like this
def update_curves(num):
# do stuff with data to get lines
title.set_text('September 5th, 1994 at 00:00h\n + {}y {}d'.format(int(time[num]/365),int(time[num]%365)))
return title, lines
Is there a way to stop the y and d from moving around?
I tried searching SO for info on how padding might work but I haven't really seen something that is compatible with matplotlib.animation. Using tabs also doesn't work since they don't get displayed properly...
You can do this using good old string formatting:
title.set_text('September 5th, 1994 at 00:00h\n + {:3}y {:5}d'.format(int(i), int(i*20)))
title.set_family("monospace")
{:3} formats the string so that it is exactly 3 characters long, and is left padded with spaces.
If you use the normal serif/sans-serif font, you will still have some jitter since each digit/letter is not equal in width, but set the font family to monospace and it works correctly.

Fastest way to get X/Y position of text or text-based shape in screenshot?

I'm trying to create a script for Linux that will detect where the text cursor is. This should be done in maximum 1 second. In order to implement this, the best solution seems to be to programmatically add some text via xdotool, take a screenshot via some other utility, try to figure out the position of that text, and then remove the text we've inserted using xdotool again.
I tried inserting a random string (like <-- CURSOR HERE). Using Tesseract 4 it takes about 20 seconds to find the position of the string, although it's very precise in terms of pixel coordinates. I was not able to use whitelisting (in version 4 of Tesseract) to narrow result to specific letters or digits only, which I assume would speed up processing.
I don't know what font the user will be using, but every font has dashes and slashes, so I could create some sort of shape (for instance, |/\|/\|/\|/\|), and use some library to detect that shape. What would be a good choice?
I don't care about what's on the rest of the screen: it could be more text, images, etc. I only need o know where my random string is (<-- CURSOR HERE, |/\|/\|/\|/\|, or can you think of anything else), and get its X/Y position in pixels.

What do ^[[m, ^[[0m escape codes represent?

Code ^[[00;00m means reset color to default, however, in some programs (like source highlighter highlight for example) code ^[[m is used as if it would also serve the same purpose. What does ANSI state about such code, and also about similar ^[[0m?
"ANSI" in this context was obsoleted long ago by ECMA-48. So the appropriate place to start is that document.
Section 8.3.117 SGR - SELECT GRAPHIC RENDITION says
Notation: (Ps...)
Representation: CSI Ps... 06/13
Parameter default value: Ps = 0
SGR
is used to establish one or more graphic rendition aspects for subsequent text. The established aspects remain in effect until the next occurrence of SGR in the data stream, depending on the setting of the
GRAPHIC RENDITION COMBINATION MODE (GRCM). Each graphic rendition aspect is specified by a parameter value:
0
default rendition (implementation-defined), cancels the effect of any preceding occurrence of SGR in the data stream regardless of the setting of the GRAPHIC RENDITION COMBINATION MODE (GRCM)
That is, 0 is the default parameter if none is given (so ^[[m and ^[[0m mean the same thing. Repeating the parameter also makes no difference (cancelling something that was already cancelled does not uncancel it), so ^[[00;00m still means the same thing.

What 12 hex digits color codes in xfce terminal configuration means?

Recently I set up my XFCE terminal to use the perfect palette of
Solarized using this prepared config.
All works fine (although midnight commander colors make me cry now) but one thing is really curious to me:
Why do color codes in xfce terminal settings contain 12 hex digits rather than 6? Like these one:
ColorPalette8=#d3d3d7d7cfcf
What does it mean? And how is it related to color codes specified on
official page
GTK uses 16 bits per colour channel, i.e. 4 hex digits. A colour value for GTK can be encoded as #rgb, #rrggbb or #rrrrggggbbbb.

OCR: How to find the right ColorMatrix to define new colors?

I'm stuck right now with defining the dimension of each line. The list I want to scrape has various colors in it, and what disturbs me the most a selection:
As you can see the picture I try to analyze got a white background with green text. The selection background is grey with black text. And every second line has a slightly greyer background, but I managed to manipulate the contrast with a ColorMatrix.
Just for reference, I do have some other ColorMatrizes like Greyscale, Negative, SetContrast, SetBrightness and so on.
My method, which is searching the lines does work good with the most part of the picture, but the selection brakes it.
So now I'm stuck and don't know what to do. I googled for an hour, but didn't find a solution.
I thought, that maybe I can transform the background grey from the selection to white without affecting the text and greyscale the rest of the picture. But I can't find a ColorMatrix which does the job.
Do you know one or got a better solution?
Why use a color-matrix at all?
It works (at least for your specific example) much easier with ImageMagick's -threshold operation:
convert \
http://img18.imageshack.us/img18/210/lobbymd9.jpg \
-threshold 50% \
result.jpg
Visual Result:
=>
Thresholding basically leaves over only 2 values (zero or maximum) for each color. Every value below the threshold gets set to 0, values above the threshold get set to 255 (or 65535 if working at 16-bit depth). The end effect is a pure black+white picture.

Resources