Exemple #1
0
void pre_lzw::do_lzw(const QDir & d){
    FreeImage_Initialise(true);
    QString label_out = "";
    QString dst = ui.lineEdit_2->text();
    QString d_src = d.path();
    QString serial_str = d_src.right(5);
    QDir dst_dir(dst);
    dst_dir.mkdir(serial_str);
    QString image_name = "", image_name_path(""), saved_name("");
    int dot_pos = 0;
    QFileInfoList handled_images = d.entryInfoList();
    QList<QFileInfo>::iterator images_iter = handled_images.begin();
    
    FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
    for(; images_iter < handled_images.end(); ++images_iter){
        image_name_path = (*images_iter).absoluteFilePath();
        if((*images_iter).isDir()){
            continue;
        }
        FIBITMAP *handled_image = 0;
        image_name = (*images_iter).fileName();
        dot_pos = image_name.indexOf(".");
        saved_name = dst + "\\" + serial_str + "\\" + image_name.left(dot_pos) + "_c.tif";
        label_out += saved_name + "\n";
        fif = FreeImage_GetFileType(image_name_path.toStdString().c_str());
        handled_image = FreeImage_Load(fif, image_name_path.toStdString().c_str());
        FreeImage_Save(FIF_TIFF, handled_image, saved_name.toStdString().c_str(), TIFF_LZW);
        FreeImage_Unload(handled_image);
    }
//    ui.label->setText(label_out);
    FreeImage_DeInitialise();

}
void SettingsDialog::accept()
{
    QSettings s;

    s.setValue("bt/seed_enabled", ui->seedCheckBox->isChecked());

    QDir src_dir(s.value("bt/datapath", getDefaultGameDataDirectory()).toString());
    QDir dst_dir(QDir::fromNativeSeparators(ui->dataPathEdit->text()));
    if (src_dir != dst_dir) {
        s.setValue("bt/datapath", ui->dataPathEdit->text());
        emit moveGameDataRequested(src_dir.absolutePath(), dst_dir.absolutePath());
    }
    s.setValue("bt/download_limit_enabled", ui->downloadCheckBox->isChecked());
    s.setValue("bt/upload_limit_enabled", ui->uploadCheckBox->isChecked());
    s.setValue("bt/download_limit_value", ui->downloadSpin->value());
    s.setValue("bt/upload_limit_value", ui->uploadSpin->value());
    s.setValue("bt/connections_limit_value", ui->connectionsSpin->value());
    s.setValue("bt/utp_enabled", ui->utpCheckBox->isChecked());

    QDialog::accept();
}
Exemple #3
0
void Application::copyFilesRecursively(const QString &src_path, const QString &dst_path)
{
    QFileInfo src_file(src_path);

    if(!src_file.exists())
        throw Exception(Exception::getErrorMessage(ERR_FILE_DIR_NOT_ACCESSED).arg(src_path),
                        __PRETTY_FUNCTION__,__FILE__,__LINE__);

    if(src_file.isDir())
    {
        QString new_src_path, new_dst_path;
        QStringList filenames;
        QDir dst_dir(dst_path),
             src_dir(src_path);

        if(!dst_dir.exists() && !dst_dir.mkpath(dst_path))
            throw Exception(Exception::getErrorMessage(ERR_FILE_DIR_NOT_WRITTEN).arg(dst_path),
                            __PRETTY_FUNCTION__,__FILE__,__LINE__);

        filenames = src_dir.entryList({QString("*%1").arg(GlobalAttributes::CONFIGURATION_EXT)},
                                      QDir::Files | QDir::NoDotAndDotDot);

        for(QString filename : filenames)
        {
            //Avoiding the copy of ui-style.conf file
            if(!filename.contains(GlobalAttributes::UI_STYLE_CONF))
            {
                new_src_path = src_path + src_dir.separator() + filename;
                new_dst_path = dst_path + dst_dir.separator() + filename;
                copyFilesRecursively(new_src_path, new_dst_path);
            }
        }
    }
    else if(!QFile::exists(dst_path) && !QFile::copy(src_path, dst_path))
    {
        throw Exception(Exception::getErrorMessage(ERR_FILE_DIR_NOT_WRITTEN).arg(dst_path),
                        __PRETTY_FUNCTION__,__FILE__,__LINE__);
    }
}
Exemple #4
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QDir src_dir("../gfx/");
    QDir dst_dir("c:/temp/");
    dst_dir.mkdir("gfx_2x/");
    dst_dir.cd("gfx_2x/");

    QRgb filter_rgb = qRgba(240, 0, 0, 255);
    QRgb mask_rgb = qRgba(255, 0, 255, 255);
    QRgb shadow_rgb = qRgba(127, 0, 127, 255);

    QStringList list = src_dir.entryList();
    foreach(const QString file, list) {
        qDebug("found file: %s", file.toStdString().c_str());
        QImage image(src_dir.filePath(file));
        if( !image.isNull() ) {
            if( image.width() % 2 != 0 ) {
                throw "image width not multiple of 2";
            }
            if( image.height() % 2 != 0 ) {
                throw "image height not multiple of 2";
            }
            int new_width = image.width() / 2;
            int new_height = image.height() / 2;
            QImage new_image(new_width, new_height, image.format());
            new_image.fill(0);
            for(int y=0;y<new_height;y++) {
                for(int x=0;x<new_width;x++) {
                    QRgb rgb00 = image.pixel(2*x, 2*y);
                    QRgb rgb10 = image.pixel(2*x+1, 2*y);
                    QRgb rgb01 = image.pixel(2*x, 2*y);
                    QRgb rgb11 = image.pixel(2*x+1, 2*y+1);
                    if( rgb00 == filter_rgb || rgb10 == filter_rgb || rgb01 == filter_rgb || rgb11 == filter_rgb ) {
                        rgb00 = filter_rgb;
                        rgb10 = filter_rgb;
                        rgb01 = filter_rgb;
                        rgb11 = filter_rgb;
                    }
                    else if( rgb00 == mask_rgb || rgb10 == mask_rgb || rgb01 == mask_rgb || rgb11 == mask_rgb ) {
                        rgb00 = mask_rgb;
                        rgb10 = mask_rgb;
                        rgb01 = mask_rgb;
                        rgb11 = mask_rgb;
                    }
                    else if( rgb00 == shadow_rgb || rgb10 == shadow_rgb || rgb01 == shadow_rgb || rgb11 == shadow_rgb ) {
                        rgb00 = shadow_rgb;
                        rgb10 = shadow_rgb;
                        rgb01 = shadow_rgb;
                        rgb11 = shadow_rgb;
                    }
                    /*if( rgb00 == mask_rgb ) {
                        rgb00 = qRgba(0, 0, 0, 0);
                    }
                    if( rgb10 == mask_rgb ) {
                        rgb10 = qRgba(0, 0, 0, 0);
                    }
                    if( rgb01 == mask_rgb ) {
                        rgb01 = qRgba(0, 0, 0, 0);
                    }
                    if( rgb11 == mask_rgb ) {
                        rgb11 = qRgba(0, 0, 0, 0);
                    }
                    if( rgb00 == shadow_rgb ) {
                        rgb00 = qRgba(0, 0, 0, 0);
                    }
                    if( rgb10 == shadow_rgb ) {
                        rgb10 = qRgba(0, 0, 0, 0);
                    }
                    if( rgb01 == shadow_rgb ) {
                        rgb01 = qRgba(0, 0, 0, 0);
                    }
                    if( rgb11 == shadow_rgb ) {
                        rgb11 = qRgba(0, 0, 0, 0);
                    }*/
                    int irgb00[] = {qRed(rgb00), qGreen(rgb00), qBlue(rgb00), qAlpha(rgb00)};
                    int irgb10[] = {qRed(rgb10), qGreen(rgb10), qBlue(rgb10), qAlpha(rgb10)};
                    int irgb01[] = {qRed(rgb01), qGreen(rgb01), qBlue(rgb01), qAlpha(rgb01)};
                    int irgb11[] = {qRed(rgb11), qGreen(rgb11), qBlue(rgb11), qAlpha(rgb11)};
                    int irgb[] = {0, 0, 0, 0};
                    for(int i=0;i<4;i++) {
                        int result = (int)((irgb00[i] + irgb10[i] + irgb01[i] + irgb11[i]) / 4.0);
                        irgb[i] = result;
                    }
                    QRgb rgb = qRgba(irgb[0], irgb[1], irgb[2], irgb[3]);
                    new_image.setPixel(x, y, rgb);
                }
            }
            QString save_filename = dst_dir.filePath(file);
            qDebug("    save as %s", save_filename.toStdString().c_str());
            if( !new_image.save(save_filename) ) {
                throw "failed to save";
            }
        }
        else {
            qDebug("    failed to load");
        }
    }