enable to cleanup with no line processing

This commit is contained in:
shun-iwasawa 2021-12-09 17:52:32 +09:00 committed by manongjohn
parent 5083a56d27
commit b21d463e35
12 changed files with 176 additions and 77 deletions

View file

@ -160,6 +160,12 @@ public:
/*--- オフセットを軸ごとにロックする ---*/
bool m_offx_lock, m_offy_lock;
// hold brightness and contrast values for each line processing modes (grey
// and color).
double m_altBrightness, m_altContrast;
// exporting file format when Line Processing = None
std::string m_lpNoneFormat;
public:
CleanupParameters();
CleanupParameters(const CleanupParameters &p) { assign(&p); }

View file

@ -92,7 +92,8 @@ time, to unlock a possibly useful memory block.
bool isCameraTest = false,
bool returnResampled = false,
bool onlyForSwatch = false,
TAffine *aff = 0);
TAffine *aff = 0,
TRasterP templateForResampled = 0);
void finalize(const TRaster32P &dst, CleanupPreprocessedImage *src);
TToonzImageP finalize(CleanupPreprocessedImage *src,

View file

@ -202,7 +202,8 @@ table) it returns the proper insertion index
// load icon (and image) data of all frames into cache
void loadAllIconsAndPutInCache(bool cacheImagesAsWell);
TRasterImageP getFrameToCleanup(const TFrameId &fid) const;
TRasterImageP getFrameToCleanup(const TFrameId &fid,
bool toBeLineProcessed) const;
std::string getImageId(const TFrameId &fid, int frameStatus = -1) const;
std::string getIconId(const TFrameId &fid, int frameStatus = -1) const;

View file

