compress.ino 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #define MAT_WIDTH 16
  2. constexpr uint32_t compress(int **mat) {
  3. uint32_t mat_compressed = 0;
  4. for (uint8_t r = 0; r < MAT_WIDTH; ++r) {
  5. for (uint8_t c = 0; c < MAT_WIDTH; ++c) {
  6. uint32_t oneDInd = 1 << (r * MAT_WIDTH + c);
  7. if (mat[r][c])
  8. mat_compressed |= oneDInd;
  9. }
  10. }
  11. return mat_compressed;
  12. }
  13. constexpr uint32_t dikk() {
  14. const int[MAT_WIDTH][MAT_WIDTH] arrayMap = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0},{0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0},{0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0},{0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0},{0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0},{0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0},{0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0},{0,0,0,1,0,0,1,0,1,1,0,0,0,0,0,0},{0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
  15. return compress(arrayMap);
  16. }
  17. void decompress(uint32_t mat_compressed) {
  18. for (uint8_t r = 0; r < MAT_WIDTH; ++r) {
  19. for (uint8_t c = 0; c < MAT_WIDTH; ++c) {
  20. uint32_t oneDInd = 1 << (r * MAT_WIDTH + c);
  21. Serial.print((mat_compressed & oneDInd) > 1);
  22. }
  23. Serial.println();
  24. }
  25. }
  26. void setup() {
  27. const uint32_t dik = dikk();
  28. decompress(dik);
  29. }
  30. void loop() {}