2016年12月27日 星期二

OTF轉TTF

google 的NotoSans字型,都只有OTF格式的,有些軟體只吃TTF,這樣就沒辦法用很麻煩,網路上有些地方有下載TTF格式的,但如果OTF那邊有更新就對應不到,因此想找個轉換方式。

後來找到這個指令

otfccdump input.otf | otfcc-c2q | otfccbuild -o output.ttf

otfccdump和 otfccbuild
來源是:
https://github.com/caryll/otfcc

前面是把otf轉成json,後面是把json build成ttf

中間的otfcc-c2q不確定是做什麼用的,感覺好像是把cubic轉成quad,但這個我在mac上一直裝不起來。
下載和安裝方法在:
https://github.com/caryll/otfcc-cubic2quad

我下npm install -g otfcc-c2q 在mac上裝完後,執行會有
這個env: node\r: No such file or directory問題,我再用dos2unix把裡面的js檔做轉換,結果又出現另一個 error
/usr/local/lib/node_modules/otfcc-c2q/ctq.js:65
var quadzs = cubicToQuad(z1.x, z1.y, z2.x, z2.y, z3.x, z3.y, z4.x, z4.y, 0.5);
                                                              ^

TypeError: Cannot read property 'x' of undefined

後來把otfcc-c2q拿掉,ttf一樣建得出來,所以不知會有什麼問題....


2015年12月4日 星期五

筆記 touch 設定

1.修改 /etc/system/config/scaling.conf
2.修改 /scirpts/hid-start.sh
 #usb touch
  devi-hid -P -r -R1024,768 touch;
 3.修改 /usr/lib/graphics/graphics.conf
  找到mtouch
    driver = devi
    options = height=768,width=1024,poll=1000
    display=1
 #   driver = lg-tsc101
 #   options = poll=1,verbose=3,skip_idle_disable=1,max_touchpoints=10

2015年9月18日 星期五

closure

之前在C#中聽過這個,但一直不知道是幹嘛用的。 現在又在lua中看到,想徹底了解一下。
    function newCounter ()
      local i = 0
      return function ()   -- anonymous function
               i = i + 1
               return i
             end
    end
    
    c1 = newCounter()
    print(c1())  --> 1
    print(c1())  --> 2

    c2 = newCounter()
    print(c2())  --> 1
    print(c1())  --> 3
    print(c2())  --> 2
這裡anonymous function使用了一個local variable i 去記count。但照理說已經離開了這個function的scope,這個i應該被清掉,而不是作用像個static variable。 這個i被視為一個up value 或又稱作是external local variable。 而當assign一個新的newCounter時,又會產生一個新的i。 "Technically speaking, what is a value in Lua is the closure, not the function. The function itself is just a prototype for closures." 因為 lua 的function被視為是first-class values。根據wiki 所謂的first-class function: "函數可以作為別的函數的參數、函數的返回值,賦值給變量或存儲在資料結構中。" 我想這種return anonymous function的做法像c1,c2 都被稱作是closure。 參考自 http://www.lua.org/pil/6.1.html

2015年4月8日 星期三

YUY420toRGB24 Shader

//shader
uniform sampler2D y_tex;
uniform sampler2D u_tex;
uniform sampler2D v_tex;
varying mediump vec2 vTexCoord;

const mediump vec3 R_cf = vec3(1.164383,  0.000000,  1.596027);
const mediump vec3 G_cf = vec3(1.164383, -0.391762, -0.812968);
const mediump vec3 B_cf = vec3(1.164383,  2.017232,  0.000000);
const mediump vec3 offset = vec3(-0.0625, -0.5, -0.5);
  
void main()
{
    precision mediump float;
    float y = texture2D(y_tex, vTexCoord).a;
    float u = texture2D(u_tex, vTexCoord).a;
    float v = texture2D(v_tex, vTexCoord).a;
    vec3 yuv = vec3(y,u,v);
    yuv += offset;
    gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
    gl_FragColor.r = dot(yuv, R_cf);
    gl_FragColor.g = dot(yuv, G_cf);
    gl_FragColor.b = dot(yuv, B_cf);
} 

