Пример #1
0
void read_from(ReadSource in, BitMap& out) {
    read(in, out.base_addr);
    read(in, out.row_bytes);
    read(in, out.bounds);

    if (out.base_addr != 0) {
        throw Exception("PixMap::base_addr must be 0");
    }
}
Пример #2
0
ScenarioList::ScenarioList() {
    linked_ptr<Entry> factory_scenario(new Entry);
    factory_scenario->identifier.assign("com.biggerplanet.ares");
    factory_scenario->title.assign("Ares");
    factory_scenario->download_url.assign("http://www.arescentral.com");
    factory_scenario->author.assign("Bigger Planet");
    factory_scenario->author_url.assign("http://www.biggerplanet.com");
    u32_to_version(0x01010100, factory_scenario->version);
    _scenarios.push_back(factory_scenario);

    ScopedGlob g;
    const String home(utf8::decode(getenv("HOME")));
    const StringSlice scenarios("Library/Application Support/Antares/Scenarios");
    const StringSlice info("scenario-info/128.nlAG");
    String str(format("{0}/{1}/*/{2}", home, scenarios, info));
    CString c_str(str);
    glob(c_str.data(), 0, NULL, &g.data);

    size_t prefix_len = home.size() + scenarios.size() + 2;
    size_t suffix_len = info.size() + 1;
    for (int i = 0; i < g.data.gl_matchc; ++i) {
        const String path(utf8::decode(g.data.gl_pathv[i]));
        StringSlice identifier = path.slice(prefix_len, path.size() - prefix_len - suffix_len);
        if (identifier == factory_scenario->identifier) {
            continue;
        }

        MappedFile file(path);
        BytesSlice data(file.data());
        scenarioInfoType info;
        read(data, info);
        linked_ptr<Entry> entry(new Entry);
        entry->identifier.assign(identifier);
        entry->title.assign(info.titleString);
        entry->download_url.assign(info.downloadURLString);
        entry->author.assign(info.authorNameString);
        entry->author_url.assign(info.authorURLString);
        u32_to_version(info.version, entry->version);
        _scenarios.push_back(entry);
    }
}
Пример #3
0
void read_from(ReadSource in, fixed32_t& out) {
    read(in, out.int_value);
}
Пример #4
0
void read_from(ReadSource in, Rect& out) {
    read(in, out.top);
    read(in, out.left);
    read(in, out.bottom);
    read(in, out.right);
}
Пример #5
0
void read_from(ReadSource in, AddressedPixMap& out) {
    read(in, out.base_addr);
    PixMap& parent = out;
    read(in, parent);
}
Пример #6
0
void read_from(ReadSource in, PixMap& out) {
    read(in, out.row_bytes);
    out.row_bytes &= 0x3fff;
    read(in, out.bounds);
    read(in, out.pm_version);
    read(in, out.pack_type);
    read(in, out.pack_size);
    read(in, out.h_res);
    read(in, out.v_res);
    read(in, out.pixel_type);
    read(in, out.pixel_size);
    read(in, out.cmp_count);
    read(in, out.cmp_size);
    read(in, out.plane_bytes);
    read(in, out.pm_table);
    read(in, out.pm_reserved);

    if (out.plane_bytes != 0) {
        throw Exception("PixMap::plane_bytes must be 0");
    }
    if (out.pm_reserved != 0) {
        throw Exception("PixMap::pm_reserved must be 0");
    }

    switch (out.pixel_type) {
        case INDEXED: {
            switch (out.pixel_size) {
              case 1:
              case 2:
              case 4:
              case 8:
                break;

              default:
                throw Exception(format("indexed pixels may not have size {0}", out.pixel_size));
            }
            if ((out.pack_type != 0) || (out.pack_size != 0)) {
                throw Exception("indexed pixels may not be packed");
            }
            if ((out.cmp_count != 1) || (out.cmp_size != out.pixel_size)) {
                throw Exception("indexed pixels must have one component");
            }
            break;
        }

        case RGB_DIRECT: {
            switch (out.pixel_size) {
                case 16: {
                    throw Exception(format("unsupported pixel_size {0}", out.pixel_size));
                    break;
                }

                case 32: {
                    if (out.cmp_size != 8) {
                        throw Exception("32-bit direct pixels must have cmp_size 8");
                    }
                    break;
                }

                default: {
                    throw Exception(format("direct pixels may not have size {0}", out.pixel_size));
                }
            }
            if ((out.cmp_count != 3) && (out.cmp_count != 4)) {
                throw Exception("direct pixels must have three or four components");
            }
            break;
        }

        default: {
            throw Exception(format("illegal PixMap pixel_type {0}", out.pixel_type));
        }
    }
}