Log in

View Full Version : True Pixel font?


Pages : [1] 2

zerowalker
27th July 2014, 16:07
Is there any pixel fonts that actually scale by nearest neighbor?

I can't find anything about this.

raffriff42
28th July 2014, 03:25
What, like this one? (http://speckyboy.com/2009/06/19/34-free-and-elegant-truetype-mini-pixel-fonts/)

https://www.dropbox.com/s/fq5mkvgvqj4s8jl/font-tt-pixel-04b03-dsg4.png?raw=1

zerowalker
28th July 2014, 04:05
Maybe, not sure what True type is (Perhaps you took it from my "True Pixel", bad wording i guess).

But as long as it scales with pixels, meaning, size 1 will look identical to size 100, other than it has been multiplied (which also means it can't be any decimal size, which i don't think normally is supported anyway).
Those pixel fonts i have tried will become blurry at higher resolutions, which clearly means they aren't "pixels fonts".

Will try these.

nhakobian
28th July 2014, 08:00
Maybe, not sure what True type is...

TrueType (no space) is the font standard developed by Apple and Microsoft more than 20 years ago (as opposed to Type 1 fonts that are more typically used in Postscript files). Linux has an implementation of TrueType as well.

For more info: http://en.wikipedia.org/wiki/TrueType

filler56789
28th July 2014, 09:15
Maybe you're looking for this:

http://en.wikipedia.org/wiki/Computer_font#BITMAP

raffriff42
28th July 2014, 13:08
Screenshot of this thread on my Commodore 64 with GEOS (https://en.wikipedia.org/wiki/GEOS_%288-bit_operating_system%29)*. Installing FireFox was tricky ;)

https://www.dropbox.com/s/wlqcvtmevf240m6/font-tt-pixel-04b03-dsg4-demo.png?raw=1





* not really.

zerowalker
28th July 2014, 13:41
Well TrueType was Not was i was looking for.

Maybe you're looking for this:

http://en.wikipedia.org/wiki/Computer_font#BITMAP

This may be it.

As long as the filtering is set to Point, and it's a pixel font. It should look the same all the time.


Screenshot of this thread on my Commodore 64 with GEOS*. Installing FireFox was tricky

You got a Commodore 64, awesome;D
Skip your current PC and use that.

zerowalker
28th July 2014, 22:07
Okay i am starting to think it may be Avisynth that's causing the issue.
In notepad pixel fonts looks fine, in Avisynth it's "smoothed" and looks quite bad.

raffriff42
29th July 2014, 03:39
You could have mentioned Avisynth in the beginning...

This might be of interest:
https://www.dropbox.com/s/lmjrwb4ku969eta/avisynth-subtitle-bitmap-fonts-3.png?raw=1
"Courier" (a bitmap font) fails to display at size > 28 (reverting to the default font, "Arial")
"Courier New" (a TrueType font) scales smoothly. I gather this is not what you are looking for.
"04b03" (another TrueType font, available here (http://speckyboy.com/2009/06/19/34-free-and-elegant-truetype-mini-pixel-fonts/)), retains its pixellated appearance better.
Subtitle does smooth the edges, presumably by design, as this works well for normal subtitles.
If you don't like Subtitle, there are alternatives out there for you to experiment with (http://avisynth.nl/index.php/External_filters#Subtitling). msg = "All your base \nare belong to us"
BlankClip(width=640, height=120, pixel_type="RGB32")
StackVertical(
\ Subtitle(msg, font="Courier" , size=48, align=5, lsp=0)
\ .Subtitle("Courier, 48" , align=8, size=24, text_color=$c0c0c0),
\
\ Subtitle(msg, font="Courier New", size=48, align=5, lsp=0)
\ .Subtitle("Courier New, 48" , align=8, size=24, text_color=$c0c0c0),
\
\ Subtitle(msg, font="04b03" , size=48, align=5, lsp=0)
\ .Subtitle("04b03, 48" , align=8, size=24, text_color=$c0c0c0)
\ )
return ConvertToYV12()

foxyshadis
29th July 2014, 04:36
Well TrueType was Not was i was looking for.

TrueType is a container that can hold both bitmap and curved fonts, not a style of font. (Other common containers are Type 1, a proprietary Adobe format, OpenType, a TrueType extension, and WOFF, a web font format.)

You could have mentioned Avisynth in the beginning...

This might be of interest:
If you don't like Subtitle, there are alternatives out there for you to experiment with (http://avisynth.nl/index.php/External_filters#Subtitling).

All of those alternatives also anti-alias, it's basically an absolute minimum requirements for any text rendering engine. The only way you could disable it entirely would be to: Render at a very high resolution on a blank (or alpha-transparent) canvas, point resize to a tiny resolution, then point resize back up to your final resolution and overlay it. 04b03 would work well for this, but you could use almost any other font as well and pixelate it this way.

You'll never get hints that way, but IMO hints are stupid and I've done my best to get rid of them since the Win9x days.

StainlessS
29th July 2014, 14:21
RT_Stats RT_Subtitle uses the mono-spaced bitmap font from Info.H in Avisynth Source. (same font that plugin metrics usually use)


S="The Quick Brown Fox"
Len=Strlen(S)
W=Len*10 # 10 pixel width characters
H=1*20 # 20 pixel height characters
blankclip(width=W,height=H)
RT_subtitle(S)
SZ=4
PointResize(SZ*W,SZ*H)


https://s20.postimg.org/775vwsosd/Quick_Brown_Fox0_zps3ff6acb7.jpg (https://postimg.org/image/t6cak05mh/)

zerowalker
29th July 2014, 16:06
Hmm, all options seems problematic, as i don't want to smooth it at all.
Notepad works fine with the fonts i choose.

Seems that RT_Subtitle may be what want to use.
Though it seems quite limited.

Is it possible to choose a certain font?

And is it possible to select a size for it, it looks like the only way it pointresize (which i don't mind), however i would need to have it overlayed to resize it right?

StainlessS
29th July 2014, 17:29
RT_Subtitle is fixed font only, as are plugin metrics, no resize.

EDIT: The font is embedded in all plugins that use it, nothing whatever to do with system fonts.

zerowalker
29th July 2014, 18:26
Okay i see. Hmm.

That's the limit to that then.

It's weird that you can't disable text AA, normally you are able to do that.
Guess it needs to be changed within the subtitle plugin, or rather Avisynth core in this case.

StainlessS
29th July 2014, 18:34
Yes, I think the AA takes a long time, thats why Subtitle is quite slow when used in Scriptclip.
RT_Subtitle fast in scriptclip,+ has built-in formatting instead of having to use eg Subtitle("Hello " + String(num,"%6.2f")+"\nGoodbye",lsp=0)
which is very clumsy if a lot of formatting is required in a single subtitle string. Instead RT_Subtitle("Hello %6.2f\nGoodbye",num).

You can also use RT_String() to do formatting and so have length of string available for Blankclip creation, and
just eg use RT_Subtitle with the resulting string.

EDIT: Mucked up the subtitle string, fixed.

EDIT: Although this works: Subtitle(String(num,"Hello %6.2f\nGoodbye"),lsp=0)
but gets more complicated if more than one number involved.

zerowalker
29th July 2014, 18:37
Problem is i can't use Fonts.
Currently the only way to do is to use the Font i want, save it to an image, and overlay it. And that's far from viable solution.

StainlessS
29th July 2014, 18:43
Look into RaffRiff42's alternatives in post #9.

zerowalker
29th July 2014, 18:46
All had AA from my understanding, both Subtitles and it's alternatives according to foxyshadis.

I tried using VSFilter with no luck, looks the same.

StainlessS
29th July 2014, 19:02
What are you actually trying to do ?

zerowalker
29th July 2014, 19:03
Use Font's in Avisynth without AA i guess.
I want to use Pixel like fonts. And AA totally ruins that for me.

StainlessS
29th July 2014, 19:06
Obviously, what I mean is are you trying to use as subtitles, ie on for a few frames and then off for a few, etc.

EDIT:
I guess that you could perhaps create a clip where each frame is a character (perhaps resized or whatever),
and overlay/layer each individual character required, taking into account resizing.

zerowalker
29th July 2014, 19:17
I just want to use Subtitles as normal.
Add text to a video, nothing fancy.

I will Trim the clip according to the Subtitle use.

So the only issue is the AA.

I guess that you could perhaps create a clip where each frame is a character (perhaps resized or whatever),
and overlay/layer each individual character required, taking into account resizing.

That seems extremely hard.

This should be supported, it's not a "new feature", it's just that Avisynth always AA even though it's an option that can be disabled in textrendering.

StainlessS
29th July 2014, 19:45
I just want to use Subtitles as normal.

No you dont, thats the problem.

This is maybe a start if you are serious, I dont have time to do it for you.


Function CharClip(Float "szw",Float "szh") {
w=Round(Default(szw,10.0)) h=Round(Default(szh,20.0))
cmin = 32 - 32
cmax = 126 - 32
bc = BlankClip(length=1,width=10,height=20,pixel_type="RGB32")
GScript("""
ACC = bc.BlankClip(length=0)
for(i=cmin,cmax) { ACC = ACC + bc.RT_Subtitle(Chr(i+32)) }
ACC.PointResize(w,h)
""")
Return Last
}

Return Charclip(400,800)


It will likely be slow.

StainlessS
29th July 2014, 22:00
Bump: A bit more (could not resist)


GSCript("""
Global G_FontW = -1 Global G_FontH = -1 Global G_FontColor =-1 Global G_FontClip = -1

Function CharClip(Int "szw",Int "szh",Int "Color") {
# Make clip of RGB character bitmaps (in alpha channel) in character range 32 (SPACE) to 126 (32 -> 126 = printable range)
# Frame 0 is Chr(32) [SPACE], frame 126-32 is last printable character Chr(126), ie subtract 32 from character code to get frame number,
w=Default(szw,10) h=Default(szh,20) Color = Default(Color,$FFFFFF)
cmin = 32 - 32 # Frame number for SPACE (first frame 0)
cmax = 126 - 32 # Frame Number for Chr(126) (last frame 94)
bc = BlankClip(length=1,width=10,height=20,pixel_type="RGB32")
Msk = bc.BlankClip(length=0) # Initialize to Empty clip (zero length)
Fmt="%c"
for(i=cmin,cmax) { # Render single character on each frame
Msk = Msk + bc.RT_Subtitle(Fmt,i+32) # Splice single frame of character bitmap, Sort of like Subtitle( Chr(i+32) )
}
Msk = Msk.PointResize(w,h) # To required size
clp = Msk.BlankClip(Color=Color) # Clp in Color, same attributes (size etc) as Msk
ClipWithAlpha = Mask(clp,Msk) # ClipWithAlpha is blankclip in color, Alpha Mask is character bitmap.
# Remember current attributes (Zubtitle called without explicit color/size will use previous settings).
Global G_Fontclip=ClipWithAlpha Global G_FontW=w Global G_FontH=h Global G_FontColor = Color
Return 0 # dummy
}

Function Zubtitle(clip clp,String txt,Int "x", Int "y",int "Level",int "Size",Int "Color") {
x=Default(x,0) y=Default(y,0)
Level=Default(Level,257) # 0 = fully transparent, 257 fully Opaque
FontHit = Default(Size,(G_FontH<0)?20:G_FontH) # Default as previously set (20 if not previously set)
FontWid = Defined(Size) ? Round(Size/2.0) : (G_FontW<0) ? 10 : G_FontW # Default as previously set (10 if not previously set)
Color = Default(Color,(G_FontColor<0) ? $FFFFFF : G_FontColor) # Default is previously set color (white if not previously set)
(FontWid != G_FontW || FontHit != G_FontH || Color != G_FontColor || !G_FontClip.IsClip) ? CharClip(FontWid,FontHit,Color) : NOP
clp
len=Strlen(txt)
LineClip=0 # Will become 1 frame line of text clip
for(i=1,len) {
char = RT_Ord(txt,i) # ASCII character code
if(char == 10) { # Line Feed ? [Chr(10)]
if(LineClip.IsClip) { # Have we a text clip ? [not empty line ie not Chr(10) only]
Layer(Last,LineClip,"add",Level=Level,x=x,y=y) # Render a single line of text on frame
LineClip=0 # Reset to empty clip
}
x=0 # Left hand side of frame
y=y + G_FontH # Next line down
} Else if(char >= 32 && char <= 126) { # Printable character ?
tmpc = G_FontClip.trim(char-32,-1) # Get the single frame with bitmap data for char
LineClip = (LineClip.IsClip) ? LineClip.StackHorizontal(tmpc) : tmpc # Append Char Bitmap to line of text clip.
}
}
if(LineClip.IsClip) {Layer(Last,LineClip,"add",Level=Level,x=x,y=y)} # Render a single line of text on frame [was not Chr(10) terminated]
}
""")

colorbars.killaudio

# CharClip(SzW=20*10,SzH=20*20) Return Trim(0,-(126-32)).Layer(G_FontClip,"add")

Format = "%d]\nThere Can Be Only One,\nStainlessS Is His Name,\nIf He Only Had A Heart..."

#Zubtitle("The Quick Brown Fox", x=0, y= 0 , Level=180, size = 50 ,Color=$FF0000)

ScriptClip("Zubtitle(RT_String(Format,current_frame), x=0, y= height + 40 - current_frame , Level=180,size=50 ,Color=$FFFF00)")

EDITED:

foxyshadis
29th July 2014, 22:04
Do you want something more like Subtitle (constant text) or more like TextSub (reading a script)? I can quickly modify either one to allow aliased text output.

zerowalker
29th July 2014, 22:57
SainlessS, i see you are as active as ever with your scripting;P

But i don't really think that's of use to me (Or well it does probably do what i want, but in a very roundabout way).

Do you want something more like Subtitle (constant text) or more like TextSub (reading a script)? I can quickly modify either one to allow aliased text output.

I simply want normal text, precisely as Subtitle works.

But without AA (as that's what makes Pixel fonts "non-pixelated").

If you could fix this, it would be great.
At the same time, if Outline could be controlled (the size), that would be great as well.

foxyshadis
30th July 2014, 01:18
I can't change the haloing quickly, the algorithm is tricky and hard-coded. Use the standard argument halo_color=$FF000000 to disable it completely.

Here's the plugin: newsubtitle.7z (https://www.dropbox.com/s/h9y4t0pr0vhuec2/newsubtitle.7z), requires VC 2013 runtime (https://www.microsoft.com/en-us/download/details.aspx?id=40784) unless you want to build it yourself. About as quick and dirty as possible. Takes over Subtitle, adds a new aa argument that defaults to true, when false it gives aliased text. I haven't actually tested, I hope it works.

zerowalker
30th July 2014, 06:18
I can't change the haloing quickly, the algorithm is tricky and hard-coded. Use the standard argument halo_color=$FF000000 to disable it completely.

Here's the plugin: newsubtitle.7z (https://www.dropbox.com/s/h9y4t0pr0vhuec2/newsubtitle.7z), requires VC 2013 runtime (https://www.microsoft.com/en-us/download/details.aspx?id=40784) unless you want to build it yourself. About as quick and dirty as possible. Takes over Subtitle, adds a new aa argument that defaults to true, when false it gives aliased text. I haven't actually tested, I hope it works.


Haloing isn't That important, was more "if it's easy to do, please look at it", the important thing is AA.

Thanks,

Sadly though, it doesn't seem to work.
I tried different Fonts at larger sizes, and AA = False/True look identical.

Can you link me the source?

Not a c/c++ programmer but can perhaps play around instead of wasting your time, have gotten far to much help without raising my hands in these topic so far.

Edit: Oh opened the file again and noticed there is a Visual Project. My bad, will look at it.

StainlessS,

Looking at your script, it's extremely complicated (for me), but works easy as always.
Even though it lacks the Font option (as it's a different approach), it does fulfill the "Pixelated" work.

Though i can't quite understand what the Char(10) does?
Is it acting as a New Line?

nhakobian
30th July 2014, 07:04
Though i can't quite understand what the Char(10) does?
Is it acting as a New Line?

It is a new line character. In ASCII character '0A' is the newline character, which converted into decimal is '10'.

raffriff42
30th July 2014, 08:07
Nice work (http://forum.doom9.org/showpost.php?p=1688343&postcount=24), StainlessS!

Here's your excellent RT_subtitle with border etc, but no multiline support.

https://www.dropbox.com/s/x6j16xl6rgbh201/RT_subtitle-demo-s67%2Cb3.jpg?raw=1

https://www.dropbox.com/s/fxs1leo8ppnkahi/RT_subtitle-demo-s40%2Cb2s.jpg?raw=1
LoadPlugin(pathBase + "RT_Stats\RT_Stats26.dll")
LoadPlugin(pathBase + "MaskTools2\mt_masktools-26.dll")
## (set your path to the above 2 required plugins, or place them in your Plugins folder)

msg="The Quick Brown Fox"

## background clip:
C = Colorbars(width=640, height=480).ConvertToRGB32()

#return rtsub(C, msg, size=64, align=8,
#\ text_color=$99cc99, halo_color=$0, halo_width=3)

## soft shadow:
return rtsub(C, msg, size=40, align=5, text_color=$99cc99,
\ halo_width=2, soft_halo=1>0)

## drop shadow:
#return rtsub(C, msg, size=40, align=5, text_color=$99cc99,
#\ halo_width=2, halo_x=0, halo_y=2, soft_halo=1>0)

## exaggerated offset:
#return rtsub(C, msg, size=40, align=5, text_color=$99cc99,
#\ halo_width=1, halo_x=16, soft_halo=0>0)


#######################################
### RT_subtitle wrapper for partial Subtitle argument compatibility.
### thank you for RT_subtitle, StainlessS!!
### http://forum.doom9.org/showthread.php?p=1688366#post1688366
##
## @ text - line of text (no line breaks)
## @ x, y - left & top position of overlay
## (not corrected for the invisible borders)
## (overrides align if supplied)
## @ size - nominal font size in pixels (default 20)
## (for best appearance, use a multiple of 20)
## @ text_color - default yellow
## @ halo_color - default black
## @ align - insert position, using "numeric keypad" notation (cf. Avisynth:Subtitle)
## *---------*
## | 7 8 9 | default 7 (top left)
## | 4 5 6 |
## | 1 2 3 |
## *---------*
## @ halo_width - 0 to 3 (default 1)
## @ halo_x, halo_y - move halo relative to text (default -4, 0)
## (negative values move left & up; positive values move right & down)
## @ soft_halo - if true, soften the halo outline, if halo_width > 1 (default false)
##
## @version 1.1 - halo_x, halo_y, soft_halo
##
function rtsub(clip C, string text,
\ float "x", float "y", int "size",
\ int "text_color", int "halo_color",
\ int "align", int "halo_width",
\ int "halo_x", int "halo_y",
\ bool "soft_halo")
{
size = Default(size, 20)
text_color = Default(text_color, $ff0000)
halo_color = Default(halo_color, $0)
align = Default(align, 7)
halo_width = Default(halo_width, 1)
halo_x = Default(halo_x, -4)
halo_y = Default(halo_y, 0)
soft_halo = Default(soft_halo, false)

x = Default(x,
\ (align==1) ? 8 : (align==2) ? -1 : (align==3) ? -2
\ : (align==4) ? 8 : (align==5) ? -1 : (align==6) ? -2
\ : (align==7) ? 8 : (align==8) ? -1 : (align==9) ? -2
\ : 8)
y = Default(y,
\ (align==1) ? -2 : (align==2) ? -2 : (align==3) ? -2
\ : (align==4) ? -1 : (align==5) ? -1 : (align==6) ? -1
\ : (align==7) ? 8 : (align==8) ? 8 : (align==9) ? 8
\ : 8)

M = rtsub_raw(C, text)
FM = rtsub_sizer(M, size)
BM = rtsub_sizer(M, size, halo_width, halo_x, halo_y, soft_halo)

F = BlankClip(C, width=FM.Width, height=FM.Height, color=text_color)
B = BlankClip(F, color=halo_color)

x = (x==-1) ? C.Width/2 - FM.Width/2
\ : (x==-2) ? C.Width - FM.Width-8
\ : x
y = (y==-1) ? C.Height/2 - FM.Height/2
\ : (y==-2) ? C.Height - FM.Height-8
\ : y

C ## Last=C
Overlay(B.Mask(BM), x, y, BM)
Overlay(F.Mask(FM), x, y, FM)
return Last
}

#######################################
### create a white on black image of a line of text
##
## @ C - template clip, for framerate etc
## @ text - line of text (no line breaks)
##
function rtsub_raw(clip C, string text)
{
L = Strlen(text)
W = L*10 # 10 pixel width characters
H = 20 # 20 pixel height characters
BlankClip(C, width=W, height=H, pixel_type="RGB32")
RT_subtitle(text)
AddBorders(0, 4, 8, 4)
return Last
}

#######################################
### resize the rtsub_raw() mask
##
## @ M - mask clip from rtsub_raw()
## @ size - nominal font size in pixels (default 20)
## @ expand - 0 to 3 (default 0)
## @ off_x, off_y - move text before scaling (default 0, 0)
## @ soft - if true, soften the outline (default false)
##
function rtsub_sizer(clip M, float "size", int "expand",
\ int "off_x", int "off_y", bool "soft")
{
size = Float(Default(size, 20))
expand = Default(expand, 0)
off_x = Default(off_x, 0)
off_y = Default(off_y, 0)
soft = Default(soft, false)

M = (expand<=0) ? M
\ : M.ConvertToY8(matrix="PC.601")
\ .UUOffset(off_x, off_y, $0)
\ .mt_expandx(expand, soft)
\ .ConvertToRGB32()

return M.PointResize(
\ 2*Round(size/40*M.Width),
\ 2*Round(size/40*M.Height))
}

#######################################
### variable mt_expand
## @ width - 0 to 3
##
function mt_expandx(clip C, int width, bool soft)
{
bf = (soft) ? 1.0 : 0.0
return (width==1) ? C.mt_expand
\ : (width==2) ? C.mt_expand.Blur(bf).mt_expand
\ : (width>=3) ? C.mt_expand.Blur(bf).mt_expand.Blur(bf).mt_expand
\ : C
}

##################################
### shift a clip up-down and left-right
#
#@version 1.0 LB 24-Jul-2012
#@version 1.1 LB 02-Apr-2014 reformat
#
function UUOffset(clip C, int offh, int offv, int "bordercolor")
{
bordercolor = Default(bordercolor, $808080)
C ## Last=C
(offh <= 0) ? Last
\ : Crop(0, 0, -offh, 0).AddBorders(offh, 0, 0, 0, color=bordercolor)
(offh >= 0) ? Last
\ : Crop(-offh, 0, 0, 0).AddBorders(0, 0, -offh, 0, color=bordercolor)
(offv <= 0) ? Last
\ : Crop(0, 0, 0, -offv).AddBorders(0, offv, 0, 0, color=bordercolor)
(offv >= 0) ? Last
\ : Crop(0, -offv, 0, 0).AddBorders(0, 0, 0, -offv, color=bordercolor)
return Last
}

StainlessS
30th July 2014, 14:21
@ZeroWalker,
As nhakobian said.
Chr(10) takes an ASCII character code (10) and changes it to a text character (as used in a string) ie NewLine,
NewLine or LineFeed, is a control character that was eg used in line printers, teletypes and the like.
RT_Ord() is the same as new function Ord() in v2.6, except that it has a 'pos' arg to get the character code
from a string at pos position instead of only the first character position that Avisynth Ord uses. Ord or RT_Ord is convienient
in that it returns an integer rather than a single character string [as eg MidStr(S,pos,1) would], and so there is no string memory
allocation overhead involved to eat up memory (string memory is never freed until Avisynth closes down).
So for any kind of string parsing, it is more economical to fetch characters as integers rather than single character strings.

Anyway, RaffRiffs rendition does it better (such a clever cloggs).

@RaffRiff, your FileSearch Classic (here (https://sourceforge.net/projects/filesearchclassic/?source=navbar)) has now supplanted my usual file search s/w (PDFind), I really like it.
Thank you very much.

EDIT:
Raffriff. RT_Stats has an RT_TxtQueryLines() func, that could be used to find the number of lines in a string,
(with or without a final terminating n/l on last line)
where you would first use RT_String() instead of RT_Subtitle() to generate a string with formatting.
There is however no function to find the invidually longest line in a multiline string, I think we need one.
With both functions, then you could establish the size of an enclosing box before using RT_subtitle(str)
where str is result from RT_String().

raffriff42
30th July 2014, 14:38
Zubtitle, haha. I was gonna call mine rt_subzero, but decided no one gets immortalized that way by me, without $$$$

Thanksss for the glowing review, StainlessS, it will go viral now for sure.

zerowalker
30th July 2014, 16:16
It is a new line character. In ASCII character '0A' is the newline character, which converted into decimal is '10'.

Ah okay that explains it.

Ord or RT_Ord is convienient
in that it returns an integer rather than a single character string [as eg MidStr(S,pos,1) would], and so there is no string memory
allocation overhead involved to eat up memory (string memory is never freed until Avisynth closes down).
So for any kind of string parsing, it is more economical to fetch characters as integers rather than single character strings.

Well that is indeed economical. Didn't even know there was a different in how they acted.


raffriff42,

Tried your mod of Zubtitles (i presume?).

And well work as excepted i guess.
Read the code, but could only grasp the idea of what is done (Great commenting). It basically work as Subtitles, except for the limitation as it's working with Images, so borders are quite problematic, as you have to use the Clip border functions to try to match the text if i understand it correctly.

It seems like the borders are, out of sync.

http://i61.tinypic.com/29xhnrm.png

rtsub("HI THERE", size=64, align=8,
\ text_color=$ffff0000, halo_color=$0, halo_width=1)


Much appreciated work, though different approach this has it's uses. And quite surprised it can even be done like this, learn new things every day.:thanks:

raffriff42
30th July 2014, 22:01
Thank you, I enjoyed doing it. Always nice to hear some positive feedback though.

I don't know where the offset is coming from; maybe there was a typo in my post. I have updated the script with what I think is a bug fix, but in case it doesn't quite work, there are new halo_x and halo_y arguments to adjust the halo offset yourself - a fudge factor (EDIT: also useful for making drop shadows (http://en.wikipedia.org/wiki/Drop_shadow)).

I have also added a soft_halo option - I think it looks good, and it should help compressibility, but it's not on by default.

When updating the script, be sure to replace *all* the functions with their new versions.

StainlessS
31st July 2014, 13:58
Post #24 updated, ~40% faster, but still slow.

zerowalker
31st July 2014, 18:15
StainlessS, Well that's an impressive amount, nearly halved the amount of time.
What did you change, if i may ask in layman terms?

foxyshadis, i looked at the source code,
I can't make out much of it though, i don't even get where the bool aa actually matter, i guess it works differently, as i looked for If (aa) "useAA".

StainlessS
31st July 2014, 19:17
Main saving was in StackHorizontal,ing the character bitmap frames and only Layer,ing once instead of for each character.
Is quite fast rendering outside of ScriptClip, just slow within ScriptClip.
Few more mods coming.

zerowalker
31st July 2014, 19:29
Ah, basically doing one Big work instead of several small, nice.

foxyshadis
31st July 2014, 23:55
StainlessS, Well that's an impressive amount, nearly halved the amount of time.
What did you change, if i may ask in layman terms?

foxyshadis, i looked at the source code,
I can't make out much of it though, i don't even get where the bool aa actually matter, i guess it works differently, as i looked for If (aa) "useAA".

CreateFont(blah blah, NONANTIALIASED_QUALITY, blah); is supposed to give old-fashioned unsmoothed text. (LoadFont is aliased to it.) I verified that it was passing the value correctly, but anti-aliased text still came out the other end. I've heard that's a problem on some forums, but I wonder if some of the alpha processing makes it antialiased even if the font isn't. I was bummed I couldn't fix it, but oh well.

zerowalker
1st August 2014, 00:04
Ah, damn. Would have thought disabling something like that would be a lot simpler, especially if you know about it (The programming).
But well it's never is simple right;P?

Thanks for trying it though, much appreciated

StainlessS
1st August 2014, 13:15
Update on post #24


GSCript("""
Global G_FontW = -1 Global G_FontH = -1 Global G_FontColor =-1 Global G_FontClip = -1

Function CharClip(Int "szw",Int "szh",Int "Color") {
# Make clip of RGB character bitmaps (in alpha channel) in character range 32 (SPACE) to 126 (32 -> 126 = printable range)
# Frame 0 is Chr(32) [SPACE], frame 126-32(94) is last printable character Chr(126), ie subtract 32 from character code to get frame number,
w=Default(szw,10) h=Default(szh,20) Color = Default(Color,$FFFFFF)
cmin = 32 - 32 # Frame number for SPACE (first frame 0)
cmax = 126 - 32 # Frame Number for Chr(126) (last frame 94)
bc = BlankClip(length=1,width=10,height=20,pixel_type="RGB32")
Msk = bc.BlankClip(length=0) # Initialize to Empty clip (zero length)
Fmt="%c"
for(i=cmin,cmax) { # Render single character on each frame
Msk = Msk + bc.RT_Subtitle(Fmt,i+32) # Splice single frame of character bitmap, Sort of like Subtitle( Chr(i+32) )
}
Msk = Msk.PointResize(w,h) # To required size
clp = Msk.BlankClip(Color=Color) # Clp in Color, same attributes (size etc) as Msk
ClipWithAlpha = Mask(clp,Msk) # ClipWithAlpha is blankclip in color, Alpha Mask is character bitmap.
# Remember current attributes (Zubtitle called without explicit color/size will use previous settings).
Global G_Fontclip=ClipWithAlpha Global G_FontW=w Global G_FontH=h Global G_FontColor = Color
Return 0 # dummy
}

Function Zubtitle(clip clp,String txt,Int "x", Int "y",Int "Size",Int "Color",Int "Align",Bool "VCent",Bool "ExpX",Bool "ExpY",int "Level") {
WW=clp.Width HH=clp.Height
FontHit = Default(Size,(G_FontH<0)?20:G_FontH) # Default as previously set (20 if not previously set)
FontWid = Defined(Size) ? Round(Size/2.0) : (G_FontW<0) ? 10 : G_FontW # Default as previously set (10 if not previously set)
Color = Default(Color,(G_FontColor<0) ? $FFFFFF : G_FontColor) # Default is previously set color (white if not previously set)
Level=Default(Level,257) # 0 = fully transparent, 257 fully Opaque
(FontWid != G_FontW || FontHit != G_FontH || Color != G_FontColor || !G_FontClip.IsClip) ? CharClip(FontWid,FontHit,Color) : NOP
Lines = RT_TxtQueryLines(txt) # Number of lines of text in multi-line string
MaxLen=0 for(i=0,Lines-1) {MaxLen=Max(Strlen(RT_TxtGetLine(txt,i)),MaxLen)}
Align = Default(Align,$80000000)
x = Default(x,$80000000)
y = Default(y,$80000000)
VCent = Default(VCent,False)
ExpX = Default(ExpX,False)
ExpY = Default(ExpY,False)
Align=(!ExpX && Align==$80000000) ? (x==-1 ? 8 : 7) : Align
Align=(Align < 1 || Align > 9) ? 7 : Align
xMidAlign=((Align+1) % 3 == 0) # 2 or 5 or 8 ie centre aligned
RgtAlign =(Align % 3 == 0) # 3 or 6 or 9 ie right aligned
BotAlign =(Align>=1 && Align<=3)
yMidAlign=(Align>=4 && Align<=6)
y = y!=$80000000 ? y : yMidAlign ? -1 : BotAlign ? HH : 0
y = ExpY ? y : y==HH ? HH-(Lines*G_FontH) : y== -1 ? (VCent ? (HH-(Lines*G_FontH))/2 : HH/2-Round(G_FontH*14/20.0)) : y
x = x!=$80000000 ? x : xMidAlign ? -1 : RgtAlign ? WW : 0
x = ExpX ? x
\ : x ==WW ? (RgtAlign?WW:xMidAlign?WW-Round(MaxLen*G_FontW/2.0):WW-(MaxLen*G_FontW))
\ : x ==-1 ? WW/2
\ : RgtAlign?x+MaxLen*G_FontW:xMidAlign?x+Round(MaxLen*G_FontW/2.0):x
len=Strlen(txt)
LineClip=0 # Will become 1 frame line of text clip
PrintLen = 0 # Length of visible print string (so far)
for(i=1,len) {
char = RT_Ord(txt,i) # ASCII character code
if(char >= 32 && char <= 126) { # Printable character ?
if(y < HH && y+G_FontH >=0) { # Within Top to bottom edges of frame ?
tmpc = G_FontClip.trim(char-32,-1) # Get the single frame with bitmap data for char
LineClip = (PrintLen>0) ? LineClip.StackHorizontal(tmpc) : tmpc # Append Char Bitmap to line of text clip.
PrintLen = PrintLen + 1
}
}
if(char == 10 || i==len) { # Line Feed ? [Chr(10)] (or last line)
if(PrintLen>0) { # Have we a text clip ? [not empty line ie not Chr(10) only]
xt = RgtAlign ? x-(PrintLen*G_FontW) : xMidAlign ? x-(PrintLen*G_FontW/2) : x
if(xt<WW && xt+PrintLen*G_FontW >=0 ) { # Within Left to Right edges of frame ?
clp=Layer(clp,LineClip,"add",Level=Level,x=xt,y=y) # Render a single line of text on frame
}
LineClip=0 # Reset to empty clip
PrintLen = 0
}
y = y + G_FontH # Next line down
}
}
clp
}

Function TxtStrLenMax(String s) {n=RT_TxtQueryLines(s) MxL=0 for(i=0,n-1) {MxL=Max(Strlen(RT_TxtGetLine(s,i)),MxL)} MxL}

Function FontWidth(Int "FontHeight") {FontW=Defined(FontHeight) ? Round(FontHeight/2.0) : G_FontW<0?10:G_FontW FontW}

""")

##########
colorbars.killaudio
ORG=Last
Format = "[%d]\nThere Can Be Only One,\nStainlessS Is His Name,\nIf He Only Had A Heart..."
Txt="Once upon a time in a land far far away"+Chr(10)+
\ "there lived a little mouse"+Chr(10)+
\ "with a louse as big as a house."+Chr(10)+
\ "The mouse said to the mice,"+Chr(10)+
\ "'you are thrice as nice as lice.'"+Chr(10)+
\ "(That mouse is a poet"+Chr(10)+
\ "and he dont even know it.)"
##########

# UnComment one of below lines for simple demo
# CharClip(SzW=20*10,SzH=20*20) Return Trim(0,-(126-32+1)).Layer(G_FontClip)
# Return Zubtitle(RT_String("The Quick Brown Fox\nJumps Over The\nLazy Dog"), size = 60 ,Align=6,Color=$FF0000,VCent=True,Level=180)
# Return ScriptClip("Zubtitle(RT_String(Format,current_frame),y=height+20-current_frame,size=20,Align=5,Color=$FFFF00,ExpY=true,VCent=True,Level=180)")

######################################
# config
DELAY=0
SIZEH=20 # Font Height
ALIGN=5 # As Numeric KeyPad
SCROLL=0 # 0 = Upwards : 1 = Downwards : 2 = Right to Left : 3 = Left to right : 4 = Karaoke
VCENT=True # Vertical Centre for ALIGN = 4 or 5 or 6 and SCROLL = 2 or 3
######################################
Lines=RT_TxtQueryLines(Txt)
MaxLen=TxtStrLenMax(Txt)
FontW=FontWidth(SIZEH)
XOFF=SCROLL==2?(ALIGN%3==0?MaxLen*FontW:(ALIGN+1)%3==0?MaxLen*FontW/2:0)
\ :((ALIGN+2)%3==0?MaxLen*FontW:(ALIGN+1)%3==0?MaxLen*FontW/2:0)
#
Last=(SCROLL==4)? ORG.Blankclip(height=80) : Last
CMD_0 = """Zubtitle(Txt,align=ALIGN,y=height+DELAY-current_frame,size=SIZEH,ExpY=true)"""
CMD_1 = """Zubtitle(Txt,align=ALIGN,y=-(Lines*SIZEH+DELAY) + current_frame,size=SIZEH,ExpY=true)"""
CMD_2 = """Zubtitle(Txt,align=ALIGN,x=width+XOFF+DELAY-current_frame,size=SIZEH,ExpX=True,VCent=VCENT)"""
CMD_3 = """Zubtitle(Txt,align=ALIGN,x=-(XOFF+DELAY)+current_frame,size=SIZEH,ExpX=true,VCent=VCENT)"""
CMD_4 = """Zubtitle(Txt,align=ALIGN,y=height+DELAY-current_frame,size=SIZEH,ExpY=true)"""
CMD_5 = """Zubtitle("BAD SCROLL COMMAND (0->4)")"""
CMD = (SCROLL<0 || SCROLL>4) ? CMD_5 : Select(Scroll,CMD_0,CMD_1,CMD_2,CMD_3,CMD_4)
ScriptClip(CMD)
Return (SCROLL==4)? StackVertical(ORG,Last) : Last

Was drivin me nuts trying to get it to work proper.

VCent, ExpX, and ExpY args same as in RT_Subtitle.

zerowalker
2nd August 2014, 00:52
How you are able to even keep check on such amounts of code is beyond me.

Impressive work, but what's new?
I looked at post 24 and this, both aren't the same, so a bit confused.

I missed the Demo with the "text scrolling up", not sure if that's been there all the time, but i like it;P

EDIT:

I tried it out in a clip where i intend to use Pixel text, looks pretty neat.
The lack of Font style and Haloing is sadly quite the hit. The pixel look is however as expected.

"Link's Awakening, Spoiler Alert*"
http://screenshotcomparison.com/comparison/86105

foxyshadis
2nd August 2014, 01:12
My hunch that a threshold would convert anything into a reasonable pixel font was correct, but on testing I found out that you don't even need to make it oversized. It works reasonably at any size. All defaults match those for Subtitle(), plus I added a little halo_size argument like you wanted. Right now it's a hell of a lot slower than SubTitle itself, because it does the work on every frame, instead of caching identical masks. But it works, so hey.


function AliasSub(clip c, string text, int "x", int "y", int "first_frame", int "last_frame", string "font", int "size", int "text_color", \
int "halo_color", int "align", int "spc", float "font_width", float "font_angle", bool "interlaced", int "halo_size") {
x = default(x,8)
y = default(y,0)
first_frame = default(first_frame,0)
last_frame = default(last_frame,c.framecount-1)
font = default(font,"Arial")
size = default(size,18)
text_color = default(text_color,$FFFF00)
halo_color = default(halo_color,$000000)
align = default(align,7)
spc = default(spc,0)
font_width = default(font_width,0.0)
font_angle = default(font_angle,0.0)
interlaced = default(interlaced,false)
halo_size = default(halo_size,3)

BlankClip(c, pixel_type="YV24", color=$000000)
base=last
subtitle(text,x=x,y=y,first_frame=first_frame,last_frame=last_frame,font=font,size=size,\
text_color=$ffffff,halo_color=$ff000000,align=align,spc=spc,font_width=font_width,\
font_angle=font_angle,interlaced=interlaced).ConvertToY8().mt_binarize(175).ConvertToYV24()
subbed=last
halomask=halo_expander(halo_size)
mt_merge(base,BlankClip(last, color=halo_color),halomask,luma=true,chroma="process")
mt_merge(last,BlankClip(last, color=text_color),subbed,luma=true,chroma="process")
mt_merge(c,last,halomask,luma=true,chroma="process")
}

function halo_expander(clip c, int iter) {
iter > 0 ? c.mt_expand().halo_expander(iter-1) : c
}

# Sample Use
YourClipSource()
ConvertToYV24()
AliasSub("The quick brown fox jumped over the dog.",font="Harrington",text_color=$800000,halo_color=$ccccff,halo_size=2,align=7,size=24)


Requires masktools2b1 (https://github.com/tp7/masktools/releases). YV24 only, no RGB. It could be converted to work with RGB if you need that.

You can play with the mt_binarize number to make fonts fatter or thinner. The one I chose just looked reasonable at smaller sizes.

zerowalker
2nd August 2014, 01:17
foxyshadis, so you are basically talking about undoing the AA afterwards, or am i missing something?

Splendid however, tried it, but i weird enough get an error about YV24.

mt_merge Luma is unsupported 422 and 444?

EDIT:

It works if Luma=false, and i also get a disco effect as a bonus;)

foxyshadis
2nd August 2014, 01:25
foxyshadis, so you are basically talking about undoing the AA afterwards, or am i missing something?

Splendid however, tried it, but i weird enough get an error about YV24.

mt_merge Luma is unsupported 422 and 444?

EDIT:

It works if Luma=false, and i also get a disco effect as a bonus;)

That's why it requires the masktools I linked. ;) Although the funky colors are fun to watch! And yeah, it just whacks the AA back into hard aliased text. A dumb but apparently effective way to do it.

zerowalker
2nd August 2014, 01:26
I already have it.
Hmm, guessing i have some conflict going about.

Will try clean up my plugins.

foxyshadis
2nd August 2014, 01:31
I already have it.
Hmm, guessing i have some conflict going about.

Will try clean up my plugins.

Ah, if you have the older mt_masktools2-26.dll, that'll take precedence. tp7 renamed his to just masktools2.dll.

zerowalker
2nd August 2014, 01:39
I had, well i just deleted all the masktools and kept the one you linked.

Was confused with all the names, they must have been there forever;P

Well here is a test.

http://i57.tinypic.com/wwhx8p.png

Top = Subtitles
Middle = AliasSub
Bottom = Standard without AA (outside of Avisynth, Photoshop in this case).

Resized by 300% with NearestNeighbor*

It's Not perfect, But it's close:)

Great Job!

EDIT:

Worth noting, the sizes aren't identical to the Photoshop, as Subtitles uses different sizes than normal fontsize*

pandy
5th August 2014, 13:18
Screenshot of this thread on my Commodore 64 with GEOS (https://en.wikipedia.org/wiki/GEOS_%288-bit_operating_system%29)*. Installing FireFox was tricky ;)

https://dl.dropboxusercontent.com/u/108089426/Screenshots/font-tt-pixel-04b03-dsg4-demo.png





* not really.

Next time give a chance to http://contiki-os.org/ on C64 ;)
http://contiki.cbm8bit.com/

Btw - i like http://damieng.com/blog/2008/08/25/the-xerox-alto-mono-spaced-font-rises-again from famous Xerox Alto machine - Apple made Macintosh based on Alto.

raffriff42
5th August 2014, 13:55
Thanks for the link, that's very interesting. My C64 is indisposed at the moment, being at the bottom of a landfill somewhere. It sure would be cool to see a screenshot of the contiki browser @ doom9.org (anybody?)