| 1 | /*************************************************************************** |
| 2 | * fheroes2: https://github.com/ihhub/fheroes2 * |
| 3 | * Copyright (C) 2020 - 2025 * |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the * |
| 17 | * Free Software Foundation, Inc., * |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | ***************************************************************************/ |
| 20 | |
| 21 | #include "pal.h" |
| 22 | |
| 23 | #include <array> |
| 24 | #include <cassert> |
| 25 | #include <cstring> |
| 26 | |
| 27 | namespace |
| 28 | { |
| 29 | const size_t paletteSize = 256; |
| 30 | |
| 31 | const std::vector<uint8_t> yellowTextTable |
| 32 | = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 115, 115, 116, 117, 117, 118, 119, 119, 120, 121, 121, 122, 123, 123, 124, 125, 125, 126, 127, 127, 128, |
| 33 | 129, 129, 130, 130, 130, 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, |
| 34 | 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, |
| 35 | 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, |
| 36 | 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 56 | |
| 57 | const std::vector<uint8_t> tanTable |
| 58 | = { 213, 213, 213, 213, 213, 213, 213, 213, 213, 213, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 200, 201, 203, 204, 206, 207, |
| 59 | 208, 209, 210, 211, 213, 213, 213, 213, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 199, 200, 201, 203, 204, 205, 207, |
| 60 | 207, 209, 210, 211, 212, 198, 198, 198, 198, 198, 201, 203, 205, 207, 208, 210, 210, 211, 212, 212, 213, 213, 213, 213, 213, 213, 213, 198, 198, |
| 61 | 198, 199, 201, 203, 204, 206, 207, 208, 209, 210, 211, 212, 213, 213, 213, 213, 213, 213, 213, 213, 213, 198, 198, 198, 198, 198, 198, 198, 198, |
| 62 | 198, 198, 198, 198, 198, 198, 198, 198, 198, 200, 201, 203, 204, 206, 207, 198, 198, 198, 198, 198, 198, 198, 198, 198, 200, 201, 203, 204, 206, |
| 63 | 207, 208, 209, 210, 212, 213, 213, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 199, 201, 203, 204, 206, 207, 208, 209, 211, 212, |
| 64 | 213, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 199, 201, 202, 204, 206, 207, 198, 198, 198, 198, 198, |
| 65 | 198, 198, 198, 198, 198, 198, 198, 198, 199, 202, 205, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, 200, 203, 204, 207, 208, 209, 201, |
| 66 | 203, 207, 209, 206, 209, 208, 198, 198, 207, 213, 198, 201, 206, 208, 213, 213, 213, 213, 213, 213, 213, 213, 213, 213 }; |
| 67 | |
| 68 | const std::vector<uint8_t> noCycleTable |
| 69 | = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, |
| 70 | 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, |
| 71 | 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, |
| 72 | 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, |
| 73 | 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, |
| 74 | 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, |
| 75 | 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, |
| 76 | 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 188, 188, 188, 188, 118, 118, 118, 118, 222, 223, 224, 225, 226, 227, 228, 229, 230, 69, |
| 77 | 69, 69, 69, 69, 236, 237, 69, 69, 69, 69, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 }; |
| 78 | |
| 79 | const std::vector<uint8_t> grayTable |
| 80 | = { 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, |
| 81 | 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 18, 19, 20, 20, 21, 22, 22, 23, 24, 25, 26, 26, 27, 28, 29, 31, 14, 16, 17, 18, 20, 21, 22, 24, 25, 26, 28, |
| 82 | 28, 29, 30, 31, 32, 32, 33, 33, 33, 34, 34, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 32, 33, 34, 35, 35, 36, 36, 36, 11, 11, 11, |
| 83 | 11, 11, 12, 12, 12, 13, 13, 14, 15, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 25, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 24, 24, 25, 26, 27, 28, 29, |
| 84 | 31, 32, 32, 33, 11, 12, 12, 13, 14, 14, 16, 16, 17, 18, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 32, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, |
| 85 | 15, 15, 16, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 10, 10, 11, 11, 11, 12, 12, 12, 12, 14, 16, 17, 18, 20, 22, 24, 17, 10, 12, 15, 19, 10, 10, 15, |
| 86 | 17, 18, 20, 21, 22, 23, 25, 26, 27, 27, 24, 21, 22, 26, 26, 27, 36, 12, 18, 25, 19, 21, 24, 26, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36 }; |
| 87 | |
| 88 | const std::vector<uint8_t> redTable |
| 89 | = { 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 180, 182, 184, 186, 208, 209, 210, 210, 211, 211, 212, 213, 213, 196, 197, 197, 197, 197, 197, |
| 90 | 197, 197, 197, 197, 197, 197, 197, 197, 180, 180, 182, 182, 184, 186, 208, 209, 209, 210, 210, 210, 211, 211, 193, 212, 212, 213, 213, 196, 197, |
| 91 | 197, 197, 197, 197, 197, 208, 209, 210, 211, 193, 212, 213, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 209, 210, |
| 92 | 210, 211, 212, 212, 213, 196, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 180, 180, 180, 180, 180, 182, 182, 183, |
| 93 | 184, 185, 208, 188, 189, 190, 210, 191, 211, 193, 193, 194, 195, 196, 197, 182, 184, 208, 209, 209, 210, 211, 211, 212, 213, 213, 196, 197, 197, |
| 94 | 197, 197, 197, 197, 197, 197, 197, 209, 209, 210, 210, 211, 211, 193, 212, 213, 213, 213, 196, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, |
| 95 | 197, 180, 180, 180, 182, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, |
| 96 | 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 187, 211, 180, 180, 215, 191, 192, 193, 194, 213, 197, 197, 197, 197, |
| 97 | 197, 197, 197, 197, 197, 197, 197, 197, 211, 197, 211, 212, 196, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197 }; |
| 98 | |
| 99 | const std::vector<uint8_t> brownTable |
| 100 | = { 50, 42, 42, 42, 42, 50, 50, 50, 50, 53, 42, 43, 43, 44, 44, 45, 46, 46, 47, 47, 48, 49, 50, 51, 52, 52, 53, 54, 55, 56, 57, 58, 60, 62, 62, 62, 62, |
| 101 | 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 45, 46, 47, 48, 50, 51, 52, 54, 55, 56, 58, |
| 102 | 58, 59, 60, 60, 61, 62, 62, 62, 62, 62, 62, 47, 48, 49, 50, 51, 52, 53, 54, 55, 57, 58, 58, 60, 60, 62, 62, 62, 62, 62, 62, 62, 62, 62, 43, 43, 44, |
| 103 | 44, 44, 45, 45, 45, 46, 47, 48, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 44, 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 53, 54, 55, 56, 57, |
| 104 | 58, 60, 62, 62, 43, 43, 44, 44, 45, 45, 46, 47, 47, 48, 49, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 43, 44, 46, 47, 48, 49, 50, 52, 53, 54, |
| 105 | 55, 57, 58, 60, 60, 62, 62, 62, 62, 62, 62, 62, 62, 44, 44, 45, 45, 46, 47, 48, 49, 50, 51, 53, 54, 55, 57, 58, 59, 54, 58, 62, 62, 42, 45, 49, 55, |
| 106 | 47, 49, 50, 51, 52, 53, 55, 56, 58, 51, 52, 55, 57, 54, 57, 56, 44, 48, 54, 62, 49, 51, 54, 57, 50, 50, 50, 50, 50, 50, 50, 50, 50, 42 }; |
| 107 | |
| 108 | const std::vector<uint8_t> mirrorImageTable |
| 109 | = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 110 | 25, 26, 27, 28, 29, 30, 31, 32, 37, 37, 37, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, |
| 111 | 54, 55, 56, 57, 58, 63, 63, 63, 63, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 85, 85, |
| 112 | 85, 85, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 108, 108, 108, 108, 108, 109, 110, 111, |
| 113 | 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 131, 131, 131, 131, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, |
| 114 | 141, 142, 143, 144, 145, 146, 147, 152, 152, 152, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, |
| 115 | 170, 175, 175, 175, 175, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 198, 198, 198, 198, 198, |
| 116 | 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 214, 215, 216, 217, 218, 219, 220, 221, 222, 222, 223, 224, 225, 226, 227, 228, 229, 231, |
| 117 | 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 242, 243, 244, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 }; |
| 118 | |
| 119 | const std::vector<uint8_t> darkeningTable |
| 120 | = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, |
| 121 | 35, 36, 36, 36, 36, 36, 36, 36, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 62, |
| 122 | 62, 62, 62, 62, 62, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 84, 84, 84, 84, 84, 91, 92, |
| 123 | 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 107, 107, 107, 107, 107, 107, 114, 115, 116, 117, 118, 119, 120, 121, |
| 124 | 122, 123, 124, 125, 126, 127, 128, 129, 130, 130, 130, 130, 130, 130, 130, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, |
| 125 | 150, 151, 151, 151, 151, 151, 151, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 174, 174, 174, 174, 174, |
| 126 | 174, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 197, 197, 197, 197, 197, 202, 203, 204, 205, 206, |
| 127 | 207, 208, 209, 210, 211, 212, 213, 213, 213, 213, 213, 214, 215, 216, 217, 218, 219, 220, 221, 225, 226, 227, 228, 229, 230, 230, 230, 230, 73, |
| 128 | 75, 77, 79, 81, 76, 78, 74, 76, 78, 80, 244, 245, 245, 245, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 129 | |
| 130 | const std::vector<uint8_t> goodToEvilInterfaceTable = { |
| 131 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
| 132 | 32, 33, 34, 35, 36, 14, 15, 16, 17, 17, 18, 23, 23, 24, 25, 26, 26, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36, 36, 63, |
| 133 | 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, |
| 134 | 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, |
| 135 | 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, |
| 136 | 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, |
| 137 | 192, 193, 194, 195, 196, 197, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, |
| 138 | 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, |
| 139 | }; |
| 140 | |
| 141 | const std::vector<uint8_t> goodToEvilButtonTable = { |
| 142 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
| 143 | 32, 33, 34, 35, 36, 14, 15, 16, 17, 17, 18, 19, 22, 21, 22, 23, 24, 25, 26, 26, 27, 28, 29, 30, 31, 32, 58, 59, 60, 35, 35, 63, |
| 144 | 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, |
| 145 | 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, |
| 146 | 31, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, |
| 147 | 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, |
| 148 | 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 31, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, |
| 149 | 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, |
| 150 | }; |
| 151 | |
| 152 | const std::vector<uint8_t> purpleTable |
| 153 | = { 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 131, 132, 133, 133, 134, 135, 136, 136, 137, 138, 139, 139, 140, 141, 142, 142, 143, 144, 145, |
| 154 | 145, 146, 147, 148, 149, 149, 150, 151, 131, 132, 133, 134, 134, 135, 136, 137, 138, 138, 139, 140, 141, 142, 142, 143, 144, 145, 146, 146, 147, |
| 155 | 148, 149, 150, 150, 151, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 151, 131, 132, |
| 156 | 133, 134, 135, 136, 137, 138, 139, 140, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 151, 131, 132, 133, 134, 135, 136, 137, 138, |
| 157 | 139, 140, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 151, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, |
| 158 | 145, 146, 147, 148, 149, 150, 151, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, |
| 159 | 151, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 151, 131, 132, 133, 135, 136, |
| 160 | 137, 139, 140, 141, 143, 144, 145, 147, 148, 149, 151, 142, 142, 142, 142, 140, 140, 140, 140, 131, 133, 135, 137, 141, 143, 147, 149, 151, 136, |
| 161 | 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 141, 144, 148, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151, 151 }; |
| 162 | |
| 163 | struct CyclingColorSet |
| 164 | { |
| 165 | uint8_t start; |
| 166 | uint8_t length; |
| 167 | bool forward; |
| 168 | }; |
| 169 | } |
| 170 | |
| 171 | std::vector<uint8_t> PAL::GetCyclingPalette( const uint32_t stepId ) |
| 172 | { |
| 173 | std::vector<uint8_t> palette = GetPalette( PaletteType::STANDARD ); |
| 174 | |
| 175 | static const std::array<CyclingColorSet, 4> cycleSet{ CyclingColorSet{ 214, 4, false }, CyclingColorSet{ 218, 4, false }, CyclingColorSet{ 231, 5, true }, |
| 176 | CyclingColorSet{ 238, 4, false } }; |
| 177 | |
| 178 | for ( const CyclingColorSet & colorSet : cycleSet ) { |
| 179 | if ( colorSet.forward ) { |
| 180 | for ( uint32_t id = 0; id < colorSet.length; ++id ) { |
| 181 | const uint32_t newColorID = colorSet.start + ( ( id + stepId ) % colorSet.length ); |
| 182 | palette[colorSet.start + id] = static_cast<uint8_t>( newColorID ); |
| 183 | } |
| 184 | } |
| 185 | else { |
| 186 | const uint32_t lastColorID = colorSet.length - 1; |
| 187 | const uint32_t lastColor = colorSet.start + lastColorID; |
| 188 | const uint32_t colorOffset = stepId + lastColorID; |
| 189 | |
| 190 | for ( uint32_t id = 0; id < colorSet.length; ++id ) { |
| 191 | const uint32_t newColorID = lastColor - ( ( colorOffset - id ) % colorSet.length ); |
| 192 | palette[colorSet.start + id] = static_cast<uint8_t>( newColorID ); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return palette; |
| 198 | } |
| 199 | |
| 200 | const std::vector<uint8_t> & PAL::GetPalette( const PaletteType type ) |
| 201 | { |
| 202 | switch ( type ) { |
| 203 | case PaletteType::YELLOW_FONT: { |
| 204 | assert( yellowTextTable.size() == paletteSize ); |
| 205 | return yellowTextTable; |
| 206 | } |
| 207 | case PaletteType::WHITE_FONT: { |
| 208 | assert( whiteTextTable.size() == paletteSize ); |
| 209 | return whiteTextTable; |
| 210 | } |
| 211 | case PaletteType::GRAY_FONT: { |
| 212 | assert( grayTextTable.size() == paletteSize ); |
| 213 | return grayTextTable; |
| 214 | } |
| 215 | case PaletteType::RED: { |
| 216 | assert( redTable.size() == paletteSize ); |
| 217 | return redTable; |
| 218 | } |
| 219 | case PaletteType::GRAY: { |
| 220 | assert( grayTable.size() == paletteSize ); |
| 221 | return grayTable; |
| 222 | } |
| 223 | case PaletteType::BROWN: { |
| 224 | assert( brownTable.size() == paletteSize ); |
| 225 | return brownTable; |
| 226 | } |
| 227 | case PaletteType::TAN: { |
| 228 | assert( tanTable.size() == paletteSize ); |
| 229 | return tanTable; |
| 230 | } |
| 231 | case PaletteType::NO_CYCLE: { |
| 232 | assert( noCycleTable.size() == paletteSize ); |
| 233 | return noCycleTable; |
| 234 | } |
| 235 | case PaletteType::MIRROR_IMAGE: { |
| 236 | assert( mirrorImageTable.size() == paletteSize ); |
| 237 | return mirrorImageTable; |
| 238 | } |
| 239 | case PaletteType::DARKENING: { |
| 240 | assert( darkeningTable.size() == paletteSize ); |
| 241 | return darkeningTable; |
| 242 | } |
| 243 | case PaletteType::GOOD_TO_EVIL_INTERFACE: { |
| 244 | assert( goodToEvilInterfaceTable.size() == paletteSize ); |
| 245 | return goodToEvilInterfaceTable; |
| 246 | } |
| 247 | case PaletteType::GOOD_TO_EVIL_BUTTON: { |
| 248 | assert( goodToEvilButtonTable.size() == paletteSize ); |
| 249 | return goodToEvilButtonTable; |
| 250 | } |
| 251 | case PaletteType::PURPLE: { |
| 252 | assert( purpleTable.size() == paletteSize ); |
| 253 | return purpleTable; |
| 254 | } |
| 255 | case PaletteType::CUSTOM: |
| 256 | assert( 0 ); |
| 257 | break; |
| 258 | case PaletteType::STANDARD: |
| 259 | break; |
| 260 | default: |
| 261 | // Did you add a new palette type? Add the corresponding palette for it! |
| 262 | assert( 0 ); |
| 263 | break; |
| 264 | } |
| 265 | |
| 266 | static std::vector<uint8_t> standard; |
| 267 | if ( standard.empty() ) { |
| 268 | standard.resize( paletteSize, 0 ); |
| 269 | for ( size_t i = 0; i < paletteSize; ++i ) { |
| 270 | standard[i] = static_cast<uint8_t>( i ); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | return standard; |
| 275 | } |
| 276 | |
| 277 | std::vector<uint8_t> PAL::CombinePalettes( const std::vector<uint8_t> & first, const std::vector<uint8_t> & second ) |
| 278 | { |
| 279 | if ( first.size() != paletteSize || second.size() != paletteSize ) { |
| 280 | // Make sure that the sizes of your palettes are correct! |
| 281 | assert( 0 ); |
| 282 | return std::vector<uint8_t>(); |
| 283 | } |
| 284 | |
| 285 | std::vector<uint8_t> combined( paletteSize, 0 ); |
| 286 | |
| 287 | for ( size_t i = 0; i < paletteSize; ++i ) { |
| 288 | combined[i] = second[first[i]]; |
| 289 | } |
| 290 | |
| 291 | return combined; |
| 292 | } |