std::vector<std::unique_ptr<style::Image>> parseSprite(const std::string& encodedImage, const std::string& json) {
    const PremultipliedImage raster = decodeImage(encodedImage);

    JSDocument doc;
    doc.Parse<0>(json.c_str());
    if (doc.HasParseError()) {
        std::stringstream message;
        message << "Failed to parse JSON: " << rapidjson::GetParseError_En(doc.GetParseError()) << " at offset " << doc.GetErrorOffset();
        throw std::runtime_error(message.str());
    } else if (!doc.IsObject()) {
        throw std::runtime_error("Sprite JSON root must be an object");
    } else {
        std::vector<std::unique_ptr<style::Image>> images;
        for (const auto& property : doc.GetObject()) {
            const std::string name = { property.name.GetString(), property.name.GetStringLength() };
            const JSValue& value = property.value;

            if (value.IsObject()) {
                const uint16_t x = getUInt16(value, "x", 0);
                const uint16_t y = getUInt16(value, "y", 0);
                const uint16_t width = getUInt16(value, "width", 0);
                const uint16_t height = getUInt16(value, "height", 0);
                const double pixelRatio = getDouble(value, "pixelRatio", 1);
                const bool sdf = getBoolean(value, "sdf", false);

                auto image = createStyleImage(name, raster, x, y, width, height, pixelRatio, sdf);
                if (image) {
                    images.push_back(std::move(image));
                }
            }
        }
        return images;
    }
}
Exemplo n.º 2
0
void Bytecode::dump(ostream& out) const {
    for (size_t bci = 0; bci < length();) {
        size_t length;
        Instruction insn = getInsn(bci);
        out << bci << ": ";
        const char* name = bcName(insn, length);
        switch (insn) {
            case BC_DLOAD:
                out << name << " " << getDouble(bci + 1);
                break;
            case BC_ILOAD:
                out << name << " " << getInt64(bci + 1);
                break;
            case BC_SLOAD:
                out << name << " @" << getUInt16(bci + 1);
                break;
            case BC_CALL:
            case BC_CALLNATIVE:
                out << name << " *" << getUInt16(bci + 1);
                break;
            case BC_LOADDVAR:
            case BC_STOREDVAR:
            case BC_LOADIVAR:
            case BC_STOREIVAR:
            case BC_LOADSVAR:
            case BC_STORESVAR:
                out << name << " @" << getUInt16(bci + 1);
                break;
            case BC_LOADCTXDVAR:
            case BC_STORECTXDVAR:
            case BC_LOADCTXIVAR:
            case BC_STORECTXIVAR:
            case BC_LOADCTXSVAR:
            case BC_STORECTXSVAR:
                out << name << " @" << getUInt16(bci + 1)
                    << ":" << getUInt16(bci + 3);
                break;
            case BC_IFICMPNE:
            case BC_IFICMPE:
            case BC_IFICMPG:
            case BC_IFICMPGE:
            case BC_IFICMPL:
            case BC_IFICMPLE:
            case BC_JA:
                out << name << " " << getInt16(bci + 1) + bci + 1;
                break;
          default:
                out << name;
        }
        out << endl;
        bci += length;
    }
}
Exemplo n.º 3
0
 StackObj getVar() {
     uint16_t  var_id = getUInt16();
     if (scope_vars.size() < var_id) {
         throw new std::runtime_error("Uncorrect var");
     }
     return scope_vars[var_id];
 }
Exemplo n.º 4
0
 void storeVar(StackObj var) {
     uint16_t  var_id = getUInt16();
     if (scope_vars.size() < var_id) {
         throw new std::runtime_error("Uncorrect var");
     }
     scope_vars[var_id] = var;
 }
