| 103 | } |
| 104 | |
| 105 | void Palette::savePal(const std::string &file) const |
| 106 | { |
| 107 | std::ofstream out(file.c_str(), std::ios::out | std::ios::binary); |
| 108 | short count = _count; |
| 109 | |
| 110 | // RIFF header |
| 111 | out << "RIFF"; |
| 112 | int length = 4 + 4 + 4 + 4 + 2 + 2 + count * 4; |
| 113 | out.write((char*) &length, sizeof(length)); |
| 114 | out << "PAL "; |
| 115 | |
| 116 | // Data chunk |
| 117 | out << "data"; |
| 118 | int data = count * 4 + 4; |
| 119 | out.write((char*) &data, sizeof(data)); |
| 120 | short version = 0x0300; |
| 121 | out.write((char*) &version, sizeof(version)); |
| 122 | out.write((char*) &count, sizeof(count)); |
| 123 | |
| 124 | // Colors |
| 125 | SDL_Color *color = getColors(); |
| 126 | for (short i = 0; i < count; ++i) |
| 127 | { |
| 128 | char c = 0; |
| 129 | out.write((char*) &color->r, 1); |
| 130 | out.write((char*) &color->g, 1); |
| 131 | out.write((char*) &color->b, 1); |
| 132 | out.write(&c, 1); |
| 133 | color++; |
| 134 | } |
| 135 | out.close(); |
| 136 | } |
| 137 | |
| 138 | } |