TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua

 找回密码
 新人加入
查看: 6962|回复: 24

[已解决] PixTexture color! [复制链接]

Rank: 4

发表于 2013-11-3 15:09:09 |显示全部楼层
When I'm using PixTexture the colors of the syllable some of them not same, some of them have more alpha


Untitled32.png


before in NyuFx have same problem but Youka have fixed

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2013-11-3 19:51:37 |显示全部楼层
The problem is because in PixTexture() function, the size of PIX_tex will be resampled to meet the PIX_txt, so, if the size of text PIX varies, the looks of PIX_texture will be different.

how to resolve the issue,
immediately, we've got two ways
1. enlarge PIX_txt (by invoking PixEnlarge() function) to meet the size of PIX_txt
2. create a PIX_tex for each PIX_txt, according to the size of PIX_txt (using PixCrop() function to cut a piece from the original PIX_tex and make a new one, then pass it to PixTexture() function)


Rank: 4

发表于 2013-11-3 21:20:39 |显示全部楼层
本帖最后由 Alex 于 2013-11-3 21:21 编辑

OK

I don't know actually which function have to write first..

this is the code
  1.     PIX_t = TextPix(Font, _txt)            
  2.    
  3.     dx = _x - int(_a / 2 + 0.5) + PIX_t[0][0]
  4.     dy = _y - int(_Fs / 2 + 0.5) + PIX_t[0][1]
  5.     dur = _KT * 10

  6.     PIX_t = PixTexture(PIX_t, PIX_tex)     
  7.     PIX_out = TextPix(FontOut, _txt)      
  8.     PIX_out = PixTexture(PIX_out, PIX_tex2)
  9.     PIX_out = PixColorMul(PIX_out, 1, 1, 1, 0)   
  10.     PIX_out = PixBlur(PIX_out, 0)           
  11.     PIX_ori = CombinePixs(PIX_out, PIX_t)   
  12.     points = PixPoints(PIX_ori)
  13.     pt_num = len(points)
复制代码
and as you said i have to use PixEnlarge(PIX,x,y) function and  PixCrop(pix, left, top, right, bottom)

pix = it will be the path on pic right?
x & y is a normal position (_x,_y) or pixs position
pixx = _x - int(_a / 2 + 0.5) + PIX_t[0][0]
pixy = _y - int(_Fs / 2 + 0.5) + PIX_t[0][1])

?

and regarding PixCrop function , pix I think is a path of pic right?!
and what should Instead of (left, top, right, bottom) write?

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2013-11-3 21:28:05 |显示全部楼层
Alex 发表于 2013-11-3 21:20
OK

I don't know actually which function have to write first..

check it out on this documentation http://www.tcax.org/docs/tcaxLib/namespacemembers_func.html

PIX is a Python structure (object), and can be passed through Pix.... functions, http://www.tcax.org/forum.php?mod=viewthread&tid=220   (unfortunately, this doc is written in Chinese)

We have several ways to create a PIX object, such as TextPix, (create a PIX from text with specified font), BlankPix (a blank square), and pmgToPix (created a PIX from magick image object).

other functions are to manipulate the PIX object, such as PixBlur, PixTexture.


so, when applying the second approach,

PIX_out = PixTexture(PIX_out, PIX_tex2)

can be

PIX_out = PixTexture(PIX_out, PixCrop(PIX_tex2, 0, 0, PIX_out[1][0], PIX_out[1][1]))

the four parameters can be chose by your decision


Rank: 4

发表于 2013-11-3 22:51:46 |显示全部楼层
本帖最后由 Alex 于 2013-11-3 22:57 编辑

Thank you very much
it's ok now



Rank: 4

发表于 2013-11-4 22:41:22 |显示全部楼层
本帖最后由 Alex 于 2013-11-4 22:41 编辑

I have another 2 question

Why the position it's not exactly correct, there is space between letters?

---

and my second question, if the line(text) position in Aegisub is alignment 7 or 9
when i'm using this postion >>
  1.         dx = _x - int(_a / 2 + 0.5)        
  2.         dy = _y - int(_Fs / 2 + 0.5)      
复制代码
the line (text) it will be in the center of video (an8), what is the right position for alignment7 and 9?

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2013-11-4 23:27:46 |显示全部楼层
Alex 发表于 2013-11-4 22:41
I have another 2 question

Why the position it's not exactly correct, there is space between letter ...
Why the position it's not exactly correct, there is space between letters?


Plz post an image to help me understand your question.


to your 2nd question

see the info below

