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.

EncodeManagerBPP.cxx 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 2000-2003 Constantin Kaplinsky. All Rights Reserved.
  2. * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
  3. * Copyright 2014 Pierre Ossman for Cendio AB
  4. *
  5. * This is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This software is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this software; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  18. * USA.
  19. */
  20. #define CONCAT2(a,b) a##b
  21. #define CONCAT2E(a,b) CONCAT2(a,b)
  22. #define UBPP CONCAT2E(U,BPP)
  23. inline bool EncodeManager::checkSolidTile(const Rect& r,
  24. rdr::UBPP colourValue,
  25. const PixelBuffer *pb)
  26. {
  27. int w, h;
  28. const rdr::UBPP* buffer;
  29. int stride, pad;
  30. w = r.width();
  31. h = r.height();
  32. buffer = (const rdr::UBPP*)pb->getBuffer(r, &stride);
  33. pad = stride - w;
  34. while (h--) {
  35. int w_ = w;
  36. while (w_--) {
  37. if (*buffer != colourValue)
  38. return false;
  39. buffer++;
  40. }
  41. buffer += pad;
  42. }
  43. return true;
  44. }
  45. inline bool EncodeManager::analyseRect(int width, int height,
  46. const rdr::UBPP* buffer, int stride,
  47. struct RectInfo *info, int maxColours)
  48. {
  49. int pad;
  50. rdr::UBPP colour;
  51. int count;
  52. info->rleRuns = 0;
  53. info->palette.clear();
  54. pad = stride - width;
  55. // For efficiency, we only update the palette on changes in colour
  56. colour = buffer[0];
  57. count = 0;
  58. while (height--) {
  59. int w_ = width;
  60. while (w_--) {
  61. if (*buffer != colour) {
  62. if (!info->palette.insert(colour, count))
  63. return false;
  64. if (info->palette.size() > maxColours)
  65. return false;
  66. // FIXME: This doesn't account for switching lines
  67. info->rleRuns++;
  68. colour = *buffer;
  69. count = 0;
  70. }
  71. buffer++;
  72. count++;
  73. }
  74. buffer += pad;
  75. }
  76. // Make sure the final pixels also get counted
  77. if (!info->palette.insert(colour, count))
  78. return false;
  79. if (info->palette.size() > maxColours)
  80. return false;
  81. return true;
  82. }