嵌入式开发之字符叠加---gb2313 国标码,utf8 国际码,unicode 无码

(1)国标码简介

(2)编码转换

(3)时间获取

(4)显示切换

  最近做了个字符叠加,包括时间叠加,字符中文叠加,位置移动,等功能开启。因为一般的字符叠加的点阵式16位,然后填充着16位的编码是gb2313编码,比如说视讯两个字,

先是视:

编码类型 二进制编码 十六进制编码
Unicode 10001001 11000110 0x89C6
UTF-8 11101000 10100111 10000110 0xE8A786
GB2312 11001010 11010011 0xCAD3

然后讯:

编码类型 二进制编码 十六进制编码
Unicode 10001011 10101111 0x8BAF
UTF-8 11101000 10101110 10101111 0xE8AEAF
GB2312 11010001 10110110 0xD1B6

gb2313国标是占用两个字节一个字,国际标utf8是三个字节一个字,

http://lijunlisu.blog.163.com/blog/static/1639814282012710101844158/

http://www.cnblogs.com/windtail/archive/2012/08/26/2657485.html

http://baike.baidu.com/link?url=CNP55LTT8JmvtkmmQm_Jy-KOLa2zh0_LtTqMpNDL_wepPK3gcqVHpRuX1USESsO4yPC_haMoplNMz34qspE0hK 汉子国标码

然后网页端提交过来给web 服务器的cgi 收到的数据是utf8而且字体间还带百分号间隔符,

编码换算在线查找网站:

http://www.mytju.com/classcode/tools/encode_gb2312.asp

http://www.2fz1.com/so/

(2)编码换算

  由于web端获取的文字编码是utf8,而点阵用的是gb2314,这里的坐下换算,将16进制的字符串转换成对应的数字!

将一个十六进制数的字符串表示形式转换成对应的整数。所谓的十六进制数的字符串形式是指字符串只包含'0'-'9'或者'a'-'z'或者'A'-'Z',前导“0x”或者“0X”是否出现都可以。

    要解决这个问题,还需要一个将大写字母转换成小写字母的工具函数:

  1. /*将大写字母转换成小写字母*/ 
  2. int tolower(int c) 
  3.     if (c >= 'A' && c <= 'Z') 
  4.     { 
  5.         return c + 'a' - 'A'; 
  6.     } 
  7.     else 
  8.     { 
  9.         return c; 
  10.     } 

    下面是转换函数:

  1. //将十六进制的字符串转换成整数 
  2. int htoi(char s[]) 
  3.     int i; 
  4.     int n = 0; 
  5.     if (s[0] == '0' && (s[1]=='x' || s[1]=='X')) //判断是否有前导0x或者0X
  6.     { 
  7.         i = 2; 
  8.     } 
  9.     else 
  10.     { 
  11.         i = 0; 
  12.     } 
  13.     for (; (s[i] >= '0' && s[i] <= '9') 
  14. || (s[i] >= 'a' && s[i] <= 'z') || (s[i] >='A' && s[i] <= 'Z');++i) 
  15.     {  
  16.         if (tolower(s[i]) > '9')
  17.         { 
  18.             n = 16 * n + (10 + tolower(s[i]) - 'a'); 
  19.         } 
  20.         else 
  21.         { 
  22.             n = 16 * n + (tolower(s[i]) - '0'); 
  23.         } 
  24.     } 
  25.     return n; 
  26. }
  27.  编码转换:
  28. void UTF_8ToUnicode(wchar_t* pOut,char *pText)
    {
    char* uchar = (char *)pOut;
    uchar[1] = ((pText[0] & 0x0F) << 4) + ((pText[1] >> 2) & 0x0F);
    uchar[0] = ((pText[1] & 0x03) << 6) + (pText[2] & 0x3F);
    }
    void UnicodeToUTF_8(char* pOut,wchar_t* pText)
    {
    // 注意 WCHAR高低字的顺序,低字节在前,高字节在后
    char* pchar = (char *)pText;
    pOut[0] = (0xE0 | ((pchar[1] & 0xF0) >> 4));
    pOut[1] = (0x80 | ((pchar[1] & 0x0F) << 2)) + ((pchar[0] & 0xC0) >> 6);
    pOut[2] = (0x80 | (pchar[0] & 0x3F));
    }
    void UnicodeToGB2312(char* pOut,wchar_t uData)
    {
    WideCharToMultiByte(CP_ACP,NULL,&uData,1,pOut,sizeof(wchar_t),NULL,NULL);
    }
    void Gb2312ToUnicode(wchar_t* pOut,char *gbBuffer)
    {
    ::MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,gbBuffer,2,pOut,1);
    }
    void GB2312ToUTF_8(string& pOut,char *pText, int pLen)
    {
    char buf[4] = {0};
    int nLength = pLen* 3;
    char* rst = new char[nLength];
    memset(rst,0,nLength);
    int i = 0 ,j = 0;
    while(i < pLen)
    {
    //如果是英文直接复制就可以
    if( *(pText + i) >= 0)
    {
    rst[j++] = pText[i++];
    }
    else
    {
    wchar_t pbuffer;
    Gb2312ToUnicode(&pbuffer,pText+i);
    UnicodeToUTF_8(buf,&pbuffer);
    rst[j] = buf[0];
    rst[j+1] = buf[1];
    rst[j+2] = buf[2];
    j += 3;
    i += 2;
    }
    }

    rst[j] ='\n'; //返回结果
    pOut = rst;
    delete []rst;
    return;
    }
    void UTF_8ToGB2312(char*pOut, char *pText, int pLen)
    {
    char Ctemp[4];
    memset(Ctemp,0,4);
    int i =0 ,j = 0;
    while(i < pLen)
    {
    if(pText[i] >= 0)
    {
    pOut[j++] = pText[i++];
    }
    else
    {
    WCHAR Wtemp;
    UTF_8ToUnicode(&Wtemp,pText + i);
    UnicodeToGB2312(Ctemp,Wtemp);
    pOut[j] = Ctemp[0];
    pOut[j + 1] = Ctemp[1];
    i += 3;
    j += 2;
    }
    }
    pOut[j] ='\n';
    return;
    }

  29.  

    当然后面还有已经实现的现成的代码 

