#include <iostream>
#include <cstdint>
#include "a83/macro.hpp"
#include <cmath>
#include "image/image-color.hpp"
uint func(uint a_, uint b_) {
  int ret;
  const Color a(a_);
  const Color b(b_);
  cauto ad = a.to_d();
  cauto bd = b.to_d();
  cauto a_is_red = a.is_red();
  cauto b_is_red = b.is_red();
  cauto val = ad - bd;
  if (a_is_red and b_is_red) { // red red
    ret = Color::from_d(val, true).val;
  } else if (a_is_red and !b_is_red) { // red gray
    ret = Color::from_d(val, true).val;
  } else if (!a_is_red and b_is_red) { // gray red
    ret = Color::from_d(val, true).val;
  } else { // gray gray
    ret = Color::from_d(val, false).val;
  }
  return std::clamp(ret, 0, 255);
} // func blend
int main() {
  using namespace std;
  cout << "constexpr uint8_t table_sub_safe[256][256] = {\n";
  for (uint y = 0; y < 256; ++y) {
    cout << "  {";
    for (uint x = 0; x < 256; ++x)
      cout << uint(func(x, y)) << ", ";
    cout << "},\n";
  }
  cout << "};\n";
}