Some open source code and etc...

本文介绍了一个简单的C++绘图库fb-graphics的实现细节,该库利用Linux帧缓冲接口进行绘图操作。包括初始化设备、保存与恢复屏幕状态、绘制基本图形等功能。

I would like to introduce some small project for study, which are list below.

 

iolib-                :OOD in C++, easy and explicit structure

fb-graphics      : linux Frambuffer

libserial           : OOD in C++

 

 

 

The following is the source code of fb- graphics .

--------------app-----------

#include "graphics.h"
int main()
{
        int i;
        InitDevice();
                for (i=0;i<=1024;i++)
                {
                        DrawPoint(i,-300*sin(0.015*i)+400);
                        usleep(300);
                }
        SaveScreen();
        scanf("%d", &i);
        RestoreScreen();
        if(i == 1)
                  DrawRect(0,100,400,600);
        else
                  DrawRect(200,200,600,400);
                ClearWorld();
                exit(0);
}

---------------lib code---------

 

#include "graphics.h"
struct FbInfo device_info;
struct Color front_color;
struct Color back_color;
int fp;
 
int InitDevice(void)
{
        char *dev_id;
        /*鍓嶇棰滆壊榛樿涓虹櫧鑹?/
        front_color.blue |= 0xFF;
        front_color.green |= 0xFF;
        front_color.red |= 0xFF;
        /*鍚庣棰滆壊榛樿涓洪粦鑹?/
        back_color.blue &= 0;
        back_color.green &= 0;
        back_color.red &= 0;
        struct fb_var_screeninfo vinfo;
        struct fb_fix_screeninfo finfo;
        if ((dev_id = getenv("FB_DEVICE")) == NULL)
        {
                dev_id = "/dev/fb0";    /*娌℃湁鎵惧埌鐜鍙橀噺锛岀寽娴嬩竴涓澶囥€?/
        }
        if((fp = open (dev_id,O_RDWR)) < 0)
                GoError("Can't open the file!");
        if ((ioctl(fp,FBIOGET_FSCREENINFO,&finfo)) < 0)
                GoError("Can't get the fixed info!");
        if ((ioctl(fp,FBIOGET_VSCREENINFO,&vinfo)) < 0)
                GoError("Can't get variable info");
        device_info.bits_per_pixel = vinfo.bits_per_pixel;
        device_info.line_len_bytes = finfo.line_length;
        device_info.screen_len = vinfo.xres * vinfo.yres * (device_info.bits_per_pixel / 8);
        device_info.x_res = vinfo.xres;
        device_info.y_res = vinfo.yres;
    if ((device_info.mem_pointer = (char *) mmap (0,
                                        device_info.screen_len,
                                        PROT_READ | PROT_WRITE,
                                        MAP_SHARED,
                                        fp, 0)) < 0)
            GoError("Can't map device into mem!");
        if ((memset((void*) device_info.mem_pointer,0,device_info.screen_len)) < 0)
                GoError("Can't memset.");
        device_info.backup_pointer = malloc(device_info.screen_len);
        if(device_info.backup_pointer == NULL)
                GoError("Can't malloc.");
        return 0;
}
 
void SaveScreen(void)
{
        memcpy(device_info.backup_pointer,device_info.mem_pointer,device_info.screen_len);
}
 
void RestoreScreen(void)
{
        memcpy(device_info.mem_pointer, device_info.backup_pointer, device_info.screen_len);
}
 
void DrawPoint(int32_t x,int32_t y)
{
        int32_t location;
 
        if(x > device_info.x_res || y > device_info.y_res )
                return;
        location = x * (device_info.bits_per_pixel / 8)
                        + (y * device_info.line_len_bytes);
        *(device_info.mem_pointer + location) = front_color.blue;
        *(device_info.mem_pointer + location + 1) = front_color.green;
        *(device_info.mem_pointer + location + 2) = front_color.red;
        *(device_info.mem_pointer + location + 3) = 0;
 
 
}
void DrawLine(int32_t x1 , int32_t y1,int32_t x2,int32_t y2)
{
        int i;
        if (x1 != x2)
        {
                for (i = MIN(x1,x2) ; i <=MAX(x1,x2) ; i++)
                {
                        DrawPoint(i , ((y2 - y1) / (x2 - x1)) * (i - x1) + y1);
                }
        }
        else if (x1 == x2)
        {
                for (i = MIN(y1 , y2) ; i <= MAX(y1,y2) ; i++)
                {
                        DrawPoint(x1,i);
                }
        }
}
 
/*
 * (x1,y1)鏄乏涓婅鐨勭偣銆?x2,y2)鏄彸涓嬭鐨勭偣銆?
 *
 */
 
void DrawRect(int32_t x1 , int32_t y1 , int32_t x2 , int32_t y2)
{
        DrawLine(x1,y1,x2,y1);
        DrawLine(x2,y1,x2,y2);
        DrawLine(x2,y2,x1,y2);
        DrawLine(x1,y2,x1,y1);
}
 
 
void FillRect(int32_t x1 , int32_t y1 , int32_t x2 , int32_t y2)
{
        while (x1 - x2 < 1 || y1 - y2 < 1)
        {
                DrawRect(x1++ , y1++ , x2-- , y2--);
        }
}
 
void DrawArc(int32_t x0 , int32_t y0, int32_t arc_start , int32_t arc_end,int32_t r)
{
        int32_t end = MAX(arc_start,arc_end);
        int32_t start = MIN(arc_start,arc_end);
        float i;
        for (i = start ; i <= end ; i++)
        {
                DrawPoint(r * cos(GETDEGREE(i)) + x0 , -r * sin(GETDEGREE(i)) +y0);
        }
}
 
void DrawCirc(int32_t x0,int32_t y0,int32_t r)
{
        DrawArc(x0,y0,0,360,r);
}
 
/*
void FillArc(int32_t x0 , int32_t y0, int32_t arc_start , int32_t arc_end,int32_t r)
{
        int32_t end = MAX(arc_start,arc_end);
        int32_t start = MIN(arc_start,arc_end);
        float i;
        for (i = start ; i <= end ; i++)
        {
                DrawPoint(r * cos(GETDEGREE(i)) + x0 , -r * sin(GETDEGREE(i)) +y0);
                DrawLine(x0,y0,r * cos(GETDEGREE(i)) + x0 , -r * sin(GETDEGREE(i)) +y0);
        }
}
*/
 
void FillCirc(int32_t x0,int32_t y0,int32_t r)
{
        int i,j;
        for (i = x0 - r; i <= x0 + r;i++)
                for(j= y0 - r; j <= y0 + r; j++)
                {
                        if(POWER(i-x0)+POWER(j-y0) <= POWER(r))
                                DrawPoint(i,j);
                }
}
 
/*
void DrawCirc2(int32_t x0,int32_t y0,int32_t r)
{
int i,j;
        for (i = x0 - r; i <= x0 + r;i++)
                for(j= y0 - r; j <= y0 + r; j++)
                {
 
                        if(POWER(i-x0)+POWER(j-y0)-POWER(r) <= 500 && POWER(i-x0)+POWER(j-y0)-POWER(r) >= 0)
                        {
                                DrawPoint(i,j);
 
 
                }
                }
 
}
*/
int ClearWorld(void)
{
        munmap(device_info.mem_pointer,device_info.screen_len);
        if(device_info.backup_pointer != NULL)
        {
                free(device_info.backup_pointer);
                device_info.backup_pointer = NULL;
        }
        close(fp);
        return 0;
}
void SetFrontColor(char red,char green,char blue)
{
        front_color.red = red;
        front_color.blue = blue;
        front_color.green = green;
}
void SetBackColor(char red,char green,char blue)
{
        int32_t location,x,y;
 
        for (x = 0;x<device_info.x_res;x++)
                for(y = 0;y<device_info.y_res;y++)
                {
        location = x * (device_info.bits_per_pixel / 8)
                        + (y * device_info.line_len_bytes);
        *(device_info.mem_pointer + location) = blue;
        *(device_info.mem_pointer + location + 1) = green;
        *(device_info.mem_pointer + location + 2) = red;
        *(device_info.mem_pointer + location + 3) = 0;
                }
 
}
 
void PrintInfo(void)
{
        printf("The mem is :%d/n",device_info.screen_len);
        printf("The line_length is :%d/n",device_info.line_len_bytes);
        printf("The xres is :%d/n",device_info.x_res);
        printf("The yres is :%d/n",device_info.y_res);
        printf("bytes_per_pixel is :%d/n",(device_info.bits_per_pixel/8));
}
 
 
int GoError(char *msg)
{
        fprintf(stderr,"%s/n",msg);
        exit(1);
}

 

------------------------

The following phase has just occured to me. :-)

