summaryrefslogtreecommitdiffstats
path: root/filters/chalk/png
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
commit698569f8428ca088f764d704034a1330517b98c0 (patch)
treebf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /filters/chalk/png
parent2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff)
downloadkoffice-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/png')
-rw-r--r--filters/chalk/png/Makefile.am44
-rw-r--r--filters/chalk/png/chalk_png.desktop57
-rw-r--r--filters/chalk/png/chalk_png_export.desktop51
-rw-r--r--filters/chalk/png/chalk_png_import.desktop51
-rw-r--r--filters/chalk/png/configure.in.bot8
-rw-r--r--filters/chalk/png/kis_png_converter.cc794
-rw-r--r--filters/chalk/png/kis_png_converter.h82
-rw-r--r--filters/chalk/png/kis_png_export.cc124
-rw-r--r--filters/chalk/png/kis_png_export.h35
-rw-r--r--filters/chalk/png/kis_png_import.cc105
-rw-r--r--filters/chalk/png/kis_png_import.h34
-rw-r--r--filters/chalk/png/kis_wdg_options_png.ui183
12 files changed, 1568 insertions, 0 deletions
diff --git a/filters/chalk/png/Makefile.am b/filters/chalk/png/Makefile.am
new file mode 100644
index 00000000..fbee1638
--- /dev/null
+++ b/filters/chalk/png/Makefile.am
@@ -0,0 +1,44 @@
+kde_module_LTLIBRARIES = libchalkpngimport.la libchalkpngexport.la
+
+libchalkpngexport_la_LDFLAGS = $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) -module -avoid-version -no-undefined -lkdecore -lkdeui $(LIB_QT) -lkjs -lkdefx -lkio -lkparts \
+ -L../../../lib/kofficecore/.libs/ -lkofficecore -llcms \
+ -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
+libchalkpngexport_la_LIBADD = \
+ $(KOFFICE_LIBS) \
+ $(top_builddir)/chalk/libchalkcommon.la \
+ -lpng
+
+libchalkpngimport_la_LDFLAGS = $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) -module -avoid-version -no-undefined -lkdecore -lkdeui $(LIB_QT) -lkjs -lkdefx -lkio -lkparts \
+ -L../../../lib/kofficecore/.libs/ -lkofficecore -llcms \
+ -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
+libchalkpngimport_la_LIBADD = \
+ $(KOFFICE_LIBS) \
+ $(top_builddir)/chalk/libchalkcommon.la \
+ -lpng
+
+INCLUDES= \
+ -I$(srcdir) \
+ $(KOFFICE_INCLUDES) \
+ -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 \
+ $(KOFFICE_INCLUDES) -I$(interfacedir) \
+ $(KOPAINTER_INCLUDES) \
+ $(all_includes)
+
+service_DATA = chalk_png_import.desktop chalk_png_export.desktop
+servicedir = $(kde_servicesdir)
+
+kdelnk_DATA = chalk_png.desktop
+kdelnkdir = $(kde_appsdir)/.hidden
+
+libchalkpngimport_la_SOURCES = kis_png_import.cc kis_png_converter.cc
+libchalkpngexport_la_SOURCES = kis_wdg_options_png.ui kis_png_export.cc kis_png_converter.cc
+
+METASOURCES = AUTO
+
+
+KDE_CXXFLAGS = $(USE_EXCEPTIONS)
diff --git a/filters/chalk/png/chalk_png.desktop b/filters/chalk/png/chalk_png.desktop
new file mode 100644
index 00000000..3605566b
--- /dev/null
+++ b/filters/chalk/png/chalk_png.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/png
+Type=Application
+Icon=chalk
+Categories=
+X-KDE-StartupNotify=true
+X-DCOP-ServiceType=Multi
diff --git a/filters/chalk/png/chalk_png_export.desktop b/filters/chalk/png/chalk_png_export.desktop
new file mode 100644
index 00000000..e4f6711b
--- /dev/null
+++ b/filters/chalk/png/chalk_png_export.desktop
@@ -0,0 +1,51 @@
+[Desktop Entry]
+Name=Chalk PNG Export Filter
+Name[bg]=Филтър за експортиране от Chalk в PNG
+Name[br]=Sil ezporzh PNG evit Chalk
+Name[ca]=Filtre d'exportació PNG per a Chalk
+Name[da]=Chalk PNG-eksportfilter
+Name[de]=Chalk PNG-Exportfilter
+Name[el]=Φίλτρο εξαγωγής PNG του Chalk
+Name[eo]=Chalk PNG-eksportfiltrilo
+Name[es]=Filtro de exportación a PNG de Chalk
+Name[et]=Chalk PNG ekspordifilter
+Name[fa]=پالایۀ صادرات Chalk PNG
+Name[fi]=Chalk PNG -viestisuodin
+Name[fr]=Filtre d'exportation PNG de Chalk
+Name[fy]=Chalk PNG Eksportfilter
+Name[ga]=Scagaire Easpórtála PNG Chalk
+Name[gl]=Filtro de Exportación de PNG para Chalk
+Name[he]=Chalk PNG מסנן יצוא
+Name[hr]=Chalk PNG filtar izvoza
+Name[hu]=Chalk PNG exportszűrő
+Name[is]=Chalk PNG útflutningssía
+Name[it]=Filtro di esportazione PNG per Chalk
+Name[ja]=Chalk PNG エクスポートフィルタ
+Name[km]=តម្រង​នាំចេញ PNG សម្រាប់ Chalk
+Name[lt]=Chalk PNG eksportavimo filtras
+Name[lv]=Chalk PNG eksporta filtrs
+Name[nb]=PNG-eksportfilter for Chalk
+Name[nds]=PNG-Exportfilter för Chalk
+Name[ne]=क्रिता पीएनजी निर्यात फिल्टर
+Name[nl]=Chalk PNG Exportfilter
+Name[pl]=Filtr eksportu do formatu PNG dla Chalk
+Name[pt]=Filtro de Exportação de PNG para o Chalk
+Name[pt_BR]=Filtro de Exportação de PNG para o Chalk
+Name[ru]=Фильтр экспорта рисунков Chalk в PNG
+Name[se]=Chalk PNG-olggosfievrridansilli
+Name[sk]=Exportný filter Chalk PNG
+Name[sl]=Izvozni filter PNG za Krito
+Name[sr]=Chalk-ин филтер за извоз у PNG
+Name[sr@Latn]=Chalk-in filter za izvoz u PNG
+Name[sv]=Chalk PNG-exportfilter
+Name[uk]=Фільтр експорту PNG для Chalk
+Name[uz]=Chalk PNG eksport filteri
+Name[uz@cyrillic]=Chalk PNG экспорт филтери
+Name[zh_CN]=Chalk PNG 导出过滤器
+Name[zh_TW]=Chalk PNG 匯出過濾程式
+X-KDE-Export=image/png
+ServiceTypes=KOfficeFilter
+Type=Service
+X-KDE-Import=application/x-chalk
+X-KDE-Weight=1
+X-KDE-Library=libchalkpngexport
diff --git a/filters/chalk/png/chalk_png_import.desktop b/filters/chalk/png/chalk_png_import.desktop
new file mode 100644
index 00000000..94b1c90f
--- /dev/null
+++ b/filters/chalk/png/chalk_png_import.desktop
@@ -0,0 +1,51 @@
+[Desktop Entry]
+Type=Service
+Name=Chalk PNG Import Filter
+Name[bg]=Филтър за импортиране от PNG в Chalk
+Name[br]=Sil enporzh PNG evit Chalk
+Name[ca]=Filtre d'importació PNG per a Chalk
+Name[da]=Chalk PNG-importfilter
+Name[de]=Chalk PNG-Importfilter
+Name[el]=Φίλτρο εισαγωγής PNG του Chalk
+Name[eo]=Chalk PNG-importfiltrilo
+Name[es]=Filtro de importación a PNG de Chalk
+Name[et]=Chalk PNG impordifilter
+Name[fa]=پالایۀ واردات Chalk PNG
+Name[fi]=Chalk PNG -tuontisuodin
+Name[fr]=Filtre d'importation PNG de Chalk
+Name[fy]=Chalk PNG Ymportfilter
+Name[ga]=Scagaire Iompórtála PNG Chalk
+Name[gl]=Filtro de Importación de PNG para Chalk
+Name[he]=Chalk PNG מסנן יבוא
+Name[hr]=Chalk PNG filtar uvoza
+Name[hu]=Chalk PNG importszűrő
+Name[is]=Chalk PNG innflutningssía
+Name[it]=Filtro di importazione PNG per Chalk
+Name[ja]=Chalk PNG インポートフィルタ
+Name[km]=តម្រង​នាំចូល PNG សម្រាប់ Chalk
+Name[lt]=Chalk PNG importavimo filtras
+Name[lv]=Chalk PNG importa filtrs
+Name[nb]=PNG-importfilter for Chalk
+Name[nds]=PNG-Importfilter för Chalk
+Name[ne]=क्रिता पीएनजी आयात फिल्टर
+Name[nl]=Chalk PNG Importfilter
+Name[pl]=Filtr importu z formatu PNG dla Chalk
+Name[pt]=Filtro de Importação de PNG para o Chalk
+Name[pt_BR]=Filtro de Importação de PNG para o Chalk
+Name[ru]=Фильтр импорта рисунков PNG в Chalk
+Name[se]=Chalk PNG-olggosfievrridansilli
+Name[sk]=PNG filter pre import do Chalk
+Name[sl]=Uvozni filter PNG za Krito
+Name[sr]=Chalk-ин филтер за увоз из PNG-а
+Name[sr@Latn]=Chalk-in filter za uvoz iz PNG-a
+Name[sv]=Chalk PNG-importfilter
+Name[uk]=Фільтр імпорту PNG для Chalk
+Name[uz]=Chalk PNG import filteri
+Name[uz@cyrillic]=Chalk PNG импорт филтери
+Name[zh_CN]=Chalk PNG 导入过滤器
+Name[zh_TW]=Chalk PNG 匯入過濾程式
+X-KDE-Export=application/x-chalk
+X-KDE-Import=image/png
+X-KDE-Weight=1
+X-KDE-Library=libchalkpngimport
+ServiceTypes=KOfficeFilter
diff --git a/filters/chalk/png/configure.in.bot b/filters/chalk/png/configure.in.bot
new file mode 100644
index 00000000..cda5270f
--- /dev/null
+++ b/filters/chalk/png/configure.in.bot
@@ -0,0 +1,8 @@
+if test -z "$LIBPNG"; then
+ echo ""
+ echo "You're missing libpng (binaries and/or headers), chalk won't be able"
+ echo "to import/export png"
+ echo ""
+ all_tests=bad
+fi
+
diff --git a/filters/chalk/png/kis_png_converter.cc b/filters/chalk/png/kis_png_converter.cc
new file mode 100644
index 00000000..b7c48b50
--- /dev/null
+++ b/filters/chalk/png/kis_png_converter.cc
@@ -0,0 +1,794 @@
+/*
+ * Copyright (c) 2005-2006 Cyrille Berger <cberger@cberger.net>
+ *
+ * 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.
+ */
+
+ // A big thank to Glenn Randers-Pehrson for it's wonderfull documentation of libpng available at http://www.libpng.org/pub/png/libpng-1.2.5-manual.html
+#include "kis_png_converter.h"
+
+#include <stdio.h>
+
+#include <tqfile.h>
+
+#include <kapplication.h>
+#include <kmessagebox.h>
+#include <klocale.h>
+
+#include <KoDocumentInfo.h>
+
+#include <kio/netaccess.h>
+
+#include <kis_abstract_colorspace.h>
+#include <kis_colorspace_factory_registry.h>
+#include <kis_doc.h>
+#include <kis_image.h>
+#include <kis_iterators_pixel.h>
+#include <kis_layer.h>
+#include <kis_meta_registry.h>
+#include <kis_profile.h>
+#include <kis_paint_layer.h>
+#include <kis_group_layer.h>
+
+namespace {
+
+ const TQ_UINT8 PIXEL_BLUE = 0;
+ const TQ_UINT8 PIXEL_GREEN = 1;
+ const TQ_UINT8 PIXEL_RED = 2;
+ const TQ_UINT8 PIXEL_ALPHA = 3;
+
+
+ int getColorTypeforColorSpace( KisColorSpace * cs , bool alpha)
+ {
+ if ( cs->id() == KisID("GRAYA") || cs->id() == KisID("GRAYA16") )
+ {
+ return alpha ? PNG_COLOR_TYPE_GRAY_ALPHA : PNG_COLOR_TYPE_GRAY;
+ }
+ if ( cs->id() == KisID("RGBA") || cs->id() == KisID("RGBA16") )
+ {
+ return alpha ? PNG_COLOR_TYPE_RGB_ALPHA : PNG_COLOR_TYPE_RGB;
+ }
+
+ KMessageBox::error(0, i18n("Cannot export images in %1.\n").tqarg(cs->id().name()) ) ;
+ return -1;
+
+ }
+
+
+ TQString getColorSpaceForColorType(int color_type,int color_nb_bits) {
+ if(color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ {
+ switch(color_nb_bits)
+ {
+ case 8:
+ return "GRAYA";
+ case 16:
+ return "GRAYA16";
+ }
+ } else if(color_type == PNG_COLOR_TYPE_RGB_ALPHA || color_type == PNG_COLOR_TYPE_RGB) {
+ switch(color_nb_bits)
+ {
+ case 8:
+ return "RGBA";
+ case 16:
+ return "RGBA16";
+ }
+ } else if(color_type == PNG_COLOR_TYPE_PALETTE) {
+ return "RGBA"; // <-- we will convert the index image to RGBA
+ }
+ return "";
+ }
+
+
+ void fillText(png_text* p_text, char* key, TQString& text)
+ {
+ p_text->compression = PNG_TEXT_COMPRESSION_zTXt;
+ p_text->key = key;
+ char* textc = new char[text.length()+1];
+ strcpy(textc, text.ascii());
+ p_text->text = textc;
+ p_text->text_length = text.length()+1;
+ }
+
+}
+
+KisPNGConverter::KisPNGConverter(KisDoc *doc, KisUndoAdapter *adapter)
+{
+ Q_ASSERT(doc);
+ Q_ASSERT(adapter);
+
+ m_doc = doc;
+ m_adapter = adapter;
+ m_stop = false;
+ m_max_row = 0;
+ m_img = 0;
+}
+
+KisPNGConverter::~KisPNGConverter()
+{
+}
+
+class KisPNGStream {
+ public:
+ KisPNGStream(TQ_UINT8* buf, TQ_UINT32 depth ) : m_posinc(8),m_depth(depth), m_buf(buf) { *m_buf = 0;};
+ int nextValue()
+ {
+ if( m_posinc == 0)
+ {
+ m_posinc = 8;
+ m_buf++;
+ }
+ m_posinc -= m_depth;
+ return (( (*m_buf) >> (m_posinc) ) & ( ( 1 << m_depth ) - 1 ) );
+ }
+ void setNextValue(int v)
+ {
+ if( m_posinc == 0)
+ {
+ m_posinc = 8;
+ m_buf++;
+ *m_buf = 0;
+ }
+ m_posinc -= m_depth;
+ *m_buf = (v << m_posinc) | *m_buf;
+ }
+ private:
+ TQ_UINT32 m_posinc, m_depth;
+ TQ_UINT8* m_buf;
+};
+
+KisImageBuilder_Result KisPNGConverter::decode(const KURL& uri)
+{
+ kdDebug(41008) << "Start decoding PNG File" << endl;
+ // open the file
+ kdDebug(41008) << TQFile::encodeName(uri.path()) << " " << uri.path() << " " << uri << endl;
+ FILE *fp = fopen(TQFile::encodeName(uri.path()), "rb");
+ if (!fp)
+ {
+ return (KisImageBuilder_RESULT_NOT_EXIST);
+ }
+ png_byte signature[8];
+ fread(signature, 1, 8, fp);
+ if (!png_check_sig(signature, 8))
+ {
+ return (KisImageBuilder_RESULT_BAD_FETCH);
+ }
+
+ // Initialize the internal structures
+ png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, (png_error_ptr)NULL, (png_error_ptr)NULL);
+ if (!KisImageBuilder_RESULT_FAILURE)
+ return (KisImageBuilder_RESULT_FAILURE);
+
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
+ return (KisImageBuilder_RESULT_FAILURE);
+ }
+
+ png_infop end_info = png_create_info_struct(png_ptr);
+ if (!end_info)
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+ return (KisImageBuilder_RESULT_FAILURE);
+ }
+
+ // Catch errors
+ if (setjmp(png_jmpbuf(png_ptr)))
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ fclose(fp);
+ return (KisImageBuilder_RESULT_FAILURE);
+ }
+
+ png_init_io(png_ptr, fp);
+ png_set_sig_bytes(png_ptr, 8);
+
+ // read all PNG info up to image data
+ png_read_info(png_ptr, info_ptr);
+
+ // Read information about the png
+ png_uint_32 width, height;
+ int color_nb_bits, color_type, interlace_type;
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &color_nb_bits, &color_type, &interlace_type, NULL, NULL);
+ kdDebug(41008) << "it's an " << color_nb_bits << " depth image" << endl;
+
+ // swap byteorder on little endian machines.
+ #ifndef WORDS_BIGENDIAN
+ if (color_nb_bits > 8 )
+ png_set_swap(png_ptr);
+ #endif
+
+ // Determine the colorspace
+ TQString csName = getColorSpaceForColorType(color_type, color_nb_bits);
+ if(csName.isEmpty()) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE;
+ }
+ bool hasalpha = (color_type == PNG_COLOR_TYPE_RGB_ALPHA || color_type == PNG_COLOR_TYPE_GRAY_ALPHA);
+
+ // Read image profile
+ png_charp profile_name, profile_data;
+ int compression_type;
+ png_uint_32 proflen;
+ int number_of_passes = 1;
+
+ if (interlace_type == PNG_INTERLACE_ADAM7)
+ number_of_passes = png_set_interlace_handling(png_ptr);
+
+ KisProfile* profile = 0;
+ if(png_get_iCCP(png_ptr, info_ptr, &profile_name, &compression_type, &profile_data, &proflen))
+ {
+ TQByteArray profile_rawdata;
+ // XXX: Hardcoded for icc type -- is that correct for us?
+ if (TQString::compare(profile_name, "icc") == 0) {
+ profile_rawdata.resize(proflen);
+ memcpy(profile_rawdata.data(), profile_data, proflen);
+ profile = new KisProfile(profile_rawdata);
+ Q_CHECK_PTR(profile);
+ if (profile) {
+ kdDebug(41008) << "profile name: " << profile->productName() << " profile description: " << profile->productDescription() << " information sur le produit: " << profile->productInfo() << endl;
+ if(!profile->isSuitableForOutput())
+ {
+ kdDebug(41008) << "the profile is not suitable for output and therefore cannot be used in chalk, we need to convert the image to a standard profile" << endl; // TODO: in ko2 popup a selection menu to inform the user
+ }
+ }
+ }
+ }
+
+ // Retrieve a pointer to the colorspace
+ KisColorSpace* cs;
+ if (profile && profile->isSuitableForOutput())
+ {
+ kdDebug(41008) << "image has embedded profile: " << profile -> productName() << "\n";
+ cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(csName, profile);
+ }
+ else
+ cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID(csName,""),"");
+
+ if(cs == 0)
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE;
+ }
+
+ // Create the cmsTransform if needed
+ cmsHTRANSFORM transform = 0;
+ if(profile && !profile->isSuitableForOutput())
+ {
+ transform = cmsCreateTransform(profile->profile(), cs->colorSpaceType(),
+ cs->getProfile()->profile() , cs->colorSpaceType(),
+ INTENT_PERCEPTUAL, 0);
+ }
+
+ // Read comments/texts...
+ png_text* text_ptr;
+ int num_comments;
+ png_get_text(png_ptr, info_ptr, &text_ptr, &num_comments);
+ KoDocumentInfo * info = m_doc->documentInfo();
+ KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( "about" ));
+ KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author"));
+ kdDebug(41008) << "There are " << num_comments << " comments in the text" << endl;
+ for(int i = 0; i < num_comments; i++)
+ {
+ kdDebug(41008) << "key is " << text_ptr[i].key << " containing " << text_ptr[i].text << endl;
+ if(TQString::compare(text_ptr[i].key, "title") == 0)
+ {
+ aboutPage->setTitle(text_ptr[i].text);
+ } else if(TQString::compare(text_ptr[i].key, "abstract") == 0)
+ {
+ aboutPage->setAbstract(text_ptr[i].text);
+ } else if(TQString::compare(text_ptr[i].key, "author") == 0)
+ {
+ authorPage->setFullName(text_ptr[i].text);
+ }
+ }
+
+ // Read image data
+ png_bytep row_pointer = 0;
+ try
+ {
+ png_uint_32 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+ row_pointer = new png_byte[rowbytes];
+ }
+ catch(std::bad_alloc& e)
+ {
+ // new png_byte[] may raise such an exception if the image
+ // is invalid / to large.
+ kdDebug(41008) << "bad alloc: " << e.what() << endl;
+ // Free only the already allocated png_byte instances.
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ return (KisImageBuilder_RESULT_FAILURE);
+ }
+
+ // Read the palette if the file is indexed
+ png_colorp palette ;
+ int num_palette;
+ if(color_type == PNG_COLOR_TYPE_PALETTE) {
+ png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
+ }
+// png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL );
+// png_bytepp row_pointers = png_get_rows(png_ptr, info_ptr); // By using this function libpng will take care of freeing memory
+// png_read_image(png_ptr, row_pointers);
+
+ // Finish reading the file
+// png_read_end(png_ptr, end_info);
+// fclose(fp);
+
+ // Creating the KisImageSP
+ if( ! m_img) {
+ m_img = new KisImage(m_doc->undoAdapter(), width, height, cs, "built image");
+ m_img->blockSignals(true); // Don't send out signals while we're building the image
+ Q_CHECK_PTR(m_img);
+ if(profile && !profile->isSuitableForOutput())
+ {
+ m_img -> addAnnotation( profile->annotation() );
+ }
+ }
+
+ KisPaintLayer* layer = new KisPaintLayer(m_img, m_img -> nextLayerName(), TQ_UINT8_MAX);
+ for (int i = 0; i < number_of_passes; i++)
+ {
+ for (png_uint_32 y = 0; y < height; y++) {
+ KisHLineIterator it = layer -> paintDevice() -> createHLineIterator(0, y, width, true);
+ png_read_rows(png_ptr, &row_pointer, NULL, 1);
+
+ switch(color_type)
+ {
+ case PNG_COLOR_TYPE_GRAY:
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
+ if(color_nb_bits == 16)
+ {
+ TQ_UINT16 *src = reinterpret_cast<TQ_UINT16 *>(row_pointer);
+ while (!it.isDone()) {
+ TQ_UINT16 *d = reinterpret_cast<TQ_UINT16 *>(it.rawData());
+ d[0] = *(src++);
+ if(transform) cmsDoTransform(transform, d, d, 1);
+ if(hasalpha) d[1] = *(src++);
+ else d[1] = TQ_UINT16_MAX;
+ ++it;
+ }
+ } else {
+ TQ_UINT8 *src = row_pointer;
+ while (!it.isDone()) {
+ TQ_UINT8 *d = it.rawData();
+ d[0] = *(src++);
+ if(transform) cmsDoTransform(transform, d, d, 1);
+ if(hasalpha) d[1] = *(src++);
+ else d[1] = TQ_UINT8_MAX;
+ ++it;
+ }
+ }
+ //FIXME:should be able to read 1 and 4 bits depth and scale them to 8 bits
+ break;
+ case PNG_COLOR_TYPE_RGB:
+ case PNG_COLOR_TYPE_RGB_ALPHA:
+ if(color_nb_bits == 16)
+ {
+ TQ_UINT16 *src = reinterpret_cast<TQ_UINT16 *>(row_pointer);
+ while (!it.isDone()) {
+ TQ_UINT16 *d = reinterpret_cast<TQ_UINT16 *>(it.rawData());
+ d[2] = *(src++);
+ d[1] = *(src++);
+ d[0] = *(src++);
+ if(transform) cmsDoTransform(transform, d, d, 1);
+ if(hasalpha) d[3] = *(src++);
+ else d[3] = TQ_UINT16_MAX;
+ ++it;
+ }
+ } else {
+ TQ_UINT8 *src = row_pointer;
+ while (!it.isDone()) {
+ TQ_UINT8 *d = it.rawData();
+ d[2] = *(src++);
+ d[1] = *(src++);
+ d[0] = *(src++);
+ if(transform) cmsDoTransform(transform, d, d, 1);
+ if(hasalpha) d[3] = *(src++);
+ else d[3] = TQ_UINT8_MAX;
+ ++it;
+ }
+ }
+ break;
+ case PNG_COLOR_TYPE_PALETTE:
+ {
+ KisPNGStream stream(row_pointer, color_nb_bits);
+ while (!it.isDone()) {
+ TQ_UINT8 *d = it.rawData();
+ png_color c = palette[ stream.nextValue() ];
+ d[2] = c.red;
+ d[1] = c.green;
+ d[0] = c.blue;
+ d[3] = TQ_UINT8_MAX;
+ ++it;
+ }
+ }
+ break;
+ default:
+ return KisImageBuilder_RESULT_UNSUPPORTED;
+ }
+ }
+ }
+ m_img->addLayer(layer, m_img->rootLayer(), 0);
+
+ png_read_end(png_ptr, end_info);
+ fclose(fp);
+
+ // Freeing memory
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+
+ delete [] row_pointer;
+
+ return KisImageBuilder_RESULT_OK;
+
+}
+
+KisImageBuilder_Result KisPNGConverter::buildImage(const KURL& uri)
+{
+ kdDebug(41008) << TQFile::encodeName(uri.path()) << " " << uri.path() << " " << uri << endl;
+ if (uri.isEmpty())
+ return KisImageBuilder_RESULT_NO_URI;
+
+ if (!KIO::NetAccess::exists(uri, false, tqApp -> mainWidget())) {
+ return KisImageBuilder_RESULT_NOT_EXIST;
+ }
+
+ // We're not set up to handle asynchronous loading at the moment.
+ KisImageBuilder_Result result = KisImageBuilder_RESULT_FAILURE;
+ TQString tmpFile;
+
+ if (KIO::NetAccess::download(uri, tmpFile, tqApp -> mainWidget())) {
+ KURL uriTF;
+ uriTF.setPath( tmpFile );
+ result = decode(uriTF);
+ KIO::NetAccess::removeTempFile(tmpFile);
+ }
+
+ return result;
+}
+
+
+KisImageSP KisPNGConverter::image()
+{
+ return m_img;
+}
+
+KisImageBuilder_Result KisPNGConverter::buildFile(const KURL& uri, KisPaintLayerSP layer, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, int compression, bool interlace, bool alpha)
+{
+ kdDebug(41008) << "Start writing PNG File" << endl;
+ if (!layer)
+ return KisImageBuilder_RESULT_INVALID_ARG;
+
+ KisImageSP img = layer -> image();
+ if (!img)
+ return KisImageBuilder_RESULT_EMPTY;
+
+ if (uri.isEmpty())
+ return KisImageBuilder_RESULT_NO_URI;
+
+ if (!uri.isLocalFile())
+ return KisImageBuilder_RESULT_NOT_LOCAL;
+ // Open file for writing
+ FILE *fp = fopen(TQFile::encodeName(uri.path()), "wb");
+ if (!fp)
+ {
+ return (KisImageBuilder_RESULT_FAILURE);
+ }
+ int height = img->height();
+ int width = img->width();
+ // Initialize structures
+ png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, (png_error_ptr)NULL, (png_error_ptr)NULL);
+ if (!png_ptr)
+ {
+ KIO::del(uri);
+ return (KisImageBuilder_RESULT_FAILURE);
+ }
+
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ KIO::del(uri);
+ png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+ return (KisImageBuilder_RESULT_FAILURE);
+ }
+
+ // If an error occurs during writing, libpng will jump here
+ if (setjmp(png_jmpbuf(png_ptr)))
+ {
+ KIO::del(uri);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ fclose(fp);
+ return (KisImageBuilder_RESULT_FAILURE);
+ }
+ // Initialize the writing
+ png_init_io(png_ptr, fp);
+ // Setup the progress function
+// FIXME png_set_write_status_fn(png_ptr, progress);
+// setProgressTotalSteps(100/*height*/);
+
+
+ /* set the zlib compression level */
+ png_set_compression_level(png_ptr, compression);
+
+ /* set other zlib parameters */
+ png_set_compression_mem_level(png_ptr, 8);
+ png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY);
+ png_set_compression_window_bits(png_ptr, 15);
+ png_set_compression_method(png_ptr, 8);
+ png_set_compression_buffer_size(png_ptr, 8192);
+
+ int color_nb_bits = 8 * layer->paintDevice()->pixelSize() / layer->paintDevice()->nChannels();
+ int color_type = getColorTypeforColorSpace(layer->paintDevice()->colorSpace(), alpha);
+
+ if(color_type == -1)
+ {
+ return KisImageBuilder_RESULT_UNSUPPORTED;
+ }
+
+ // Try to compute a table of color if the colorspace is RGB8f
+ png_colorp palette ;
+ int num_palette = 0;
+ if(!alpha && layer->paintDevice()->colorSpace()->id() == KisID("RGBA") )
+ { // png doesn't handle indexed images and alpha, and only have indexed for RGB8
+ palette = new png_color[255];
+ KisRectIteratorPixel it = layer->paintDevice()->createRectIterator(0,0, img->width(), img->height(), false);
+ bool toomuchcolor = false;
+ while( !it.isDone() )
+ {
+ const TQ_UINT8* c = it.rawData();
+ bool findit = false;
+ for(int i = 0; i < num_palette; i++)
+ {
+ if(palette[i].red == c[2] &&
+ palette[i].green == c[1] &&
+ palette[i].blue == c[0] )
+ {
+ findit = true;
+ break;
+ }
+ }
+ if(!findit)
+ {
+ if( num_palette == 255)
+ {
+ toomuchcolor = true;
+ break;
+ }
+ palette[num_palette].red = c[2];
+ palette[num_palette].green = c[1];
+ palette[num_palette].blue = c[0];
+ num_palette++;
+ }
+ ++it;
+ }
+ if(!toomuchcolor)
+ {
+ kdDebug(41008) << "Found a palette of " << num_palette << " colors" << endl;
+ color_type = PNG_COLOR_TYPE_PALETTE;
+ if( num_palette <= 2)
+ {
+ color_nb_bits = 1;
+ } else if( num_palette <= 4)
+ {
+ color_nb_bits = 2;
+ } else if( num_palette <= 16)
+ {
+ color_nb_bits = 4;
+ } else {
+ color_nb_bits = 8;
+ }
+ } else {
+ delete palette;
+ }
+ }
+
+ int interlacetype = interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
+
+ png_set_IHDR(png_ptr, info_ptr,
+ width,
+ height,
+ color_nb_bits,
+ color_type, interlacetype,
+ PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+
+ png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_ABSOLUTE);
+ // set the palette
+ if( color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
+ }
+ // Save annotation
+ vKisAnnotationSP_it it = annotationsStart;
+ while(it != annotationsEnd) {
+ if (!(*it) || (*it) -> type() == TQString()) {
+ kdDebug(41008) << "Warning: empty annotation" << endl;
+ ++it;
+ continue;
+ }
+
+ kdDebug(41008) << "Trying to store annotation of type " << (*it) -> type() << " of size " << (*it) -> annotation() . size() << endl;
+
+ if ((*it) -> type().startsWith("chalk_attribute:")) { // Attribute
+ // FIXME: it should be possible to save chalk_attributes in the "CHUNKs"
+ kdDebug(41008) << "can't save this annotation : " << (*it) -> type() << endl;
+ } else { // Profile
+ char* name = new char[(*it)->type().length()+1];
+ strcpy(name, (*it)->type().ascii());
+ png_set_iCCP(png_ptr, info_ptr, name, PNG_COMPRESSION_TYPE_BASE, (char*)(*it)->annotation().data(), (*it) -> annotation() . size());
+ }
+ ++it;
+ }
+
+ // read comments from the document information
+ png_text texts[3];
+ int nbtexts = 0;
+ KoDocumentInfo * info = m_doc->documentInfo();
+ KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(info->page( "about" ));
+ TQString title = aboutPage->title();
+ if(!title.isEmpty())
+ {
+ fillText(texts+nbtexts, "title", title);
+ nbtexts++;
+ }
+ TQString abstract = aboutPage->abstract();
+ if(!abstract.isEmpty())
+ {
+ fillText(texts+nbtexts, "abstract", abstract);
+ nbtexts++;
+ }
+ KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
+ TQString author = authorPage->fullName();
+ if(!author.isEmpty())
+ {
+ fillText(texts+nbtexts, "author", author);
+ nbtexts++;
+ }
+
+ png_set_text(png_ptr, info_ptr, texts, nbtexts);
+
+ // Save the information to the file
+ png_write_info(png_ptr, info_ptr);
+ png_write_flush(png_ptr);
+
+ // swap byteorder on little endian machines.
+ #ifndef WORDS_BIGENDIAN
+ if (color_nb_bits > 8 )
+ png_set_swap(png_ptr);
+ #endif
+
+ // Write the PNG
+// png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
+
+ // Fill the data structure
+ png_byte** row_pointers= new png_byte*[height];
+
+ for (int y = 0; y < height; y++) {
+ KisHLineIterator it = layer->paintDevice()->createHLineIterator(0, y, width, false);
+ row_pointers[y] = new png_byte[width*layer->paintDevice()->pixelSize()];
+ switch(color_type)
+ {
+ case PNG_COLOR_TYPE_GRAY:
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
+ if(color_nb_bits == 16)
+ {
+ TQ_UINT16 *dst = reinterpret_cast<TQ_UINT16 *>(row_pointers[y]);
+ while (!it.isDone()) {
+ const TQ_UINT16 *d = reinterpret_cast<const TQ_UINT16 *>(it.rawData());
+ *(dst++) = d[0];
+ if(alpha) *(dst++) = d[1];
+ ++it;
+ }
+ } else {
+ TQ_UINT8 *dst = row_pointers[y];
+ while (!it.isDone()) {
+ const TQ_UINT8 *d = it.rawData();
+ *(dst++) = d[0];
+ if(alpha) *(dst++) = d[1];
+ ++it;
+ }
+ }
+ break;
+ case PNG_COLOR_TYPE_RGB:
+ case PNG_COLOR_TYPE_RGB_ALPHA:
+ if(color_nb_bits == 16)
+ {
+ TQ_UINT16 *dst = reinterpret_cast<TQ_UINT16 *>(row_pointers[y]);
+ while (!it.isDone()) {
+ const TQ_UINT16 *d = reinterpret_cast<const TQ_UINT16 *>(it.rawData());
+ *(dst++) = d[2];
+ *(dst++) = d[1];
+ *(dst++) = d[0];
+ if(alpha) *(dst++) = d[3];
+ ++it;
+ }
+ } else {
+ TQ_UINT8 *dst = row_pointers[y];
+ while (!it.isDone()) {
+ const TQ_UINT8 *d = it.rawData();
+ *(dst++) = d[2];
+ *(dst++) = d[1];
+ *(dst++) = d[0];
+ if(alpha) *(dst++) = d[3];
+ ++it;
+ }
+ }
+ break;
+ case PNG_COLOR_TYPE_PALETTE:
+ {
+ TQ_UINT8 *dst = row_pointers[y];
+ KisPNGStream writestream(dst, color_nb_bits);
+ while (!it.isDone()) {
+ const TQ_UINT8 *d = it.rawData();
+ int i;
+ for(i = 0; i < num_palette; i++)
+ {
+ if(palette[i].red == d[2] &&
+ palette[i].green == d[1] &&
+ palette[i].blue == d[0] )
+ {
+ break;
+ }
+ }
+ writestream.setNextValue(i);
+ ++it;
+ }
+ }
+ break;
+ default:
+ kdDebug(41008) << "Unsupported color type for writting : " << color_type << endl;
+ KIO::del(uri);
+ return KisImageBuilder_RESULT_UNSUPPORTED;
+ }
+ }
+
+ png_write_image(png_ptr, row_pointers);
+
+
+ // Writting is over
+ png_write_end(png_ptr, info_ptr);
+
+ // Free memory
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ for (int y = 0; y < height; y++) {
+ delete[] row_pointers[y];
+ }
+ delete[] row_pointers;
+
+ if( color_type == PNG_COLOR_TYPE_PALETTE)
+ {
+ delete palette;
+ }
+
+ fclose(fp);
+
+ return KisImageBuilder_RESULT_OK;
+}
+
+
+void KisPNGConverter::cancel()
+{
+ m_stop = true;
+}
+
+void KisPNGConverter::progress(png_structp png_ptr, png_uint_32 row_number, int pass)
+{
+ if(png_ptr == NULL || row_number > PNG_MAX_UINT || pass > 7) return;
+// setProgress(row_number);
+}
+
+
+#include "kis_png_converter.moc"
+
diff --git a/filters/chalk/png/kis_png_converter.h b/filters/chalk/png/kis_png_converter.h
new file mode 100644
index 00000000..a4f1140b
--- /dev/null
+++ b/filters/chalk/png/kis_png_converter.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
+ *
+ * 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_PNG_CONVERTER_H_
+#define _KIS_PNG_CONVERTER_H_
+
+#include <png.h>
+
+#include <tqvaluevector.h>
+
+#include <kio/job.h>
+
+#include <kis_progress_subject.h>
+
+#include "kis_types.h"
+#include "kis_global.h"
+#include "kis_annotation.h"
+class KisDoc;
+class KisUndoAdapter;
+
+/**
+ * Image import/export plugins can use these results to report about success or failure.
+ */
+enum KisImageBuilder_Result {
+ KisImageBuilder_RESULT_FAILURE = -400,
+ KisImageBuilder_RESULT_NOT_EXIST = -300,
+ KisImageBuilder_RESULT_NOT_LOCAL = -200,
+ KisImageBuilder_RESULT_BAD_FETCH = -100,
+ KisImageBuilder_RESULT_INVALID_ARG = -50,
+ KisImageBuilder_RESULT_OK = 0,
+ KisImageBuilder_RESULT_PROGRESS = 1,
+ KisImageBuilder_RESULT_EMPTY = 100,
+ KisImageBuilder_RESULT_BUSY = 150,
+ KisImageBuilder_RESULT_NO_URI = 200,
+ KisImageBuilder_RESULT_UNSUPPORTED = 300,
+ KisImageBuilder_RESULT_INTR = 400,
+ KisImageBuilder_RESULT_PATH = 500,
+ KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE = 600
+};
+
+class KisPNGConverter : public KisProgressSubject {
+ Q_OBJECT
+ TQ_OBJECT
+ public:
+ KisPNGConverter(KisDoc *doc, KisUndoAdapter *adapter);
+ virtual ~KisPNGConverter();
+ public:
+ KisImageBuilder_Result buildImage(const KURL& uri);
+ KisImageBuilder_Result buildFile(const KURL& uri, KisPaintLayerSP layer, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, int compression, bool interlace, bool alpha);
+ /** Retrieve the constructed image
+ */
+ KisImageSP image();
+ public slots:
+ virtual void cancel();
+ private:
+ KisImageBuilder_Result decode(const KURL& uri);
+ void progress(png_structp png_ptr, png_uint_32 row_number, int pass);
+ private:
+ png_uint_32 m_max_row;
+ KisImageSP m_img;
+ KisDoc *m_doc;
+ KisUndoAdapter *m_adapter;
+ bool m_stop;
+};
+
+#endif
diff --git a/filters/chalk/png/kis_png_export.cc b/filters/chalk/png/kis_png_export.cc
new file mode 100644
index 00000000..8154866a
--- /dev/null
+++ b/filters/chalk/png/kis_png_export.cc
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2005-2006 Cyrille Berger <cberger@cberger.net>
+ *
+ * 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 "kis_png_export.h"
+
+#include <tqcheckbox.h>
+#include <tqslider.h>
+
+#include <kapplication.h>
+#include <kdialogbase.h>
+#include <kgenericfactory.h>
+
+#include <KoFilterChain.h>
+
+#include <kis_colorspace.h>
+#include <kis_doc.h>
+#include <kis_image.h>
+#include <kis_iterators_pixel.h>
+#include <kis_paint_layer.h>
+#include <kis_progress_display_interface.h>
+
+#include "kis_png_converter.h"
+#include "kis_wdg_options_png.h"
+
+typedef KGenericFactory<KisPNGExport, KoFilter> KisPNGExportFactory;
+K_EXPORT_COMPONENT_FACTORY(libchalkpngexport, KisPNGExportFactory("kofficefilters"))
+
+KisPNGExport::KisPNGExport(KoFilter *, const char *, const TQStringList&) : KoFilter()
+{
+}
+
+KisPNGExport::~KisPNGExport()
+{
+}
+
+KoFilter::ConversiontqStatus KisPNGExport::convert(const TQCString& from, const TQCString& to)
+{
+ kdDebug(41008) << "Png export! From: " << from << ", To: " << to << "\n";
+
+ KisDoc *output = dynamic_cast<KisDoc*>(m_chain->inputDocument());
+ TQString filename = m_chain->outputFile();
+
+ if (!output)
+ return KoFilter::CreationError;
+
+
+ if (filename.isEmpty()) return KoFilter::FileNotFound;
+
+ if (from != "application/x-chalk")
+ return KoFilter::NotImplemented;
+
+
+ KDialogBase* kdb = new KDialogBase(0, "", false, i18n("PNG Export Options"), KDialogBase::Ok | KDialogBase::Cancel);
+
+ KisImageSP img = output->currentImage();
+ KisPaintDeviceSP pd = new KisPaintDevice(*img->projection());
+ KisPaintLayerSP l = new KisPaintLayer(img, "projection", OPACITY_OPAQUE, pd);
+
+ KisRectIteratorPixel it = l->paintDevice()->createRectIterator(0,0, img->width(), img->height(), false);
+ KisColorSpace* cs = l->paintDevice()->colorSpace();
+ bool isThereAlpha = false;
+ while( !it.isDone() )
+ {
+ if(cs->getAlpha( it.rawData() ) != 255)
+ {
+ isThereAlpha = true;
+ break;
+ }
+ ++it;
+ }
+
+ KisWdgOptionsPNG* wdg = new KisWdgOptionsPNG(kdb);
+ wdg->alpha->setChecked(isThereAlpha);
+ wdg->alpha->setEnabled(isThereAlpha);
+ kdb->setMainWidget(wdg);
+ kapp->restoreOverrideCursor();
+ if(kdb->exec() == TQDialog::Rejected)
+ {
+ return KoFilter::OK; // FIXME Cancel doesn't exist :(
+ }
+
+ bool alpha = wdg->alpha->isChecked();
+ bool interlace = wdg->interlacing->isChecked();
+ int compression = wdg->compressionLevel->value();
+
+ delete kdb;
+
+
+ KURL url;
+ url.setPath(filename);
+
+ KisPNGConverter kpc(output, output->undoAdapter());
+
+ vKisAnnotationSP_it beginIt = img->beginAnnotations();
+ vKisAnnotationSP_it endIt = img->endAnnotations();
+ KisImageBuilder_Result res;
+
+
+ if ( (res = kpc.buildFile(url, l, beginIt, endIt, compression, interlace, alpha)) == KisImageBuilder_RESULT_OK) {
+ kdDebug(41008) << "success !" << endl;
+ return KoFilter::OK;
+ }
+ kdDebug(41008) << " Result = " << res << endl;
+ return KoFilter::InternalError;
+}
+
+#include <kis_png_export.moc>
+
diff --git a/filters/chalk/png/kis_png_export.h b/filters/chalk/png/kis_png_export.h
new file mode 100644
index 00000000..d962523d
--- /dev/null
+++ b/filters/chalk/png/kis_png_export.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
+ *
+ * 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_PNG_EXPORT_H_
+#define _KIS_PNG_EXPORT_H_
+
+#include <KoFilter.h>
+
+class KisPNGExport : public KoFilter {
+ Q_OBJECT
+ TQ_OBJECT
+ public:
+ KisPNGExport(KoFilter *tqparent, const char *name, const TQStringList&);
+ virtual ~KisPNGExport();
+ public:
+ virtual KoFilter::ConversiontqStatus convert(const TQCString& from, const TQCString& to);
+};
+
+#endif
diff --git a/filters/chalk/png/kis_png_import.cc b/filters/chalk/png/kis_png_import.cc
new file mode 100644
index 00000000..ccfe4388
--- /dev/null
+++ b/filters/chalk/png/kis_png_import.cc
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
+ *
+ * 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 "kis_png_import.h"
+
+#include <kgenericfactory.h>
+
+#include <KoFilterChain.h>
+
+#include <kis_doc.h>
+#include <kis_image.h>
+#include <kis_progress_display_interface.h>
+#include <kis_view.h>
+
+#include "kis_png_converter.h"
+
+typedef KGenericFactory<KisPNGImport, KoFilter> PNGImportFactory;
+K_EXPORT_COMPONENT_FACTORY(libchalkpngimport, PNGImportFactory("kofficefilters"))
+
+KisPNGImport::KisPNGImport(KoFilter *, const char *, const TQStringList&) : KoFilter()
+{
+}
+
+KisPNGImport::~KisPNGImport()
+{
+}
+
+KoFilter::ConversiontqStatus KisPNGImport::convert(const TQCString&, const TQCString& to)
+{
+ kdDebug(41008) << "Importing using PNGImport!\n";
+
+ if (to != "application/x-chalk")
+ return KoFilter::BadMimeType;
+
+ KisDoc * doc = dynamic_cast<KisDoc*>(m_chain -> outputDocument());
+ KisView * view = static_cast<KisView*>(doc -> views().getFirst());
+
+ TQString filename = m_chain -> inputFile();
+
+ if (!doc)
+ return KoFilter::CreationError;
+
+ doc -> prepareForImport();
+
+
+ if (!filename.isEmpty()) {
+
+ KURL url;
+ url.setPath(filename);
+
+ if (url.isEmpty())
+ return KoFilter::FileNotFound;
+
+ KisPNGConverter ib(doc, doc -> undoAdapter());
+
+ if (view != 0)
+ view -> canvasSubject() -> progressDisplay() -> setSubject(&ib, false, true);
+
+ switch (ib.buildImage(url)) {
+ case KisImageBuilder_RESULT_UNSUPPORTED:
+ return KoFilter::NotImplemented;
+ break;
+ case KisImageBuilder_RESULT_INVALID_ARG:
+ return KoFilter::BadMimeType;
+ break;
+ case KisImageBuilder_RESULT_NO_URI:
+ case KisImageBuilder_RESULT_NOT_LOCAL:
+ return KoFilter::FileNotFound;
+ break;
+ case KisImageBuilder_RESULT_BAD_FETCH:
+ case KisImageBuilder_RESULT_EMPTY:
+ return KoFilter::ParsingError;
+ break;
+ case KisImageBuilder_RESULT_FAILURE:
+ return KoFilter::InternalError;
+ break;
+ case KisImageBuilder_RESULT_OK:
+ doc -> setCurrentImage( ib.image());
+ return KoFilter::OK;
+ default:
+ break;
+ }
+
+ }
+ return KoFilter::StorageCreationError;
+}
+
+#include <kis_png_import.moc>
+
diff --git a/filters/chalk/png/kis_png_import.h b/filters/chalk/png/kis_png_import.h
new file mode 100644
index 00000000..d0b8502a
--- /dev/null
+++ b/filters/chalk/png/kis_png_import.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
+ *
+ * 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_PNG_IMPORT_H_
+#define _KIS_PNG_IMPORT_H_
+
+#include <KoFilter.h>
+
+class KisPNGImport : public KoFilter {
+ Q_OBJECT
+ TQ_OBJECT
+ public:
+ KisPNGImport(KoFilter *tqparent, const char *name, const TQStringList&);
+ virtual ~KisPNGImport();
+ public:
+ virtual KoFilter::ConversiontqStatus convert(const TQCString& from, const TQCString& to);
+};
+
+#endif
diff --git a/filters/chalk/png/kis_wdg_options_png.ui b/filters/chalk/png/kis_wdg_options_png.ui
new file mode 100644
index 00000000..405db2fe
--- /dev/null
+++ b/filters/chalk/png/kis_wdg_options_png.ui
@@ -0,0 +1,183 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>KisWdgOptionsPNG</class>
+<widget class="TQWidget">
+ <property name="name">
+ <cstring>KisWdgOptionsPNG</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>286</width>
+ <height>106</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string>Options of Your PNG</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <widget class="TQLayoutWidget" row="0" column="0">
+ <property name="name">
+ <cstring>tqlayout6</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="TQLabel">
+ <property name="name">
+ <cstring>textLabel1</cstring>
+ </property>
+ <property name="text">
+ <string>Compress:</string>
+ </property>
+ <property name="tqalignment">
+ <set>AlignTop</set>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Note: the compression level does not change the quality of the result</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>&lt;p&gt;Adjust the compression time. Better compression takes longer.
+&lt;br&gt;Note: the compression level does not change the quality of the result.&lt;/p&gt;</string>
+ </property>
+ </widget>
+ <widget class="TQLayoutWidget">
+ <property name="name">
+ <cstring>tqlayout5</cstring>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="TQSlider">
+ <property name="name">
+ <cstring>compressionLevel</cstring>
+ </property>
+ <property name="minValue">
+ <number>1</number>
+ </property>
+ <property name="maxValue">
+ <number>9</number>
+ </property>
+ <property name="pageStep">
+ <number>1</number>
+ </property>
+ <property name="value">
+ <number>9</number>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="tickmarks">
+ <enum>Below</enum>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Note: the compression level doesn't change the quality of the result</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>&lt;p&gt;Adjust the compression time. Better compression takes longer.
+&lt;br&gt;Note: the compression level doesn't change the quality of the result.&lt;/p&gt;</string>
+ </property>
+ </widget>
+ <widget class="TQLayoutWidget">
+ <property name="name">
+ <cstring>tqlayout4</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="TQLabel">
+ <property name="name">
+ <cstring>textLabel3</cstring>
+ </property>
+ <property name="text">
+ <string>Fast</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>&lt;p&gt;Adjust the compression time. Better compression takes longer.
+&lt;br&gt;Note: the compression level doesn't change the quality of the result.&lt;/p&gt;</string>
+ </property>
+ </widget>
+ <widget class="TQLabel">
+ <property name="name">
+ <cstring>textLabel4</cstring>
+ </property>
+ <property name="text">
+ <string>Small</string>
+ </property>
+ <property name="tqalignment">
+ <set>AlignVCenter|AlignRight</set>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>&lt;p&gt;Adjust the compression time. Better compression takes longer.
+&lt;br&gt;Note: the compression level doesn't change the quality of the result.&lt;/p&gt;</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </vbox>
+ </widget>
+ </hbox>
+ </widget>
+ <spacer row="3" column="0">
+ <property name="name">
+ <cstring>spacer1</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="tqsizeHint">
+ <size>
+ <width>20</width>
+ <height>5</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="TQCheckBox" row="1" column="0">
+ <property name="name">
+ <cstring>interlacing</cstring>
+ </property>
+ <property name="text">
+ <string>Interlacing</string>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Use interlacing when publishing on the Internet</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>&lt;p&gt;Interlacing is useful if you intend to publish your image on the Internet.&lt;br&gt;
+Enabling interlacing will cause the image to be displayed by the browser even while downloading.&lt;/p&gt;</string>
+ </property>
+ </widget>
+ <widget class="TQCheckBox" row="2" column="0">
+ <property name="name">
+ <cstring>alpha</cstring>
+ </property>
+ <property name="text">
+ <string>Store alpha channel (transparency)</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Disable to get smaller files if your image has no transparency</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>&lt;p&gt;The Portable Network Graphics (PNG) file format allows transparency in your image to be stored by saving an alpha channel.
+You can uncheck the box if you are not using transparency and you want to make the resulting file smaller .&lt;br&gt;Always saving the alpha channel is recommended.&lt;/p&gt;</string>
+ </property>
+ </widget>
+ </grid>
+</widget>
+<tqlayoutdefaults spacing="6" margin="11"/>
+</UI>