You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* Copyright 2013-2014 Pierre Ossman <ossman@cendio.se> for Cendio AB
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. #include <config.h>
  20. #endif
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <time.h>
  25. #include <rfb/PixelFormat.h>
  26. #include "util.h"
  27. static const int tile = 64;
  28. static const int fbsize = 4096;
  29. static rdr::U8 *fb1, *fb2;
  30. typedef void (*testfn) (rfb::PixelFormat&, rfb::PixelFormat&, rdr::U8*, rdr::U8*);
  31. struct TestEntry {
  32. const char *label;
  33. testfn fn;
  34. };
  35. static void testMemcpy(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
  36. rdr::U8 *dst, rdr::U8 *src)
  37. {
  38. int h;
  39. h = tile;
  40. while (h--) {
  41. memcpy(dst, src, tile * dstpf.bpp/8);
  42. dst += fbsize * dstpf.bpp/8;
  43. src += fbsize * dstpf.bpp/8;
  44. }
  45. }
  46. static void testBuffer(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
  47. rdr::U8 *dst, rdr::U8 *src)
  48. {
  49. dstpf.bufferFromBuffer(dst, srcpf, src, tile, tile, fbsize, fbsize);
  50. }
  51. static void testToRGB(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
  52. rdr::U8 *dst, rdr::U8 *src)
  53. {
  54. srcpf.rgbFromBuffer(dst, src, tile, fbsize, tile);
  55. }
  56. static void testFromRGB(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
  57. rdr::U8 *dst, rdr::U8 *src)
  58. {
  59. dstpf.bufferFromRGB(dst, src, tile, fbsize, tile);
  60. }
  61. static void doTest(testfn fn, rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf)
  62. {
  63. startCpuCounter();
  64. for (int i = 0;i < 10000;i++) {
  65. int x, y;
  66. rdr::U8 *dst, *src;
  67. x = rand() % (fbsize - tile);
  68. y = rand() % (fbsize - tile);
  69. dst = fb1 + (x + y * fbsize) * dstpf.bpp/8;
  70. src = fb2 + (x + y * fbsize) * srcpf.bpp/8;
  71. fn(dstpf, srcpf, dst, src);
  72. }
  73. endCpuCounter();
  74. float data, time;
  75. data = (double)tile * tile * 10000;
  76. time = getCpuCounter();
  77. printf("%g", data / (1000.0*1000.0) / time);
  78. }
  79. struct TestEntry tests[] = {
  80. {"memcpy", testMemcpy},
  81. {"bufferFromBuffer", testBuffer},
  82. {"rgbFromBuffer", testToRGB},
  83. {"bufferFromRGB", testFromRGB},
  84. };
  85. static void doTests(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf)
  86. {
  87. size_t i;
  88. char dstb[256], srcb[256];
  89. dstpf.print(dstb, sizeof(dstb));
  90. srcpf.print(srcb, sizeof(srcb));
  91. printf("%s,%s", srcb, dstb);
  92. for (i = 0;i < sizeof(tests)/sizeof(tests[0]);i++) {
  93. printf(",");
  94. doTest(tests[i].fn, dstpf, srcpf);
  95. }
  96. printf("\n");
  97. }
  98. int main(int argc, char **argv)
  99. {
  100. size_t bufsize;
  101. time_t t;
  102. char datebuffer[256];
  103. size_t i;
  104. bufsize = fbsize * fbsize * 4;
  105. fb1 = new rdr::U8[bufsize];
  106. fb2 = new rdr::U8[bufsize];
  107. for (i = 0;i < bufsize;i++) {
  108. fb1[i] = rand();
  109. fb2[i] = rand();
  110. }
  111. time(&t);
  112. strftime(datebuffer, sizeof(datebuffer), "%Y-%m-%d %H:%M UTC", gmtime(&t));
  113. printf("# Pixel Conversion Performance Test %s\n", datebuffer);
  114. printf("#\n");
  115. printf("# Frame buffer: %dx%d pixels\n", fbsize, fbsize);
  116. printf("# Tile size: %dx%d pixels\n", tile, tile);
  117. printf("#\n");
  118. printf("# Note: Results are Mpixels/sec\n");
  119. printf("#\n");
  120. printf("Source format,Destination Format");
  121. for (i = 0;i < sizeof(tests)/sizeof(tests[0]);i++)
  122. printf(",%s", tests[i].label);
  123. printf("\n");
  124. rfb::PixelFormat dstpf, srcpf;
  125. /* rgb888 targets */
  126. printf("\n");
  127. dstpf.parse("rgb888");
  128. srcpf.parse("rgb888");
  129. doTests(dstpf, srcpf);
  130. srcpf.parse("bgr888");
  131. doTests(dstpf, srcpf);
  132. srcpf.parse("rgb565");
  133. doTests(dstpf, srcpf);
  134. srcpf.parse("rgb232");
  135. doTests(dstpf, srcpf);
  136. /* rgb565 targets */
  137. printf("\n");
  138. dstpf.parse("rgb565");
  139. srcpf.parse("rgb888");
  140. doTests(dstpf, srcpf);
  141. srcpf.parse("bgr565");
  142. doTests(dstpf, srcpf);
  143. srcpf.parse("rgb232");
  144. doTests(dstpf, srcpf);
  145. /* rgb232 targets */
  146. printf("\n");
  147. dstpf.parse("rgb232");
  148. srcpf.parse("rgb888");
  149. doTests(dstpf, srcpf);
  150. srcpf.parse("rgb565");
  151. doTests(dstpf, srcpf);
  152. srcpf.parse("bgr232");
  153. doTests(dstpf, srcpf);
  154. /* rgb565 with endian conversion (both ways) */
  155. printf("\n");
  156. dstpf = rfb::PixelFormat(32, 24, false, true, 255, 255, 255, 0, 8, 16);
  157. srcpf = rfb::PixelFormat(32, 24, true, true, 255, 255, 255, 0, 8, 16);
  158. doTests(srcpf, dstpf);
  159. doTests(dstpf, srcpf);
  160. dstpf = rfb::PixelFormat(16, 16, false, true, 31, 63, 31, 0, 5, 11);
  161. srcpf = rfb::PixelFormat(16, 16, true, true, 31, 63, 31, 0, 5, 11);
  162. doTests(srcpf, dstpf);
  163. doTests(dstpf, srcpf);
  164. return 0;
  165. }