@ -411,7 +411,10 @@ static void cleanupLevel(TXshSimpleLevel *xl, std::set<TFrameId> fidsInXsheet,
QString::fromStdString(fid.expand()));
continue;
}
TRasterImageP original = xl->getFrameToCleanup(fid);
CleanupParameters *params = scene->getProperties()->getCleanupParameters();
// if lines are not processed, obtain the original sampled image
bool toBeLineProcessed = params->m_lineProcessingMode != lpNone;
TRasterImageP original = xl->getFrameToCleanup(fid, toBeLineProcessed);
if (!original) {
string err = " *error* missed frame";
m_userLog.error(err);
@ -419,11 +422,9 @@ static void cleanupLevel(TXshSimpleLevel *xl, std::set<TFrameId> fidsInXsheet,
continue;
}
CleanupParameters *params = scene->getProperties()->getCleanupParameters();
if (params->m_lineProcessingMode == lpNone) {
TRasterImageP ri;
if (params->m_autocenterType == CleanupTypes::AUTOCENTER_NONE)
TRasterImageP ri(original);
/*if (params->m_autocenterType == CleanupTypes::AUTOCENTER_NONE)
ri = original;
else {
bool autocentered;
@ -432,7 +433,9 @@ static void cleanupLevel(TXshSimpleLevel *xl, std::set<TFrameId> fidsInXsheet,
m_userLog.error("The autocentering failed on the current drawing.");
cout << "The autocentering failed on the current drawing." << endl;
}
}
}*/
cl->process(original, false, ri, false, true, true, nullptr,
ri->getRaster());
updater.update(fid, ri);
continue;
}

View file

@ -565,6 +565,8 @@ bool CleanupPopup::analyzeCleanupList() {
m_overwriteDialog->reset();
}
m_overwriteDialog->enableOptions(inputPath == outputPath);
// Prompt user for file conflict resolution
clt.m_resolution =
Resolution(m_overwriteDialog->execute(&clt.m_outputPath));
@ -634,7 +636,7 @@ bool CleanupPopup::analyzeCleanupList() {
TPointD outDpi;
m_params->getOutputImageInfo(outRes, outDpi.x, outDpi.y);
if (oldRes != outRes) {
if (oldRes != outRes && inputPath != outputPath) {
DVGui::warning(
tr("The resulting resolution of level \"%1\"\ndoes not match "
"with that of previously cleaned up level drawings.\n\nPlease "
@ -789,7 +791,13 @@ TImageP CleanupPopup::currentImage() const {
if (!isValidPosition(m_idx)) return TImageP();
const CleanupLevel &cl = m_cleanupLevels[m_idx.first];
return cl.m_sl->getFrameToCleanup(cl.m_frames[m_idx.second]);
// if lines are not processed, obtain the original sampled image
bool toBeLineProcessed =
TCleanupper::instance()->getParameters()->m_lineProcessingMode != lpNone;
return cl.m_sl->getFrameToCleanup(cl.m_frames[m_idx.second],
toBeLineProcessed);
}
//-----------------------------------------------------------------------------
@ -1195,31 +1203,6 @@ void CleanupPopup::cleanupFrame() {
TCleanupper *cl = TCleanupper::instance();
const CleanupParameters *params = cl->getParameters();
if (params->m_lineProcessingMode == lpNone) {
// No line processing
TRasterImageP ri(original);
if (params->m_autocenterType != CleanupTypes::AUTOCENTER_NONE) {
bool autocentered;
ri = cl->autocenterOnly(original, false, autocentered);
if (!autocentered)
DVGui::warning(
QObject::tr("The autocentering failed on the current drawing."));
}
sl->setFrame(fid, ri);
// Update the associated file. In case the operation throws, oh well the
// image gets skipped.
try {
m_updater->update(fid, ri);
} catch (...) {
}
IconGenerator::instance()->invalidate(sl, fid);
} else {
// Perform main processing
// Obtain the source dpi. Changed it to be done once at the first frame of
// each level in order to avoid the following problem:
// If the original raster level has no dpi (such as TGA images), obtaining
@ -1234,6 +1217,33 @@ void CleanupPopup::cleanupFrame() {
cl->setSourceDpi(dpi);
}
if (params->m_lineProcessingMode == lpNone) {
// No line processing
TRasterImageP ri(original);
/*if (params->m_autocenterType != CleanupTypes::AUTOCENTER_NONE) {
bool autocentered;
ri = cl->autocenterOnly(original, false, autocentered);
if (!autocentered)
DVGui::warning(
QObject::tr("The autocentering failed on the current drawing."));
}*/
cl->process(original, false, ri, false, true, true, nullptr,
ri->getRaster());
if (TRaster32P(ri->getRaster())) sl->setFrame(fid, ri);
// Update the associated file. In case the operation throws, oh well the
// image gets skipped.
try {
m_updater->update(fid, ri);
} catch (...) {
}
IconGenerator::instance()->invalidate(sl, fid);
} else {
// Perform main processing
CleanupPreprocessedImage *cpi;
{
TRasterImageP resampledRaster;
@ -1503,6 +1513,14 @@ void CleanupPopup::OverwriteDialog::reset() {
//-----------------------------------------------------------------------------
void CleanupPopup::OverwriteDialog::enableOptions(bool writingOnSource) {
if (writingOnSource && m_buttonGroup->button(REPLACE)->isChecked())
m_buttonGroup->button(OVERWRITE)->setChecked(true);
m_buttonGroup->button(REPLACE)->setDisabled(writingOnSource);
}
//-----------------------------------------------------------------------------
QString CleanupPopup::OverwriteDialog::acceptResolution(void *obj,
int resolution,
bool applyToAll) {

View file

@ -144,6 +144,7 @@ public:
OverwriteDialog();
void reset() override;
void enableOptions(bool writingOnSource);
private:
DVGui::LineEdit *m_suffix;

View file

@ -405,7 +405,7 @@ void CleanupSettingsModel::rebuildPreview() {
void CleanupSettingsModel::processFrame(TXshSimpleLevel *sl, TFrameId fid) {
assert(sl);
TRasterImageP imageToCleanup = sl->getFrameToCleanup(fid);
TRasterImageP imageToCleanup = sl->getFrameToCleanup(fid, true);
if (!imageToCleanup) return;
// Store the original image
@ -741,5 +741,6 @@ TFilePath CleanupSettingsModel::getOutputPath(TXshSimpleLevel *sl,
const TFilePath &outDir = params->getPath(scene);
return lineProcessing ? (outDir + inPath.getWideName()).withType("tlv")
: (outDir + inPath.getLevelNameW()).withType("tif");
: (outDir + inPath.getLevelNameW())
.withType(params->m_lpNoneFormat);
}

View file

@ -7,6 +7,7 @@
#include "toonz/tscenehandle.h"
#include "toonz/toonzscene.h"
#include "toonz/toonzfolders.h"
#include "toonz/cleanupcolorstyles.h"
// ToonzQt includes
#include "toonzqt/gutil.h"
@ -101,6 +102,8 @@ CleanupSettingsPane::CleanupSettingsPane(QWidget *parent)
m_aaValueLabel = new QLabel(tr("MLAA Intensity:"));
m_aaValue = new IntField(this);
m_lineProcessing = new QComboBox(this);
m_lpNoneFormatLabel = new QLabel(tr("Format:"));
m_lpNoneFormat = new QComboBox(this);
m_paletteViewer = new CleanupPaletteViewer(this);
m_pathField = new CleanupSaveInField(this, QString(""));
@ -143,6 +146,13 @@ CleanupSettingsPane::CleanupSettingsPane(QWidget *parent)
items << tr("None") << tr("Greyscale") << tr("Color");
m_lineProcessing->addItems(items);
items.clear();
items << "tif"
<< "png"
<< "jpg"
<< "tga";
m_lpNoneFormat->addItems(items);
m_sharpness->setValues(90, 0, 100);
m_despeckling->setValues(2, 0, 20);
m_aaValue->setValues(70, 0, 100);
@ -223,15 +233,15 @@ CleanupSettingsPane::CleanupSettingsPane(QWidget *parent)
lineProcLay->addWidget(m_aaValueLabel, 4, 0,
Qt::AlignRight | Qt::AlignVCenter);
lineProcLay->addWidget(m_aaValue, 4, 1);
lineProcLay->addWidget(m_lpNoneFormatLabel, 5, 0,
Qt::AlignRight | Qt::AlignVCenter);
lineProcLay->addWidget(m_lpNoneFormat, 5, 1,
Qt::AlignLeft | Qt::AlignVCenter);
lineProcLay->addWidget(m_paletteViewer, 5, 0, 1, 2);
lineProcLay->addWidget(m_paletteViewer, 6, 0, 1, 2);
}
lineProcLay->setRowStretch(0, 0);
lineProcLay->setRowStretch(1, 0);
lineProcLay->setRowStretch(2, 0);
lineProcLay->setRowStretch(3, 0);
lineProcLay->setRowStretch(4, 0);
lineProcLay->setRowStretch(5, 1);
for (int r = 0; r <= 5; r++) lineProcLay->setRowStretch(r, 0);
lineProcLay->setRowStretch(6, 1);
lineProcLay->setColumnStretch(0, 0);
lineProcLay->setColumnStretch(1, 1);
@ -286,6 +296,8 @@ CleanupSettingsPane::CleanupSettingsPane(QWidget *parent)
SLOT(onGenericSettingsChange()));
ret = ret && connect(m_lineProcessing, SIGNAL(activated(int)),
SLOT(onGenericSettingsChange()));
ret = ret && connect(m_lpNoneFormat, SIGNAL(activated(int)),
SLOT(onGenericSettingsChange()));
ret = ret && connect(m_despeckling, SIGNAL(valueChanged(bool)),
SLOT(onGenericSettingsChange()));
ret = ret && connect(m_aaValue, SIGNAL(valueChanged(bool)),
@ -404,6 +416,8 @@ void CleanupSettingsPane::updateGui(CleanupParameters *params,
m_sharpness->setValue(params->m_sharpness);
m_despeckling->setValue(params->m_despeckling);
m_aaValue->setValue(params->m_aaValue);
m_lpNoneFormat->setCurrentText(
QString::fromStdString(params->m_lpNoneFormat));
updateVisibility();
@ -462,6 +476,8 @@ void CleanupSettingsPane::updateVisibility() {
for (QWidget *w : m_lpWidgets) w->setVisible(lp);
m_aaValueLabel->setVisible(MLAA);
m_aaValue->setVisible(MLAA);
m_lpNoneFormatLabel->setVisible(!lp);
m_lpNoneFormat->setVisible(!lp);
m_paletteViewer->setMode(lpGrey);
m_paletteViewer->setContrastEnabled(m_antialias->currentIndex() == 0);
@ -525,15 +541,30 @@ void CleanupSettingsPane::onGenericSettingsChange() {
params->m_flipy = m_flipY->isChecked();
//------
if (params->m_lineProcessingMode != m_lineProcessing->currentIndex()) {
int oldMode = params->m_lineProcessingMode;
params->m_lineProcessingMode = m_lineProcessing->currentIndex();
if (params->m_lineProcessingMode == lpNone) {
params->m_transparencyCheckEnabled = false;
}
// When switching from/to Greyscale processing, replace the brightness and
// contrast values by the registered ones.
if (oldMode == lpGrey || params->m_lineProcessingMode == lpGrey) {
TCleanupStyle *blackStyle =
dynamic_cast<TCleanupStyle *>(params->m_cleanupPalette->getStyle(1));
double b = params->m_altBrightness;
double c = params->m_altContrast;
params->m_altBrightness = blackStyle->getBrightness();
params->m_altContrast = blackStyle->getContrast();
blackStyle->setBrightness(b);
blackStyle->setContrast(c);
}
}
params->m_noAntialias = (m_antialias->currentIndex() > 0);
params->m_postAntialias = (m_antialias->currentIndex() == 2);
params->m_despeckling = m_despeckling->getValue();
params->m_aaValue = m_aaValue->getValue();
if (params->m_lineProcessingMode == lpNone)
params->m_transparencyCheckEnabled = false;
params->m_lpNoneFormat = m_lpNoneFormat->currentText().toStdString();
//------
m_cameraWidget->getFields(model->getCurrentParameters());

View file

@ -62,6 +62,8 @@ private:
QLabel *m_aaValueLabel;
DVGui::IntField *m_aaValue;
QComboBox *m_lineProcessing;
QLabel *m_lpNoneFormatLabel;
QComboBox *m_lpNoneFormat;
//----Cleanup Palette
CleanupPaletteViewer *m_paletteViewer;
//----Bottom Parts

View file

@ -6,6 +6,7 @@
#include "toonz/toonzscene.h"
#include "toonz/sceneproperties.h"
#include "toonz/txshleveltypes.h"
#include "toonz/cleanupcolorstyles.h"
#include "tsystem.h"
#include "tenv.h"
#include "tconvert.h"
@ -193,7 +194,10 @@ CleanupParameters::CleanupParameters()
, m_dirtyFlag(false)
//, m_resName("")
, m_offx_lock(false)
, m_offy_lock(false) {}
, m_offy_lock(false)
, m_altBrightness(0)
, m_altContrast(50)
, m_lpNoneFormat("tif") {}
//---------------------------------------------------------
@ -302,6 +306,9 @@ void CleanupParameters::assign(const CleanupParameters *param,
m_offx_lock = param->m_offx_lock;
m_offy_lock = param->m_offy_lock;
m_altBrightness = param->m_altBrightness;
m_altContrast = param->m_altContrast;
m_lpNoneFormat = param->m_lpNoneFormat;
}
//---------------------------------------------------------
@ -366,6 +373,8 @@ void CleanupParameters::saveData(TOStream &os) const {
os.openCloseChild("fdg", attr);
attr.clear();
if (m_path != TFilePath()) os.child("path") << m_path;
os.child("altBrightnessContrast") << m_altBrightness << m_altContrast;
os.child("lpNoneFormat") << m_lpNoneFormat;
}
//---------------------------------------------------------
@ -380,6 +389,9 @@ void CleanupParameters::loadData(TIStream &is, bool globalParams) {
m_lineProcessingMode = lpNone;
m_noAntialias = false;
m_postAntialias = false;
// hold brightness and contrast values of another processing mode
m_altBrightness = -1.0;
m_altContrast = -1.0;
while (is.matchTag(tagName)) {
if (tagName == "cleanupPalette") {
@ -433,10 +445,26 @@ void CleanupParameters::loadData(TIStream &is, bool globalParams) {
} else if (tagName == "path") {
is >> m_path;
is.closeChild();
} else if (tagName == "altBrightnessContrast") {
is >> m_altBrightness >> m_altContrast;
is.closeChild();
} else if (tagName == "lpNoneFormat") {
is >> m_lpNoneFormat;
is.closeChild();
} else
is.skipCurrentTag();
}
if ((m_altBrightness < 0.0 || m_altContrast < 0.0) && m_cleanupPalette &&
m_cleanupPalette->getStyleCount() >= 2) {
TCleanupStyle *blackStyle =
dynamic_cast<TCleanupStyle *>(m_cleanupPalette->getStyle(1));
if (blackStyle) {
m_altBrightness = blackStyle->getBrightness();
m_altContrast = blackStyle->getContrast();
}
}
CleanupParameters::LastSavedParameters.assign(this);
if (globalParams) CleanupParameters::GlobalParameters.assign(this);
}

View file

@ -569,7 +569,7 @@ TRasterP TCleanupper::processColors(const TRasterP &rin) {
CleanupPreprocessedImage *TCleanupper::process(
TRasterImageP &image, bool first_image, TRasterImageP &onlyResampledImage,
bool isCameraTest, bool returnResampled, bool onlyForSwatch,
TAffine *resampleAff) {
TAffine *resampleAff, TRasterP templateForResampled) {
TAffine aff;
double blur;
TDimension outDim(0, 0);
@ -682,7 +682,9 @@ CleanupPreprocessedImage *TCleanupper::process(
TRasterP tmp_ras;
if (returnResampled || (fromGr8 && toGr8)) {
if (fromGr8 && toGr8)
if (templateForResampled)
tmp_ras = templateForResampled->create(outDim.lx, outDim.ly);
else if (fromGr8 && toGr8)
tmp_ras = TRasterGR8P(outDim);
else
tmp_ras = TRaster32P(outDim);
@ -709,7 +711,7 @@ CleanupPreprocessedImage *TCleanupper::process(
flt_type = TRop::Hann2;
TRop::resample(tmp_ras, image->getRaster(), aff, flt_type, blur);
if ((TRaster32P)tmp_ras)
if ((TRaster32P)tmp_ras && !templateForResampled)
// Add white background to deal with semitransparent pixels
TRop::addBackground(tmp_ras, TPixel32::White);

View file

@ -643,7 +643,8 @@ void TXshSimpleLevel::loadAllIconsAndPutInCache(bool cacheImagesAsWell) {
//-----------------------------------------------------------------------------
TRasterImageP TXshSimpleLevel::getFrameToCleanup(const TFrameId &fid) const {
TRasterImageP TXshSimpleLevel::getFrameToCleanup(const TFrameId &fid,
bool toBeLineProcessed) const {
assert(m_type != UNKNOWN_XSHLEVEL);
FramesSet::const_iterator ft = m_frames.find(fid);
@ -653,8 +654,12 @@ TRasterImageP TXshSimpleLevel::getFrameToCleanup(const TFrameId &fid) const {
std::string imageId = getImageId(fid, flag ? Scanned : 0);
ImageLoader::BuildExtData extData(this, fid, 1);
TRasterImageP img = ImageManager::instance()->getImage(
imageId, ImageManager::dontPutInCache, &extData);
UCHAR imFlags = ImageManager::dontPutInCache;
// if lines are not processed, obtain the original sampled image
if (!toBeLineProcessed) imFlags |= ImageManager::is64bitEnabled;
TRasterImageP img =
ImageManager::instance()->getImage(imageId, imFlags, &extData);
if (!img) return img;
double x_dpi, y_dpi;