< alignment = 7 >
#  indicate where to put the texts, you can refer to the number keyboard. Default alignment for horizontal layout is an1, default alignment for vertical layout is an9


the alignment set in the TCC file only affects the Offset of the line.
use an() tag function to apply an alignment effect for your FX

Rank: 4

发表于 2013-11-5 12:25:47 |显示全部楼层

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2013-11-5 22:18:53 |显示全部楼层
Alex 发表于 2013-11-5 12:25

any description? I can't get your meaning from the pic

Rank: 4

发表于 2013-11-5 23:11:06 |显示全部楼层
本帖最后由 Alex 于 2013-11-5 23:52 编辑

When i used pixel, I got some space between letters, I think it's happening for pixels
you can see the pic, and you will see there is a space between letters

anyway it's ok

Thank you for your patience with me, it's just a testing XD

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2013-11-7 20:48:41 |显示全部楼层
Alex 发表于 2013-11-5 23:11
When i used pixel, I got some space between letters, I think it's happening for pixels
you can see  ...


the text layout, in the horizontal direction, letters are put with 'advance' distance between each other. not just incremented by just 'width', so there may be space between letters.

you can find more information about text layout, by Googling FreeType Text Layout

glyph

glyph

Rank: 4

发表于 2013-11-8 00:34:46 |显示全部楼层
I knew what is the problem before ur answer , thank you =D

Rank: 4

发表于 2013-11-12 18:28:27 |显示全部楼层
milky!

How can I use width & height to get metrics of text?

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2013-11-12 22:55:23 |显示全部楼层
Alex 发表于 2013-11-12 18:28
milky!

How can I use width & height to get metrics of text?


if you have a PIX object, there is a quick way to get width and height
  1. width = PIX[1][0]
  2. height = PIX[1][1]
复制代码
if you want to get the pre-calculated metrics of texts, use
  1. # tm info (horizontal)
  2. val_Ascender         = 33        # 字体上行高度
  3. val_Descender        = 34        # 字体下行高度 通常为负数
  4. val_TextWidth        = 35        # 第i句卡拉OK歌词的j个字符的宽度
  5. val_TextHeight       = 36        # 第i句卡拉OK歌词的j个字符的高度
  6. val_TextKerning      = 37        # 第i句卡拉OK歌词的j个字符与之前一个字符的kerning 一句歌词第一个字符的kerning为0
  7. val_TextAdvance      = 38        # 第i句卡拉OK歌词的j个字符的水平步距
  8. val_TextAdvanceDiff  = 39        # 从初始位置到第i句卡拉OK歌词的j个字符的水平步距
  9. val_TextLength       = 40        # 第i句卡拉OK歌词的文字总长度
  10. val_TextInitX        = 41        # 第i句卡拉OK歌词的j个字符的左上角X轴坐标
  11. val_TextInitY        = 42        # 第i句卡拉OK歌词的j个字符的左上角Y轴坐标
  12. val_TextBearingY     = 43        # 第i句卡拉OK歌词的j个字符的Y轴bearing
复制代码
e.g.width of the text in the i(th) line j(th) \k tag,
  1. width = GetVal(val_TextWidth)[i][j]
复制代码
the last but least common way is to use

## Initialize a font and retrieves the metrics of the specified text from the font.
# @param font_file a string, filename of the target font file
# @param face_id an integer, font face id, should always be 1 in TTF files
# @param font_size an integer, font size, in em height
# @param spacing an integer, spacing between texts, can be negative
# @param space_scale a float, scale of white spaces
# @param text a string, the text that is going to be measured
# @return (0 width, 1 height, 2 horiBearingX, 3 horiBearingY, 4 horiAdvance, 5 vertBearingX, 6 vertBearingY, 7 vertAdvance, 8 x_ppem, 9 y_ppem, 10 x_scale, 11 y_scale, 12 ascender, 13 descender, 14 px_height, 15 max_advance)
def TextMetrics(font_file, face_id, font_size, spacing, space_scale, text):

## Retrieve the metrics of the specified text from a font.
# @param font a handler, the handler to the font
# @param text a string, the text that is going to generate a PIX
# @return (0 width, 1 height, 2 horiBearingX, 3 horiBearingY, 4 horiAdvance, 5 vertBearingX, 6 vertBearingY, 7 vertAdvance, 8 x_ppem, 9 y_ppem, 10 x_scale, 11 y_scale, 12 ascender, 13 descender, 14 px_height, 15 max_advance)
def TextMetrics(font, text):



