According to this idea, the framebuffer is operated to display pictures and videos. Pictures and videos in any format must finally be converted into RGB values for each pixel. deepin uses RGB32, or BGRA. This method must be used in a text terminal and cannot be used in a terminal with GUI enabled. My computer uses ctrl+alt+F2 to start a text terminal. ctrl+alt+F1 Return to the gui interface from the terminal.
fim: This program can display pictures in a text terminal
ffmpeg: Add parameters to display video in a text terminal
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <string.h>
#include <unistd.h>
#include <linux/fb.h>
int main(int argc, char *argv[])
{
struct fb_var_screeninfo var;
int fd_fb = open("/dev/fb0", O_RDWR);
if (fd_fb < 0)
{
puts("/dev/fb0 error");
return -1;
}
if (ioctl(fd_fb, FBIOGET_VSCREENINFO, &var))
{
puts("ioctl error");
return -1;
}
unsigned int line_width = var.xres * var.bits_per_pixel / 8;
unsigned int pixel_width = var.bits_per_pixel / 8; //deepin=32
int screen_size = var.xres * var.yres * var.bits_per_pixel / 8;
unsigned char *fb_base = (unsigned char *)mmap(NULL, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0);
if (fb_base == NULL)
{
puts("mmap error");
return -1;
}
memset(fb_base, 0xff, screen_size);
for (int i = 0; i < 1920; i++)
{
int x=i;
int y = var.yres / 2;
int color = 0; //block
unsigned char *pen_8 = fb_base + y * line_width + x * pixel_width;
unsigned int *pen_32 = (unsigned int *)pen_8; //char->int 这句非常重要
*pen_32=color;
}
munmap(fb_base, screen_size);
close(fd_fb);
return 0;
}