海思osd+freetype+SDL+SDL_ttf字体颜色的设定

/*************sdl***********/
        TTF_Font *font;
        SDL_PixelFormat *fmt;
        SDL_Surface *text;
        SDL_Surface *temp;
        if (TTF_Init() < 0)
        {
            fprintf(stderr, "Couldn't initialize TTF:%s\n", SDL_GetError());
            SDL_Quit();
            return -1;
        }
    
        font = TTF_OpenFont("./simhei.ttf", 16);
        if (NULL == font)
        {
            fprintf(stderr, "Couldn't load %d pt font from %s:%s\n", 18, "ptsize", SDL_GetError());
            return -2;
        }


    char *strings[32] = 
    {
        "HIDE MENU        ",
   "FOCUS     AUTO   ", 
        "ROI       OFF    ", 
        "FBL       OFF    ", 
   "BRIGHT    0      ", 
        "EXPMODE   AUTO   ", 
        "WBMODE    AUTO   ", 
        "SHARP     4      ", 
        "DEFAULT   OFF    ", 
        "GAMMA     1      ", 
        "FRAMERATE 1080P30"
    };
    SDL_Color forecol[11] = 
    {
        { 0xff, 0x00, 0x00, 0xff },
        { 0x80, 0xff, 0x00, 0xff },
        { 0x80, 0xff, 0x00, 0xff },
        { 0x80, 0xff, 0x00, 0xff },
        { 0x80, 0xff, 0x00, 0xff },
        { 0x80, 0xff, 0x00, 0xff },
        { 0x80, 0xff, 0x00, 0xff },
        { 0x80, 0xff, 0x00, 0xff },
        { 0x80, 0xff, 0x00, 0xff },
        { 0x80, 0xff, 0x00, 0xff },
        { 0x80 0xff, 0x00, 0xff }
    };
    fmt = (SDL_PixelFormat*)malloc(sizeof(SDL_PixelFormat));
    memset(fmt, 0, sizeof(SDL_PixelFormat));
    fmt->BitsPerPixel = 16;
    fmt->BytesPerPixel = 2;
    fmt->colorkey = 0xffffffff;
    fmt->alpha = 0xff;
    for (i = 0; i < 8; i++)
    {
        text = TTF_RenderUTF8_Solid(font, strings[i], forecol[i]);
        temp = SDL_ConvertSurface(text, fmt, 0x00);
    //SDL_SaveBMP(temp, "save.bmp");


        stBitmap[i].u32Width = temp->w;
        //printf("temp->w:%d\n", temp->w);
        stBitmap[i].u32Height = temp->h;
        //printf("temp->h:%d\n", temp->h);
        stBitmap[i].pData = temp->pixels;
        stBitmap[i].enPixelFormat = PIXEL_FORMAT_RGB_1555;


        s32Ret = HI_MPI_RGN_SetBitMap(i, &(stBitmap[i]));
        if (s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_RGN_SetBitMap failed with %#x!\n", s32Ret);
            return s32Ret;

        }

我采用的方式是利用sdl+freetype生成字符图像,然后将图像的像素赋值给stBitmap.pData,再调用HI_MPI_RGN_SetBitMap来添加osd

其中设置字体颜色的变量是SDL_Color,按RGBA的格式设置

这里有一点要注意的是,(不清楚海思开发人员是如何编写HI_MPI_RGN_SetBitMap的字体叠加逻辑的)

{ 0x7f,   0xff, 0x00, 0xff },
        { 0x80, 0xff, 0x00, 0xff },

这是两个SDL_Color的值,按第一个设置的话,字体镂空,字体的空隙被设定像素填充

                                                按第二个设置的话,字体空隙镂空,字体被设定像素填充(一般情况,这才是我们想要的效果)

也就是说字体镂空还是字体空隙镂空取决于RGBA的第一个分量R的值,如果R大于等0x80则字体空隙镂空,否则的话则字体镂空

这一点海思竟然没有在开发文档中标明,这也提醒各位开发者们,自己开发的产品,一定要有写文档的习惯,不要给其他开发者留下不必要的坑。



你可能感兴趣的:(嵌入式,图像&视频,linux)