7,.OSD叠加学习之在YUV图片是叠加单个Ascii字模与获取实时时间信息并叠加至YUV图片(考虑行越界)

在YUV图片是叠加单个Ascii字模

思路:

在上一篇博文中,我们已经成功在终端成功打印了字模,依照之前的思路。在YUV图片上打印同理。遍历字模文件,有 1 就给对应的 YUV 数值, 0 就保持原来分量。同样需要注意的就是 换行问题。而显示叠加多个字模也就是叠加一个字模的循环叠加。需注意的就是偏移量间隔的控制

总的思路就是 获取 --> 遍历 --> 打印

代码:

int LUX_check_Letter(int offsize ,char *backGroun)
{
    int bit          = 0;
    int width        = 0;
    int bety         = 0;
    int higth        = 0;
    char buf[144]    = {0};
    const int oneBit = 8;
    FILE *fileAddr   = NULL;

    fileAddr = fopen(LUX_one_file,"rb+");

    fread(buf,1,LUX_oneLetter_size,fileAddr);

    for(bety = 0 ;bety < LUX_oneLetter_size ;bety++)
    {
        if(bety%LUX_oneLine_bety == 0)
        {
            printf("\n");
            higth++;
            width = 0;
        }
        for(bit = 0 ;bit < oneBit ;bit++)
        {
            if (buf[bety] & (0x80 >> bit))
            {
                memset(backGroun + LUV_U_START + bit + higth * LUV_UV_WIDTH + width*oneBit + offsize,128,1);
                memset(backGroun + LUV_V_START + bit + higth * LUV_UV_WIDTH + width*oneBit + offsize,50,1);
                printf("*");
            }
            else
            printf(" ");
        }   
        width++;
    }
    fclose(fileAddr);
}
int LUV_Superimpose(int offsetBuf[])
{
    FILE *backGroundFp  = NULL;
    FILE *OSDFp         = NULL;        
    int num             = 0;
    int nRet            = 0;
    int stringInterval  = 1500;
    char *backGround    = NULL;

    backGround = (char *)malloc(LUX_background_size);

    backGroundFp = fopen(LUX_background,"rb+");
    if(backGroundFp == NULL)
    {
        printf("fopen LUX_background fail\n");
        perror("why:");
        return -1;
    }
    OSDFp = fopen(LUX_OSDPicture,"wb+");
    if(OSDFp == NULL)
    {
        printf("fopen LUX_OSDPicture fail\n");
        perror("why:");
        return -2;
    }

    nRet = fread(backGround,1,LUX_background_size,backGroundFp);
    if(!nRet)
    {
        printf("fread backGroundFp fail\n");
        perror("why:");
        return -3;
    }
    
    while(offsetBuf[num])
    {
        LUV_GetCharacter(offsetBuf[num]);
        LUX_check_Letter(stringInterval,backGround);

        stringInterval = stringInterval + 20;/*每个字模偏移量间隔*/
        if(stringInterval >= 1920)
        {
            printf("Out of bounds\n");
            break;
        }
        num++;
    }
    

    nRet = fwrite(backGround,1,LUX_background_size,OSDFp);
    if(!nRet)
    {
        printf("fwrite OSDFp fail\n");
        perror("why:");
        return -4;
    }
    
   

    free(backGround);
    fclose(backGroundFp);
    fclose(OSDFp);
}

获取实时时间信息并叠加至YUV图片

思路:

上面我们已经解决了将字符串 叠加到YUV 图片的操作。那我们现在就只需要获取日期时间存入字符串中。就可以实现将时间信息叠加了。(具体API作用就不介绍了,需要了解需自行学习)

代码:

/*获取时间戳*/
char *LUX_GET_TimeStamp(char *buf)
{
    time_t t1;
    struct tm *localTime = NULL;
   
    time(&t1);
    localTime = localtime(&t1);
    sprintf(buf,"%d,%d,%d--%d:%d:%d",1900+localTime->tm_year,localTime->tm_mon+1,localTime->tm_mday
                                            ,localTime->tm_hour,localTime->tm_min,localTime->tm_sec);
}
#include "getAcsii.h"
#include "getTimestamp.h"
#include <stdio.h>
#include <stdlib.h>

#define LUX_oneLetter_size      144

int LUV_showString()
{
    int num              = 0;
    int size             = 0;
    int offset           = 0;
    int stringInterval   = 0;
    char *pString        = NULL;
    int offsetBuf[1280]  = {0};
    
    pString = malloc(sizeof(char));

    LUX_GET_TimeStamp(pString);
    
    while(pString[num] != '\0')
    {
        size   = (int)pString[num];
        offset = LUX_oneLetter_size*( size - 0x20 );

        offsetBuf[num] = offset;
        num++;
    }
    LUV_Superimpose(offsetBuf);
    free(pString);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值