1920x1080 YUV/YCbCR framebuffer

Ideas and dreaming will go this forum
Post Reply

sbav1
Official SamyGO Developer
Posts: 374
Joined: Fri Jan 15, 2010 10:20 am

1920x1080 YUV/YCbCR framebuffer

Post by sbav1 »

Just noticed something, while messing (out of boredom ) with TV mmaped RAM regions. When TV is in JPEG display mode, it uses two fixed memory regions as full-hd Y[UV]/Y[CbCr] framebuffer:
Chroma plane: 0x6d21a000, 16 (8+8) bits per pixel, V1U1V2U2V3U3V4U4... format (1920*1080*2 == 4147200 bytes)
Luma plane: 0x6c400000, 8 bits per pixel, Y1Y2Y3Y4.. format (1920*1080 == 2073700 bytes)

Those regions are writable (i.e it's possible to draw arbitrarily on the screen in full-res mode).
Sadly, this mixed packed/planar framebuffer format is an uncommon one. Does X11 server implementation exists that will allow such an oddity ( without heavy patching etc.) ?

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/mman.h>

#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \
  __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)

int main(int argc, char **argv) {
   int fd;
   off_t target;

   if (argc != 4) {
       fprintf(stderr, "\nUsage:\t%s address byteval count\n\n", argv[0]);
       exit(1); }
   target=strtoul(argv[1], 0, 0);
   int writeval=strtoul(argv[2], 0, 0);
   int bcount=strtoul(argv[3], 0, 0);
   int map_size=bcount/4096; map_size*=4096;
   if (map_size < bcount) map_size+=4096;
   if (target % 4096 || bcount < 1) {
      fprintf(stderr, "Address / size not valid\n");
      exit(1); }

   if ((fd=open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;
   void *map_base=mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target);
   if (map_base == (void *) -1) FATAL;
   printf("Memory mapped at address %p; size=%d\n", map_base, map_size);

   memset(map_base, writeval, bcount);
   if(munmap(map_base, map_size) == -1) FATAL;
   close(fd);
   return 0;
}
User avatar
erdem_ua
SamyGO Admin
Posts: 3125
Joined: Thu Oct 01, 2009 6:02 am
Location: Istanbul, Turkey
Contact:

Re: 1920x1080 YUV/YCbCR framebuffer

Post by erdem_ua »

Good achievement. I don't know if X support such a framebuffer format. Is it possible to put a wrapper between framebuffer with X ? Anyway there will be huge slowdown... :)

Post Reply

Return to “[B] Brainstorm”