http://www.linuxidc.com/Linux/2012-01/51571.htm

http://blog.163.com/lyq_163_2009/blog/static/13408269620116752322992/

http://blog.csdn.net/yeyuangen/article/details/6722193

http://blog.csdn.net/searchsun/article/details/2443867 yuv格式详解

http://www.cnblogs.com/skywang12345/p/3360348.html

http://blog.csdn.net/shen_001/article/details/7785713 opengl

http://blog.csdn.net/shen_001/article/details/7818972 

http://blog.csdn.net/hitexam/article/details/5996607

(3)时间获取

a8 linux 端的时间获取容易直接调用localtime函数,但是dsp m3端的数据获取则只能通过util_time,获取自开机开始的定时时间,并没有从a8端获取准确时间,做的时候以为dsp端能获取时间,后面发现没有时间获取,发现之前的ipnc也是从a8端通过消息发送过来的,所以最后也是通过数据结构体把整个时间获取过来从dsp,

dsp 端的秒换算:

/*
* 毫秒转化
*/
public static String formatTime(long ms) {
            
             int ss = 1000;
             int mi = ss * 60;
             int hh = mi * 60;
             int dd = hh * 24;

             long day = ms / dd;
             long hour = (ms - day * dd) / hh;
             long minute = (ms - day * dd - hour * hh) / mi;
             long second = (ms - day * dd - hour * hh - minute * mi) / ss;
             long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;

             String strDay = day < 10 ? "0" + day : "" + day; //天
             String strHour = hour < 10 ? "0" + hour : "" + hour;//小时
             String strMinute = minute < 10 ? "0" + minute : "" + minute;//分钟
             String strSecond = second < 10 ? "0" + second : "" + second;//秒
             String strMilliSecond = milliSecond < 10 ? "0" + milliSecond : "" + milliSecond;//毫秒
             strMilliSecond = milliSecond < 100 ? "0" + strMilliSecond : "" + strMilliSecond;
            
             return strMinute + " 分钟 " + strSecond + " 秒";
   }

http://www.educity.cn/wenda/307912.html

http://blog.csdn.net/fuxiaohui/article/details/25505823

http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/717/p/300747/1048610

http://www.deyisupport.com/question_answer/dsp_arm/davinci_digital_media_processors/f/39/t/67246.aspx 潘哥哥 吼吼!

http://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=8148%20m3%20time&rsv_pq=bda1d8430003d3c6&rsv_t=b4a1GGNFu6c4DQJDxpoJ24o5SVfYK1%2BUvQhz4DOtkNLPQrCQ0P5%2FsAlbY6k&rsv_enter=1&inputT=1233&rsv_sug3=25&rsv_sug4=2728&rsv_sug2=0

http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/717/t/271976

http://www.360doc.com/content/12/0306/17/19692_192255025.shtml

http://net.pku.edu.cn/~yhf/linux_c/function/02.html

http://blog.donews.com/quickmouse/archive/2008/05/08/1287733.aspx

http://blog.donews.com/quickmouse/archive/2008/05/08/1287733.aspx

(4)显示切换

  这次做布局显示切换时发现,48的功能还是挺强大的,可以做任意矩形图布局,而且还可以做屏幕叠加。

http://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=8148%20m3%20time&rsv_pq=bda1d8430003d3c6&rsv_t=b4a1GGNFu6c4DQJDxpoJ24o5SVfYK1%2BUvQhz4DOtkNLPQrCQ0P5%2FsAlbY6k&rsv_enter=1&inputT=1233&rsv_sug3=25&rsv_sug4=2728&rsv_sug2=0

http://www.deyisupport.com/question_answer/dsp_arm/davinci_digital_media_processors/f/39/t/17971.aspx m3端的地址转换

 

http://www.deyisupport.com/question_answer/dsp_arm/davinci_digital_media_processors/f/39/t/54118.aspx display

http://www.deyisupport.com/question_answer/dsp_arm/davinci_digital_media_processors/f/39/t/59513.aspx display link

http://www.deyisupport.com/question_answer/dsp_arm/davinci_digital_media_processors/f/39/p/18848/63772.aspx 12路解码

 

 

树莓派

http://www.2fz1.com/

posted @ 2014-12-31 18:59  midu  阅读(1676)  评论(0编辑  收藏  举报