ASEPRITE::ASEPRITE(std::string filename) { std::ifstream file(filename, std::ios::in | std::ios::binary); if (!file.good()) { std::cout << "File " << filename << " not good\n"; file.close(); return; } if (!ASEPRITE::tinf_initialized) { tinf_init(); ASEPRITE::tinf_initialized = true; } if (file & header) { //header.toString(); PIXELTYPE pixelFormat = header.bitDepth == 8 ? INDEXED : header.bitDepth == 16 ? GRAYSCALE : RGBA; frames.resize(header.frames); for (size_t f = 0; f < header.frames && file.good(); f++) { //std::cout << " FRAME " << f << "\n"; if(!frames[f].read(file, pixelFormat)){ std::cout << " Failed to read FRAME " << f << " in " << filename << " ...stopping.\n"; break; } } } file.close(); }
// Decompress and read keyboard adjacency graphs bool zxcppvbn::build_graphs() { // Decompress from byte array tinf_init(); unsigned int dsize = calc_decompressed_size(adjacency_graphs, adjacency_graphs_size); std::unique_ptr<uint8_t[]> raw(new uint8_t[dsize]); if (tinf_gzip_uncompress(raw.get(), &dsize, adjacency_graphs, adjacency_graphs_size) != TINF_OK) { return false; } // Read simple format (file end - 0, keyboard end - 1, keyboard name and keys separator - 2, key and neighbors separator - 3) size_t i = 0; while (raw[i] != 0) { // Keyboard name size_t kbegin = i; while (raw[i] != 2) { i++; } std::string k(&raw[kbegin], &raw[i++]); // Keyboard neighbor maps std::map<char, std::vector<std::string>> m; while (raw[i] != 1) { // Key char c = raw[i++]; i++; // Neighbor list std::vector<std::string> l; while (raw[i] != 2) { // Neighbor characters size_t wbegin = i; while (raw[i] != 3) { i++; } std::string w(&raw[wbegin], &raw[i++]); l.push_back(std::move(w)); } m.insert(std::make_pair(std::move(c), std::move(l))); i++; } graphs.insert(std::make_pair(std::move(k), std::move(m))); i++; } return true; }
// Decompress and read dictionaries bool zxcppvbn::build_ranked_dicts() { // Decompress from byte array tinf_init(); unsigned int dsize = calc_decompressed_size(frequency_lists, frequency_lists_size); std::unique_ptr<uint8_t[]> raw(new uint8_t[dsize]); if (tinf_gzip_uncompress(raw.get(), &dsize, frequency_lists, frequency_lists_size) != TINF_OK) { return false; } // Read simple format (file end - 0, dictionary end - 1, dictionary name and value separator - 2) size_t i = 0; while (raw[i] != 0) { // Dictionary name size_t dbegin = i; while (raw[i] != 2) { i++; } std::string d(&raw[dbegin], &raw[i++]); // Dictionary words int rank = 1; std::map<std::string, int> l; while (raw[i] != 1) { // Word size_t wbegin = i; while (raw[i] != 2) { i++; } std::string w(&raw[wbegin], &raw[i++]); l.insert(std::make_pair(std::move(w), rank++)); } ranked_dictionaries.insert(std::make_pair(std::move(d), std::move(l))); i++; } return true; }