pp_test.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 StarFive Technology Co., Ltd.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <assert.h>
  9. #include <getopt.h>
  10. #include <fcntl.h>
  11. #include <unistd.h>
  12. #include <errno.h>
  13. #include <malloc.h>
  14. #include <sys/stat.h>
  15. #include <sys/types.h>
  16. #include <sys/time.h>
  17. #include <time.h>
  18. #include <sys/mman.h>
  19. #include <sys/ioctl.h>
  20. #include <stdbool.h>
  21. #include <asm/types.h>
  22. #include <linux/videodev2.h>
  23. // #include "jpeglib.h"
  24. // #include <libv4l2.h>
  25. #include <signal.h>
  26. #include <stdint.h>
  27. #include <inttypes.h>
  28. #include <linux/fb.h>
  29. enum COLOR_FORMAT{
  30. COLOR_YUV422_UYVY = 0, // 00={Y1,V0,Y0,U0}
  31. COLOR_YUV422_VYUY = 1, // 01={Y1,U0,Y0,V0}
  32. COLOR_YUV422_YUYV = 2, // 10={V0,Y1,U0,Y0}
  33. COLOR_YUV422_YVYU = 3, // 11={U0,Y1,V0,Y0}
  34. COLOR_YUV420P, // 4
  35. COLOR_YUV420_NV21, // 5
  36. COLOR_YUV420_NV12, // 6
  37. COLOR_RGB888_ARGB, // 7
  38. COLOR_RGB888_ABGR, // 8
  39. COLOR_RGB888_RGBA, // 9
  40. COLOR_RGB888_BGRA, // 10
  41. COLOR_RGB565, // 11
  42. };
  43. struct pp_video_mode {
  44. enum COLOR_FORMAT format;
  45. unsigned int height;
  46. unsigned int width;
  47. unsigned int addr;
  48. };
  49. struct pp_mode {
  50. char pp_id;
  51. bool bus_out; /*out to ddr*/
  52. bool fifo_out; /*out to lcdc*/
  53. bool inited;
  54. struct pp_video_mode src;
  55. struct pp_video_mode dst;
  56. };
  57. #define FBIOPAN_GET_PP_MODE 0x4609
  58. #define FBIOPAN_SET_PP_MODE 0x460a
  59. static unsigned char *g_fb_buf = NULL;
  60. static int g_fb_fd = -1;
  61. long g_screensize = 1920 * 1080 * 2;
  62. //static unsigned char jpegQuality = 70;
  63. struct fb_var_screeninfo g_vinfo;
  64. struct fb_fix_screeninfo g_finfo;
  65. static const char short_options[] = "f:";
  66. static const struct option long_options[] = {
  67. { "format", required_argument, NULL, 'f' },
  68. { 0, 0, 0, 0 }
  69. };
  70. /**
  71. print usage information
  72. */
  73. static void usage(FILE* fp, int argc, char** argv)
  74. {
  75. fprintf(fp,
  76. "Usage: %s [options]\n\n"
  77. "Options:\n"
  78. "-f | --format image format RGB/Yuv\n"
  79. "",
  80. argv[0]);
  81. }
  82. /**
  83. Write image to jpeg file.
  84. \param img image to write
  85. */
  86. int write_file (char * filename,unsigned char *image_buffer, int size)
  87. {
  88. /* More stuff */
  89. FILE * outfile; /* target file */
  90. if ((outfile = fopen(filename, "w+")) == NULL) {
  91. fprintf(stderr, "can't open %s\n", filename);
  92. return -1;
  93. }
  94. fwrite(image_buffer, size, 1, outfile);
  95. fclose(outfile);
  96. return 0 ;
  97. }
  98. //Y' = 0.257*R' + 0.504*G' + 0.098*B' + 16
  99. static int Rgb2Y(int r0, int g0, int b0)
  100. {
  101. // float y0 = 0.257f*r0 + 0.504f*g0 + 0.098f*b0 + 16.0f;
  102. // int y0 = (257*r0 + 504*g0 + 98*b0)/1000 + 16;
  103. // Y = (77*R + 150*G + 29*B)>>8;
  104. int y0 = (77*r0+150*g0+29*b0) >> 8;
  105. return y0;
  106. }
  107. //U equals Cb'
  108. //Cb' = -0.148*R' - 0.291*G' + 0.439*B' + 128
  109. static int Rgb2U(int r0, int g0, int b0)
  110. {
  111. // float u0 = -0.148f*r0 - 0.291f*g0 + 0.439f*b0 + 128.0f;
  112. // int u0 = (-148*r0 - 291*g0 + 439*b0)/1000 + 128;
  113. // U = ((-44*R - 87*G + 131*B)>>8) + 128;
  114. int u0 = ((-44*r0 - 87*g0 + 131*b0)>>8) + 128;
  115. return u0;
  116. }
  117. //V equals Cr'
  118. //Cr' = 0.439*R' - 0.368*G' - 0.071*B' + 128
  119. static int Rgb2V(int r0, int g0, int b0)
  120. {
  121. // float v0 = 0.439f*r0 - 0.368f*g0 - 0.071f*b0 + 128.0f;
  122. // int v0 = (439*r0 - 368*g0 - 71*b0)/1000 + 128;
  123. // V = ((131*R - 110*G - 21*B)>>8) + 128 ;
  124. int v0 = ((131*r0 - 110*g0 - 21*b0)>>8) + 128;
  125. return v0;
  126. }
  127. //Convert two rows from RGB to two Y rows, and one row of interleaved U,V.
  128. //I0 and I1 points two sequential source rows.
  129. //I0 -> rgbrgbrgbrgbrgbrgb...
  130. //I1 -> rgbrgbrgbrgbrgbrgb...
  131. //Y0 and Y1 points two sequential destination rows of Y plane.
  132. //Y0 -> yyyyyy
  133. //Y1 -> yyyyyy
  134. //UV0 points destination rows of interleaved UV plane.
  135. //UV0 -> uvuvuv
  136. static void Rgb2NV12TwoRows(const unsigned char I0[],
  137. const unsigned char I1[],
  138. int step,
  139. const int image_width,
  140. unsigned char Y0[],
  141. unsigned char Y1[],
  142. unsigned char UV0[],
  143. int is_nv21)
  144. {
  145. int x; //Column index
  146. //Process 4 source pixels per iteration (2 pixels of row I0 and 2 pixels of row I1).
  147. for (x = 0; x < image_width; x += 2) {
  148. //Load R,G,B elements from first row (and convert to int).
  149. unsigned char b00 = (I0[x*step + 0] & 0x1F) << 3;
  150. unsigned char g00 = ((I0[x*step + 1] & 0x7) << 3 | I0[x*step + 0] >> 5) << 2;
  151. unsigned char r00 = I0[x*step + 1] & (~0x7);
  152. //Load next R,G,B elements from first row (and convert to int).
  153. unsigned char b01 = (I0[x*step + step+0] & 0x1F) << 3;
  154. unsigned char g01 = ((I0[x*step + step+1] & 0x7) << 3 | I0[x*step + step+0] >> 5) << 2;
  155. unsigned char r01 = I0[x*step + step+1] & (~0x7);
  156. //Load R,G,B elements from second row (and convert to int).
  157. unsigned char b10 = (I1[x*step + 0] & 0x1F) << 3;
  158. unsigned char g10 = ((I1[x*step + 1] & 0x7) << 3 | I1[x*step + 0] >> 5) << 2;
  159. unsigned char r10 = I1[x*step + 1] & (~0x7);
  160. //Load next R,G,B elements from second row (and convert to int).
  161. unsigned char b11 = (I1[x*step + step+0] & 0x1F) << 3;
  162. unsigned char g11 = ((I1[x*step + step+1] & 0x7) << 3 | I1[x*step + step+0] >> 5) << 2;
  163. unsigned char r11 = I1[x*step + step+1] & (~0x7);
  164. //Calculate 4 Y elements.
  165. unsigned char y00 = Rgb2Y(r00, g00, b00);
  166. unsigned char y01 = Rgb2Y(r01, g01, b01);
  167. unsigned char y10 = Rgb2Y(r10, g10, b10);
  168. unsigned char y11 = Rgb2Y(r11, g11, b11);
  169. //Calculate 4 U elements.
  170. unsigned char u00 = Rgb2U(r00, g00, b00);
  171. unsigned char u01 = Rgb2U(r01, g01, b01);
  172. unsigned char u10 = Rgb2U(r10, g10, b10);
  173. unsigned char u11 = Rgb2U(r11, g11, b11);
  174. //Calculate 4 V elements.
  175. unsigned char v00 = Rgb2V(r00, g00, b00);
  176. unsigned char v01 = Rgb2V(r01, g01, b01);
  177. unsigned char v10 = Rgb2V(r10, g10, b10);
  178. unsigned char v11 = Rgb2V(r11, g11, b11);
  179. //Calculate destination U element: average of 2x2 "original" U elements.
  180. unsigned char u0 = (u00 + u01 + u10 + u11)/4;
  181. //Calculate destination V element: average of 2x2 "original" V elements.
  182. unsigned char v0 = (v00 + v01 + v10 + v11)/4;
  183. //Store 4 Y elements (two in first row and two in second row).
  184. Y0[x + 0] = y00;
  185. Y0[x + 1] = y01;
  186. Y1[x + 0] = y10;
  187. Y1[x + 1] = y11;
  188. if (is_nv21) {
  189. // //Store destination U element.
  190. UV0[x + 0] = v0;
  191. // //Store destination V element (next to stored U element).
  192. UV0[x + 1] = u0;
  193. } else {
  194. // //Store destination U element.
  195. UV0[x + 0] = u0;
  196. // //Store destination V element (next to stored U element).
  197. UV0[x + 1] = v0;
  198. }
  199. }
  200. }
  201. //Convert image I from pixel ordered RGB to NV12 format.
  202. //I - Input image in pixel ordered RGB format
  203. //image_width - Number of columns of I
  204. //image_height - Number of rows of I
  205. //J - Destination "image" in NV12 format.
  206. //I is pixel ordered RGB color format (size in bytes is image_width*image_height*3):
  207. //RGBRGBRGBRGBRGBRGB
  208. //RGBRGBRGBRGBRGBRGB
  209. //RGBRGBRGBRGBRGBRGB
  210. //RGBRGBRGBRGBRGBRGB
  211. //
  212. //J is in NV12 format (size in bytes is image_width*image_height*3/2):
  213. //YYYYYY
  214. //YYYYYY
  215. //UVUVUV
  216. //Each element of destination U is average of 2x2 "original" U elements
  217. //Each element of destination V is average of 2x2 "original" V elements
  218. //
  219. //Limitations:
  220. //1. image_width must be a multiple of 2.
  221. //2. image_height must be a multiple of 2.
  222. //3. I and J must be two separate arrays (in place computation is not supported).
  223. void Rgb2NV12(const unsigned char I[], int step,
  224. const int image_width,
  225. const int image_height,
  226. unsigned char J[],
  227. int is_nv21)
  228. {
  229. //In NV12 format, UV plane starts below Y plane.
  230. // unsigned char *UV = &J[image_width*image_height];
  231. unsigned char *UV = J;
  232. //I0 and I1 points two sequential source rows.
  233. const unsigned char *I0; //I0 -> rgbrgbrgbrgbrgbrgb...
  234. const unsigned char *I1; //I1 -> rgbrgbrgbrgbrgbrgb...
  235. //Y0 and Y1 points two sequential destination rows of Y plane.
  236. unsigned char *Y0; //Y0 -> yyyyyy
  237. unsigned char *Y1; //Y1 -> yyyyyy
  238. //UV0 points destination rows of interleaved UV plane.
  239. unsigned char *UV0; //UV0 -> uvuvuv
  240. int y; //Row index
  241. int width, height;
  242. int x_offset, y_offset;
  243. width = image_width > g_vinfo.xres ? g_vinfo.xres : image_width;
  244. height = image_height > g_vinfo.yres ? g_vinfo.yres : image_height;
  245. x_offset = (g_vinfo.xres - width) / 2;
  246. y_offset = (g_vinfo.yres - height) / 2;
  247. //In each iteration: process two rows of Y plane, and one row of interleaved UV plane.
  248. for (y = 0; y < height; y += 2)
  249. {
  250. I0 = &I[y*image_width*step]; //Input row width is image_width*3 bytes (each pixel is R,G,B).
  251. I1 = &I[(y+1)*image_width*step];
  252. Y0 = &J[(y+y_offset)*g_vinfo.xres+x_offset]; //Output Y row width is image_width bytes (one Y element per pixel).
  253. Y1 = &J[(y+1+y_offset)*g_vinfo.xres+x_offset];
  254. UV0 = &UV[g_vinfo.xres*g_vinfo.yres+((y+y_offset)/2*g_vinfo.xres/2+x_offset/2)*2]; //Output UV row - width is same as Y row width.
  255. //Process two source rows into: Two Y destination row, and one destination interleaved U,V row.
  256. Rgb2NV12TwoRows(I0,
  257. I1,
  258. step,
  259. width,
  260. Y0,
  261. Y1,
  262. UV0,
  263. is_nv21);
  264. }
  265. }
  266. int convert_rgb565_to_nv12(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int is_nv21)
  267. {
  268. unsigned char *tmp = malloc(g_screensize);
  269. unsigned int start_timems;
  270. unsigned int end_timems;
  271. struct timespec ts_start, ts_end;
  272. printf("convert rgb565 to %s\n", is_nv21 ? "nv21" : "nv12");
  273. clock_gettime(CLOCK_MONOTONIC, &ts_start);
  274. Rgb2NV12(inBuf, 2, imgWidth, imgHeight, tmp, is_nv21);
  275. clock_gettime(CLOCK_MONOTONIC, &ts_end);
  276. start_timems = ts_start.tv_sec * 1000 + ts_start.tv_nsec/1000000;
  277. end_timems = ts_end.tv_sec * 1000 + ts_end.tv_nsec/1000000;
  278. printf("%s: convert use %dms\n", __func__, end_timems - start_timems);
  279. clock_gettime(CLOCK_MONOTONIC, &ts_start);
  280. memcpy(outBuf, tmp, g_screensize);
  281. clock_gettime(CLOCK_MONOTONIC, &ts_end);
  282. start_timems = ts_start.tv_sec * 1000 + ts_start.tv_nsec/1000000;
  283. end_timems = ts_end.tv_sec * 1000 + ts_end.tv_nsec/1000000;
  284. printf("%s: use %dms\n", __func__, end_timems - start_timems);
  285. free(tmp);
  286. return 0;
  287. }
  288. int convert_rgb565_to_rgb(unsigned char *inBuf, unsigned char *outBuf, int imgWidth, int imgHeight, int cvtMethod)
  289. {
  290. int rows ,cols;
  291. unsigned char *RGB565data, *RGBdata;
  292. int RGBpos;
  293. int width, height;
  294. int x_offset, y_offset;
  295. unsigned char *tmp = malloc(g_screensize);
  296. printf("%s, %d\n", __func__, __LINE__);
  297. width = imgWidth > g_vinfo.xres ? g_vinfo.xres : imgWidth;
  298. height = imgHeight > g_vinfo.yres ? g_vinfo.yres : imgHeight;
  299. x_offset = (g_vinfo.xres - width) / 2;
  300. y_offset = (g_vinfo.yres - height) / 2;
  301. RGB565data = inBuf;
  302. RGBdata = tmp;
  303. if (imgWidth == g_vinfo.xres) {
  304. RGBpos = (y_offset * g_vinfo.xres + x_offset) * 2;
  305. memcpy(&tmp[RGBpos], inBuf, imgWidth * height * 2);
  306. memcpy(&outBuf[RGBpos], &tmp[RGBpos], imgWidth * height * 2);
  307. // memcpy(&outBuf[RGBpos], inBuf, imgWidth * height * 2);
  308. free(tmp);
  309. return 0;
  310. }
  311. RGBpos = 0;
  312. for(rows = 0; rows < imgHeight; rows++)
  313. {
  314. RGBdata = tmp + ((rows + y_offset) * g_vinfo.xres + x_offset) * g_vinfo.bits_per_pixel / 8;
  315. RGBpos = rows * imgWidth * 2;
  316. if (g_vinfo.bits_per_pixel == 16) { // RGB565
  317. memcpy(RGBdata, &RGB565data[RGBpos], imgWidth * 2);
  318. } else {
  319. for(cols = 0; cols < imgWidth; cols++)
  320. {
  321. *(RGBdata ++) = RGB565data[RGBpos] & 0x1F;
  322. *(RGBdata ++) = (RGB565data[RGBpos + 1] & 0x7) << 3 | RGB565data[RGBpos] >> 5;
  323. *(RGBdata ++) = RGB565data[RGBpos + 1] >> 3;
  324. if (g_vinfo.bits_per_pixel == 32) { // RGB888
  325. *(RGBdata ++) = 0xFF;
  326. }
  327. RGBpos += 2;
  328. }
  329. }
  330. }
  331. memcpy(outBuf, tmp, g_screensize);
  332. free(tmp);
  333. return 0;
  334. }
  335. static void deviceInit(void)
  336. {
  337. g_fb_fd = open("/dev/fb0", O_RDWR);
  338. if (g_fb_fd == -1) {
  339. printf("Error: cannot open framebuffer device.\n");
  340. exit (EXIT_FAILURE);
  341. }
  342. // Get fixed screen information
  343. if (-1 == ioctl(g_fb_fd, FBIOGET_FSCREENINFO, &g_finfo)) {
  344. printf("Error reading fixed information.\n");
  345. exit (EXIT_FAILURE);
  346. }
  347. // Get variable screen information
  348. if (-1 == ioctl(g_fb_fd, FBIOGET_VSCREENINFO, &g_vinfo)) {
  349. printf("Error reading variable information.\n");
  350. exit (EXIT_FAILURE);
  351. }
  352. printf("g_vinfo.xres = %d, g_vinfo.yres = %d, grayscale = %d\n", g_vinfo.xres, g_vinfo.yres, g_vinfo.grayscale);
  353. printf("g_vinfo.xoffset = %d, g_vinfo.yoffset = %d\n", g_vinfo.xoffset, g_vinfo.yoffset);
  354. printf("g_vinfo.bits_per_pixel = %d, g_finfo.line_length = %d\n", g_vinfo.bits_per_pixel, g_finfo.line_length);
  355. g_screensize = g_vinfo.xres * g_vinfo.yres * g_vinfo.bits_per_pixel / 8;
  356. //mmap framebuffer
  357. g_fb_buf = (unsigned char *)mmap(NULL, g_screensize, PROT_READ | PROT_WRITE, MAP_SHARED, g_fb_fd, 0);
  358. if (g_fb_buf == (void *)(-1)) {
  359. printf("Error: failed to map framebuffer device to memory.\n");
  360. exit (EXIT_FAILURE) ;
  361. }
  362. memset(g_fb_buf, 0x00, g_screensize);
  363. }
  364. static void deviceUninit(void)
  365. {
  366. if (-1 == munmap((void *)g_fb_buf, g_screensize)) {
  367. printf(" Error: framebuffer device munmap() failed.\n");
  368. exit (EXIT_FAILURE) ;
  369. }
  370. close(g_fb_fd);
  371. }
  372. int main(int argc, char **argv)
  373. {
  374. struct pp_mode pp_info[3];
  375. int stfbc_fd = -1;
  376. int format = 0;
  377. int i, j;
  378. unsigned char *rgb565demo_buffer = NULL;
  379. int pixformat = COLOR_YUV420_NV21; // or COLOR_RGB565
  380. for (;;) {
  381. int index, c = 0;
  382. c = getopt_long(argc, argv, short_options, long_options, &index);
  383. if (-1 == c) {
  384. break;
  385. }
  386. switch (c) {
  387. case 0: /* getopt_long() flag */
  388. break;
  389. case 'f':
  390. printf("format: %s\n", optarg);
  391. format = atoi(optarg);
  392. switch (format) {
  393. case 0:
  394. pixformat = COLOR_RGB565;
  395. break;
  396. case 1:
  397. pixformat = COLOR_RGB888_ARGB;
  398. break;
  399. case 2:
  400. pixformat = COLOR_YUV420P;
  401. break;
  402. case 3:
  403. pixformat = COLOR_YUV422_YUYV;
  404. break;
  405. case 4:
  406. pixformat = COLOR_YUV420_NV21;
  407. break;
  408. case 5:
  409. pixformat = COLOR_YUV420_NV12;
  410. break;
  411. case 6:
  412. pixformat = COLOR_YUV422_YVYU;
  413. break;
  414. default:
  415. pixformat = COLOR_RGB565;
  416. break;
  417. }
  418. break;
  419. default:
  420. usage(stderr, argc, argv);
  421. exit(EXIT_FAILURE);
  422. }
  423. }
  424. stfbc_fd = open("/dev/stfbcdev", O_RDWR);
  425. if (stfbc_fd == -1) {
  426. printf("Error: cannot open framebuffer device./n");
  427. exit (EXIT_FAILURE);
  428. }
  429. if (-1 == ioctl(stfbc_fd, FBIOPAN_GET_PP_MODE, &pp_info[0])) {
  430. printf("Error reading variable information./n");
  431. exit (EXIT_FAILURE);
  432. }
  433. printf(" get pp format :%d,%d\n",pp_info[1].src.format,__LINE__);
  434. pp_info[1].src.format = pixformat;
  435. if (-1 == ioctl(stfbc_fd, FBIOPAN_SET_PP_MODE, &pp_info[0])) {
  436. printf("Error reading variable information./n");
  437. exit (EXIT_FAILURE);
  438. }
  439. if (-1 == ioctl(stfbc_fd, FBIOPAN_GET_PP_MODE, &pp_info[0])) {
  440. printf("Error reading variable information./n");
  441. exit (EXIT_FAILURE);
  442. }
  443. printf(" get pp format :%d,%d\n",pp_info[1].src.format,__LINE__);
  444. pixformat = pp_info[1].src.format;
  445. deviceInit();
  446. rgb565demo_buffer = malloc(g_screensize);
  447. if (!rgb565demo_buffer) {
  448. exit (EXIT_FAILURE);
  449. }
  450. unsigned char *dst = NULL;
  451. dst = malloc(g_screensize);
  452. if (!dst) {
  453. exit (EXIT_FAILURE);
  454. }
  455. // init rgb raw data
  456. for (j = 0; j < g_vinfo.yres/4; j++)
  457. for (i = 0; i < g_vinfo.xres; i++) {
  458. rgb565demo_buffer[2*(j*g_vinfo.xres+i)] = 0b00000000;
  459. rgb565demo_buffer[2*(j*g_vinfo.xres+i)+1] = 0b11111000;
  460. }
  461. for (j = g_vinfo.yres/4; j < g_vinfo.yres/2; j++)
  462. for (i = 0; i < g_vinfo.xres; i++) {
  463. rgb565demo_buffer[2*(j*g_vinfo.xres+i)] = 0b11100000;
  464. rgb565demo_buffer[2*(j*g_vinfo.xres+i)+1] = 0b00000111;
  465. }
  466. for (j = g_vinfo.yres/2; j < g_vinfo.yres * 3/4; j++)
  467. for (i = 0; i < g_vinfo.xres; i++) {
  468. rgb565demo_buffer[2*(j*g_vinfo.xres+i)] = 0b00011111;
  469. rgb565demo_buffer[2*(j*g_vinfo.xres+i)+1] = 0b00000000;
  470. }
  471. for (j = g_vinfo.yres * 3/4; j < g_vinfo.yres; j++)
  472. for (i = 0; i < g_vinfo.xres; i++) {
  473. rgb565demo_buffer[2*(j*g_vinfo.xres+i)] = 0b11111111;
  474. rgb565demo_buffer[2*(j*g_vinfo.xres+i)+1] = 0b11111111;
  475. }
  476. switch (pixformat) {
  477. case COLOR_RGB565:
  478. convert_rgb565_to_rgb(rgb565demo_buffer, g_fb_buf, g_vinfo.xres, g_vinfo.yres, 1);
  479. convert_rgb565_to_rgb(rgb565demo_buffer, dst, g_vinfo.xres, g_vinfo.yres, 1);
  480. write_file("test_format-rgb565.raw", dst, g_screensize);
  481. break;
  482. case COLOR_RGB888_ARGB:
  483. break;
  484. case COLOR_YUV420P:
  485. break;
  486. case COLOR_YUV422_YUYV:
  487. break;
  488. case COLOR_YUV420_NV21:
  489. convert_rgb565_to_nv12(rgb565demo_buffer, g_fb_buf, g_vinfo.xres, g_vinfo.yres, 1);
  490. convert_rgb565_to_nv12(rgb565demo_buffer, dst, g_vinfo.xres, g_vinfo.yres, 1);
  491. write_file("test_format-nv21.raw", dst, g_screensize);
  492. break;
  493. case COLOR_YUV420_NV12:
  494. convert_rgb565_to_nv12(rgb565demo_buffer, g_fb_buf, g_vinfo.xres, g_vinfo.yres, 0);
  495. convert_rgb565_to_nv12(rgb565demo_buffer, dst, g_vinfo.xres, g_vinfo.yres, 0);
  496. write_file("test_format-nv12.raw", dst, g_screensize);
  497. break;
  498. case COLOR_YUV422_YVYU:
  499. break;
  500. default:
  501. break;
  502. }
  503. write_file("test_rgb565.raw", rgb565demo_buffer, g_screensize);
  504. free(rgb565demo_buffer);
  505. free(dst);
  506. sleep(10);
  507. deviceUninit();
  508. return 0;
  509. }