APIs from tcaxLib module can be found on http://www.tcax.org/docs/tcaxLib/namespacemembers_func.html

mofe info about PIX, and TCAS FX, http://www.tcax.org/forum.php?mod=viewthread&tid=220, if I not showed you this link before

Rank: 4

发表于 2013-11-13 18:03:19 |显示全部楼层
本帖最后由 Alex 于 2013-11-13 18:31 编辑

Ok

I'm trying to make a square clip by using text metrics ( Height & width Only)
but I got a problem -_-



Why I can't use %d ?


Im using a normal "\k"
  1. from tcaxPy import *


  2. def tcaxPy_Init():
  3.     global _FD                              
  4.     global _Blur
  5.     global _text
  6.     global _textLength
  7.     global _width
  8.     global _height
  9.     global _advance
  10.     global _fx_width
  11.     global _fx_height

  12.     _fx_width = GetVal (val_ResolutionX)
  13.     _fx_height = GetVal (val_ResolutionY)
  14.     _text = GetVal (val_Text)
  15.     _textLength = GetVal (val_TextLength)
  16.     _width = GetVal(val_TextWidth)
  17.     _height = GetVal (val_TextHeight)
  18.     _advance = GetVal (val_TextAdvance)
  19.     _FD = 1000 / GetVal(val_FXFPS)
  20.     _Blur = GetVal(val_Blur)


  21. def tcaxPy_Fin():
  22.     pass



  23. def tcaxPy_Main(_i, _j, _n, _start, _end, _elapk, _k, _x, _y, _a, _txt):
  24.     ASS_BUF  = []         
  25.     TCAS_BUF = []      

  26.     x = _x
  27.     y = _y

  28.     text = "{\\pos(%d,%d)\\clip(m %d %d l %d %d l %d %d)} " % (x,y, _width[_i],y-10,x+10,y-10,x+10,y+10)
  29.     text1 = "{\\pos(%d,%d)}%s" % (x,y,_txt)
  30.     ass_main(ASS_BUF, SubL(_start , _end , 2), '', text)
  31.     ass_main(ASS_BUF, SubL(_start , _end , 2), '', text1)                           

  32.     return (ASS_BUF, TCAS_BUF)
复制代码

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2013-11-13 22:01:56 |显示全部楼层
Alex 发表于 2013-11-13 18:03
Ok

I'm trying to make a square clip by using text metrics ( Height & width Only)

then you can try "%i" xD

or a more python 3k way, using the string format function
  1. def t1(t1, t2, code):    # deprecated
  2.     return '\\t({0},{1},{2})'.format(int(t1), int(t2), code)

  3. def t(a1, a2 = None, a3 = None, a4 = None):
  4.     if a2 == None:
  5.         return '\\t({code})'.format(code = a1)
  6.     elif a3 == None:
  7.         if a1 == int(a1):
  8.             A = str(int(a1))
  9.         else:
  10.             A = str(format(a1, '.2f'))
  11.         return '\\t({a},{code})'.format(a = A, code = a2)
  12.     elif a4 == None:
  13.         return '\\t({t1},{t2},{code})'.format(t1 = int(a1), t2 = int(a2), code = a3)
  14.     else:
  15.         if a3 == int(a3):
  16.             A = str(int(a3))
  17.         else:
  18.             A = str(format(a3, '.2f'))
  19.         return '\\t({t1},{t2},{a},{code})'.format(t1 = int(a1), t2 = int(a2), a = A, code = a4)
复制代码
you can find these ASS tag functions in tcaxPy.py under the TCAX's root directory.

Rank: 4

发表于 2013-11-14 15:16:28 |显示全部楼层


Nothing happened ,  saying that %i same %d +_+
I tested everything, doesn't solve my problem!

Administrator

Shanzhai Pro.

Rank: 7Rank: 7Rank: 7

发表于 2013-11-14 18:11:51 |显示全部楼层
Alex 发表于 2013-11-14 15:16
Nothing happened ,  saying that %i same %d +_+
I tested everything, doesn't solve m ...

change _width[_i] to _width[_i] [_j]

Rank: 4

发表于 2013-11-14 20:07:14 |显示全部楼层
as I remember I have did that _width[_i] [_j]
anyway I will see again

Administrator

Shanzhai Pro.

Rank: 7Rank: 7Rank: 7

发表于 2013-11-14 21:19:06 |显示全部楼层
Alex 发表于 2013-11-14 20:07
as I remember I have did that _width[_i] [_j]
anyway I will see again

Are you sure?
您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-3-29 01:26

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH