Linux 下使用s3c6410的post处理器的进行硬件缩放

来源:互联网 发布:simlab软件敏感性分析 编辑:程序博客网 时间:2024/05/16 16:19
转自:http://blog.chinaunix.net/uid-20587912-id-2876217.html 
Linux 下使用s3c6410的post处理器的进行硬件缩放 2011-09-19 23:05:13


Andrew Huang <bluedrum@163.com> 转载请注明作者及出处

 在嵌入式下,在移植软件时经常会碰到这样的问题,就是显示分辩率的变化.一般软件往往针对桌面机的环境编译没有太多问题,但是在嵌入式环境下,受限的LCD显示有着很大的问题.

  这种情况下,一种方法是修改代码,让其在嵌入式的LCD上显示.另外一种是使用软件进行显示缩放. 这两个方法只在部分条件有效,而且修改的工作量极大,更多情况是无法修改,比如SDL下的Dosbox是针对 640*480,修改源码的分辩率成 480*272 后,基本屏幕显示完全错位.软件无法正常运行.

 这里有一种思路是使用s3c6410的post process.它是一个硬件进行图像和视频缩放的的模块.用POST后,只需要简单调整frame buffer显示库代码,即可以让原来无法移植的软件在嵌入式环境下自由缩放.

 一.Post Process 说明
   s3c6410的Post Process支持图像和视频缩放和格式转换,因为是硬件操作,所以速度非常之快.
  这是DataSheet 对其功能说明.

  •  Dedicated DMA with offset address 
• 3 Channel scaling pipelines for video/graphic scaling up/down or zooming in/out 
• Video input format: 420, 422 format 
• Graphic input format: 16-bit (565format) or 24-bit 
• Graphics Output format to Memory: 16-bit (565 format) / 24-bit graphic data (progressive only) 
• Video Output format to Memory: YCbCr420, YCbCr422 
• Output format to external FIFO: YCbCr444 / RGB (30-bit) for interlace and progressive 
• FreeRun Mode Operation  
• Programmable source image size up to 4096 × 4096 resolution 
• Programmable destination image size up to 2048 × 2048 resolution 
• Programmable scaling ratio 
• Format conversion for video signals 
• Color space conversion from YCbCr to RGB 
• Color Space conversion from RGB to YCbCr  

  它的主要处理流程是在系一种统内存中开辟一个PP的帧内存.其中数据被PP处理后,有两个流向,一个是通过DMA直接传到例如显存当中,这样可以直接显示,另外一种是传到硬件队列当中,然后可以发送到LCD,TV等设备当中.
  
   
 二.官方的Linux PP测试程序.
  
  官方有一个Linux下的测试程序,是演示的如果使用Post Process的驱动 s3c-pp的演示代码.它是用双缓冲的把两幅640*480的原始图像,在任意分辩率下进行缩放后,交替在屏幕上显示.
   
  这里有两个版本,我选择是 Multimedia_DD\PP_V2.5\v3.xx\pp_app 的测试程序.
  我是在4.3"的s3c6410开发板上运行.fb的信息是 480*272 bpp采用16.

  这样需要对原有的代码post_test.c进行简单修改.
  
  1.23行,设备结点修改为 #define PP_DEVICE_FILE_NAME"/dev/s3c-pp"

  2. 25,26行,分辩率修改为4.3"的配置
     #define LCD_WIDTH 480
     #define LCD_HEIGHT 272

  Makefile 的修改,将CC=....的值调整为 CC=arm-linux-gcc

  编译成功后,可以选择如下两种方式运行.
    ./post_test 0 10000
   其中第一个参数是PP的输出方式,0是采用DMA输出,1是采用FIFO,两种情况测试均成功.
   第二个参数是两幅图像交错显示时,每次显示的时间.单位是微秒.

这是在我的开发板显示效果,结果是比较令人满意.

   
     
    
   

 三.封装后的S3C PP 库代码
   
   分析后的PP处理流程.官方只给一个简单中测试程序.简单分析其处理机制,大体按如下流程进行处理.

   1.打开/dev/s3c-pp结点进行操作
   2.对PP的设备使用ioctl命令 ioctl(pp_dev->pp_fd, S3C_PP_SET_PARAMS, &pp_param)来设置缩放前后的分辩率,bpp和格式.其结构定义在 s3c_pp_params_t 之中.
  3. 对pp设备使用ioctl命令ioctl(pp_dev->pp_fd, S3C_PP_ALLOC_KMEM, &alloc_info[0]),分配转换前的在内存.如果输出是LCD的,输出缓冲直接采用显存.
  4.将转换前数据拷贝到转换前内存之中
  5,对于PP调用 ioctl(pp_dev->pp_fd, S3C_PP_START); 进行转换. 
     如果是显存,则直接显示在LCD之上.
  6.退出时,调用ioctl(pp_dev->pp_fd, S3C_PP_FREE_KMEM, &alloc_info[0])  释放转换前的内存.
  7.关闭pp的设备设点
   
  1. #ifndef __S3C_PP_LIB_H__
  2. #define __S3C_PP_LIB_H__
  3. /*
  4.   Author: Andrew Huang <bluedrum@163.com>
  5.     descrition S3C6410 Post Process library 
  6. */

  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif

  10. typedef enum {
  11.     DMA_ONESHOT,
  12.     FIFO_FREERUN
  13. } s3c_pp_out_path_t;

  14. typedef enum {
  15.     PAL1, PAL2, PAL4, PAL8,
  16.     RGB8, ARGB8, RGB16, ARGB16, RGB18, RGB24, RGB30, ARGB24,
  17.     YC420, YC422, // Non-interleave
  18.     CRYCBY, CBYCRY, YCRYCB, YCBYCR, YUV444 // Interleave
  19. } s3c_color_space_t;

  20. typedef enum {
  21.     INTERLACE_MODE,
  22.     PROGRESSIVE_MODE
  23. } s3c_pp_scan_mode_t;


  24. // Structure type for IOCTL commands S3C_PP_SET_PARAMS, S3C_PP_SET_INPUT_BUF_START_ADDR_PHY, 
  25. // S3C_PP_SET_INPUT_BUF_NEXT_START_ADDR_PHY, S3C_PP_SET_OUTPUT_BUF_START_ADDR_PHY.
  26. typedef struct {
  27.     unsigned int src_full_width;        // Source Image Full Width (Virtual screen size)
  28.     unsigned int src_full_height;        // Source Image Full Height (Virtual screen size)
  29.     unsigned int src_start_x;             // Source Image Start width offset
  30.     unsigned int src_start_y;             // Source Image Start height offset
  31.     unsigned int src_width;                // Source Image Width
  32.     unsigned int src_height;             // Source Image Height
  33.     unsigned int src_buf_addr_phy;         // Base Address of the Source Image : Physical Address
  34.     unsigned int src_next_buf_addr_phy; // Base Address of Source Image to be displayed next time in FIFO_FREERUN Mode
  35.     s3c_color_space_t src_color_space;     // Color Space of the Source Image

  36.     unsigned int dst_full_width;         // Destination Image Full Width (Virtual screen size)
  37.     unsigned int dst_full_height;         // Destination Image Full Height (Virtual screen size)
  38.     unsigned int dst_start_x;             // Destination Image Start width offset
  39.     unsigned int dst_start_y;             // Destination Image Start height offset
  40.     unsigned int dst_width;             // Destination Image Width
  41.     unsigned int dst_height;             // Destination Image Height
  42.     unsigned int dst_buf_addr_phy;        // Base Address of the Destination Image : Physical Address
  43.     s3c_color_space_t dst_color_space;     // Color Space of the Destination Image

  44.     s3c_pp_out_path_t out_path;      // output and run mode (DMA_ONESHOT or FIFO_FREERUN)
  45.     s3c_pp_scan_mode_t scan_mode; // INTERLACE_MODE, PROGRESSIVE_MODE
  46. } s3c_pp_params_t;

  47. // Structure type for IOCTL commands S3C_PP_ALLOC_KMEM, S3C_PP_FREE_KMEM.
  48. typedef struct {
  49.     int         size;
  50.     unsigned int     vir_addr;
  51.     unsigned int     phy_addr;
  52. } s3c_pp_mem_alloc_t;

  53. #define PP_IOCTL_MAGIC 'P'

  54. #define S3C_PP_SET_PARAMS             _IO(PP_IOCTL_MAGIC, 0)
  55. #define S3C_PP_START                     _IO(PP_IOCTL_MAGIC, 1)
  56. #define S3C_PP_GET_SRC_BUF_SIZE          _IO(PP_IOCTL_MAGIC, 2)
  57. #define S3C_PP_SET_SRC_BUF_ADDR_PHY _IO(PP_IOCTL_MAGIC, 3)
  58. #define S3C_PP_SET_SRC_BUF_NEXT_ADDR_PHY _IO(PP_IOCTL_MAGIC, 4)
  59. #define S3C_PP_GET_DST_BUF_SIZE          _IO(PP_IOCTL_MAGIC, 5)
  60. #define S3C_PP_SET_DST_BUF_ADDR_PHY     _IO(PP_IOCTL_MAGIC, 6)
  61. #define S3C_PP_ALLOC_KMEM _IO(PP_IOCTL_MAGIC, 7)
  62. #define S3C_PP_FREE_KMEM _IO(PP_IOCTL_MAGIC, 8)
  63. #define S3C_PP_GET_RESERVED_MEM_SIZE _IO(PP_IOCTL_MAGIC, 9)
  64. #define S3C_PP_GET_RESERVED_MEM_ADDR_PHY _IO(PP_IOCTL_MAGIC, 10)

  65. struct video_view {
  66.   int x;
  67.   int y;
  68.   int w;
  69.   int h;
  70.   int bpp;
  71.   int format;
  72.   char * buf;
  73.   int size; 
  74.   char * phy_addr;
  75. };

  76.  struct fb_pp {
  77.       struct video_view fb_view;
  78.      struct video_view src_view;
  79.      int fb_fd;
  80.      int pp_fd;
  81.      int out_path;
  82.      int scan_mode;
  83.      s3c_pp_params_t    pp_param;
  84.      };

  85.  typedef struct
  86. {
  87.     unsigned int map_dma_f1;
  88.     unsigned int map_dma_f2;
  89. } s3c_fb_dma_info_t;

  90. extern int s3c_pp_setup(struct fb_pp * pp_dev,struct video_view * src,int out_path);
  91. extern int s3c_pp_open(struct fb_pp * pp_dev,int bpp);
  92. extern int s3c_pp_write(struct fb_pp * pp_dev,char * buf,int buf_len);

  93. extern int s3c_pp_write_file(struct fb_pp * pp_dev,char * filename);

  94. extern int s3c_pp_apply(struct fb_pp * pp_dev);

  95. #ifdef __cplusplus
  96. }
  97. #endif

  98. #endif /* __S3C_PP_LIB_H__ */
   

原创粉丝点击