Exemplo n.º 5
0
UInt16List* MtpDataPacket::getAUInt16() {
    UInt16List* result = new UInt16List;
    int count = getUInt32();
    for (int i = 0; i < count; i++)
        result->push_back(getUInt16());
    return result;
}
Exemplo n.º 6
0
int TwoWireCallback(uint8_t address, uint8_t *data, uint8_t len, uint8_t maxLen) {
	
	if (len < 3) {
		return 0;
	}
	
	switch (data[0]) {
		case FUNCTION_GLOBAL_RESET:
		case FUNCTION_EXIT_BOOTLOADER:
			bootloaderRunning = false;
			break;
		case FUNCTION_GET_BOOTLOADER_VERSION:
			if (len == 5 && checkDeviceID(data+2)) {
				// Return the device ID
				data[0] = BOOTLOADER_VERSION & 0xFF;
				data[1] = BOOTLOADER_VERSION >> 8;
				return 2;
			}
			break;
		case FUNCTION_GET_NEXT_DEVICE_ID:
			if (len == 5) {
				uint16_t previousID = getUInt16(data+2);
				uint16_t deviceID = selfProgram.getDeviceID();
				if (previousID < deviceID) {
					// Return the device ID
					data[1] = deviceID & 0xFF;
					data[0] = deviceID >> 8;
					return 2;
				}
Exemplo n.º 7
0
 /** Return value as unsigned integer, depending on length.
   */
 unsigned getUInt()   {
    switch(mLength) {
       case sizeof(uint8_t): return getUInt8(); break;
       case sizeof(uint16_t): return getUInt16(); break;
       case sizeof(uint32_t): default: return getUInt32(); break;
    }
    return 0;
 }
Exemplo n.º 8
0
SpriteParseResult parseSprite(const std::string& image, const std::string& json) {
    Sprites sprites;
    PremultipliedImage raster;

    try {
        raster = decodeImage(image);
    } catch (...) {
        return std::current_exception();
    }

    JSDocument doc;
    doc.Parse<0>(json.c_str());

    if (doc.HasParseError()) {
        std::stringstream message;
        message << "Failed to parse JSON: " << rapidjson::GetParseError_En(doc.GetParseError()) << " at offset " << doc.GetErrorOffset();
        return std::make_exception_ptr(std::runtime_error(message.str()));
    } else if (!doc.IsObject()) {
        return std::make_exception_ptr(std::runtime_error("Sprite JSON root must be an object"));
    } else {
        for (JSValue::ConstMemberIterator itr = doc.MemberBegin(); itr != doc.MemberEnd(); ++itr) {
            const std::string name = { itr->name.GetString(), itr->name.GetStringLength() };
            const JSValue& value = itr->value;

            if (value.IsObject()) {
                const uint16_t x = getUInt16(value, "x", 0);
                const uint16_t y = getUInt16(value, "y", 0);
                const uint16_t width = getUInt16(value, "width", 0);
                const uint16_t height = getUInt16(value, "height", 0);
                const double pixelRatio = getDouble(value, "pixelRatio", 1);
                const bool sdf = getBoolean(value, "sdf", false);

                auto sprite = createSpriteImage(raster, x, y, width, height, pixelRatio, sdf);
                if (sprite) {
                    sprites.emplace(name, sprite);
                }
            }
        }
    }

    return sprites;
}
Exemplo n.º 9
0
UInt16List* MtpDataPacket::getAUInt16() {
    uint32_t count;
    if (!getUInt32(count))
        return NULL;
    UInt16List* result = new UInt16List;
    for (uint32_t i = 0; i < count; i++) {
        uint16_t value;
        if (!getUInt16(value)) {
            delete result;
            return NULL;
        }
        result->push(value);
    }
    return result;
}
Exemplo n.º 10
0
void qipinfium::loadMessages(const QString &path)
{
	QDir dir = path;
	if(!dir.cd("History"))
		return;
	QHash<QString,QString> protocols;
	protocols[QLatin1String("icq")]    = QLatin1String("ICQ");
	protocols[QLatin1String("jabber")] = QLatin1String("Jabber");
	protocols[QLatin1String("mra")]    = QLatin1String("MRIM");
	QStringList filters;
	foreach(QString format,protocols.keys())
		filters << (format + QLatin1String("*.qhf")) << (format + QLatin1String("*.ahf"));
	QFileInfoList files = dir.entryInfoList(filters, QDir::Files);
	setMaxValue(files.size());
	for(int i = 0; i < files.size(); i++)
	{
		setValue(i + 1);
		QString protocol = files[i].fileName().section("_",0,0);
		while(!protocol.isEmpty() && protocol.at(protocol.length() - 1).isDigit())
			protocol.chop(1);
		protocol = protocols[protocol.toLower()];
		if(protocol.isEmpty())
		{
			warning() << "Unknown protocol: " << files[i].fileName();
			continue;
		}
		setProtocol(protocol);
		setAccount(m_accounts.value(protocol));
		QFile file(files[i].absoluteFilePath());
		if(file.open(QFile::ReadOnly))
		{
			QByteArray bytearray = file.readAll();
			const uchar *data = (const uchar *)bytearray.constData();
			const uchar *end = data + bytearray.size();
			if(memcmp(data, "QHF", 3))
				continue;
			uchar version = data[3];
			data += 44;
			QString uin = getString(data, getUInt16(data));
			QString name = getString(data, getUInt16(data));
			Q_UNUSED(name);
			QDateTime time;
			setContact(uin);
			while(data < end)
			{
				quint16 type = getUInt16(data);
				quint32 index = getUInt32(data);
				data += 2;
				if(type == 1)
				{
					Message message;
					data += 10;
					time = QDateTime::fromTime_t(getUInt32(data));
					time.setTimeSpec(Qt::LocalTime);
					if(version == 1)
						time = time.toUTC().addDays(2);
					else
						time = time.toUTC();
					message.setTime(time);
					data += 4;
					message.setIncoming(getUInt8(data) == 0);
					data += 4;
					int mes_len = version == 3 ? getUInt32(data) : getUInt16(data);
					message.setText(getString(data, mes_len, version > 1));
					appendMessage(message);
				}
				else
					data += index;
			}
		}
	}
}
Exemplo n.º 11
0
int Hdf::compare(uint16_t v2) const {
  uint16_t v1 = getUInt16();
  if (v1 == v2) return 0;
  return v1 > v2 ? 1 : -1;
}
Exemplo n.º 12
0
uint16_t MtpPacket::getContainerType() const {
    return getUInt16(MTP_CONTAINER_TYPE_OFFSET);
}
Exemplo n.º 13
0
uint16_t MtpPacket::getContainerCode() const {
    return getUInt16(MTP_CONTAINER_CODE_OFFSET);
}
Exemplo n.º 14
0
 void storeContextVar(StackObj var) {
     uint16_t context_id = getUInt16();
     uint16_t  var_id = getUInt16();
     storeContextVar(var, context_id, var_id);
 }
Exemplo n.º 15
0
 StackObj getContextVar() {
     uint16_t context_id = getUInt16();
     uint16_t var_id = getUInt16();
     return getContextVar(context_id, var_id);
 }
Exemplo n.º 16
0
int checkDeviceID(uint8_t *data) {
	return (getUInt16(data) == selfProgram.getDeviceID());
}