//init
 result = kzuSharedImageTextureCreate(kzuUIDomainGetResourceManager(kzuObjectNodeGetUIDomain(layerNode)), "video Y texture", 
   KZU_TEXTURE_CHANNELS_ALPHA, VideoGetWidth(video), VideoGetHeight(video), KZ_NULL,
   KZ_NULL, KZ_FALSE, &videoPlayer->y_texture);

 kzuTextureSetFilter(kzuSharedImageTextureToTexture(videoPlayer->y_texture), KZU_TEXTURE_FILTER_POINT_SAMPLE);

 result = kzuSharedImageTextureCreate(kzuUIDomainGetResourceManager(kzuObjectNodeGetUIDomain(layerNode)), "video U texture", 
   KZU_TEXTURE_CHANNELS_ALPHA, VideoGetWidth(video)/2, VideoGetHeight(video)/2, KZ_NULL,
   KZ_NULL, KZ_FALSE, &videoPlayer->u_texture);

 kzuTextureSetFilter(kzuSharedImageTextureToTexture(videoPlayer->u_texture), KZU_TEXTURE_FILTER_POINT_SAMPLE);

 result = kzuSharedImageTextureCreate(kzuUIDomainGetResourceManager(kzuObjectNodeGetUIDomain(layerNode)), "video V texture", 
   KZU_TEXTURE_CHANNELS_ALPHA, VideoGetWidth(video)/2, VideoGetHeight(video)/2, KZ_NULL,
   KZ_NULL, KZ_FALSE, &videoPlayer->v_texture);

 kzuTextureSetFilter(kzuSharedImageTextureToTexture(videoPlayer->v_texture), KZU_TEXTURE_FILTER_POINT_SAMPLE);

 struct KzuPropertyType* y_tex = kzuPropertyRegistryFindPropertyType("y_tex");
 struct KzuPropertyType* u_tex = kzuPropertyRegistryFindPropertyType("u_tex");
 struct KzuPropertyType* v_tex = kzuPropertyRegistryFindPropertyType("v_tex");
 
 result = kzuObjectNodeSetResourceIDResourceProperty(layerNode, y_tex,  kzuSharedImageTextureToResource(videoPlayer->y_texture));
 result = kzuObjectNodeSetResourceIDResourceProperty(layerNode, u_tex,  kzuSharedImageTextureToResource(videoPlayer->u_texture));
 result = kzuObjectNodeSetResourceIDResourceProperty(layerNode, v_tex,  kzuSharedImageTextureToResource(videoPlayer->v_texture));


//update
  result = kzuSharedImageTextureLock(videoplayer->y_texture);
  result = kzuSharedImageTextureLock(videoplayer->u_texture);
  result = kzuSharedImageTextureLock(videoplayer->v_texture);
  kzsErrorForward(result);
  result = kzuSharedImageTextureUpdate(videoplayer->y_texture, (kzByte*)data[0], videoWidth * videoHeight);
  kzsErrorForward(result);

  result = kzuSharedImageTextureUpdate(videoplayer->u_texture, (kzByte*)data[1], videoWidth * videoHeight / 4);
  kzsErrorForward(result);
  result = kzuSharedImageTextureUpdate(videoplayer->v_texture, (kzByte*)data[2], videoWidth * videoHeight / 4);
  kzsErrorForward(result);
  result = kzuSharedImageTextureUnlock(videoplayer->y_texture);
  result = kzuSharedImageTextureUnlock(videoplayer->u_texture);
  result = kzuSharedImageTextureUnlock(videoplayer->v_texture);
  kzsErrorForward(result);

2015年3月23日 星期一

Kanzi 在QNX video capture的問題

