Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. RGB_color defaultcolors[32] = {
  2. {0,0,0},
  3. {0,0,255},
  4. {0,85,0},
  5. {0,85,255},
  6. {0,170,0},
  7. {0,170,255},
  8. {0,255,0},
  9. {0,255,255},
  10. {85,0,0},
  11. {85,0,255},
  12. {85,85,0},
  13. {85,85,255},
  14. {85,170,0},
  15. {85,170,255},
  16. {85,255,0},
  17. {85,255,255},
  18. {170,0,0},
  19. {170,0,255},
  20. {170,85,0},
  21. {170,85,255},
  22. {170,170,0},
  23. {170,170,255},
  24. {170,255,0},
  25. {170,255,255},
  26. {255,0,0},
  27. {255,0,255},
  28. {255,85,0},
  29. {255,85,255},
  30. {255,170,0},
  31. {255,170,255},
  32. {255,255,0},
  33. {255,255,255}
  34. };
  35. BSDM_PALETTE defaultPalette{
  36. 32,defaultcolors
  37. };
  38.  
  39.  
  40. void ditheringColor(const uint8_t* src, uint8_t* dst,const BITMAPINFOHEADER& infoHeader, BSDM_PALETTE* palette)
  41. {
  42. uint32_t dataSizeWithoutPitches = infoHeader.biWidth * infoHeader.biHeight * 3;
  43. uint32_t width = infoHeader.biWidth;
  44. RGB_color newColor;
  45. for (int i = 0; i < dataSizeWithoutPitches; i += 3)
  46. {
  47. uint8_t oldR = src[i];
  48. uint8_t oldG = src[i + 1];
  49. uint8_t oldB = src[i + 2];
  50. RGB_color oldColor = { oldR,oldG,oldB };
  51. newColor = palette->colors[findClosestColorIndexFromPalette(oldColor, palette)];
  52. uint8_t newR = newColor.r;
  53. uint8_t newG = newColor.g;
  54. uint8_t newB = newColor.b;
  55.  
  56. dst[i] = newR;
  57. dst[i + 1] = newG;
  58. dst[i + 2] = newB;
  59. std::cout <<"dst["<<i<<"] "<<(int)dst[i];
  60. std::cout << "dst[" << i+1 << "] " <<(int) dst[i+1];
  61. std::cout << "dst[" << i+2 << "] " << (int)dst[i+2];
  62. std::cout << "\n";
  63. int errorR = dst[i] - newR;
  64. int errorG = dst[i + 1] - newG;
  65. int errorB = dst[i + 2] - newB;
  66.  
  67. dst[i + 3] = dst[i + 3] + errorR * (7.0f / 16.0f);
  68. dst[i + 4] = dst[i + 4] + errorG * (7.0f / 16.0f);
  69. dst[i + 5] = dst[i + 5] + errorB * (7.0f / 16.0f);
  70.  
  71. dst[i + width - 3] = dst[i + width - 3] + errorR * (3.0f / 16.0f);
  72. dst[i + width - 2] = dst[i + width - 2] + errorG * (3.0f / 16.0f);
  73. dst[i + width - 1] = dst[i + width - 1] + errorB * (3.0f / 16.0f);
  74.  
  75. dst[i + width] = dst[i + width] + errorR * (5.0f / 16.0f);
  76. dst[i + width + 1] = dst[i + width + 1] + errorG * (5.0f / 16.0f);
  77. dst[i + width + 2] = dst[i + width + 2] + errorB * (5.0f / 16.0f);
  78.  
  79. dst[i + width + 3] = dst[i + width + 3] + errorR * (1.0f / 16.0f);
  80. dst[i + width + 4] = dst[i + width + 4] + errorG * (1.0f / 16.0f);
  81. dst[i + width + 5] = dst[i + width + 5] + errorB * (1.0f / 16.0f);
  82.  
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement