找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4628|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

基于ARM平臺的鋼琴游戲 08實現(xiàn)音樂鋼琴效果

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:222305 發(fā)表于 2017-7-25 15:41 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
//////////////////////////////////////////////////////////////////
//
//  Copyright(C), 2013-2016, GEC Tech. Co., Ltd.
//
//  File name: GPLE/bmp.c
//
//  Author: Vincent Lin (林世霖)  微信公眾號:秘籍酷
//
//  Date: 2016-11
//  
//  Description: 處理BMP格式圖像數(shù)據(jù)
//
//  GitHub: github.com/vincent040   Bug Report: 2437231462@qq.com
//
//////////////////////////////////////////////////////////////////

#include <errno.h>
#include "bmp.h"
#include "ts.h"

char * load_bmp(const char *bmpfile, struct image_info *minfo)
{
        int fd = open(bmpfile, O_RDONLY);
        if(fd == -1)
        {
                fprintf(stderr, "opening \"%s\" failed: %s\n",
                                        bmpfile, strerror(errno));
                exit(0);
        }

        // 獲得文件大小,并分配內(nèi)存
        struct stat fileinfo;
        fstat(fd, &fileinfo);

        int   rgb_size = fileinfo.st_size;
        char *rgb_buf  = calloc(1, rgb_size);

        // 讀取BMP內(nèi)容到內(nèi)存中
        struct bitmap_header header;
        struct bitmap_info info;
        struct rgb_quad quad;
        read(fd, &header, sizeof(header));
        read(fd, &info, sizeof(info));
        if(info.compression != 0)
        {
                read(fd, &quad, sizeof(quad));
                fprintf(stderr, "read quad! \n");
        }
        read(fd, rgb_buf, rgb_size);

        minfo->width = info.width;
        minfo->height= info.height;
        minfo->pixel_size = info.bit_count/8;

        #ifdef DEBUG
        printf("width: %d\n", minfo->width);
        printf("height: %d\n", minfo->height);
        printf("pixel_size: %d\n", minfo->pixel_size);
        #endif

        close(fd);
        return rgb_buf;
}

void bmp2lcd(char *bmpfile, char *FB,
                         struct fb_var_screeninfo *vinfo,
                         int xoffset, int yoffset)
{
        xoffset = xoffset>(65*12+10) ? (65*10+10) : xoffset;

        struct image_info *minfo = calloc(1, sizeof(struct image_info));
        char *rgb_buf = load_bmp(bmpfile, minfo);
        char *tmp = rgb_buf;

        // 從最后一行開始顯示BMP圖像
        int pad = ((4-( minfo->width * minfo->pixel_size ) % 4)) % 4; // 0-3
        rgb_buf += (minfo->width * minfo->pixel_size + pad) * (minfo->height-1);        

        FB += (yoffset * vinfo->xres + xoffset) * 4;
        int lcd_w = vinfo->xres - xoffset;
        int lcd_h = vinfo->yres - yoffset;

        int x, y;
        for(x=0; x<lcd_h && x<minfo->height; x++)
        {
                for(y=0; y<lcd_w && y<minfo->width; y++)
                {
                        unsigned long lcd_offset = (vinfo->xres*x + y) * 4;
                        rgb_buf += minfo->pixel_size;

                        memcpy(FB + lcd_offset + vinfo->red.offset/8,   rgb_buf + 2, 1);
                        memcpy(FB + lcd_offset + vinfo->green.offset/8, rgb_buf + 1, 1);
                        memcpy(FB + lcd_offset + vinfo->blue.offset/8,  rgb_buf + 0, 1);
                }

                rgb_buf += pad;
                rgb_buf -= (minfo->width * minfo->pixel_size + pad) * 2;
        }

        free(tmp);
}


08實現(xiàn)音樂鋼琴效果.rar

474.99 KB, 下載次數(shù): 23, 下載積分: 黑幣 -5

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表