本來想用Kanzi的記憶體管理來建立Capture buffer 的大小,參考vcapture的例子,影像是用SCREEN_FORMAT_YUY2的格式。

大小應該是width*height*2

但這樣做,一直有random的crash或是不正常的綠邊,後來改自行malloc,但也不正確,影像會抖得很厲害。


最後只能用它的screen來create,才會得到穩定的效果

rc = screen_get_buffer_property_pv(video->screen_buf[i], SCREEN_PROPERTY_POINTER, &(video->pointers[i]));

推測是抓回來的capture data不只有yuy2的data,可能還有些其它的東西,導致size不大一樣。


但是即使這樣,畫面仍會規律的抖動。印log一直有drop frame的狀況。

經過很多交叉測試,發現是我用軟體做yuy2 to RGB24,速度太慢,導致會抖動。

後來只能用Shader來做。

每個frame不做軟體decode,把raw的fame data 傳到shader裡。

return (kzByte*)video->pointers[buf_idx];

因為是yuy2的格式,剛好找到一個Nvidia的Demo有提供一個轉換的shader

首先在kanzi那建立format為KZU_TEXTURE_CHANNELS_LUMINANCE_ALPHA的貼圖。
result = kzuSharedImageTextureCreate(kzuUIDomainGetResourceManager(kzuObjectNodeGetUIDomain(layerNode)), "video texture",
KZU_TEXTURE_CHANNELS_LUMINANCE_ALPHA, VideoCaptureGetWidth(video), VideoCaptureGetHeight(video), KZ_NULL,
KZ_NULL, KZ_FALSE, &videoCapturePlayer->texture);

update時把它寫入
result = kzuSharedImageTextureUpdate(videoCapturePlayer->texture, data, videoWidth * videoHeight * 2);


uniform sampler2D Texture;
uniform sampler2D TextureMask;
uniform lowp float BlendIntensity;
uniform lowp vec4 Ambient;
varying mediump vec2 vTexCoord;
varying highp vec2 vScreenPos;

// CCIR 601 standard
const mediump vec3 std601R = vec3(  1.0, -0.00092674, 1.4017        );
const mediump vec3 std601G = vec3(  1.0, -0.3437,    -0.71417    );
const mediump vec3 std601B = vec3( 1.0,  1.7722,     0.00099022         );
const mediump vec4 stdbias = vec4(  0, -0.5,       -0.5, 0       );

void main()
{
    precision mediump float;
 vec2 uv0, uv1;    
    float SrcTexWidth=720.0;
    float texel_sample = 1.0 / (SrcTexWidth);
    //float isOddUV = floor(fract((vTexCoord.x * SrcTexWidth) * 0.5) * 2.0);
    float isOddUV = fract(floor(vTexCoord.x * SrcTexWidth) * 0.5) * 2.0;
    uv0 = vTexCoord;
    uv1 = vTexCoord;
 //   vec2 screen_uv = vScreenPos.xy/vScreenPos.w;
  //  screen_uv = (screen_uv.xy + vec2(1.0)) / 2.0;
    // If (x,y) address is ODD,  then we need the (x-1,y) sample to decode it
    // If (x,y) address is EVEN, then we need the (x+1,y) sample to decode it.
 uv0.x = vTexCoord.x - (isOddUV * texel_sample);
 uv1.x = vTexCoord.x + texel_sample;
 uv1.y = vTexCoord.y;

 // we sample the neighboring texture samples
 vec4 texColor0 = texture2D( Texture, uv0 );
 vec4 texColor1 = texture2D( Texture, uv1 );
 vec4 mask = texture2D(TextureMask,vScreenPos);
 // For A8L8, assume A8<-alpha L8<-rgb
 texColor0.r = texColor0.r; // assign Y0 (1st position) automatic
 texColor0.g = texColor0.a; // assign U0 (2nd position)
 texColor0.b = texColor1.a; // assign V0 (3rd position)
 
 texColor1.r = texColor1.r; // assign Y1 (1st position) automatic
 texColor1.g = texColor0.a; // assign U0 (2nd position)
 texColor1.b = texColor1.a; // assign V0 (3rd position)
 
 // assume RGBA0 (Y0 U0)
 // assume RGBA1 (Y1 V0)
    // Let's just average the luma, to make it simple 
 texColor0 += stdbias;
 texColor0 *= (1.0-isOddUV);

 // assume RGBA0 (Y0 U0)
 // assume RGBA1 (Y1 V0)
 texColor1 += stdbias; 
 texColor1 *= (isOddUV);
 
 texColor0 = texColor0 + texColor1;
 vec4 color = vec4((texColor0.r + 1.37075*texColor0.b),
         (texColor0.r - (0.698001 *texColor0.b-0.337633*texColor0.g)),
           (texColor0.r +  1.73246*texColor0.g),
           1.0 );
           
    //vec4 color = vec4(dot(std601R, texColor0.rgb),
        //   dot(std601G, texColor0.rgb),
        //   dot(std601B, texColor0.rgb),
        //   1.0 );
   gl_FragColor.rgba = clamp(color.rgba,0.0,1.0);// *Ambient* BlendIntensity;
   gl_FragColor.a *=  ((1.0-mask.a));
    
}

不過,出來的顏色很奇怪。試了不同的轉換matrix都一樣,只好展開用微調的...猜測可能是kanzi在寫入sharetexutre時有做gamma correct,因為我找不到地方可以關掉,也不知道它有沒做,文件裡沒寫,只好先將就一下了...

2014年11月12日 星期三

QNX graphic path on vmware

整理筆記一下....
QNX® Software Development Platform 6.6 Graphics Patch [Patch ID 3875]

download下來後在pc上
參考
在command line執行下面bat設定環境變數
base_directory\qnx660-env.bat
再apply patch
applypatch -F download_path/patch-660-3875-660-Graphics-GA.tar

vmware上設置

1‧設定環境變數
  export GRAPHICS_ROOT=/usr/lib/graphics/vmware/
  export LD_LIBRARY_PATH=/usr/lib:/lib:/lib/dll:$GRAPHICS_ROOT:$LD_LIBRARY_PATH

2.copy patch的file到vmware。
  我先mount到pc下的share,並把相關的patch檔copy過去。

cp -f etc/system/config/scaling.conf /etc/system/config/scaling.conf
cp -f usr/share/gles/textures/brick_wall.tga /usr/share/gles/textures/brick_wall.tga
cp -f usr/share/gles/textures/bubble.png /usr/share/gles/textures/bubble.png
cp -f usr/share/images/wallpaper.jpg /usr/share/images/wallpaper.jpg
cp -f x86/bin/screeninfo /bin/screeninfo
cp -f x86/lib/dll/libwfdcfg-sample.so /lib/dll/libwfdcfg-sample.so
cp -f x86/lib/dll/screen-gles1.so /lib/dll/screen-gles1.so
cp -f x86/lib/dll/screen-gles2blt.so /lib/dll/screen-gles2blt.so
cp -f x86/lib/dll/screen-gles2.so /lib/dll/screen-gles2.so
cp -f x86/lib/dll/screen-sw.so /lib/dll/screen-sw.so
cp -f x86/lib/libgestures.so.1 /lib/libgestures.so.1
cp -f x86/lib/libinputevents.so.1 /lib/libinputevents.so.1
cp -f x86/lib/libkalman.so.1 /lib/libkalman.so.1
cp -f x86/lib/libmtouch-calib.so.1 /lib/libmtouch-calib.so.1
cp -f x86/lib/libmtouch-devi.so.1 /lib/libmtouch-devi.so.1
cp -f x86/lib/libmtouch-fake.so.1 /lib/libmtouch-fake.so.1
cp -f x86/lib/libmtouch-inject.so.1 /lib/libmtouch-inject.so.1
cp -f x86/sbin/gpu_drv /sbin/gpu_drv
cp -f x86/sbin/screen /sbin/screen
cp -f x86/usr/bin/calib-touch /usr/bin/calib-touch
cp -f x86/usr/bin/display_image /usr/bin/display_image
cp -f x86/usr/bin/egl-configs /usr/bin/egl-configs
cp -f x86/usr/bin/events /usr/bin/events
cp -f x86/usr/bin/font-freetype /usr/bin/font-freetype
cp -f x86/usr/bin/gles1-gears /usr/bin/gles1-gears
cp -f x86/usr/bin/gles2-gears /usr/bin/gles2-gears
cp -f x86/usr/bin/gles2-maze /usr/bin/gles2-maze
cp -f x86/usr/bin/gpudbg /usr/bin/gpudbg
cp -f x86/usr/bin/print-gestures /usr/bin/print-gestures
cp -f x86/usr/bin/screenshot /usr/bin/screenshot
cp -f x86/usr/bin/sw-vsync /usr/bin/sw-vsync
cp -f x86/usr/bin/vkey /usr/bin/vkey
cp -f x86/usr/bin/yuv-test /usr/bin/yuv-test
cp -f x86/usr/lib/graphics/vmware/graphics.conf /usr/lib/graphics/vmware/graphics.conf
cp -f x86/usr/lib/graphics/vmware/libAtcDecompressor.so /usr/lib/graphics/vmware/libAtcDecompressor.so
cp -f x86/usr/lib/graphics/vmware/libAtcDecompressor.so.1 /usr/lib/graphics/vmware/libAtcDecompressor.so.1
cp -f x86/usr/lib/graphics/vmware/libegl_gallium.so /usr/lib/graphics/vmware/libegl_gallium.so
cp -f x86/usr/lib/graphics/vmware/libHwEGL.so /usr/lib/graphics/vmware/libHwEGL.so
cp -f x86/usr/lib/graphics/vmware/libHwglapi.so /usr/lib/graphics/vmware/libHwglapi.so
cp -f x86/usr/lib/graphics/vmware/libHwGLESv1_CM_g.so /usr/lib/graphics/vmware/libHwGLESv1_CM_g.so
cp -f x86/usr/lib/graphics/vmware/libHwGLESv1_CM.so /usr/lib/graphics/vmware/libHwGLESv1_CM.so
cp -f x86/usr/lib/graphics/vmware/libHwGLESv2.so /usr/lib/graphics/vmware/libHwGLESv2.so
cp -f x86/usr/lib/graphics/vmware/libHwGPU.so /usr/lib/graphics/vmware/libHwGPU.so
cp -f x86/usr/lib/graphics/vmware/libHwWFDvmware.so /usr/lib/graphics/vmware/libHwWFDvmware.so
cp -f x86/usr/lib/graphics/vmware/libllvmpipe_drv.so /usr/lib/graphics/vmware/libllvmpipe_drv.so
cp -f x86/usr/lib/graphics/vmware/libmesa_texcompress_atc.so /usr/lib/graphics/vmware/libmesa_texcompress_atc.so
cp -f x86/usr/lib/graphics/vmware/libmesa_texcompress_pvrt.so /usr/lib/graphics/vmware/libmesa_texcompress_pvrt.so
cp -f x86/usr/lib/graphics/vmware/libmesa_texcompress.so /usr/lib/graphics/vmware/libmesa_texcompress.so
cp -f x86/usr/lib/graphics/vmware/libpipe_vmwgfx_drv.so /usr/lib/graphics/vmware/libpipe_vmwgfx_drv.so
cp -f x86/usr/lib/graphics/vmware/libst_HwGL_g.so /usr/lib/graphics/vmware/libst_HwGL_g.so
cp -f x86/usr/lib/graphics/vmware/libst_HwGL.so /usr/lib/graphics/vmware/libst_HwGL.so
cp -f x86/usr/lib/graphics/vmware/libvmwsvga.so /usr/lib/graphics/vmware/libvmwsvga.so
cp -f x86/usr/lib/libEGL.so.1 /usr/lib/libEGL.so.1
cp -f x86/usr/lib/libGLESv1_CL.so.1 /usr/lib/libGLESv1_CL.so.1
cp -f x86/usr/lib/libGLESv1_CM.so.1 /usr/lib/libGLESv1_CM.so.1
cp -f x86/usr/lib/libGLESv2.so.1 /usr/lib/libGLESv2.so.1
cp -f x86/usr/lib/libscreen.so.1 /usr/lib/libscreen.so.1
cp -f x86/usr/lib/libswblit.so.1 /usr/lib/libswblit.so.1
cp -f x86/usr/lib/libWFD.so.1 /usr/lib/libWFD.so.1
cp -f x86/lib/libgestures.so /lib/libgestures.so
cp -f x86/lib/libinputevents.so /lib/libinputevents.so
cp -f x86/lib/libkalman.so /lib/libkalman.so
cp -f x86/lib/libmtouch-calib.so /lib/libmtouch-calib.so
cp -f x86/lib/libmtouch-devi.so /lib/libmtouch-devi.so
cp -f x86/lib/libmtouch-fake.so /lib/libmtouch-fake.so
cp -f x86/lib/libmtouch-inject.so /lib/libmtouch-inject.so
cp -f x86/usr/lib/libEGL.so /usr/lib/libEGL.so
cp -f x86/usr/lib/libGLESv1_CL.so /usr/lib/libGLESv1_CL.so
cp -f x86/usr/lib/libGLESv1_CM.so /usr/lib/libGLESv1_CM.so
cp -f x86/usr/lib/libGLESv2.so /usr/lib/libGLESv2.so
cp -f x86/usr/lib/libscreen.so /usr/lib/libscreen.so
cp -f x86/usr/lib/libswblit.so /usr/lib/libswblit.so
cp -f x86/usr/lib/libWFD.so /usr/lib/libWFD.so
echo "Done!"

