Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

convperf.cxx 4.9KB

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