"屁股决定脑袋"

“ 一般来说,人都是个人利益高于公司利益,如果个人利益都没有得到满足,谁会去考虑公司利益啊”

“ 对搞技术的人说, 不是光为了钱 才就给你干活的~”

### Android Hardware Audio Service Documentation and Troubleshooting For addressing issues related to the Android hardware audio service, understanding both the architecture of how Android handles audio as well as common troubleshooting steps is essential. The Android system manages audio through a layered software stack that includes applications interacting with an application framework which then communicates with native daemons via binder IPC (Inter-Process Communication). These components eventually interact with the Linux kernel's ALSA (Advanced Linux Sound Architecture) drivers responsible for direct hardware control[^1]. When encountering problems with the hardware audio services on Android devices, several areas can be investigated: #### Checking Permissions Ensure all necessary permissions are granted within the app manifest file or dynamically at runtime when accessing microphone features or adjusting volume levels. Missing these may lead to silent failures where no sound output occurs despite code execution appearing successful. #### Verifying Configuration Files Inspect configuration files such as `audio_policy.conf` located typically under `/system/etc/`. Misconfigurations here could prevent proper routing between input/output streams leading to distorted sounds or complete lack thereof during playback/recording sessions. #### Utilizing Logcat Diagnostics Leverage logcat diagnostics by filtering logs specifically tagged towards media/audio subsystems using commands like: ```bash adb shell dumpsys media.audio_flinger | grep "AudioFlinger" ``` This command helps identify any anomalies reported from lower layers up into user space processes handling multimedia content presentation tasks. #### Testing With Native Tools Use built-in tools provided by AOSP (Android Open Source Project), including MediaCodecTester and AudioLoopbackTest apps available in platform testing packages. Running tests against known good configurations allows isolating whether defects lie within custom ROM modifications versus potential hardware malfunctions present even before OS installation took place. --related questions-- 1. How does one interpret specific error messages found inside logcat outputs concerning audio issues? 2. What role do HAL modules play regarding interaction between upper-level APIs exposed to developers versus underlying driver implementations managing actual silicon chipsets? 3. Can third-party applications interfere negatively impacting overall performance characteristics exhibited across entire device ecosystems especially pertaining to real-time sensitive operations involving low latency requirements demanded often times within gaming experiences? 4. Are there particular settings within developer options menu items worth toggling while diagnosing intermittent glitches experienced sporadically without clear reproducible patterns linking back directly attributable causes rooted deeply embedded somewhere hidden away amongst countless lines source codes spread throughout sprawling repositories maintained separately yet interconnected forming complex web dependencies spanning multiple projects simultaneously. 5. In what ways might over-the-air updates introduce regressions affecting previously stable functionalities associated closely tied together alongside evolving standards continuously advancing forward pushing boundaries ever outward expanding horizons opening doors possibilities never imagined before now becoming reality thanks largely due contributions made open-source communities around world collaborating efforts transcending borders uniting people shared goals aspirations creating better future everyone involved.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值