注意: 如果從window上編輯上面的成為.sh執行的話,記得要改換行字元,不然到QNX上時檔名結尾會多一個^M。在notepad ++ 的檔案格式轉換可改成unix就不會有這問題。

再執行
gpu_drv
screen
即可



2014年9月29日 星期一

Kanzi: Render Transparent Objects


在Kanzi裡畫半透明物件,比想像中麻煩一點,因為它不是你把物件用半透明材質,然後給個Transparent Queue就會幫你排序做好。

首先,必須在Composing > Pipeline 裡,加一個Property is Equal Filter。在Property Type選blendMode,Operation 選Include,Blend Mode選你的半透明物件所在的Mode。(這邊在弄時有發生怪事,Blend Mode怎麼設都不鳥我,preview視窗重開好幾次也沒用,後來不知怎突然可以用了...)

另一個要注意的點是,它是照物件上的Property排,所以你把BlendMode在Material裡設好,以為用了這個Material就會知道這個屬性。別傻了,它會當你是Opaque的物件....

接者同上步驟建一個畫Opaque的Filter。

然後在Composer建2個render pass 第一個畫Opaque物件。第二個畫半透明的Filter。(在Render Pass的Object Source選剛才的Filter)。把Color Buffer :Clear Enable > false, Depth Buffer: Clear Enable > False,Test Enable打開,Write Enable關掉。


發現怪事了嗎?

ZTest、ZWrite、甚至是Back , Front Culling不在Material上,而是在Render Pass上...WTF....Material要是複雜一點,不是要用一堆Render Pass..... 想到頭皮就發麻....

設完後,疑....排序怎是錯的....原來排序要自己再建一個Sorting Filter,Filter的Source選剛才的Transparent objects。同理,如果用到Tag Filter的話...我已經不敢想那個排列組合了.....