MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / calculate

Method calculate

src/render/quantization.cpp:386–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

384}
385
386void PaletteOptimizer::calculate(Palette& palette, int maskIndex,
387 PaletteOptimizerDelegate* delegate)
388{
389 bool addMask;
390
391 if ((palette.size() > 1) &&
392 (maskIndex >= 0 && maskIndex < palette.size())) {
393 palette.resize(palette.size()-1);
394 addMask = true;
395 }
396 else
397 addMask = false;
398
399 // If the sprite has a background layer, the first entry can be
400 // used, in other case the 0 indexed will be the mask color, so it
401 // will not be used later in the color conversion (from RGB to
402 // Indexed).
403 int usedColors = m_histogram.createOptimizedPalette(palette);
404
405 if (addMask) {
406 palette.resize(usedColors+1);
407
408 Remap remap(palette.size());
409 for (int i=0; i<usedColors; ++i)
410 remap.map(i, i + (i >= maskIndex ? 1: 0));
411
412 palette.applyRemap(remap);
413
414 if (maskIndex < palette.size())
415 palette.setEntry(maskIndex, rgba(0, 0, 0, 255));
416 }
417 else
418 palette.resize(MAX(1, usedColors));
419}
420
421} // namespace render

Callers 3

Calls 7

mapMethod · 0.80
applyRemapMethod · 0.80
setEntryMethod · 0.80
rgbaFunction · 0.50
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected