/* * colorspaceconversion.cpp -- Part of Chalk * * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kis_meta_registry.h" #include #include #include #include #include #include "colorspaceconversion.h" #include "dlg_colorspaceconversion.h" #include "wdgconvertcolorspace.h" typedef KGenericFactory ColorSpaceConversionFactory; K_EXPORT_COMPONENT_FACTORY( chalkcolorspaceconversion, ColorSpaceConversionFactory( "chalk" ) ) ColorSpaceConversion::ColorSpaceConversion(TQObject *parent, const char *name, const TQStringList &) : KParts::Plugin(parent, name) { if ( parent->inherits("KisView") ) { m_view = (KisView*) parent; setInstance(ColorSpaceConversionFactory::instance()); setXMLFile(locate("data","chalkplugins/colorspaceconversion.rc"), true); (void) new TDEAction(i18n("&Convert Image Type..."), 0, 0, this, TQT_SLOT(slotImgColorSpaceConversion()), actionCollection(), "imgcolorspaceconversion"); (void) new TDEAction(i18n("&Convert Layer Type..."), 0, 0, this, TQT_SLOT(slotLayerColorSpaceConversion()), actionCollection(), "layercolorspaceconversion"); } } ColorSpaceConversion::~ColorSpaceConversion() { m_view = 0; } void ColorSpaceConversion::slotImgColorSpaceConversion() { KisImageSP image = m_view->canvasSubject()->currentImg(); if (!image) return; if (image->colorSpace()->willDegrade(TO_LAB16)) { if (KMessageBox::warningContinueCancel(m_view, i18n("This conversion will convert your %1 image through 16-bit L*a*b* and back.\n" "Watercolor and openEXR colorspaces will even be converted through 8-bit RGB.\n") .arg(image->colorSpace()->id().name()), i18n("Colorspace Conversion"), KGuiItem(i18n("Continue")), "lab16degradation") != KMessageBox::Continue) return; } DlgColorSpaceConversion * dlgColorSpaceConversion = new DlgColorSpaceConversion(m_view, "ColorSpaceConversion"); TQ_CHECK_PTR(dlgColorSpaceConversion); dlgColorSpaceConversion->setCaption(i18n("Convert All Layers From ") + image->colorSpace()->id().name()); if (dlgColorSpaceConversion->exec() == TQDialog::Accepted) { // XXX: Do the rest of the stuff KisID cspace = dlgColorSpaceConversion->m_page->cmbColorSpaces->currentItem(); KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace, dlgColorSpaceConversion->m_page->cmbDestProfile->currentText()); TQApplication::setOverrideCursor(KisCursor::waitCursor()); image->convertTo(cs, dlgColorSpaceConversion->m_page->grpIntent->selectedId()); TQApplication::restoreOverrideCursor(); } delete dlgColorSpaceConversion; } void ColorSpaceConversion::slotLayerColorSpaceConversion() { KisImageSP image = m_view->canvasSubject()->currentImg(); if (!image) return; KisPaintDeviceSP dev = image->activeDevice(); if (!dev) return; if (dev->colorSpace()->willDegrade(TO_LAB16)) { if (KMessageBox::warningContinueCancel(m_view, i18n("This conversion will convert your %1 layer through 16-bit L*a*b* and back.\n" "Watercolor and openEXR colorspaces will even be converted through 8-bit RGB.\n") .arg(dev->colorSpace()->id().name()), i18n("Colorspace Conversion"), KGuiItem(i18n("Continue")), "lab16degradation") != KMessageBox::Continue) return; } DlgColorSpaceConversion * dlgColorSpaceConversion = new DlgColorSpaceConversion(m_view, "ColorSpaceConversion"); TQ_CHECK_PTR(dlgColorSpaceConversion); dlgColorSpaceConversion->setCaption(i18n("Convert Current Layer From") + dev->colorSpace()->id().name()); if (dlgColorSpaceConversion->exec() == TQDialog::Accepted) { KisID cspace = dlgColorSpaceConversion->m_page->cmbColorSpaces->currentItem(); KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry() -> getColorSpace(cspace, dlgColorSpaceConversion->m_page->cmbDestProfile->currentText()); TQApplication::setOverrideCursor(KisCursor::waitCursor()); dev->convertTo(cs, dlgColorSpaceConversion->m_page->grpIntent->selectedId()); TQApplication::restoreOverrideCursor(); } delete dlgColorSpaceConversion; } #include "colorspaceconversion.moc"