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.

convperf.cxx 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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,
  36. rfb::PixelFormat& /*srcpf*/,
  37. rdr::U8 *dst, rdr::U8 *src)
  38. {
  39. int h;
  40. h = tile;
  41. while (h--) {
  42. memcpy(dst, src, tile * dstpf.bpp/8);
  43. dst += fbsize * dstpf.bpp/8;
  44. src += fbsize * dstpf.bpp/8;
  45. }
  46. }
  47. static void testBuffer(rfb::PixelFormat &dstpf,
  48. rfb::PixelFormat &srcpf,
  49. rdr::U8 *dst, rdr::U8 *src)
  50. {
  51. dstpf.bufferFromBuffer(dst, srcpf, src, tile, tile, fbsize, fbsize);
  52. }
  53. static void testToRGB(rfb::PixelFormat& /*dstpf*/,
  54. rfb::PixelFormat &srcpf,
  55. rdr::U8 *dst, rdr::U8 *src)
  56. {
  57. srcpf.rgbFromBuffer(dst, src, tile, fbsize, tile);
  58. }
  59. static void testFromRGB(rfb::PixelFormat &dstpf,
  60. rfb::PixelFormat& /*srcpf*/,
  61. rdr::U8 *dst, rdr::U8 *src)
  62. {
  63. dstpf.bufferFromRGB(dst, src, tile, fbsize, tile);
  64. }
  65. static void doTest(testfn fn, rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf)
  66. {
  67. startCpuCounter();
  68. for (int i = 0;i < 10000;i++) {
  69. int x, y;
  70. rdr::U8 *dst, *src;
  71. x = rand() % (fbsize - tile);
  72. y = rand() % (fbsize - tile);
  73. dst = fb1 + (x + y * fbsize) * dstpf.bpp/8;
  74. src = fb2 + (x + y * fbsize) * srcpf.bpp/8;
  75. fn(dstpf, srcpf, dst, src);
  76. }
  77. endCpuCounter();
  78. float data, time;
  79. data = (double)tile * tile * 10000;
  80. time = getCpuCounter();
  81. printf("%g", data / (1000.0*1000.0) / time);
  82. }
  83. struct TestEntry tests[] = {
  84. {"memcpy", testMemcpy},
  85. {"bufferFromBuffer", testBuffer},
  86. {"rgbFromBuffer", testToRGB},
  87. {"bufferFromRGB", testFromRGB},
  88. };
  89. static void doTests(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf)
  90. {
  91. size_t i;
  92. char dstb[256], srcb[256];
  93. dstpf.print(dstb, sizeof(dstb));
  94. srcpf.print(srcb, sizeof(srcb));
  95. printf("%s,%s", srcb, dstb);
  96. for (i = 0;i < sizeof(tests)/sizeof(tests[0]);i++) {
  97. printf(",");
  98. doTest(tests[i].fn, dstpf, srcpf);
  99. }
  100. printf("\n");
  101. }
  102. int main(int /*argc*/, char** /*argv*/)
  103. {
  104. size_t bufsize;
  105. time_t t;
  106. char datebuffer[256];
  107. size_t i;
  108. bufsize = fbsize * fbsize * 4;
  109. fb1 = new rdr::U8[bufsize];
  110. fb2 = new rdr::U8[bufsize];
  111. for (i = 0;i < bufsize;i++) {
  112. fb1[i] = rand();
  113. fb2[i] = rand();
  114. }
  115. time(&t);
  116. strftime(datebuffer, sizeof(datebuffer), "%Y-%m-%d %H:%M UTC", gmtime(&t));
  117. printf("# Pixel Conversion Performance Test %s\n", datebuffer);
  118. printf("#\n");
  119. printf("# Frame buffer: %dx%d pixels\n", fbsize, fbsize);
  120. printf("# Tile size: %dx%d pixels\n", tile, tile);
  121. printf("#\n");
  122. printf("# Note: Results are Mpixels/sec\n");
  123. printf("#\n");
  124. printf("Source format,Destination Format");
  125. for (i = 0;i < sizeof(tests)/sizeof(tests[0]);i++)
  126. printf(",%s", tests[i].label);
  127. printf("\n");
  128. rfb::PixelFormat dstpf, srcpf;
  129. /* rgb888 targets */
  130. printf("\n");
  131. dstpf.parse("rgb888");
  132. srcpf.parse("rgb888");
  133. doTests(dstpf, srcpf);
  134. srcpf.parse("bgr888");
  135. doTests(dstpf, srcpf);
  136. srcpf.parse("rgb565");
  137. doTests(dstpf, srcpf);
  138. srcpf.parse("rgb232");
  139. doTests(dstpf, srcpf);
  140. /* rgb565 targets */
  141. printf("\n");
  142. dstpf.parse("rgb565");
  143. srcpf.parse("rgb888");
  144. doTests(dstpf, srcpf);
  145. srcpf.parse("bgr565");
  146. doTests(dstpf, srcpf);
  147. srcpf.parse("rgb232");
  148. doTests(dstpf, srcpf);
  149. /* rgb232 targets */
  150. printf("\n");
  151. dstpf.parse("rgb232");
  152. srcpf.parse("rgb888");
  153. doTests(dstpf, srcpf);
  154. srcpf.parse("rgb565");
  155. doTests(dstpf, srcpf);
  156. srcpf.parse("bgr232");
  157. doTests(dstpf, srcpf);
  158. /* rgb565 with endian conversion (both ways) */
  159. printf("\n");
  160. dstpf = rfb::PixelFormat(32, 24, false, true, 255, 255, 255, 0, 8, 16);
  161. srcpf = rfb::PixelFormat(32, 24, true, true, 255, 255, 255, 0, 8, 16);
  162. doTests(srcpf, dstpf);
  163. doTests(dstpf, srcpf);
  164. dstpf = rfb::PixelFormat(16, 16, false, true, 31, 63, 31, 0, 5, 11);
  165. srcpf = rfb::PixelFormat(16, 16, true, true, 31, 63, 31, 0, 5, 11);
  166. doTests(srcpf, dstpf);
  167. doTests(dstpf, srcpf);
  168. return 0;
  169. }