Beispiel #1
0
QString FileWriter::suffixesForCompressedImage(const AssetInformation & info)
{
	const FileNameSuffix suffix(info.property("width").toInt(), info.property("height").toInt(),
		static_cast<GLenum>(info.property("compressedFormat").toInt()));

	return suffix.get();
}
Beispiel #2
0
bool ConvertManager::process(const QString & sourcePath)
{
    assert(!m_converter.isNull());
    assert(!m_writer.isNull());
    
    if (!QFile::exists(sourcePath))
    {
        qDebug() << "Input file does not exist.";
        return false;
    }
    
    QImage image(sourcePath);
    if (image.isNull())
    {
        qDebug() << "Loading image from input file failed.";
        return false;
    }

    AssetInformation info;
    info.setProperty("width", image.width());
    info.setProperty("height", image.height());

    for (auto editor : m_editors)
        editor->editImage(image, info);

    QByteArray imageData = m_converter->convert(image, info);

    if (imageData.isEmpty())
        return false;
    
    m_writer->write(imageData, sourcePath, info);

    return true;
}
Beispiel #3
0
QByteArray Converter::convert(std::unique_ptr<Canvas> & image, AssetInformation & info)
{  
	info.setProperty("format", static_cast<int>(m_format));
	info.setProperty("type", static_cast<int>(m_type));
    
    return image->imageFromTexture(m_format, m_type);
}
Beispiel #4
0
AssetInformation ConvertManager::generateAssetInformation(const QImage & image)
{
	AssetInformation info;
	info.setProperty("width", image.width());
	info.setProperty("height", image.height());

	return info;
}
Beispiel #5
0
QByteArray Converter::convert(QImage & image, AssetInformation & info)
{
    m_canvas.loadTextureFromImage(image);
    
    if (hasFragmentShader() && !m_canvas.process(m_fragmentShader, m_uniforms))
        return QByteArray();
    
    info.setProperty("format", QVariant(static_cast<int>(m_format)));
    info.setProperty("type", QVariant(static_cast<int>(m_type)));
    
    return m_canvas.imageFromTexture(m_format, m_type);
}
Beispiel #6
0
void FileWriter::writeHeader(QDataStream & dataStream, QFile & file, AssetInformation & info)
{
    if (info.properties().empty())
        return;

    dataStream << static_cast<quint16>(RawFile::s_signature);

    quint64 rawDataOffsetPosition = file.pos();
    dataStream << static_cast<quint64>(0);

    QMapIterator<QVariantMap::key_type, QVariantMap::mapped_type> iterator(info.properties());

    while (iterator.hasNext())
    {
        iterator.next();

        QString key = iterator.key();
        QVariant value = iterator.value();

		RawFile::PropertyType type = propertyType(value.type());

        if (type == RawFile::PropertyType::Unknown)
            continue;

        dataStream << static_cast<uint8_t>(type);
        writeString(dataStream, key);

        writeValue(dataStream, value);
    }

    quint64 rawDataOffset = file.pos();

    file.seek(rawDataOffsetPosition);
    dataStream << rawDataOffset;
    file.seek(rawDataOffset);
}
Beispiel #7
0
QString FileWriter::targetFilePath(const QString & sourcePath, const AssetInformation & info)
{
    QFileInfo fileInfo(sourcePath);

    const QString fileExtension = m_headerEnabled ? "glraw" : "raw";
    
    const QString path = outputPathSet() ? m_outputPath : fileInfo.absolutePath();
    
    if (!m_suffixesEnabled)
        return path + "/" + fileInfo.baseName() + "." + fileExtension;
    
    QString suffixes;
    if (info.propertyExists("compressedFormat"))
        suffixes = suffixesForCompressedImage(info);
    else
        suffixes = suffixesForImage(info);
    
    return path + "/" + fileInfo.baseName() + suffixes + "." + fileExtension;
}