diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-26 00:41:16 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-26 00:41:16 +0000 |
commit | 698569f8428ca088f764d704034a1330517b98c0 (patch) | |
tree | bf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /filters/chalk/openexr | |
parent | 2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff) | |
download | koffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz koffice-698569f8428ca088f764d704034a1330517b98c0.zip |
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'filters/chalk/openexr')
-rw-r--r-- | filters/chalk/openexr/Makefile.am | 51 | ||||
-rw-r--r-- | filters/chalk/openexr/chalk_openexr.desktop | 57 | ||||
-rw-r--r-- | filters/chalk/openexr/chalk_openexr_export.desktop | 52 | ||||
-rw-r--r-- | filters/chalk/openexr/chalk_openexr_import.desktop | 52 | ||||
-rw-r--r-- | filters/chalk/openexr/configure.in.bot | 9 | ||||
-rw-r--r-- | filters/chalk/openexr/kis_openexr_export.cpp | 155 | ||||
-rw-r--r-- | filters/chalk/openexr/kis_openexr_export.h | 38 | ||||
-rw-r--r-- | filters/chalk/openexr/kis_openexr_import.cpp | 160 | ||||
-rw-r--r-- | filters/chalk/openexr/kis_openexr_import.h | 38 |
9 files changed, 612 insertions, 0 deletions
diff --git a/filters/chalk/openexr/Makefile.am b/filters/chalk/openexr/Makefile.am new file mode 100644 index 00000000..26470890 --- /dev/null +++ b/filters/chalk/openexr/Makefile.am @@ -0,0 +1,51 @@ +AM_CPPFLAGS= \ + -I$(srcdir) \ + -I$(top_srcdir)/chalk \ + -I$(top_srcdir)/chalk/core \ + -I$(top_srcdir)/chalk/sdk \ + -I$(top_srcdir)/chalk/core/tiles \ + -I$(top_srcdir)/chalk/chalkcolor \ + -I$(top_srcdir)/chalk/ui \ + -I$(top_srcdir)/chalk/colorspaces/rgb_f32 \ + -I$(top_srcdir)/chalk/colorspaces/rgb_f16half \ + $(KOFFICE_INCLUDES) \ + -I$(interfacedir) \ + $(OPENEXR_CFLAGS) \ + $(all_includes) + +kde_module_LTLIBRARIES = libchalk_openexr_import.la libchalk_openexr_export.la + +libchalk_openexr_export_la_LDFLAGS = $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) -module -avoid-version -no-undefined $(all_libraries) -lkdecore -lkdeui $(LIB_QT) -lkjs -lkdefx -lkio -lkparts \ + -L../../../lib/kofficecore/.libs/ -lkofficecore \ + -L../../../lib/kofficeui/.libs/ -lkofficeui -L../../../lib/store/.libs/ -lkstore -L../../../chalk/core/.libs/ -lchalkimage -L../../../chalk/ui/.libs/ -lchalkui -L../../../chalk/chalkcolor/.libs/ -lchalkcolor +libchalk_openexr_export_la_LIBADD = \ + $(KOFFICE_LIBS) \ + $(OPENEXR_LIBS) \ + $(top_builddir)/chalk/libchalkcommon.la \ + $(top_builddir)/chalk/colorspaces/rgb_f32/libchalk_rgb_f32.la \ + $(top_builddir)/chalk/colorspaces/rgb_f16half/libchalk_rgb_f16half.la + + +libchalk_openexr_import_la_LDFLAGS = $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) -module -avoid-version -no-undefined $(all_libraries) -lkdecore -lkdeui $(LIB_QT) -lkjs -lkdefx -lkio -lkparts -L../../../lib/kofficecore/.libs/ -lkofficecore \ + -L../../../lib/kofficeui/.libs/ -lkofficeui -L../../../lib/store/.libs/ -lkstore -L../../../chalk/core/.libs/ -lchalkimage -L../../../chalk/ui/.libs/ -lchalkui -L../../../chalk/chalkcolor/.libs/ -lchalkcolor +libchalk_openexr_import_la_LIBADD = \ + $(KOFFICE_LIBS) \ + $(OPENEXR_LIBS) \ + $(top_builddir)/chalk/libchalkcommon.la \ + $(top_builddir)/chalk/colorspaces/rgb_f32/libchalk_rgb_f32.la \ + $(top_builddir)/chalk/colorspaces/rgb_f16half/libchalk_rgb_f16half.la + + +service_DATA = chalk_openexr_import.desktop chalk_openexr_export.desktop +servicedir = $(kde_servicesdir) + +kdelnk_DATA = chalk_openexr.desktop +kdelnkdir = $(kde_appsdir)/.hidden + +libchalk_openexr_import_la_SOURCES = kis_openexr_import.cpp +libchalk_openexr_export_la_SOURCES = kis_openexr_export.cpp + +METASOURCES = AUTO + +KDE_CXXFLAGS = $(USE_EXCEPTIONS) + diff --git a/filters/chalk/openexr/chalk_openexr.desktop b/filters/chalk/openexr/chalk_openexr.desktop new file mode 100644 index 00000000..26f81ccd --- /dev/null +++ b/filters/chalk/openexr/chalk_openexr.desktop @@ -0,0 +1,57 @@ +[Desktop Entry] +Name=Chalk +Name[hi]=के-रिता +Name[km]= Chalk +Name[lo]=ກຣິຕາ +Name[ne]=क्रिता +Exec=chalk %u +GenericName=Painting and Image Editing Application +GenericName[bg]=Редактор на графични изображения +GenericName[ca]=Programa de dibuix i manipulació d'imatges +GenericName[cs]=Malování a úpravy obrázků +GenericName[cy]=Cymhwysiad Peintio Golygu Delweddau +GenericName[da]=Male- og billedredigeringsprogram +GenericName[de]=Mal- und Bildbearbeitungsprogramm +GenericName[el]=Εφαρμογή επεξεργασίας εικόνων +GenericName[eo]=Aplikaĵo por Pentrado kaj Bildredaktado +GenericName[es]=Aplicación de pintura y de edición de imágenes +GenericName[et]=Joonistamise ja pilditöötluse rakendus +GenericName[eu]=Irudien marrazketa eta ediziorako aplikazioa +GenericName[fa]=کاربرد ویرایش تصویر و نقاشی +GenericName[fi]=Maalaus- ja kuvankäsitelyohjelma +GenericName[fr]=Application de dessin et de manipulation d'images +GenericName[fy]=Ofbyldingsmanipulaasje +GenericName[gl]=Aplicación de Pintura e Manipulación de Imaxes +GenericName[he]=יישום לציור ועריכת תמונות +GenericName[hr]=Aplikacija za obradu slika i fotografija +GenericName[hu]=Képszerkesztő +GenericName[is]=Málun og myndritill +GenericName[it]=Applicazione di disegno e di modifica delle immagini +GenericName[ja]=描画と画像編集のためのアプリケーション +GenericName[km]=កម្មវិធីគូរគំនូរ និងកែសម្រួលរូបភាព +GenericName[lv]=Zīmēšanas un attēlu apstrādes programma +GenericName[nb]=Program for tegning og bilderedigering +GenericName[nds]=Programm för't Malen un Bildbewerken +GenericName[ne]=पेन्टीङ्ग र छवि सम्पादन अनुप्रयोग +GenericName[nl]=Afbeeldingsmanipulatie +GenericName[pl]=Program do edycji zdjęć oraz rysunków +GenericName[pt]=Aplicação de Pintura e Edição de Imagens +GenericName[pt_BR]=Aplicação de Pintura e Edição de Imagens +GenericName[ru]=Растровые изображения +GenericName[se]=Málen- ja govvagieđahallanprográmma +GenericName[sk]=Program pre tvorbu a úpravu obrázkov +GenericName[sl]=Program za risanje in obdelavo slik +GenericName[sr]=Програм за цртање и уређивање слика +GenericName[sr@Latn]=Program za crtanje i uređivanje slika +GenericName[sv]=Målnings- och bildredigeringsprogram +GenericName[uk]=Програма для малювання і редагування зображень +GenericName[uz]=Rasmlar bilan ishlaydigan dastur +GenericName[uz@cyrillic]=Расмлар билан ишлайдиган дастур +GenericName[zh_CN]=绘图和图像编辑应用程序 +GenericName[zh_TW]=繪圖與影像處理程式 +MimeType=image/x-exr +Type=Application +Icon=chalk +Categories= +X-KDE-StartupNotify=true +X-DCOP-ServiceType=Multi diff --git a/filters/chalk/openexr/chalk_openexr_export.desktop b/filters/chalk/openexr/chalk_openexr_export.desktop new file mode 100644 index 00000000..92b68518 --- /dev/null +++ b/filters/chalk/openexr/chalk_openexr_export.desktop @@ -0,0 +1,52 @@ +[Desktop Entry] +Name=Chalk OpenEXR Export Filter +Name[bg]=Филтър за експортиране от Chalk в OpenEXR +Name[br]=Sil ezporzh OpenEXR evit Chalk +Name[ca]=Filtre d'exportació OpenEXR per a Chalk +Name[cy]=Hidl Allforio OpenEXR Chalk +Name[da]=Chalk OpenEXR-eksportfilter +Name[de]=Chalk OpenEXR-Exportfilter +Name[el]=Φίλτρο εξαγωγής OpenEXR του Chalk +Name[eo]=Chalk OpenEXR-eksportfiltrilo +Name[es]=Filtro de exportación a OpenEXR de Chalk +Name[et]=Chalk OpenEXR'i ekspordifilter +Name[fa]=پالایۀ صادرات Chalk OpenEXR +Name[fi]=Chalk OpenEXR -vientisuodin +Name[fr]=Filtre d'exportation OpenEXR de Chalk +Name[fy]=Chalk OpenEXR Eksportfilter +Name[ga]=Scagaire Easpórtála OpenEXR Chalk +Name[gl]=Filtro de Exportación de OpenEXR de Chalk +Name[he]=Chalk OpenEXR מסנן יצוא +Name[hr]=Chalk OpenEXR filtar izvoza +Name[hu]=Chalk OpenEXR exportszűrő +Name[is]=Chalk OpenEXR útflutningssía +Name[it]=Filtro di esportazione OpenEXR per Chalk +Name[ja]=Chalk OpenEXR エクスポートフィルタ +Name[km]=តម្រងនាំចេញ OpenEXR សម្រាប់ Chalk +Name[lt]=Chalk OpenEXR eksportavimo filtras +Name[lv]=Chalk OpenEXR eksporta filtrs +Name[nb]=OpenEXR-eksportfilter for Chalk +Name[nds]=OpenEXR-Exportfilter för Chalk +Name[ne]=क्रिता खुलाEXR निर्यात फिल्टर +Name[nl]=Chalk OpenEXR Exportfilter +Name[pl]=Filtr eksportu do formatu OpenEXR z Chalk +Name[pt]=Filtro de Exportação de OpenEXR do Chalk +Name[pt_BR]=Filtro de Exportação de OpenEXR do Chalk +Name[ru]=Фильтр экспорта рисунков Chalk в OpenEXR +Name[se]=Chalk OpenEXR-olggosfievrridansilli +Name[sk]=Exportný filter Chalk OpenEXR +Name[sl]=Izvozni filter OpenEXR za Krito +Name[sr]=Chalk-ин филтер за извоз у OpenEXR +Name[sr@Latn]=Chalk-in filter za izvoz u OpenEXR +Name[sv]=Chalk OpenEXR-exportfilter +Name[uk]=Фільтр експорту OpenEXR для Chalk +Name[uz]=Chalk OpenEXR eksport filteri +Name[uz@cyrillic]=Chalk OpenEXR экспорт филтери +Name[zh_CN]=Chalk OpenEXR 导出过滤器 +Name[zh_TW]=Chalk OpenEXR 匯出過濾程式 +X-KDE-Export=image/x-exr +ServiceTypes=KOfficeFilter +Type=Service +X-KDE-Import=application/x-chalk +X-KDE-Weight=1 +X-KDE-Library=libchalk_openexr_export diff --git a/filters/chalk/openexr/chalk_openexr_import.desktop b/filters/chalk/openexr/chalk_openexr_import.desktop new file mode 100644 index 00000000..60f6bc54 --- /dev/null +++ b/filters/chalk/openexr/chalk_openexr_import.desktop @@ -0,0 +1,52 @@ +[Desktop Entry] +Type=Service +Name=Chalk OpenEXR Import Filter +Name[bg]=Филтър за импортиране от OpenEXR в Chalk +Name[br]=Sil enporzh OpenEXR evit Chalk +Name[ca]=Filtre d'importació OpenEXR per a Chalk +Name[cy]=Hidl Mewnforio OpenEXR Chalk +Name[da]=Chalk OpenEXR-importfilter +Name[de]=Chalk OpenEXR-Importfilter +Name[el]=Φίλτρο εισαγωγής OpenEXR του Chalk +Name[eo]=Chalk OpenEXR-importfiltrilo +Name[es]=Filtro de importación a OpenEXR de Chalk +Name[et]=Chalk OpenEXR'i impordifilter +Name[fa]=پالایۀ واردات Chalk OpenEXR +Name[fi]=Chalk OpenEXR -tuontisuodin +Name[fr]=Filtre d'importation OpenEXT de Chalk +Name[fy]=Chalk OpenEXR Ymportfilter +Name[ga]=Scagaire Iompórtála OpenEXR Chalk +Name[gl]=Filtro de Importación de OpenEXR para Chalk +Name[he]=Chalk OpenEXR מסנן יבוא +Name[hr]=Chalk OpenEXR filtar uvoza +Name[hu]=Chalk OpenEXR importszűrő +Name[is]=Chalk OpenEXR innflutningssía +Name[it]=Filtro di importazione OpenEXR per Chalk +Name[ja]=Chalk OpenEXR インポートフィルタ +Name[km]=តម្រងនាំចូល OpenEXR សម្រាប់ Chalk +Name[lt]=Chalk OpenEXR importavimo filtras +Name[lv]=Chalk OpenEXR importa filtrs +Name[nb]=OpenEXR-importfilter for Chalk +Name[nds]=OpenEXR-Importfilter för Chalk +Name[ne]=क्रिता खुलाEXR आयात फिल्टर +Name[nl]=Chalk OpenEXR Importfilter +Name[pl]=Filtr importu formatu OpenEXR do Chalk +Name[pt]=Filtro de Importação de OpenEXR para o Chalk +Name[pt_BR]=Filtro de Importação de OpenEXR para o Chalk +Name[ru]=Фильтр импорта рисунков OpenEXR в Chalk +Name[se]=Chalk OpenEXR-sisafievrridansilli +Name[sk]=OpenEXR filter pre import do Chalk +Name[sl]=Uvozni filter OpenEXR za Krito +Name[sr]=Chalk-ин филтер за увоз из OpenEXR-а +Name[sr@Latn]=Chalk-in filter za uvoz iz OpenEXR-a +Name[sv]=Chalk OpenEXR-importfilter +Name[uk]=Фільтр імпорту OpenEXR для Chalk +Name[uz]=Chalk OpenEXR import filteri +Name[uz@cyrillic]=Chalk OpenEXR импорт филтери +Name[zh_CN]=Chalk OpenEXR 导入过滤器 +Name[zh_TW]=Chalk OpenEXR 匯入過濾程式 +X-KDE-Export=application/x-chalk +X-KDE-Import=image/x-exr +X-KDE-Weight=1 +X-KDE-Library=libchalk_openexr_import +ServiceTypes=KOfficeFilter diff --git a/filters/chalk/openexr/configure.in.bot b/filters/chalk/openexr/configure.in.bot new file mode 100644 index 00000000..3a743f82 --- /dev/null +++ b/filters/chalk/openexr/configure.in.bot @@ -0,0 +1,9 @@ +if test -z "$OPENEXR_LIBS"; then + echo "" + echo "You're missing the OpenEXR library. Chalk's OpenEXR import/export filter will " + echo "not be compiled. You can download OpenEXR from http://www.openexr.com or " + echo "install it from an appropriate binary package." + echo "" + all_tests=bad +fi + diff --git a/filters/chalk/openexr/kis_openexr_export.cpp b/filters/chalk/openexr/kis_openexr_export.cpp new file mode 100644 index 00000000..4859f5d9 --- /dev/null +++ b/filters/chalk/openexr/kis_openexr_export.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com> + * + * 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 <tqfile.h> + +#include <kmessagebox.h> + +#include <half.h> +#include <ImfRgbaFile.h> + +#include <kgenericfactory.h> +#include <KoDocument.h> +#include <KoFilterChain.h> + +#include "kis_doc.h" +#include "kis_image.h" +#include "kis_layer.h" +#include "kis_paint_layer.h" +#include "kis_annotation.h" +#include "kis_types.h" +#include "kis_iterators_pixel.h" +#include "kis_abstract_colorspace.h" +#include "kis_paint_device.h" +#include "kis_rgb_f32_colorspace.h" +#include "kis_rgb_f16half_colorspace.h" + +#include "kis_openexr_export.h" + +using namespace std; +using namespace Imf; +using namespace Imath; + +typedef KGenericFactory<KisOpenEXRExport, KoFilter> KisOpenEXRExportFactory; +K_EXPORT_COMPONENT_FACTORY(libchalk_openexr_export, KisOpenEXRExportFactory("kofficefilters")) + +KisOpenEXRExport::KisOpenEXRExport(KoFilter *, const char *, const TQStringList&) : KoFilter() +{ +} + +KisOpenEXRExport::~KisOpenEXRExport() +{ +} + +KoFilter::ConversiontqStatus KisOpenEXRExport::convert(const TQCString& from, const TQCString& to) +{ + if (to != "image/x-exr" || from != "application/x-chalk") { + return KoFilter::NotImplemented; + } + + kdDebug(41008) << "Chalk exporting to OpenEXR\n"; + + // XXX: Add dialog about flattening layers here + + KisDoc *doc = dynamic_cast<KisDoc*>(m_chain -> inputDocument()); + TQString filename = m_chain -> outputFile(); + + if (!doc) { + return KoFilter::CreationError; + } + + if (filename.isEmpty()) { + return KoFilter::FileNotFound; + } + + KisImageSP img = new KisImage(*doc -> currentImage()); + Q_CHECK_PTR(img); + + // Don't store this information in the document's undo adapter + bool undo = doc -> undoAdapter() -> undo(); + doc -> undoAdapter() -> setUndo(false); + + img -> flatten(); + + KisPaintLayerSP layer = dynamic_cast<KisPaintLayer*>(img->activeLayer().data()); + Q_ASSERT(layer); + + doc -> undoAdapter() -> setUndo(undo); + + //KisF32RgbColorSpace * cs = static_cast<KisF32RgbColorSpace *>((KisColorSpaceRegistry::instance() -> get(KisID("RGBAF32", "")))); + KisRgbF16HalfColorSpace *cs = dynamic_cast<KisRgbF16HalfColorSpace *>(layer->paintDevice()->colorSpace()); + + if (cs == 0) { + // We could convert automatically, but the conversion wants to be done with + // selectable profiles and rendering intent. + KMessageBox::information(0, i18n("The image is using an unsupported color space. " + "Please convert to 16-bit floating point RGB/Alpha " + "before saving in the OpenEXR format.")); + + // Don't show the couldn't save error dialog. + doc -> setErrorMessage("USER_CANCELED"); + + return KoFilter::WrongFormat; + } + + Box2i displayWindow(V2i(0, 0), V2i(img -> width() - 1, img -> height() - 1)); + + TQRect dataExtent = layer -> exactBounds(); + int dataWidth = dataExtent.width(); + int dataHeight = dataExtent.height(); + + Box2i dataWindow(V2i(dataExtent.left(), dataExtent.top()), V2i(dataExtent.right(), dataExtent.bottom())); + + RgbaOutputFile file(TQFile::encodeName(filename), displayWindow, dataWindow, WRITE_RGBA); + + TQMemArray<Rgba> pixels(dataWidth); + + for (int y = 0; y < dataHeight; ++y) { + + file.setFrameBuffer(pixels.data() - dataWindow.min.x - (dataWindow.min.y + y) * dataWidth, 1, dataWidth); + + KisHLineIterator it = layer->paintDevice()->createHLineIterator(dataWindow.min.x, dataWindow.min.y + y, dataWidth, false); + Rgba *rgba = pixels.data(); + + while (!it.isDone()) { + + // XXX: Currently we use unmultiplied data so premult it. + half unmultipliedRed; + half unmultipliedGreen; + half unmultipliedBlue; + half alpha; + + cs -> getPixel(it.rawData(), &unmultipliedRed, &unmultipliedGreen, &unmultipliedBlue, &alpha); + rgba -> r = unmultipliedRed * alpha; + rgba -> g = unmultipliedGreen * alpha; + rgba -> b = unmultipliedBlue * alpha; + rgba -> a = alpha; + ++it; + ++rgba; + } + file.writePixels(); + } + + //vKisAnnotationSP_it beginIt = img -> beginAnnotations(); + //vKisAnnotationSP_it endIt = img -> endAnnotations(); + return KoFilter::OK; +} + +#include "kis_openexr_export.moc" + diff --git a/filters/chalk/openexr/kis_openexr_export.h b/filters/chalk/openexr/kis_openexr_export.h new file mode 100644 index 00000000..56568e57 --- /dev/null +++ b/filters/chalk/openexr/kis_openexr_export.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com> + * + * 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. + */ + +#ifndef KIS_OPENEXR_EXPORT_H_ +#define KIS_OPENEXR_EXPORT_H_ + +#include <KoFilter.h> + +class KisOpenEXRExport : public KoFilter { + Q_OBJECT + TQ_OBJECT + +public: + KisOpenEXRExport(KoFilter *tqparent, const char *name, const TQStringList&); + virtual ~KisOpenEXRExport(); + +public: + virtual KoFilter::ConversiontqStatus convert(const TQCString& from, const TQCString& to); +}; + +#endif // KIS_OPENEXR_EXPORT_H_ + diff --git a/filters/chalk/openexr/kis_openexr_import.cpp b/filters/chalk/openexr/kis_openexr_import.cpp new file mode 100644 index 00000000..974d4a67 --- /dev/null +++ b/filters/chalk/openexr/kis_openexr_import.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com> + * + * 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 <tqstring.h> +#include <tqfile.h> + +#include <kgenericfactory.h> +#include <KoDocument.h> +#include <KoFilterChain.h> + +#include <half.h> +#include <ImfRgbaFile.h> +//#include <ImfStringAttribute.h> +//#include <ImfMatrixAttribute.h> +//#include <ImfArray.h> +//#include <drawImage.h> + +#include <iostream> + +#include "kis_types.h" +#include "kis_openexr_import.h" +#include "kis_doc.h" +#include "kis_image.h" +#include "kis_meta_registry.h" +#include "kis_layer.h" +#include "kis_paint_layer.h" +#include "kis_annotation.h" +#include "kis_colorspace_factory_registry.h" +#include "kis_iterators_pixel.h" +#include "kis_abstract_colorspace.h" +#include "kis_rgb_f32_colorspace.h" +#include "kis_rgb_f16half_colorspace.h" + +using namespace std; +using namespace Imf; +using namespace Imath; + +typedef KGenericFactory<KisOpenEXRImport, KoFilter> KisOpenEXRImportFactory; +K_EXPORT_COMPONENT_FACTORY(libchalk_openexr_import, KisOpenEXRImportFactory("kofficefilters")) + +KisOpenEXRImport::KisOpenEXRImport(KoFilter *, const char *, const TQStringList&) : KoFilter() +{ +} + +KisOpenEXRImport::~KisOpenEXRImport() +{ +} + +KoFilter::ConversiontqStatus KisOpenEXRImport::convert(const TQCString& from, const TQCString& to) +{ + if (from != "image/x-exr" || to != "application/x-chalk") { + return KoFilter::NotImplemented; + } + + kdDebug(41008) << "\n\n\nChalk importing from OpenEXR\n"; + + KisDoc * doc = dynamic_cast<KisDoc*>(m_chain -> outputDocument()); + if (!doc) { + return KoFilter::CreationError; + } + + doc -> prepareForImport(); + + TQString filename = m_chain -> inputFile(); + + if (filename.isEmpty()) { + return KoFilter::FileNotFound; + } + + RgbaInputFile file(TQFile::encodeName(filename)); + Box2i dataWindow = file.dataWindow(); + Box2i displayWindow = file.displayWindow(); + + kdDebug(41008) << "Data window: " << TQRect(dataWindow.min.x, dataWindow.min.y, dataWindow.max.x - dataWindow.min.x + 1, dataWindow.max.y - dataWindow.min.y + 1) << endl; + kdDebug(41008) << "Display window: " << TQRect(displayWindow.min.x, displayWindow.min.y, displayWindow.max.x - displayWindow.min.x + 1, displayWindow.max.y - displayWindow.min.y + 1) << endl; + + int imageWidth = displayWindow.max.x - displayWindow.min.x + 1; + int imageHeight = displayWindow.max.y - displayWindow.min.y + 1; + + TQString imageName = "Imported from OpenEXR"; + + int dataWidth = dataWindow.max.x - dataWindow.min.x + 1; + int dataHeight = dataWindow.max.y - dataWindow.min.y + 1; + + KisRgbF16HalfColorSpace *cs = static_cast<KisRgbF16HalfColorSpace *>((KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBAF16HALF", ""),""))); + + if (cs == 0) { + return KoFilter::InternalError; + } + + doc -> undoAdapter() -> setUndo(false); + + KisImageSP image = new KisImage(doc->undoAdapter(), imageWidth, imageHeight, cs, imageName); + + if (image == 0) { + return KoFilter::CreationError; + } + + KisPaintLayerSP layer = dynamic_cast<KisPaintLayer*>(image->newLayer(image -> nextLayerName(), OPACITY_OPAQUE).data()); + + if (layer == 0) { + return KoFilter::CreationError; + } + + TQMemArray<Rgba> pixels(dataWidth); + + for (int y = 0; y < dataHeight; ++y) { + + file.setFrameBuffer(pixels.data() - dataWindow.min.x - (dataWindow.min.y + y) * dataWidth, 1, dataWidth); + file.readPixels(dataWindow.min.y + y); + + KisHLineIterator it = layer->paintDevice()->createHLineIterator(dataWindow.min.x, dataWindow.min.y + y, dataWidth, true); + Rgba *rgba = pixels.data(); + + while (!it.isDone()) { + + // XXX: For now unmultiply the alpha, though compositing will be faster if we + // keep it premultiplied. + half unmultipliedRed = rgba -> r; + half unmultipliedGreen = rgba -> g; + half unmultipliedBlue = rgba -> b; + + if (rgba -> a >= HALF_EPSILON) { + unmultipliedRed /= rgba -> a; + unmultipliedGreen /= rgba -> a; + unmultipliedBlue /= rgba -> a; + } + + cs -> setPixel(it.rawData(), unmultipliedRed, unmultipliedGreen, unmultipliedBlue, rgba -> a); + ++it; + ++rgba; + } + } + + layer->setDirty(); + doc -> setCurrentImage(image); + doc -> undoAdapter() -> setUndo(true); + doc -> setModified(false); + + return KoFilter::OK; +} + +#include "kis_openexr_import.moc" + diff --git a/filters/chalk/openexr/kis_openexr_import.h b/filters/chalk/openexr/kis_openexr_import.h new file mode 100644 index 00000000..f8cd5144 --- /dev/null +++ b/filters/chalk/openexr/kis_openexr_import.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com> + * + * 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. + */ + +#ifndef KIS_OPENEXR_IMPORT_H_ +#define KIS_OPENEXR_IMPORT_H_ + +#include <KoFilter.h> + +class KisOpenEXRImport : public KoFilter { + Q_OBJECT + TQ_OBJECT + +public: + KisOpenEXRImport(KoFilter *tqparent, const char *name, const TQStringList&); + virtual ~KisOpenEXRImport(); + +public: + virtual KoFilter::ConversiontqStatus convert(const TQCString& from, const TQCString& to); +}; + +#endif // KIS_OPENEXR_IMPORT_H_ + |