DirectFB 之 实例图像不断右移

/**********************************************
 * Author: younger.liucn@gmail.com
 * File name: imgrotate.c
 * Description: animation
 * Modified:
 *   date:   2014-01-06  create
 *********************************************/
#include <directfb.h>

#include "animation.h"

#define MAX_LOOP        2
#define INTERVAL_PIXEL   2
#define EYE_HZ          50
#define INTERVAL_TIME   (1000 / EYE_HZ)

static int animation(int argc, char **argv);

int main(int argc, char **argv)
{
    return  animation(argc, argv);
}

static int animation(int argc, char **argv)
{
    int i, loop = 0;
    int screen_width = 0, screen_height = 0;
    DFBSurfaceDescription dsc;
    /*
     * For collecting infomation of image,
     * and provide image to IDirectFBSurface
     */
    IDirectFBImageProvider *provider;
    IDirectFB *dfb = NULL;
    IDirectFBSurface *primary = NULL;
    IDirectFBSurface *logo = NULL;

    /* 初始化整个DirectFB库,为后续画图等操作做准备 */
    DirectFBInit(&argc, &argv);
    DirectFBCreate(&dfb);
    
    /* 设置协作等级为全屏模式,具体请阅读SetCooperativeLevel接口解析 */
    dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN);
    dsc.flags = DSDESC_CAPS;
    dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING;

    /* 根据dsc创建一个基本平面 */
    dfb->CreateSurface(dfb, &dsc, &primary);
    /* 获取该基本平面的宽度和高度 */
    primary->GetSize(primary, &screen_width, &screen_height);

    /* 将要显示的图片及其相关信息保存在provider中 */
    dfb->CreateImageProvider(dfb, BA_IMG_NAME, &provider);

    /* 将保存在provider中的图片信息提取出来,存于dsc中 */
    provider->GetSurfaceDescription(provider, &dsc);

    /* 根据dsc创建一个图像平面 */
    dfb->CreateSurface(dfb, &dsc, &logo);

    /* 将图片呈递给刚才建立的logo平面,如果大小不一,则进行缩放 */
    provider->RenderTo(provider, logo, NULL);

    /* 释放资源provider */
    provider->Release(provider);

    for (i = -dsc.width;
            i < screen_width && !ba_check_exit(shared_mem);
            i = i + INTERVAL_PIXEL) {
        /* 清空屏幕 */
        primary->FillRectangle(primary, 0, 0,
                    screen_width, screen_height);
        primary->Blit(primary, logo, NULL, i,
                    (screen_height - dsc.height) / 2);
        /*
         * Blit model:将图片blit到平面
         * Blit(IDirectFBSurface *thiz, IDirectFBSurface *source,
         *          const DFBRectangle *source_rect, int x, int y);
         * if source_rect == NULL,use entire surface.
         * DFBRctangle is rectangular frame defined by two points.
         * (x, y):the point of top left corner.
         */

        /* flit整个屏幕 */
        primary->Flip(primary, NULL, DSFLIP_WAITFORSYNC);

        msleep(INTERVAL_TIME);

        if ((screen_width - INTERVAL_PIXEL) <= i && loop < MAX_LOOP) {
            BA_LOG(1, "screen_width:%d, loop:%d.\n", screen_width, loop);
            loop++;
            i = -dsc.width;
        }

    }

    logo->Release(logo);
    primary->Release(primary);
    dfb->Release(dfb);
    return 0;
}

posted on   YoungerChina  阅读(500)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示