QStringList MainWindow::do_save_color_ranges(QString &base) { QMap<QString, rc_map> jobs; const QString& palId = current_pal_name(); const QList<QRgb>& palData = current_pal_data(); QStringList needOverwriteFiles; for(int k = 0; k < ui->listRanges->count(); ++k) { QListWidgetItem* itemw = ui->listRanges->item(k); Q_ASSERT(itemw); if(itemw->checkState() == Qt::Checked) { const QString& rangeId = itemw->data(Qt::UserRole).toString(); const QString& filePath = base + "/" + QFileInfo(img_path_).completeBaseName() + "-RC-" + palId + "-" + QString::number(k + 1) + "-" + rangeId + ".png"; jobs[filePath] = recolor_range(color_ranges_.value(rangeId), palData); if(QFileInfo(filePath).exists()) { needOverwriteFiles.push_back(filePath); } } } if(!needOverwriteFiles.isEmpty() && !confirm_existing_files(needOverwriteFiles)) { throw canceled_job(); } return do_run_jobs(jobs); }
std::vector<color_t> palette(const color_range& cr) { std::vector<color_t> temp, res; std::unordered_set<color_t> clist; // Use blue to make master set of possible colors for(int i = 255; i != 0; i--) { const int j = 255 - i; temp.emplace_back(static_cast<uint8_t>(0), static_cast<uint8_t>(0), static_cast<uint8_t>(i)); temp.emplace_back(static_cast<uint8_t>(j), static_cast<uint8_t>(j), static_cast<uint8_t>(255)); } // Use recolor function to generate list of possible colors. // Could use a special function, would be more efficient, but harder to maintain. color_range_map cmap = recolor_range(cr, temp); for(const auto& cm : cmap) { clist.insert(cm.second); } res.push_back(cmap[{0,0,255}]); for(const auto& cs : clist) { if(cs != res[0] && !cs.null() && cs != color_t(255, 255, 255)) { res.push_back(cs); } } return res; }
void MainWindow::refresh_previews() { if(this->img_original_.isNull() || this->signalsBlocked()) return; rc_map cvtMap; const QList<QRgb>& palData = current_pal_data(); if(ui->staFunctionOpts->currentIndex()) { const QList<QRgb>& targetPalData = current_pal_data(true); cvtMap = recolor_palettes(palData, targetPalData); } else { cvtMap = recolor_range(color_ranges_.value(ui->listRanges->currentIndex().data(Qt::UserRole).toString()), palData); } rc_image(img_original_, img_transview_, cvtMap); const QSize& scaled_size = img_original_.size() * zoom_; ui->previewOriginal->setPixmap(QPixmap::fromImage(img_original_)); ui->previewRc->setPixmap(QPixmap::fromImage(img_transview_)); ui->previewOriginal->resize(scaled_size); ui->previewRc->resize(scaled_size); ui->previewOriginal->parentWidget()->adjustSize(); ui->previewRc->parentWidget()->adjustSize(); centerScrollArea(ui->previewOriginalContainer); centerScrollArea(ui->previewRcContainer); }