Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RGB_color defaultcolors[32] = {
- {0,0,0},
- {0,0,255},
- {0,85,0},
- {0,85,255},
- {0,170,0},
- {0,170,255},
- {0,255,0},
- {0,255,255},
- {85,0,0},
- {85,0,255},
- {85,85,0},
- {85,85,255},
- {85,170,0},
- {85,170,255},
- {85,255,0},
- {85,255,255},
- {170,0,0},
- {170,0,255},
- {170,85,0},
- {170,85,255},
- {170,170,0},
- {170,170,255},
- {170,255,0},
- {170,255,255},
- {255,0,0},
- {255,0,255},
- {255,85,0},
- {255,85,255},
- {255,170,0},
- {255,170,255},
- {255,255,0},
- {255,255,255}
- };
- BSDM_PALETTE defaultPalette{
- 32,defaultcolors
- };
- void ditheringColor(const uint8_t* src, uint8_t* dst,const BITMAPINFOHEADER& infoHeader, BSDM_PALETTE* palette)
- {
- uint32_t dataSizeWithoutPitches = infoHeader.biWidth * infoHeader.biHeight * 3;
- uint32_t width = infoHeader.biWidth;
- RGB_color newColor;
- for (int i = 0; i < dataSizeWithoutPitches; i += 3)
- {
- uint8_t oldR = src[i];
- uint8_t oldG = src[i + 1];
- uint8_t oldB = src[i + 2];
- RGB_color oldColor = { oldR,oldG,oldB };
- newColor = palette->colors[findClosestColorIndexFromPalette(oldColor, palette)];
- uint8_t newR = newColor.r;
- uint8_t newG = newColor.g;
- uint8_t newB = newColor.b;
- dst[i] = newR;
- dst[i + 1] = newG;
- dst[i + 2] = newB;
- std::cout <<"dst["<<i<<"] "<<(int)dst[i];
- std::cout << "dst[" << i+1 << "] " <<(int) dst[i+1];
- std::cout << "dst[" << i+2 << "] " << (int)dst[i+2];
- std::cout << "\n";
- int errorR = dst[i] - newR;
- int errorG = dst[i + 1] - newG;
- int errorB = dst[i + 2] - newB;
- dst[i + 3] = dst[i + 3] + errorR * (7.0f / 16.0f);
- dst[i + 4] = dst[i + 4] + errorG * (7.0f / 16.0f);
- dst[i + 5] = dst[i + 5] + errorB * (7.0f / 16.0f);
- dst[i + width - 3] = dst[i + width - 3] + errorR * (3.0f / 16.0f);
- dst[i + width - 2] = dst[i + width - 2] + errorG * (3.0f / 16.0f);
- dst[i + width - 1] = dst[i + width - 1] + errorB * (3.0f / 16.0f);
- dst[i + width] = dst[i + width] + errorR * (5.0f / 16.0f);
- dst[i + width + 1] = dst[i + width + 1] + errorG * (5.0f / 16.0f);
- dst[i + width + 2] = dst[i + width + 2] + errorB * (5.0f / 16.0f);
- dst[i + width + 3] = dst[i + width + 3] + errorR * (1.0f / 16.0f);
- dst[i + width + 4] = dst[i + width + 4] + errorG * (1.0f / 16.0f);
- dst[i + width + 5] = dst[i + width + 5] + errorB * (1.0f / 16.0f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement