Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

PixelFormatBPP.cxx 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* Copyright 2014 Pierre Ossman 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. #define CONCAT2(a,b) a##b
  19. #define CONCAT2E(a,b) CONCAT2(a,b)
  20. #define UIN CONCAT2E(U,INBPP)
  21. #define UOUT CONCAT2E(U,OUTBPP)
  22. #define SWAP16(n) ((((n) & 0xff) << 8) | (((n) >> 8) & 0xff))
  23. #define SWAP32(n) (((n) >> 24) | (((n) & 0x00ff0000) >> 8) | \
  24. (((n) & 0x0000ff00) << 8) | ((n) << 24))
  25. #define SWAPIN CONCAT2E(SWAP,INBPP)
  26. #define SWAPOUT CONCAT2E(SWAP,OUTBPP)
  27. #if INBPP == 32
  28. void PixelFormat::directBufferFromBufferFrom888(rdr::UOUT* dst,
  29. const PixelFormat &srcPF,
  30. const rdr::U8* src,
  31. int w, int h,
  32. int dstStride,
  33. int srcStride) const
  34. {
  35. const rdr::U8 *r, *g, *b;
  36. int dstPad, srcPad;
  37. const rdr::U8 *redDownTable, *greenDownTable, *blueDownTable;
  38. redDownTable = &downconvTable[(redBits-1)*256];
  39. greenDownTable = &downconvTable[(greenBits-1)*256];
  40. blueDownTable = &downconvTable[(blueBits-1)*256];
  41. if (srcPF.bigEndian) {
  42. r = src + (24 - srcPF.redShift)/8;
  43. g = src + (24 - srcPF.greenShift)/8;
  44. b = src + (24 - srcPF.blueShift)/8;
  45. } else {
  46. r = src + srcPF.redShift/8;
  47. g = src + srcPF.greenShift/8;
  48. b = src + srcPF.blueShift/8;
  49. }
  50. dstPad = (dstStride - w);
  51. srcPad = (srcStride - w) * 4;
  52. while (h--) {
  53. int w_ = w;
  54. while (w_--) {
  55. rdr::UOUT d;
  56. d = redDownTable[*r] << redShift;
  57. d |= greenDownTable[*g] << greenShift;
  58. d |= blueDownTable[*b] << blueShift;
  59. #if OUTBPP != 8
  60. if (endianMismatch)
  61. d = SWAPOUT(d);
  62. #endif
  63. *dst = d;
  64. dst++;
  65. r += 4;
  66. g += 4;
  67. b += 4;
  68. }
  69. dst += dstPad;
  70. r += srcPad;
  71. g += srcPad;
  72. b += srcPad;
  73. }
  74. }
  75. #endif /* INBPP == 32 */
  76. #if OUTBPP == 32
  77. void PixelFormat::directBufferFromBufferTo888(rdr::U8* dst,
  78. const PixelFormat &srcPF,
  79. const rdr::UIN* src,
  80. int w, int h,
  81. int dstStride,
  82. int srcStride) const
  83. {
  84. rdr::U8 *r, *g, *b, *x;
  85. int dstPad, srcPad;
  86. const rdr::U8 *redUpTable, *greenUpTable, *blueUpTable;
  87. redUpTable = &upconvTable[(srcPF.redBits-1)*256];
  88. greenUpTable = &upconvTable[(srcPF.greenBits-1)*256];
  89. blueUpTable = &upconvTable[(srcPF.blueBits-1)*256];
  90. if (bigEndian) {
  91. r = dst + (24 - redShift)/8;
  92. g = dst + (24 - greenShift)/8;
  93. b = dst + (24 - blueShift)/8;
  94. x = dst + (24 - (48 - redShift - greenShift - blueShift))/8;
  95. } else {
  96. r = dst + redShift/8;
  97. g = dst + greenShift/8;
  98. b = dst + blueShift/8;
  99. x = dst + (48 - redShift - greenShift - blueShift)/8;
  100. }
  101. dstPad = (dstStride - w) * 4;
  102. srcPad = (srcStride - w);
  103. while (h--) {
  104. int w_ = w;
  105. while (w_--) {
  106. rdr::UIN s;
  107. s = *src;
  108. #if INBPP != 8
  109. if (srcPF.endianMismatch)
  110. s = SWAPIN(s);
  111. #endif
  112. *r = redUpTable[(s >> srcPF.redShift) & 0xff];
  113. *g = greenUpTable[(s >> srcPF.greenShift) & 0xff];
  114. *b = blueUpTable[(s >> srcPF.blueShift) & 0xff];
  115. *x = 0;
  116. r += 4;
  117. g += 4;
  118. b += 4;
  119. x += 4;
  120. src++;
  121. }
  122. r += dstPad;
  123. g += dstPad;
  124. b += dstPad;
  125. x += dstPad;
  126. src += srcPad;
  127. }
  128. }
  129. #endif /* OUTBPP == 32 */