bsnes/nall/encode/mtf.hpp
Tim Allen bd814f0358 Update to v106r59 release.
byuu says:

Changelog:

  - fixed bug in Emulator::Game::Memory::operator bool()
  - nall: renamed view<string> back to `string_view`
  - nall:: implemented `array_view`
  - Game Boy: split cartridge-specific input mappings (rumble,
    accelerometer) to their own separate ports
  - Game Boy: fixed MBC7 accelerometer x-axis
  - icarus: Game Boy, Super Famicom, Mega Drive cores output internal
    header game titles to heuristics manifests
  - higan, icarus, hiro/gtk: improve viewport geometry configuration;
    fixed higan crashing bug with XShm driver
  - higan: connect Video::poll(),update() functionality
  - hiro, ruby: several compilation / bugfixes, should get the macOS
    port compiling again, hopefully [Sintendo]
  - ruby/video/xshm: fix crashing bug on window resize
      - a bit hacky; it's throwing BadAccess Xlib warnings, but they're
        not fatal, so I am catching and ignoring them
  - bsnes: removed Application::Windows::onModalChange hook that's no
    longer needed [Screwtape]
2018-08-26 16:49:54 +10:00

31 lines
588 B
C++

#pragma once
//move to front
namespace nall { namespace Encode {
inline auto MTF(array_view<uint8_t> input) -> vector<uint8_t> {
vector<uint8_t> output;
output.resize(input.size());
uint8_t order[256];
for(uint n : range(256)) order[n] = n;
for(uint offset : range(input.size())) {
uint data = input[offset];
for(uint index : range(256)) {
uint value = order[index];
if(value == data) {
output[offset] = index;
memory::move(&order[1], &order[0], index);
order[0] = value;
break;
}
}
}
return output;
}
}}