diff options
Diffstat (limited to 'tdefile-plugins')
128 files changed, 13377 insertions, 0 deletions
diff --git a/tdefile-plugins/CMakeLists.txt b/tdefile-plugins/CMakeLists.txt new file mode 100644 index 00000000..238bc4b2 --- /dev/null +++ b/tdefile-plugins/CMakeLists.txt @@ -0,0 +1,31 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +add_subdirectory( dependencies ) +add_subdirectory( dvi ) +add_subdirectory( png ) +add_subdirectory( ps ) +add_subdirectory( jpeg ) +add_subdirectory( xbm ) +add_subdirectory( xpm ) +add_subdirectory( bmp ) +add_subdirectory( tga ) +add_subdirectory( rgb ) +add_subdirectory( ico ) +add_subdirectory( pcx ) +add_subdirectory( pnm ) +add_subdirectory( dds ) +add_subdirectory( gif ) +add_subdirectory( raw ) + +tde_conditional_add_subdirectory( WITH_TIFF tiff ) +tde_conditional_add_subdirectory( WITH_OPENEXR exr ) +tde_conditional_add_subdirectory( WITH_PDF pdf ) diff --git a/tdefile-plugins/Makefile.am b/tdefile-plugins/Makefile.am new file mode 100644 index 00000000..bc15008f --- /dev/null +++ b/tdefile-plugins/Makefile.am @@ -0,0 +1,14 @@ +if include_EXR_MODULES +KFILE_EXR_SUBDIR=exr +endif + +if include_TIFF +KFILE_TIFF_SUBDIR=tiff +endif + +if include_PDF +KFILE_PDF_SUBDIR=pdf +endif + +SUBDIRS=dependencies dvi png ps jpeg xbm xpm bmp tga rgb ico pcx $(KFILE_TIFF_SUBDIR) pnm \ + $(KFILE_EXR_SUBDIR) $(KFILE_PDF_SUBDIR) dds gif raw diff --git a/tdefile-plugins/RETURNED_ITEMS b/tdefile-plugins/RETURNED_ITEMS new file mode 100644 index 00000000..70a3b519 --- /dev/null +++ b/tdefile-plugins/RETURNED_ITEMS @@ -0,0 +1,245 @@ +If you make a new plugin, please add the list of returned items to this list. + + +pdf plugin: +=========== + +Date Created +Date Modiified +Int Pages +Bool Encrypted +and everything else pdfinfo returns as string + + +png plugin: +=========== + +type key W/A details +------------------------------------------------------------------------ +Size Dimensions -/- +Int BitDepth -/- +String ColorMode -/- +String Compression -/- Compression type. Right now always "deflate" + +Other keys corresponding to the png comment keys are returned as non-editable +String. + +Common keys that are recommended in the png spec: +Title, Author, Description, Copyright, Creation Time, Software, Disclaimer, +Warning, Source, Comment + + +PostScript plugin: +================== + +String Title +String Creator +String CreationDate +String For +Int Pages + + + +Jpeg plugin: +============ +Note: number.number means precision of converted number + +type key Comment +----------------------------------------------------------------------------- +String Camera make +String Camera model +String Date/time +Size Dimensions Width x Height in pixels +int Qt::Orientation 1 - "The 0th row is at the visual top of the image, + and the 0th column is the visual left-hand side." + 2 - "The 0th row is at the visual top of the image, + and the 0th column is the visual right-hand side." + 3 - "The 0th row is at the visual bottom of the image, + and the 0th column is the visual right-hand side." + 4 - "The 0th row is at the visual bottom of the image, + and the 0th column is the visual left-hand side." + 5 - "The 0th row is the visual left-hand side of of the image, + and the 0th column is the visual top." + 6 - "The 0th row is the visual right-hand side of of the image, + and the 0th column is the visual top." + 7 - "The 0th row is the visual right-hand side of of the image, + and the 0th column is the visual bottom." + 8 - "The 0th row is the visual left-hand side of of the image, + and the 0th column is the visual bottom." +String ColorMode "Grayscale" "Color" +String Flash used "Yes" "No" +String Focal length 4.1 mm, 35mm equivalent +String Exposure time 6.3 (if < 0.5 also in 1/xx) sec +String Aperture "f/3.1" +String Focus dist. "Infinite" or 5.2 m +String CCD width 4.2 Postfix mm +String Exposure bias 4.2 +String Whitebalance 0 = unknown + 1 = Daylight + 2 = Fluorescent + 3 = Tungsten + 17 = Standard light A + 18 = Standard light B + 19 = Standard light C + 20 = D55 + 21 = D65 + 22 = D75 + 23 to 254 = reserved + 255 = other +String Metering mode 0 = unknown + 1 = Average + 2 = CenterWeightedAverage + 3 = Spot + 4 = MultiSpot + 5 = Pattern + 6 = Partial + 7 to 254 = reserved + 255 = other +String Exposure 0 = Not defined + 1 = Manual + 2 = Normal program + 3 = Aperture priority + 4 = Shutter priority + 5 = Creative program (biased toward depth of field) + 6 = Action program + (biased toward fast shutter speed) + 7 = Portrait mode + (for closeup photos with the background out of focus) + 8 = Landscape mode + (for landscape photos with the background in focus) + 9 to 255 = reserved +String ISO equiv. 2digits ??? +String JPG quality 1 - "basic" + 2 - "normal" + 4 - "fine" + default: unknown +String User comment +String Comment +QImage Thumbnail + + +gif plugin: +=========== + +type key Comment +----------------------------------------------------------------------------- +Size Dimensions Width x Height in pixels. +String Comment gif comment blocks, which we permit to be utf-8 encoded + in clear violation/extension of the specification which + calls for 7 bit ASCII. See: + http://www.geocities.co.jp/SiliconValley/3453/gif_info/index_en.html + + +TIFF plugin: +=========== + +:: Group: General :: + +type key Comment +------ -------------- ----------------------------------------------------- +String ColorMode Color Mode (Monochrome, RGB, RGBA etc) +Size Dimensions Width & height as a QSize object +Size Resolution x & y resolution in dpi as a QSize object +Int BitDepth No. of bits per pixel (e.g. 24 for 8-bit RGB) +String Compression Compression used (None, Deflate, LZW, JPEG etc.) +Int FaxPages No. of pages if this is fax +String Software Software used to produce this image +String Description Image description +String Copyright Copyright information +String DateTime Date and time of image creation +String Artist Name of the person who created this image + +:: Group: Scanner :: + +type key Comment +------ -------------- ----------------------------------------------------- +String Make Make of the scanner used +String Model Model of the scanner used + + + + + +xbm plugin: +=========== + +type key W/A details +------------------------------------------------------------------------ +QSize Dimensions -/- Dimensions in pixels + +xpm plugin: +=========== + +type key W/A details +------------------------------------------------------------------------ +QSize Dimensions -/- Dimensions in pixels +Int BitDepth -/- Bits per pixel + + +bmp plugin: +=========== + +type key W/A details +------------------------------------------------------------------------ +String Type -/- Bitmap type (Windows / OS/2) +QSize Dimensions -/- Dimensions in pixels +Int BitDepth -/- Bits per pixel +String Compression -/- Compression type + + +tga plugin: +=========== + +type key W/A details +------------------------------------------------------------------------ +QSize Dimensions -/- Dimensions in pixels +Int BitDepth -/- Bits per pixel +String ColorMode -/- Color mode (e.g. RGB) +String Compression -/- Compression type, if any + + +ico plugin: +=========== + +type key W/A details +------------------------------------------------------------------------ +Int Number -/- Number of icons in file +QSize Dimensions -/- Dimensions +QSize DimensionsM -/- Dimensions [of 1st icon] +Int Colors -/- Number of colors [in 1st icon] + +pcx plugin: +=========== + +type key W/A details +------------------------------------------------------------------------ +QSize Dimensions -/- Dimensions in pixels +Int BitDepth -/- Bits per pixel +QSize Resolution -/- Resolution in DPI +String Compression -/- Compression type, if any + + +rgb plugin: +=========== + +type key details +------------------------------------------------------------------------ +String ImageName Image name (or comment) +QSize Dimensions Dimensions in pixels +Int BitDepth Bits per pixel +String ColorMode Color Mode (Monochrome, RGB, RGBA etc) +String Compression Compression type +String SharedRows Percentage of shared rows + (amount of "aggression" -> see GIMP) +dds plugin: +=========== + +type key details +------------------------------------------------------------------------ +QSize Dimensions Dimensions in pixels +Int Depth Depth in pixels +Int BitDepth Bits per pixel +String ColorMode Color Mode (RGB, RGBA) +String Type 2D, volume or cube map +String Compression Compression type + diff --git a/tdefile-plugins/bmp/CMakeLists.txt b/tdefile-plugins/bmp/CMakeLists.txt new file mode 100644 index 00000000..1bc54e24 --- /dev/null +++ b/tdefile-plugins/bmp/CMakeLists.txt @@ -0,0 +1,34 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + +#### other data ################################# + +install( FILES tdefile_bmp.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_bmp (module) ######################### + +tde_add_kpart( tdefile_bmp AUTOMOC + SOURCES tdefile_bmp.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/bmp/Makefile.am b/tdefile-plugins/bmp/Makefile.am new file mode 100644 index 00000000..f8f70112 --- /dev/null +++ b/tdefile-plugins/bmp/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for bmp file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_bmp.h + +kde_module_LTLIBRARIES = tdefile_bmp.la + +tdefile_bmp_la_SOURCES = tdefile_bmp.cpp +tdefile_bmp_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_bmp_la_LIBADD = $(LIB_KSYCOCA) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) tdefile_bmp.cpp -o $(podir)/tdefile_bmp.pot + +services_DATA = tdefile_bmp.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/bmp/tdefile_bmp.cpp b/tdefile-plugins/bmp/tdefile_bmp.cpp new file mode 100644 index 00000000..354ea54e --- /dev/null +++ b/tdefile-plugins/bmp/tdefile_bmp.cpp @@ -0,0 +1,174 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Shane Wright <me@shanewright.co.uk> + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include <config.h> +#include "tdefile_bmp.h" + +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kstringvalidator.h> +#include <kdebug.h> + +#include <tqdict.h> +#include <tqvalidator.h> +#include <tqcstring.h> +#include <tqfile.h> +#include <tqdatetime.h> + +#if !defined(__osf__) +#include <inttypes.h> +#else +typedef unsigned long uint32_t; +typedef unsigned short uint16_t; +#endif + +typedef KGenericFactory<KBmpPlugin> BmpFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_bmp, BmpFactory( "tdefile_bmp" )) + +KBmpPlugin::KBmpPlugin(TQObject *parent, const char *name, + const TQStringList &args) + + : KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( "image/x-bmp" ); + + KFileMimeTypeInfo::GroupInfo* group = 0L; + + group = addGroupInfo(info, "Technical", i18n("Technical Details")); + + KFileMimeTypeInfo::ItemInfo* item; + + item = addItemInfo(group, "Type", i18n("Type"), TQVariant::String); + + item = addItemInfo(group, "Dimensions", i18n("Dimensions"), TQVariant::Size); + setHint( item, KFileMimeTypeInfo::Size ); + setUnit(item, KFileMimeTypeInfo::Pixels); + + item = addItemInfo(group, "BitDepth", i18n("Bit Depth"), TQVariant::Int); + setUnit(item, KFileMimeTypeInfo::BitsPerPixel); + + item = addItemInfo(group, "Compression", i18n("Compression"), TQVariant::String); + +} + + +bool KBmpPlugin::readInfo( KFileMetaInfo& info, uint what) +{ + const char * bmptype_bm = "BM"; + const char * bmptype_ba = "BA"; + const char * bmptype_ci = "CI"; + const char * bmptype_cp = "CP"; + const char * bmptype_ic = "IC"; + const char * bmptype_pt = "PT"; + + TQFile file(info.path()); + + if (!file.open(IO_ReadOnly)) + { + kdDebug(7034) << "Couldn't open " << TQFile::encodeName(info.path()).data() << endl; + return false; + } + + TQDataStream dstream(&file); + + // BMP files are little-endian + dstream.setByteOrder(TQDataStream::LittleEndian); + + // create this now because we output image type early on + KFileMetaInfoGroup group = appendGroup(info, "Technical"); + + + // read the beginning of the file and make sure it looks ok + unsigned char * bmp_id = (unsigned char *) malloc(2); + file.readBlock((char *) bmp_id, 2); + + if (memcmp(bmp_id, bmptype_bm, 2) == 0) { + appendItem(group, "Type", i18n("Windows Bitmap")); + } else if (memcmp(bmp_id, bmptype_ba, 2) == 0) { + appendItem(group, "Type", i18n("OS/2 Bitmap Array")); + } else if (memcmp(bmp_id, bmptype_ci, 2) == 0) { + appendItem(group, "Type", i18n("OS/2 Color Icon")); + } else if (memcmp(bmp_id, bmptype_cp, 2) == 0) { + appendItem(group, "Type", i18n("OS/2 Color Pointer")); + } else if (memcmp(bmp_id, bmptype_ic, 2) == 0) { + appendItem(group, "Type", i18n("OS/2 Icon")); + } else if (memcmp(bmp_id, bmptype_pt, 2) == 0) { + appendItem(group, "Type", i18n("OS/2 Pointer")); + } else { + return false; + } + + free(bmp_id); + + + // read the next bits, we ignore them, but anyways... + uint32_t bmp_size; + uint16_t bmp_reserved1; + uint16_t bmp_reserved2; + uint32_t bmp_offbits; + + dstream >> bmp_size; + dstream >> bmp_reserved1; + dstream >> bmp_reserved2; + dstream >> bmp_offbits; + + + // we should now be at the file info structure + uint32_t bmpi_size; + uint32_t bmpi_width; + uint32_t bmpi_height; + uint16_t bmpi_planes; + uint16_t bmpi_bitcount; + uint32_t bmpi_compression; + + dstream >> bmpi_size; + dstream >> bmpi_width; + dstream >> bmpi_height; + dstream >> bmpi_planes; + dstream >> bmpi_bitcount; + dstream >> bmpi_compression; + + + // output the useful bits + appendItem(group, "Dimensions", TQSize(bmpi_width, bmpi_height)); + appendItem(group, "BitDepth", bmpi_bitcount); + + switch (bmpi_compression) { + case 0 : + appendItem(group, "Compression", i18n("None")); + break; + case 1 : + appendItem(group, "Compression", i18n("RLE 8bit/pixel")); + break; + case 2 : + appendItem(group, "Compression", i18n("RLE 4bit/pixel")); + break; + case 3 : + appendItem(group, "Compression", i18n("Bitfields")); + break; + default : + appendItem(group, "Compression", i18n("Unknown")); + } + + return true; +} + +#include "tdefile_bmp.moc" diff --git a/tdefile-plugins/bmp/tdefile_bmp.desktop b/tdefile-plugins/bmp/tdefile_bmp.desktop new file mode 100644 index 00000000..6331c397 --- /dev/null +++ b/tdefile-plugins/bmp/tdefile_bmp.desktop @@ -0,0 +1,66 @@ +[Desktop Entry] +Type=Service +Name=BMP Info +Name[af]=Bmp Inligting +Name[ar]=معلومات BMP +Name[br]=Titouroù BMP +Name[ca]=Informació de BMP +Name[cs]=BMP info +Name[cy]=Gwybodaeth BMP +Name[da]=BMP-info +Name[de]=BMP-Info +Name[el]=Πληροφορίες BMP +Name[eo]=BMP-informo +Name[es]=Info BMP +Name[et]=BMP info +Name[fa]=اطلاعات BMP +Name[fi]=BMP-tiedot +Name[fr]=Informations BMP +Name[ga]=Eolas faoi BMP +Name[gl]=Inf. BMP +Name[he]=מידע BMP +Name[hi]=BMP जानकारी +Name[hr]=BMP informacije +Name[hu]=BMP-jellemzők +Name[is]=BMP upplýsingar +Name[it]=Informazioni BMP +Name[ja]=BMP 情報 +Name[kk]=BMP мәліметі +Name[km]=ព័ត៌មាន BMP +Name[lt]=BMP informacija +Name[ms]=Maklumat BMP +Name[nds]=BMP-Info +Name[ne]=BMP सूचना +Name[nl]=BMP-info +Name[nn]=BMP-info +Name[nso]=Tshedimoso ya BMP +Name[pa]=BMP ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku BMP +Name[pt]=Informação do BMP +Name[pt_BR]=Informação sobre BMP +Name[ro]=Informaţii BMP +Name[ru]=Информация о BMP +Name[se]=BMP-dieđut +Name[sl]=Podatki o BMP +Name[sr]=BMP информације +Name[sr@Latn]=BMP informacije +Name[sv]=BMP-information +Name[ta]=BMP தகவல் +Name[tg]=Иттилоот оиди BMP +Name[th]=ข้อมูลแฟ้ม BMP +Name[tr]=BMP Bilgisi +Name[uk]=Інформація по BMP +Name[uz]=BMP haqida maʼlumot +Name[uz@cyrillic]=BMP ҳақида маълумот +Name[ven]=Mafhungo BMP +Name[wa]=Informåcion sol imådje BMP +Name[xh]=Ulwazi lwe BMP +Name[zh_CN]=BMP 信息 +Name[zh_HK]=BMP 資訊 +Name[zh_TW]=BMP 資訊 +Name[zu]=Ulwazi lwe-BMP +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_bmp +MimeType=image/x-bmp +PreferredGroups=Technical +PreferredItems=Type,Resolution,Bitdepth,Compression diff --git a/tdefile-plugins/bmp/tdefile_bmp.h b/tdefile-plugins/bmp/tdefile_bmp.h new file mode 100644 index 00000000..27bc31a6 --- /dev/null +++ b/tdefile-plugins/bmp/tdefile_bmp.h @@ -0,0 +1,38 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Shane Wright <me@shanewright.co.uk> + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_BMP_H__ +#define __KFILE_BMP_H__ + +#include <tdefilemetainfo.h> + +class TQStringList; + +class KBmpPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KBmpPlugin( TQObject *parent, const char *name, const TQStringList& args ); + + virtual bool readInfo( KFileMetaInfo& info, uint what); +}; + +#endif diff --git a/tdefile-plugins/configure.in.bot b/tdefile-plugins/configure.in.bot new file mode 100644 index 00000000..f03bc711 --- /dev/null +++ b/tdefile-plugins/configure.in.bot @@ -0,0 +1,32 @@ +if test -z "$LIBTIFF"; then + echo "" + echo "You're missing libtiff. The additional info plugin for TIFF images" + echo "files won't be compiled without libtiff." + echo "You can download it from http://www.libtiff.org" + echo "" + all_tests=bad +fi + +#if test -z "$POPPLER_LIBS"; then +# echo "" +# echo "You're missing poppler. The additional info plugin for PDF files" +# echo "files won't be compiled without poppler >= 0.3.1." +# echo "You can download poppler from http://poppler.freedesktop.org/" +# echo "" +#fi + +if test "$EXRSTATUS" = "no"; then + echo "" + echo "No OpenEXR Libraries were found" + echo "Install the OpenEXR package (from http://www.openexr.org)" + echo "if you want EXR image format support" + echo "" +fi + +if test "$EXRSTATUS" = "old"; then + echo "" + echo "OpenEXR libraries were found, but at least version 1.1.0 is required" + echo "Install a newer OpenEXR package (from http://www.openexr.org)" + echo "if you want EXR image format support" + echo "" +fi diff --git a/tdefile-plugins/dds/CMakeLists.txt b/tdefile-plugins/dds/CMakeLists.txt new file mode 100644 index 00000000..eb367982 --- /dev/null +++ b/tdefile-plugins/dds/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################## + +install( FILES tdefile_dds.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_dds (module) ########################## + +tde_add_kpart( tdefile_dds AUTOMOC + SOURCES tdefile_dds.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/dds/Makefile.am b/tdefile-plugins/dds/Makefile.am new file mode 100644 index 00000000..ce77c9c3 --- /dev/null +++ b/tdefile-plugins/dds/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for dds file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_dds.h + +kde_module_LTLIBRARIES = tdefile_dds.la + +tdefile_dds_la_SOURCES = tdefile_dds.cpp +tdefile_dds_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_dds_la_LIBADD = $(LIB_KSYCOCA) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) tdefile_dds.cpp -o $(podir)/tdefile_dds.pot + +services_DATA = tdefile_dds.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/dds/tdefile_dds.cpp b/tdefile-plugins/dds/tdefile_dds.cpp new file mode 100644 index 00000000..e49bf498 --- /dev/null +++ b/tdefile-plugins/dds/tdefile_dds.cpp @@ -0,0 +1,317 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Ignacio Casta�o <castano@ludicon.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include <config.h> +#include "tdefile_dds.h" + +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kstringvalidator.h> +#include <kdebug.h> + +#include <tqdict.h> +#include <tqvalidator.h> +#include <tqcstring.h> +#include <tqfile.h> +#include <tqdatetime.h> + + +typedef KGenericFactory<KDdsPlugin> DdsFactory; + +typedef TQ_UINT32 uint; +typedef TQ_UINT16 ushort; +typedef TQ_UINT8 uchar; + +namespace { // Private. + +#if !defined(MAKEFOURCC) +# define MAKEFOURCC(ch0, ch1, ch2, ch3) \ + (uint(uchar(ch0)) | (uint(uchar(ch1)) << 8) | \ + (uint(uchar(ch2)) << 16) | (uint(uchar(ch3)) << 24 )) +#endif + + static const uint FOURCC_DDS = MAKEFOURCC('D', 'D', 'S', ' '); + static const uint FOURCC_DXT1 = MAKEFOURCC('D', 'X', 'T', '1'); + static const uint FOURCC_DXT2 = MAKEFOURCC('D', 'X', 'T', '2'); + static const uint FOURCC_DXT3 = MAKEFOURCC('D', 'X', 'T', '3'); + static const uint FOURCC_DXT4 = MAKEFOURCC('D', 'X', 'T', '4'); + static const uint FOURCC_DXT5 = MAKEFOURCC('D', 'X', 'T', '5'); + static const uint FOURCC_RXGB = MAKEFOURCC('R', 'X', 'G', 'B'); + + static const uint DDSD_CAPS = 0x00000001l; + static const uint DDSD_PIXELFORMAT = 0x00001000l; + static const uint DDSD_WIDTH = 0x00000004l; + static const uint DDSD_HEIGHT = 0x00000002l; + static const uint DDSD_PITCH = 0x00000008l; + + static const uint DDSCAPS_TEXTURE = 0x00001000l; + static const uint DDSCAPS2_VOLUME = 0x00200000l; + static const uint DDSCAPS2_CUBEMAP = 0x00000200l; + + static const uint DDPF_RGB = 0x00000040l; + static const uint DDPF_FOURCC = 0x00000004l; + static const uint DDPF_ALPHAPIXELS = 0x00000001l; + + enum DDSType { + DDS_A8R8G8B8 = 0, + DDS_A1R5G5B5 = 1, + DDS_A4R4G4B4 = 2, + DDS_R8G8B8 = 3, + DDS_R5G6B5 = 4, + DDS_DXT1 = 5, + DDS_DXT2 = 6, + DDS_DXT3 = 7, + DDS_DXT4 = 8, + DDS_DXT5 = 9, + DDS_RXGB = 10, + DDS_UNKNOWN + }; + + + struct DDSPixelFormat { + uint size; + uint flags; + uint fourcc; + uint bitcount; + uint rmask; + uint gmask; + uint bmask; + uint amask; + }; + + TQDataStream & operator>> ( TQDataStream & s, DDSPixelFormat & pf ) + { + s >> pf.size; + s >> pf.flags; + s >> pf.fourcc; + s >> pf.bitcount; + s >> pf.rmask; + s >> pf.gmask; + s >> pf.bmask; + s >> pf.amask; + return s; + } + + struct DDSCaps { + uint caps1; + uint caps2; + uint caps3; + uint caps4; + }; + + TQDataStream & operator>> ( TQDataStream & s, DDSCaps & caps ) + { + s >> caps.caps1; + s >> caps.caps2; + s >> caps.caps3; + s >> caps.caps4; + return s; + } + + struct DDSHeader { + uint size; + uint flags; + uint height; + uint width; + uint pitch; + uint depth; + uint mipmapcount; + uint reserved[11]; + DDSPixelFormat pf; + DDSCaps caps; + uint notused; + }; + + TQDataStream & operator>> ( TQDataStream & s, DDSHeader & header ) + { + s >> header.size; + s >> header.flags; + s >> header.height; + s >> header.width; + s >> header.pitch; + s >> header.depth; + s >> header.mipmapcount; + for( int i = 0; i < 11; i++ ) { + s >> header.reserved[i]; + } + s >> header.pf; + s >> header.caps; + s >> header.notused; + return s; + } + + static bool IsValid( const DDSHeader & header ) + { + if( header.size != 124 ) { + return false; + } + const uint required = (DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS|DDSD_PIXELFORMAT); + if( (header.flags & required) != required ) { + return false; + } + if( header.pf.size != 32 ) { + return false; + } + if( !(header.caps.caps1 & DDSCAPS_TEXTURE) ) { + return false; + } + return true; + } + +} // namespace + + + +K_EXPORT_COMPONENT_FACTORY(tdefile_dds, DdsFactory( "tdefile_dds" )) + +// Constructor, init mime type info. +KDdsPlugin::KDdsPlugin(TQObject *parent, const char *name, const TQStringList &args) : + KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo * info = addMimeTypeInfo( "image/x-dds" ); + + KFileMimeTypeInfo::GroupInfo * group = 0L; + + group = addGroupInfo(info, "Technical", i18n("Technical Details")); + + KFileMimeTypeInfo::ItemInfo * item; + + item = addItemInfo(group, "Dimensions", i18n("Dimensions"), TQVariant::Size); + setHint(item, KFileMimeTypeInfo::Size); + setUnit(item, KFileMimeTypeInfo::Pixels); + + item = addItemInfo(group, "Depth", i18n("Depth"), TQVariant::Int); + setUnit(item, KFileMimeTypeInfo::Pixels); + + item = addItemInfo(group, "BitDepth", i18n("Bit Depth"), TQVariant::Int); + setUnit(item, KFileMimeTypeInfo::BitsPerPixel); + + addItemInfo(group, "MipmapCount", i18n("Mipmap Count"), TQVariant::Int); + + addItemInfo(group, "Type", i18n("Type"), TQVariant::String); + addItemInfo(group, "ColorMode", i18n("Color Mode"), TQVariant::String); + addItemInfo(group, "Compression", i18n("Compression"), TQVariant::String); +} + +// Read mime type info. +bool KDdsPlugin::readInfo( KFileMetaInfo& info, uint /*what*/) +{ + TQFile file(info.path()); + + if (!file.open(IO_ReadOnly)) { + kdDebug(7034) << "Couldn't open " << TQFile::encodeName(info.path()).data() << endl; + return false; + } + + TQDataStream s(&file); + s.setByteOrder(TQDataStream::LittleEndian); + + // Validate header. + uint fourcc; + s >> fourcc; + if( fourcc != FOURCC_DDS ) { + kdDebug(7034) << TQFile::encodeName(info.path()).data() << " is not a DDS file." << endl; + return false; + } + + // Read image header. + DDSHeader header; + s >> header; + + // Check image file format. + if( s.atEnd() || !IsValid( header ) ) { + kdDebug(7034) << TQFile::encodeName(info.path()).data() << " is not a valid DDS file." << endl; + return false; + } + + // Set file info. + KFileMetaInfoGroup group = appendGroup(info, "Technical"); + appendItem(group, "Dimensions", TQSize(header.width, header.height)); + appendItem(group, "MipmapCount", header.mipmapcount); + + // Set file type. + if( header.caps.caps2 & DDSCAPS2_CUBEMAP ) { + appendItem(group, "Type", i18n("Cube Map Texture")); + } + else if( header.caps.caps2 & DDSCAPS2_VOLUME ) { + appendItem(group, "Type", i18n("Volume Texture")); + appendItem(group, "Depth", header.depth); + } + else { + appendItem(group, "Type", i18n("2D Texture")); + } + + // Set file color depth and compression. + if( header.pf.flags & DDPF_RGB ) { + appendItem(group, "BitDepth", header.pf.bitcount); + appendItem(group, "Compression", i18n("Uncompressed")); + if( header.pf.flags & DDPF_ALPHAPIXELS ) { + appendItem(group, "ColorMode", "RGB/Alpha"); + } + else { + appendItem(group, "ColorMode", "RGB"); + } + } + else if( header.pf.flags & DDPF_FOURCC ) { + switch( header.pf.fourcc ) { + case FOURCC_DXT1: + appendItem(group, "BitDepth", 4); + appendItem(group, "Compression", "DXT1"); + appendItem(group, "ColorMode", "RGB"); + break; + case FOURCC_DXT2: + appendItem(group, "BitDepth", 16); + appendItem(group, "Compression", "DXT2"); + appendItem(group, "ColorMode", "RGB/Alpha"); + break; + case FOURCC_DXT3: + appendItem(group, "BitDepth", 16); + appendItem(group, "Compression", "DXT3"); + appendItem(group, "ColorMode", "RGB/Alpha"); + break; + case FOURCC_DXT4: + appendItem(group, "BitDepth", 16); + appendItem(group, "Compression", "DXT4"); + appendItem(group, "ColorMode", "RGB/Alpha"); + break; + case FOURCC_DXT5: + appendItem(group, "BitDepth", 16); + appendItem(group, "Compression", "DXT5"); + appendItem(group, "ColorMode", "RGB/Alpha"); + break; + case FOURCC_RXGB: + appendItem(group, "BitDepth", 16); + appendItem(group, "Compression", "RXGB"); + appendItem(group, "ColorMode", "RGB"); + break; + default: + appendItem(group, "Compression", "Unknown"); + break; + } + } + else { + appendItem(group, "Compression", "Unknown"); + } + + return true; +} + +#include "tdefile_dds.moc" + diff --git a/tdefile-plugins/dds/tdefile_dds.desktop b/tdefile-plugins/dds/tdefile_dds.desktop new file mode 100644 index 00000000..c98f0181 --- /dev/null +++ b/tdefile-plugins/dds/tdefile_dds.desktop @@ -0,0 +1,53 @@ +[Desktop Entry] +Type=Service +Name=DirectDraw Surface Info +Name[ca]=Informació de superfície DirectDraw +Name[cs]=DirectDraw Surface info +Name[da]=DirectDraw overflade-info +Name[de]=DirectDraw Oberflächeninfo +Name[el]=Πληροφορίες επιφάνειας DirectDraw +Name[eo]=DirectDraw surfac-informo +Name[es]=Información de la primera vista de DirectDraw +Name[et]=DirectDraw Surface'i info +Name[eu]=DirectDraw Surface informazioa +Name[fa]=اطلاعات سطح DirectDraw +Name[fi]=DirectDraw pintatieto +Name[fr]=Informations de surface DirectDraw +Name[ga]=Eolas faoi DirectDraw Surface +Name[gl]=Información de Superficie de DirectDraw +Name[he]=מיגע אודות משטח DirectDraw +Name[hu]=DirectDraw felületinformáció +Name[is]=DirectDraw yfirborðs upplýsingar +Name[it]=Informazioni superficie DirectDraw +Name[ja]=DDS (DirectDraw Surface) 情報 +Name[kk]=DirectDraw бедерінің мәлметі +Name[km]=ព័ត៌មានផ្ទៃខាងក្រៅអំពី DirectDraw +Name[lt]=DirectDraw Surface informacija +Name[ms]=Maklumat Permukaan LukisTerus +Name[nb]=DirectDraw Overflate info +Name[nds]="DirectDraw"-Böversietinfo +Name[ne]=प्रत्यक्ष रेखाचित्र सतह सूचना +Name[nl]=DirectDraw Surface-info +Name[nn]=DirectDraw-overflateinfo +Name[pl]=Informacja o powierzchni DirectDraw +Name[pt]=Informação de Superfície DirectDraw +Name[pt_BR]=Informações Sobre Superfícies Direct Draw +Name[ro]=Informaţii Suprafaţă DirectDraw +Name[ru]=Сведения о поверхности DirectDraw +Name[sk]=DirectDraw informácie o povrchu +Name[sl]=Podatki o površini DirectDraw +Name[sr]=Информације о DirectDraw површини +Name[sr@Latn]=Informacije o DirectDraw površini +Name[sv]=Directdraw ytinformation +Name[ta]=நேரடி மேற்பரப்பு தகவல் +Name[th]=ข้อมูลแฟ้มพื้นผิว DirectDraw +Name[tr]=DirectDraw Yüzey Bilgisi +Name[uk]=Інформація про поверхню DirectDraw +Name[zh_CN]=DirectDraw 表面信息 +Name[zh_HK]=DirectDraw 表面資訊 +Name[zh_TW]=DirectDraw Surface 資訊 +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_dds +MimeType=image/x-dds +PreferredGroups=Technical +PreferredItems=Dimensions,Depth,BitDepth,Type,ColorMode,Compression diff --git a/tdefile-plugins/dds/tdefile_dds.h b/tdefile-plugins/dds/tdefile_dds.h new file mode 100644 index 00000000..464ed6fd --- /dev/null +++ b/tdefile-plugins/dds/tdefile_dds.h @@ -0,0 +1,38 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Ignacio Castao <castano@ludicon.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_DDS_H__ +#define __KFILE_DDS_H__ + +#include <tdefilemetainfo.h> + +class TQStringList; + +class KDdsPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KDdsPlugin( TQObject *parent, const char *name, const TQStringList& args ); + + virtual bool readInfo( KFileMetaInfo& info, uint what); +}; + +#endif diff --git a/tdefile-plugins/dependencies/CMakeLists.txt b/tdefile-plugins/dependencies/CMakeLists.txt new file mode 100644 index 00000000..a4b1da2c --- /dev/null +++ b/tdefile-plugins/dependencies/CMakeLists.txt @@ -0,0 +1,14 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +if( WITH_PDF ) + add_subdirectory( poppler-tqt ) +endif ( ) diff --git a/tdefile-plugins/dependencies/Makefile.am b/tdefile-plugins/dependencies/Makefile.am new file mode 100644 index 00000000..1c8d5d88 --- /dev/null +++ b/tdefile-plugins/dependencies/Makefile.am @@ -0,0 +1 @@ +SUBDIRS=poppler-tqt diff --git a/tdefile-plugins/dependencies/poppler-tqt/CMakeLists.txt b/tdefile-plugins/dependencies/poppler-tqt/CMakeLists.txt new file mode 100644 index 00000000..26e87e1c --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/CMakeLists.txt @@ -0,0 +1,54 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +project( libpoppler-tqt ) + +##### configure checks ########################## + +include( ConfigureChecks.cmake ) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/tdefile-plugins/dependencies/poppler-tqt + ${POPPLER_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + +##### pc files ################################## + +configure_file( poppler-tqt.pc.cmake poppler-tqt.pc @ONLY ) + +install( FILES ${CMAKE_CURRENT_BINARY_DIR}/poppler-tqt.pc DESTINATION ${PKGCONFIG_INSTALL_DIR} ) + +##### headers ################################### + +install( FILES + poppler-qt.h poppler-page-transition.h poppler-link-qt3.h + DESTINATION ${INCLUDE_INSTALL_DIR} ) + +##### poppler-tqt (shared) ############################ + +tde_add_library( poppler-tqt SHARED AUTOMOC + SOURCES + poppler-document.cc poppler-fontinfo.cc + poppler-link.cc poppler-page.cc + poppler-page-transition.cc poppler-page-transition-private.h + poppler-private.cc poppler-private.h + VERSION 0.0.0 + LINK poppler ${TQT_LIBRARIES} + DESTINATION ${LIB_INSTALL_DIR} +) diff --git a/tdefile-plugins/dependencies/poppler-tqt/ConfigureChecks.cmake b/tdefile-plugins/dependencies/poppler-tqt/ConfigureChecks.cmake new file mode 100644 index 00000000..b15057c9 --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/ConfigureChecks.cmake @@ -0,0 +1,21 @@ +# Poppler +pkg_search_module( POPPLER poppler ) +if( POPPLER_FOUND ) + set( HAVE_POPPLER 1 ) +else( ) + tde_message_fatal( "poppler is required, but was not found on your system" ) +endif( ) + +tde_save( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES ) +set( CMAKE_REQUIRED_INCLUDES ${DBUS_TQT_INCLUDE_DIRS} ${TQT_INCLUDE_DIRS} ${QT_INCLUDE_DIRS} ${POPPLER_INCLUDE_DIRS}) +set( CMAKE_REQUIRED_LIBRARIES ${DBUS_TQT_LDFLAGS} ${TQT_LDFLAGS} ${QT_LDFLAGS} ${POPPLER_LDFLAGS} ) +check_cxx_source_compiles(" + #include <poppler/PSOutputDev.h> + int main(int, char**) { int a; int b; PSOutputDev *psOut = new PSOutputDev(\"test\", (PDFDoc*)0, (XRef*)0, (Catalog*)0, NULL, 0, 0, psModePS, a, b); } " + HAVE_POPPLER_016 ) +check_cxx_source_compiles(" + #include <poppler/PSOutputDev.h> + int main(int, char**) { int a; int b; PSOutputDev *psOut = new PSOutputDev(\"test\", (PDFDoc*)0, NULL, 0, 0, psModePS, a, b); } " + HAVE_POPPLER_020 ) +tde_restore( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES ) + diff --git a/tdefile-plugins/dependencies/poppler-tqt/Makefile.am b/tdefile-plugins/dependencies/poppler-tqt/Makefile.am new file mode 100644 index 00000000..949dc2a4 --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/Makefile.am @@ -0,0 +1,40 @@ +INCLUDES = \ + -I$(top_srcdir) \ + -I/usr/include/poppler \ + $(cairo_includes) \ + $(QT_INCLUDES) \ + $(FREETYPE_CFLAGS) \ + $(FONTCONFIG_CFLAGS) + + +poppler_includedir = $(includedir)/ +poppler_include_HEADERS = \ + poppler-qt.h \ + poppler-page-transition.h \ + poppler-link-qt3.h + +lib_LTLIBRARIES = libpoppler-tqt.la +libpoppler_tqt_la_SOURCES = \ + poppler-document.cc \ + poppler-fontinfo.cc \ + poppler-link.cc \ + poppler-page.cc \ + poppler-page-transition.cc \ + poppler-page-transition-private.h \ + poppler-private.cc \ + poppler-private.h + +libpoppler_tqt_la_LIBADD = \ + -lpoppler \ + $(QT_LIBS) \ + $(FREETYPE_LIBS) \ + $(FONTCONFIG_LIBS) + +test_poppler_tqt_SOURCES = \ + test-poppler-qt.cpp + +test_poppler_tqt_LDADD = \ + $(top_builddir)/poppler/libpoppler.la \ + libpoppler-tqt.la \ + $(QT_LIBS) \ + $(FREETYPE_LIBS) diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-document.cc b/tdefile-plugins/dependencies/poppler-tqt/poppler-document.cc new file mode 100644 index 00000000..2e7cc516 --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-document.cc @@ -0,0 +1,341 @@ +/* poppler-document.cc: qt interface to poppler + * Copyright (C) 2005, Net Integration Technologies, Inc. + * Copyright (C) 2005-2009, Albert Astals Cid <aacid@kde.org> + * Copyright (C) 2006, Stefan Kebekus <stefan.kebekus@math.uni-koeln.de> + * Copyright (C) 2006, Wilfried Huss <Wilfried.Huss@gmx.at> + * + * 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, 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 <config.h> +#include <poppler-qt.h> +#include <tqfile.h> +#include <GlobalParams.h> +#include <Outline.h> +#include <PDFDoc.h> +#include <PSOutputDev.h> +#include <Catalog.h> +#include <ErrorCodes.h> +#include <SplashOutputDev.h> +#include <splash/SplashBitmap.h> +#include <DateInfo.h> +#include "poppler-private.h" + +#undef bool + +namespace Poppler { + +Document *Document::load(const TQString &filePath) +{ + if (!globalParams) { + globalParams = new GlobalParams(); + } + + DocumentData *doc = new DocumentData(new GooString(TQFile::encodeName(filePath)), NULL); + Document *pdoc; + if (doc->doc.isOk() || doc->doc.getErrorCode() == errEncrypted) { + pdoc = new Document(doc); + if (doc->doc.getErrorCode() == errEncrypted) + pdoc->data->locked = true; + else + pdoc->data->locked = false; + pdoc->data->m_fontInfoScanner = new FontInfoScanner(&(doc->doc)); + return pdoc; + } + else + return NULL; +} + +Document::Document(DocumentData *dataA) +{ + data = dataA; +} + +Document::~Document() +{ + delete data; +} + +bool Document::isLocked() const +{ + return data->locked; +} + +bool Document::unlock(const TQCString &password) +{ + if (data->locked) { + /* racier then it needs to be */ + GooString *filename = new GooString(data->doc.getFileName()); + GooString *pwd = new GooString(password.data()); + DocumentData *doc2 = new DocumentData(filename, pwd); + delete pwd; + if (!doc2->doc.isOk()) { + delete doc2; + } else { + delete data; + data = doc2; + data->locked = false; + data->m_fontInfoScanner = new FontInfoScanner(&(data->doc)); + } + } + return data->locked; +} + +Document::PageMode Document::getPageMode(void) const +{ + switch (data->doc.getCatalog()->getPageMode()) { + case Catalog::pageModeNone: + return UseNone; + case Catalog::pageModeOutlines: + return UseOutlines; + case Catalog::pageModeThumbs: + return UseThumbs; + case Catalog::pageModeFullScreen: + return FullScreen; + case Catalog::pageModeOC: + return UseOC; + default: + return UseNone; + } +} + +int Document::getNumPages() const +{ + return data->doc.getNumPages(); +} + +TQValueList<FontInfo> Document::fonts() const +{ + TQValueList<FontInfo> ourList; + scanForFonts(getNumPages(), &ourList); + return ourList; +} + +bool Document::scanForFonts( int numPages, TQValueList<FontInfo> *fontList ) const +{ + GooList *items = data->m_fontInfoScanner->scan( numPages ); + + if ( NULL == items ) + return false; + + for ( int i = 0; i < items->getLength(); ++i ) { + TQString fontName; + if (((::FontInfo*)items->get(i))->getName()) + fontName = ((::FontInfo*)items->get(i))->getName()->getCString(); + + FontInfo font(fontName, + ((::FontInfo*)items->get(i))->getEmbedded(), + ((::FontInfo*)items->get(i))->getSubset(), + (Poppler::FontInfo::Type)((::FontInfo*)items->get(i))->getType()); + fontList->append(font); + } + deleteGooList(items, ::FontInfo); + return true; +} + +/* borrowed from kpdf */ +TQString Document::getInfo( const TQString & type ) const +{ + // [Albert] Code adapted from pdfinfo.cc on xpdf + Object info; + if ( data->locked ) + return NULL; + + data->doc.getDocInfo( &info ); + if ( !info.isDict() ) + return NULL; + + TQString result; + Object obj; + GooString *s1; + GBool isUnicode; + Unicode u; + int i; + Dict *infoDict = info.getDict(); + + if ( infoDict->lookup( (char*)type.latin1(), &obj )->isString() ) + { + s1 = obj.getString(); + if ( ( s1->getChar(0) & 0xff ) == 0xfe && ( s1->getChar(1) & 0xff ) == 0xff ) + { + isUnicode = gTrue; + i = 2; + } + else + { + isUnicode = gFalse; + i = 0; + } + while ( i < obj.getString()->getLength() ) + { + if ( isUnicode ) + { + u = ( ( s1->getChar(i) & 0xff ) << 8 ) | ( s1->getChar(i+1) & 0xff ); + i += 2; + } + else + { + u = s1->getChar(i) & 0xff; + ++i; + } + result += unicodeToTQString( &u, 1 ); + } + obj.free(); + info.free(); + return result; + } + obj.free(); + info.free(); + return NULL; +} + +/* borrowed from kpdf */ +TQDateTime Document::getDate( const TQString & type ) const +{ + // [Albert] Code adapted from pdfinfo.cc on xpdf + if ( data->locked ) + return TQDateTime(); + + Object info; + data->doc.getDocInfo( &info ); + if ( !info.isDict() ) { + info.free(); + return TQDateTime(); + } + + Object obj; + int year, mon, day, hour, min, sec, tz_hour, tz_minute; + char tz; + Dict *infoDict = info.getDict(); + TQString result; + + if ( infoDict->lookup( (char*)type.latin1(), &obj )->isString() ) + { + TQString s = UnicodeParsedString(obj.getString()); + // TODO do something with the timezone information + if ( parseDateString( s.latin1(), &year, &mon, &day, &hour, &min, &sec, &tz, &tz_hour, &tz_minute ) ) + { + TQDate d( year, mon, day ); //CHECK: it was mon-1, Jan->0 (??) + TQTime t( hour, min, sec ); + if ( d.isValid() && t.isValid() ) { + obj.free(); + info.free(); + return TQDateTime( d, t ); + } + } + } + obj.free(); + info.free(); + return TQDateTime(); +} + +bool Document::isEncrypted() const +{ + return data->doc.isEncrypted(); +} + +bool Document::isLinearized() const +{ + return data->doc.isLinearized(); +} + +bool Document::okToPrint() const +{ + return data->doc.okToPrint(); +} + +bool Document::okToChange() const +{ + return data->doc.okToChange(); +} + +bool Document::okToCopy() const +{ + return data->doc.okToCopy(); +} + +bool Document::okToAddNotes() const +{ + return data->doc.okToAddNotes(); +} + +double Document::getPDFVersion() const +{ + return data->doc.getPDFMajorVersion () + data->doc.getPDFMinorVersion() / 10.0; +} + +void Document::getPdfVersion(int *major, int *minor) const +{ + if (major) + *major = data->doc.getPDFMajorVersion(); + if (minor) + *minor = data->doc.getPDFMinorVersion(); +} + +TQDomDocument *Document::toc() const +{ + Outline * outline = data->doc.getOutline(); + if ( !outline ) + return NULL; + + GooList * items = outline->getItems(); + if ( !items || items->getLength() < 1 ) + return NULL; + + TQDomDocument *toc = new TQDomDocument(); + if ( items->getLength() > 0 ) + data->addTocChildren( toc, toc, items ); + + return toc; +} + +LinkDestination *Document::linkDestination( const TQString &name ) +{ + GooString * namedDest = TQStringToGooString( name ); + LinkDestinationData ldd(NULL, namedDest, data); + LinkDestination *ld = new LinkDestination(ldd); + delete namedDest; + return ld; +} + +bool Document::print(const TQString &fileName, TQValueList<int> pageList, double hDPI, double vDPI, int rotate) +{ + return print(fileName, pageList, hDPI, vDPI, rotate, -1, -1); +} + +bool Document::print(const TQString &file, TQValueList<int> pageList, double hDPI, double vDPI, int rotate, int paperWidth, int paperHeight) +{ +#if defined(HAVE_POPPLER_020) + PSOutputDev *psOut = new PSOutputDev(file.latin1(), &(data->doc), NULL, 1, data->doc.getNumPages(), psModePS, paperWidth, paperHeight); +#elif defined(HAVE_POPPLER_016) + PSOutputDev *psOut = new PSOutputDev(file.latin1(), &(data->doc), data->doc.getXRef(), data->doc.getCatalog(), NULL, 1, data->doc.getNumPages(), psModePS, paperWidth, paperHeight); +#else + PSOutputDev *psOut = new PSOutputDev(file.latin1(), data->doc.getXRef(), data->doc.getCatalog(), NULL, 1, data->doc.getNumPages(), psModePS, paperWidth, paperHeight); +#endif + + if (psOut->isOk()) { + TQValueList<int>::iterator it; + for (it = pageList.begin(); it != pageList.end(); ++it ) + data->doc.displayPage(psOut, *it, hDPI, vDPI, rotate, gFalse, gTrue, gTrue); + + delete psOut; + return true; + } else { + delete psOut; + return false; + } +} + +} diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-fontinfo.cc b/tdefile-plugins/dependencies/poppler-tqt/poppler-fontinfo.cc new file mode 100644 index 00000000..c0e777a7 --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-fontinfo.cc @@ -0,0 +1,83 @@ +/* poppler-qt.h: qt interface to poppler + * Copyright (C) 2005, Albert Astals Cid <aacid@kde.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, 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 "poppler-qt.h" + +namespace Poppler { + +class FontInfoData +{ + public: + TQString fontName; + bool isEmbedded; + bool isSubset; + FontInfo::Type type; +}; + +FontInfo::FontInfo( const TQString &fontName, const bool isEmbedded, const bool isSubset, Type type ) +{ + data = new FontInfoData(); + data->fontName = fontName; + data->isEmbedded = isEmbedded; + data->isSubset = isSubset; + data->type = type; +} + +FontInfo::FontInfo( const FontInfo &fi ) +{ + data = new FontInfoData(); + data->fontName = fi.data->fontName; + data->isEmbedded = fi.data->isEmbedded; + data->isSubset = fi.data->isSubset; + data->type = fi.data->type; +} + +FontInfo::FontInfo() +{ + data = new FontInfoData(); + data->isEmbedded = false; + data->isSubset = false; + data->type = unknown; +} + +FontInfo::~FontInfo() +{ + delete data; +} + +const TQString &FontInfo::name() const +{ + return data->fontName; +} + +bool FontInfo::isEmbedded() const +{ + return data->isEmbedded; +} + +bool FontInfo::isSubset() const +{ + return data->isSubset; +} + +FontInfo::Type FontInfo::type() const +{ + return data->type; +} + +} diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-link-qt3.h b/tdefile-plugins/dependencies/poppler-tqt/poppler-link-qt3.h new file mode 100644 index 00000000..fc22d8ed --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-link-qt3.h @@ -0,0 +1,188 @@ +/* poppler-link.h: qt interface to poppler + * Copyright (C) 2006, Albert Astals Cid <aacid@kde.org> + * Adapting code from + * Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> + * + * 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, 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 _POPPLER_LINK_H_ +#define _POPPLER_LINK_H_ + +#include <tqstring.h> +#include <tqrect.h> + +namespace Poppler { + +class LinkDestinationData; + +class LinkDestination +{ + public: + enum Kind + { + destXYZ = 1, + destFit = 2, + destFitH = 3, + destFitV = 4, + destFitR = 5, + destFitB = 6, + destFitBH = 7, + destFitBV = 8 + }; + + LinkDestination(const LinkDestinationData &data); + LinkDestination(const TQString &description); + + // Accessors. + Kind kind() const; + int pageNumber() const; + double left() const; + double bottom() const; + double right() const; + double top() const; + double zoom() const; + bool isChangeLeft() const; + bool isChangeTop() const; + bool isChangeZoom() const; + + TQString toString() const; + + private: + Kind m_kind; // destination type + int m_pageNum; // page number + double m_left, m_bottom; // position + double m_right, m_top; + double m_zoom; // zoom factor + bool m_changeLeft, m_changeTop; // for destXYZ links, which position + bool m_changeZoom; // components to change +}; + +/** + * @short Encapsulates data that describes a link. + * + * This is the base class for links. It makes mandatory for inherited + * widgets to reimplement the 'linkType' method and return the type of + * the link described by the reimplemented class. + */ +class Link +{ + public: + Link( const TQRect &linkArea ); + + // get link type (inherited classes mustreturn an unique identifier) + enum LinkType { None, Goto, Execute, Browse, Action, Movie }; + virtual LinkType linkType() const; + + // virtual destructor + virtual ~Link(); + + TQRect linkArea() const; + + private: + TQRect m_linkArea; +}; + + +/** Goto: a viewport and maybe a reference to an external filename **/ +class LinkGoto : public Link +{ + public: + LinkGoto( const TQRect &linkArea, TQString extFileName, const LinkDestination & destination ); + + // query for goto parameters + bool isExternal() const; + const TQString & fileName() const; + const LinkDestination & destination() const; + LinkType linkType() const; + + private: + TQString m_extFileName; + LinkDestination m_destination; +}; + +/** Execute: filename and parameters to execute **/ +class LinkExecute : public Link +{ + public: + // query for filename / parameters + const TQString & fileName() const; + const TQString & parameters() const; + + // create a Link_Execute + LinkExecute( const TQRect &linkArea, const TQString & file, const TQString & params ); + LinkType linkType() const; + + private: + TQString m_fileName; + TQString m_parameters; +}; + +/** Browse: an URL to open, ranging from 'http://' to 'mailto:' etc.. **/ +class LinkBrowse : public Link +{ + public: + // query for URL + const TQString & url() const; + + // create a Link_Browse + LinkBrowse( const TQRect &linkArea, const TQString &url ); + LinkType linkType() const; + + private: + TQString m_url; +}; + +/** Action: contains an action to perform on document / viewer **/ +class LinkAction : public Link +{ + public: + // define types of actions + enum ActionType { PageFirst = 1, + PagePrev = 2, + PageNext = 3, + PageLast = 4, + HistoryBack = 5, + HistoryForward = 6, + Quit = 7, + Presentation = 8, + EndPresentation = 9, + Find = 10, + GoToPage = 11, + Close = 12 }; + + // query for action type + ActionType actionType() const; + + // create a Link_Action + LinkAction( const TQRect &linkArea, ActionType actionType ); + LinkType linkType() const; + + private: + ActionType m_type; +}; + +/** Movie: Not yet defined -> think renaming to 'Media' link **/ +class LinkMovie : public Link +// TODO this (Movie link) +{ + public: + LinkMovie( const TQRect &linkArea ); + LinkType linkType() const; +}; + +} + +#endif diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-link.cc b/tdefile-plugins/dependencies/poppler-tqt/poppler-link.cc new file mode 100644 index 00000000..72db1fff --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-link.cc @@ -0,0 +1,267 @@ +/* poppler-link.cc: qt interface to poppler + * Copyright (C) 2006, 2008 Albert Astals Cid + * Adapting code from + * Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> + * + * 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, 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 <poppler-qt.h> +#include <poppler-private.h> + +#include <tqstringlist.h> + +#include <Link.h> + +namespace Poppler { + + LinkDestination::LinkDestination(const LinkDestinationData &data) + { + bool deleteDest = false; + LinkDest *ld = data.ld; + + if ( data.namedDest && !ld ) + { + deleteDest = true; + ld = data.doc->doc.findDest( data.namedDest ); + } + + if (!ld) return; + + if (ld->getKind() == ::destXYZ) m_kind = destXYZ; + else if (ld->getKind() == ::destFit) m_kind = destFit; + else if (ld->getKind() == ::destFitH) m_kind = destFitH; + else if (ld->getKind() == ::destFitV) m_kind = destFitV; + else if (ld->getKind() == ::destFitR) m_kind = destFitR; + else if (ld->getKind() == ::destFitB) m_kind = destFitB; + else if (ld->getKind() == ::destFitBH) m_kind = destFitBH; + else if (ld->getKind() == ::destFitBV) m_kind = destFitBV; + + if ( !ld->isPageRef() ) m_pageNum = ld->getPageNum(); + else + { + Ref ref = ld->getPageRef(); + m_pageNum = data.doc->doc.findPage( ref.num, ref.gen ); + } + double left = ld->getLeft(); + double bottom = ld->getBottom(); + double right = ld->getRight(); + double top = ld->getTop(); + m_zoom = ld->getZoom(); + m_changeLeft = ld->getChangeLeft(); + m_changeTop = ld->getChangeTop(); + m_changeZoom = ld->getChangeZoom(); + + int leftAux = 0, topAux = 0, rightAux = 0, bottomAux = 0; + +#if defined(HAVE_SPLASH) + SplashOutputDev *sod = data.doc->getOutputDev(); + sod->cvtUserToDev( left, top, &leftAux, &topAux ); + sod->cvtUserToDev( right, bottom, &rightAux, &bottomAux ); +#endif + + m_left = leftAux; + m_top = topAux; + m_right = rightAux; + m_bottom = bottomAux; + + if (deleteDest) delete ld; + } + + LinkDestination::LinkDestination(const TQString &description) + { + TQStringList tokens = TQStringList::split(';', description); + m_kind = static_cast<Kind>(tokens[0].toInt()); + m_pageNum = tokens[1].toInt(); + m_left = tokens[2].toDouble(); + m_bottom = tokens[3].toDouble(); + m_right = tokens[4].toDouble(); + m_top = tokens[5].toDouble(); + m_zoom = tokens[6].toDouble(); + m_changeLeft = static_cast<bool>(tokens[7].toInt()); + m_changeTop = static_cast<bool>(tokens[8].toInt()); + m_changeZoom = static_cast<bool>(tokens[9].toInt()); + } + + LinkDestination::Kind LinkDestination::kind() const + { + return m_kind; + } + + int LinkDestination::pageNumber() const + { + return m_pageNum; + } + + double LinkDestination::left() const + { + return m_left; + } + + double LinkDestination::bottom() const + { + return m_bottom; + } + + double LinkDestination::right() const + { + return m_right; + } + + double LinkDestination::top() const + { + return m_top; + } + + double LinkDestination::zoom() const + { + return m_zoom; + } + + bool LinkDestination::isChangeLeft() const + { + return m_changeLeft; + } + + bool LinkDestination::isChangeTop() const + { + return m_changeTop; + } + + bool LinkDestination::isChangeZoom() const + { + return m_changeZoom; + } + + TQString LinkDestination::toString() const + { + TQString s = TQString::number( (TQ_INT8)m_kind ); + s += ";" + TQString::number( m_pageNum ); + s += ";" + TQString::number( m_left ); + s += ";" + TQString::number( m_bottom ); + s += ";" + TQString::number( m_right ); + s += ";" + TQString::number( m_top ); + s += ";" + TQString::number( m_zoom ); + s += ";" + TQString::number( (TQ_INT8)m_changeLeft ); + s += ";" + TQString::number( (TQ_INT8)m_changeTop ); + s += ";" + TQString::number( (TQ_INT8)m_changeZoom ); + return s; + } + + + // Link + Link::~Link() + { + } + + Link::Link(const TQRect &linkArea) : m_linkArea(linkArea) + { + } + + Link::LinkType Link::linkType() const + { + return None; + } + + TQRect Link::linkArea() const + { + return m_linkArea; + } + + // LinkGoto + LinkGoto::LinkGoto( const TQRect &linkArea, TQString extFileName, const LinkDestination & destination ) : Link(linkArea), m_extFileName(extFileName), m_destination(destination) + { + } + + bool LinkGoto::isExternal() const + { + return !m_extFileName.isEmpty(); + } + + const TQString &LinkGoto::fileName() const + { + return m_extFileName; + } + + const LinkDestination &LinkGoto::destination() const + { + return m_destination; + } + + Link::LinkType LinkGoto::linkType() const + { + return Goto; + } + + // LinkExecute + LinkExecute::LinkExecute( const TQRect &linkArea, const TQString & file, const TQString & params ) : Link(linkArea), m_fileName(file), m_parameters(params) + { + } + + const TQString & LinkExecute::fileName() const + { + return m_fileName; + } + const TQString & LinkExecute::parameters() const + { + return m_parameters; + } + + Link::LinkType LinkExecute::linkType() const + { + return Execute; + } + + // LinkBrowse + LinkBrowse::LinkBrowse( const TQRect &linkArea, const TQString &url ) : Link(linkArea), m_url(url) + { + } + + const TQString & LinkBrowse::url() const + { + return m_url; + } + + Link::LinkType LinkBrowse::linkType() const + { + return Browse; + } + + // LinkAction + LinkAction::LinkAction( const TQRect &linkArea, ActionType actionType ) : Link(linkArea), m_type(actionType) + { + } + + LinkAction::ActionType LinkAction::actionType() const + { + return m_type; + } + + Link::LinkType LinkAction::linkType() const + { + return Action; + } + + // LinkMovie + LinkMovie::LinkMovie( const TQRect &linkArea ) : Link(linkArea) + { + } + + Link::LinkType LinkMovie::linkType() const + { + return Movie; + } + +} diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-page-transition-private.h b/tdefile-plugins/dependencies/poppler-tqt/poppler-page-transition-private.h new file mode 100644 index 00000000..8bc70825 --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-page-transition-private.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2005, Albert Astals Cid + * + * 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, 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 POPPLER_PAGE_TRANSITION_PRIVATE_H +#define POPPLER_PAGE_TRANSITION_PRIVATE_H + +class Object; + +namespace Poppler { + +class PageTransitionParams { + public: + Object *dictObj; +}; + +} + +#endif // POPPLER_PAGE_TRANSITION_PRIVATE_H diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-page-transition.cc b/tdefile-plugins/dependencies/poppler-tqt/poppler-page-transition.cc new file mode 100644 index 00000000..cde8818d --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-page-transition.cc @@ -0,0 +1,95 @@ +/* PageTransition.cc + * Copyright (C) 2005, Net Integration Technologies, Inc. + * + * 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, 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 "PageTransition.h" +#include "poppler-page-transition.h" +#include "poppler-page-transition-private.h" + +namespace Poppler { + +class PageTransitionData +{ + public: + PageTransitionData(Object *trans) + { + pt = new ::PageTransition(trans); + } + + PageTransitionData(const PageTransitionData &ptd) + { + pt = new ::PageTransition(*ptd.pt); + } + + ~PageTransitionData() + { + delete pt; + } + + ::PageTransition *pt; +}; + +PageTransition::PageTransition(const PageTransitionParams ¶ms) +{ + data = new PageTransitionData(params.dictObj); +} + +PageTransition::PageTransition(const PageTransition &pt) +{ + data = new PageTransitionData(*pt.data); +} + +PageTransition::~PageTransition() +{ + delete data; +} + +PageTransition::Type PageTransition::type() const +{ + return (Poppler::PageTransition::Type)data->pt->getType(); +} + +int PageTransition::duration() const +{ + return data->pt->getDuration(); +} + +PageTransition::Alignment PageTransition::alignment() const +{ + return (Poppler::PageTransition::Alignment)data->pt->getAlignment(); +} + +PageTransition::Direction PageTransition::direction() const +{ + return (Poppler::PageTransition::Direction)data->pt->getDirection(); +} + +int PageTransition::angle() const +{ + return data->pt->getAngle(); +} + +double PageTransition::scale() const +{ + return data->pt->getScale(); +} +bool PageTransition::isRectangular() const +{ + return data->pt->isRectangular(); +} + +} diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-page-transition.h b/tdefile-plugins/dependencies/poppler-tqt/poppler-page-transition.h new file mode 100644 index 00000000..53002ff9 --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-page-transition.h @@ -0,0 +1,146 @@ +/* PageTransition.h + * Copyright (C) 2005, Net Integration Technologies, Inc. + * Copyright (C) 2005, Brad Hards <bradh@frogmouth.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, 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 __PAGETRANSITION_X_H__ +#define __PAGETRANSITION_X_H__ + +namespace Poppler { + +class PageTransitionParams; +class PageTransitionData; + +/** + \brief Describes how a PDF file viewer shall perform the transition + from one page to another + + In PDF files there is a way to specify if the viewer shall use + certain effects to perform the transition from one page to + another. This feature can be used, e.g., in a PDF-based beamer + presentation. + + This utility class represents the transition effect, and can be + used to extract the information from a PDF object. +*/ + + +class PageTransition { + public: + + /** \brief transition effect that shall be used + */ + // if changed remember to keep in sync with PageTransition.h enum + enum Type { + Replace = 0, + Split, + Blinds, + Box, + Wipe, + Dissolve, + Glitter, + Fly, + Push, + Cover, + Uncover, + Fade + }; + + /** \brief alignment of the transition effect that shall be used + */ + // if changed remember to keep in sync with PageTransition.h enum + enum Alignment { + Horizontal = 0, + Vertical + }; + + /** \brief direction of the transition effect that shall be used + */ + // if changed remember to keep in sync with PageTransition.h enum + enum Direction { + Inward = 0, + Outward + }; + + /** \brief Construct a new PageTransition object from a page dictionary. + + Users of the library will rarely need to construct a + PageTransition object themselves. Instead, the method + Poppler::Page::transition() can be used to find out if a certain + transition effect is specified. + + @warning In case or error, this method will print an error message to stderr, + and construct a default object. + + @param params an object whose dictionary will be read and + parsed. This must be a valid object, whose dictionaries are + accessed by the constructor. The object is only accessed by this + constructor, and may be deleted after the constructor returns. + */ + PageTransition(const PageTransitionParams ¶ms); + + /** \brief copy constructor */ + PageTransition(const PageTransition &pt); + + /** + Destructor + */ + ~PageTransition(); + + /** + \brief Get type of the transition. + */ + Type type() const; + + /** + \brief Get duration of the transition in seconds. + */ + int duration() const; + + /** + \brief Get dimension in which the transition effect occurs. + */ + Alignment alignment() const; + + /** + \brief Get direction of motion of the transition effect. + */ + Direction direction() const; + + /** + \brief Get direction in which the transition effect moves. + */ + int angle() const; + + /** + \brief Get starting or ending scale. + */ + double scale() const; + + /** + \brief Returns true if the area to be flown is rectangular and + opaque. + */ + bool isRectangular() const; + + private: + PageTransitionData *data; +}; + +} + +#endif diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-page.cc b/tdefile-plugins/dependencies/poppler-tqt/poppler-page.cc new file mode 100644 index 00000000..3d1e6569 --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-page.cc @@ -0,0 +1,370 @@ +/* poppler-page.cc: qt interface to poppler + * Copyright (C) 2005, Net Integration Technologies, Inc. + * Copyright (C) 2005-2006, Albert Astals Cid <aacid@kde.org> + * Copyright (C) 2005, Tobias Koening <tokoe@kde.org> + * Copyright (C) 2005, Stefan Kebekus <stefan.kebekus@math.uni-koeln.de> + * Copyright (C) 2006, Wilfried Huss <Wilfried.Huss@gmx.at> + * Copyright (C) 2006, Jerry Epplin <jepplin@globalvelocity.com> + * Copyright (C) 2007, 2010, Pino Toscano <pino@kde.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, 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 <poppler-qt.h> +#include <tqfile.h> +#include <tqimage.h> +#include <config.h> +#include <GlobalParams.h> +#include <PDFDoc.h> +#include <Catalog.h> +#include <ErrorCodes.h> +#include <TextOutputDev.h> +#include <Link.h> +#if defined(HAVE_SPLASH) +#include <SplashOutputDev.h> +#include <splash/SplashBitmap.h> +#endif + +#include "poppler-private.h" +#include "poppler-page-transition-private.h" + +namespace Poppler { + +class PageData { + public: + const Document *doc; + int index; + PageTransition *transition; +}; + +Page::Page(const Document *doc, int index) { + data = new PageData(); + data->index = index; + data->doc = doc; + data->transition = 0; +} + +Page::~Page() +{ + delete data->transition; + delete data; +} + +void Page::renderToPixmap(TQPixmap **q, int x, int y, int w, int h, bool doLinks) const +{ + renderToPixmap(q, x, y, w, h, 72.0, 72.0, doLinks); +} + +void Page::renderToPixmap(TQPixmap **q, int x, int y, int w, int h, double xres, double yres, bool doLinks) const +{ + TQImage img = renderToImage(xres, yres, doLinks); + *q = new TQPixmap( img ); +} + +TQImage Page::renderToImage(double xres, double yres, bool doLinks) const +{ +#if defined(HAVE_SPLASH) + SplashOutputDev *output_dev; + SplashBitmap *bitmap; + SplashColorPtr color_ptr; + output_dev = data->doc->data->getOutputDev(); + + data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, xres, yres, + 0, false, true, false, -1, -1, -1, -1); + bitmap = output_dev->getBitmap (); + color_ptr = bitmap->getDataPtr (); + int bw = output_dev->getBitmap()->getWidth(); + int bh = output_dev->getBitmap()->getHeight(); + SplashColorPtr dataPtr = output_dev->getBitmap()->getDataPtr(); + + if (TQImage::BigEndian == TQImage::systemByteOrder()) + { + uchar c; + int count = bw * bh * 4; + for (int k = 0; k < count; k += 4) + { + c = dataPtr[k]; + dataPtr[k] = dataPtr[k+3]; + dataPtr[k+3] = c; + + c = dataPtr[k+1]; + dataPtr[k+1] = dataPtr[k+2]; + dataPtr[k+2] = c; + } + } + + // construct a qimage SHARING the raw bitmap data in memory + TQImage img( dataPtr, bw, bh, 32, 0, 0, TQImage::IgnoreEndian ); + img = img.copy(); + // unload underlying xpdf bitmap + output_dev->startPage( 0, NULL ); + + return img; +#else + (void)xres; + (void)xres; + (void)doLinks; + + return TQImage(); +#endif +} + +TQString Page::getText(const Rectangle &r) const +{ + TextOutputDev *output_dev; + GooString *s; + PDFRectangle *rect; + TQString result; + ::Page *p; + +#if defined(HAVE_POPPLER_020) + output_dev = new TextOutputDev(0, gFalse, 0, gFalse, gFalse); +#else + output_dev = new TextOutputDev(0, gFalse, gFalse, gFalse); +#endif + data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, 72, 72, + 0, false, false, false, -1, -1, -1, -1); + p = data->doc->data->doc.getCatalog()->getPage(data->index + 1); + if (r.isNull()) + { + rect = p->getCropBox(); + s = output_dev->getText(rect->x1, rect->y1, rect->x2, rect->y2); + } + else + { + double height, y1, y2; + height = p->getCropHeight(); + y1 = height - r.m_y2; + y2 = height - r.m_y1; + s = output_dev->getText(r.m_x1, y1, r.m_x2, y2); + } + + result = TQString::fromUtf8(s->getCString()); + + delete output_dev; + delete s; + return result; +} + +TQValueList<TextBox*> Page::textList() const +{ + TextOutputDev *output_dev; + + TQValueList<TextBox*> output_list; + +#if defined(HAVE_POPPLER_020) + output_dev = new TextOutputDev(0, gFalse, 0, gFalse, gFalse); +#else + output_dev = new TextOutputDev(0, gFalse, gFalse, gFalse); +#endif + + data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, 72, 72, + 0, false, false, false, -1, -1, -1, -1); + + TextWordList *word_list = output_dev->makeWordList(); + + if (!word_list) { + delete output_dev; + return output_list; + } + + for (int i = 0; i < word_list->getLength(); i++) { + TextWord *word = word_list->get(i); + GooString *word_str = word->getText(); + TQString string = TQString::fromUtf8(word_str->getCString()); + delete word_str; + double xMin, yMin, xMax, yMax; + word->getBBox(&xMin, &yMin, &xMax, &yMax); + + TextBox* text_box = new TextBox(string, Rectangle(xMin, yMin, xMax, yMax)); + + output_list.append(text_box); + } + + delete word_list; + delete output_dev; + + return output_list; +} + +PageTransition *Page::getTransition() const +{ + if (!data->transition) + { + Object o; + PageTransitionParams params; + params.dictObj = data->doc->data->doc.getCatalog()->getPage(data->index + 1)->getTrans(&o); + data->transition = new PageTransition(params); + o.free(); + } + return data->transition; +} + +TQSize Page::pageSize() const +{ + ::Page *p; + + p = data->doc->data->doc.getCatalog()->getPage(data->index + 1); + if ( ( Page::Landscape == orientation() ) || (Page::Seascape == orientation() ) ) { + return TQSize( (int)p->getCropHeight(), (int)p->getCropWidth() ); + } else { + return TQSize( (int)p->getCropWidth(), (int)p->getCropHeight() ); + } +} + +Page::Orientation Page::orientation() const +{ + ::Page *p = data->doc->data->doc.getCatalog()->getPage(data->index + 1); + + int rotation = p->getRotate(); + switch (rotation) { + case 90: + return Page::Landscape; + break; + case 180: + return Page::UpsideDown; + break; + case 270: + return Page::Seascape; + break; + default: + return Page::Portrait; + } +} + +TQValueList<Link*> Page::links() const +{ + TQValueList<Link*> popplerLinks; + +#if defined(HAVE_SPLASH) + Links *xpdfLinks = data->doc->data->doc.getLinks(data->index + 1); + for (int i = 0; i < xpdfLinks->getNumLinks(); ++i) + { + ::Link *xpdfLink = xpdfLinks->getLink(i); + + double left, top, right, bottom; + int leftAux, topAux, rightAux, bottomAux; + xpdfLink->getRect( &left, &top, &right, &bottom ); + TQRect linkArea; + + data->doc->data->m_outputDev->cvtUserToDev( left, top, &leftAux, &topAux ); + data->doc->data->m_outputDev->cvtUserToDev( right, bottom, &rightAux, &bottomAux ); + linkArea.setLeft(leftAux); + linkArea.setTop(topAux); + linkArea.setRight(rightAux); + linkArea.setBottom(bottomAux); + + if (!xpdfLink->isOk()) continue; + + Link *popplerLink = NULL; + ::LinkAction *a = xpdfLink->getAction(); + if ( a ) + { + switch ( a->getKind() ) + { + case actionGoTo: + { + LinkGoTo * g = (LinkGoTo *) a; + // create link: no ext file, namedDest, object pointer + popplerLink = new LinkGoto( linkArea, TQString(), LinkDestination( LinkDestinationData(g->getDest(), g->getNamedDest(), data->doc->data ) ) ); + } + break; + + case actionGoToR: + { + LinkGoToR * g = (LinkGoToR *) a; + // copy link file + const TQString fileName = UnicodeParsedString( g->getFileName() ); + // ceate link: fileName, namedDest, object pointer + popplerLink = new LinkGoto( linkArea, fileName, LinkDestination( LinkDestinationData(g->getDest(), g->getNamedDest(), data->doc->data ) ) ); + } + break; + + case actionLaunch: + { + LinkLaunch * e = (LinkLaunch *)a; + GooString * p = e->getParams(); + popplerLink = new LinkExecute( linkArea, e->getFileName()->getCString(), p ? p->getCString() : 0 ); + } + break; + + case actionNamed: + { + const char * name = ((LinkNamed *)a)->getName()->getCString(); + if ( !strcmp( name, "NextPage" ) ) + popplerLink = new LinkAction( linkArea, LinkAction::PageNext ); + else if ( !strcmp( name, "PrevPage" ) ) + popplerLink = new LinkAction( linkArea, LinkAction::PagePrev ); + else if ( !strcmp( name, "FirstPage" ) ) + popplerLink = new LinkAction( linkArea, LinkAction::PageFirst ); + else if ( !strcmp( name, "LastPage" ) ) + popplerLink = new LinkAction( linkArea, LinkAction::PageLast ); + else if ( !strcmp( name, "GoBack" ) ) + popplerLink = new LinkAction( linkArea, LinkAction::HistoryBack ); + else if ( !strcmp( name, "GoForward" ) ) + popplerLink = new LinkAction( linkArea, LinkAction::HistoryForward ); + else if ( !strcmp( name, "Quit" ) ) + popplerLink = new LinkAction( linkArea, LinkAction::Quit ); + else if ( !strcmp( name, "GoToPage" ) ) + popplerLink = new LinkAction( linkArea, LinkAction::GoToPage ); + else if ( !strcmp( name, "Find" ) ) + popplerLink = new LinkAction( linkArea, LinkAction::Find ); + else if ( !strcmp( name, "FullScreen" ) ) + popplerLink = new LinkAction( linkArea, LinkAction::Presentation ); + else if ( !strcmp( name, "Close" ) ) + { + // acroread closes the document always, doesnt care whether + // its presentation mode or not + // popplerLink = new LinkAction( linkArea, LinkAction::EndPresentation ); + popplerLink = new LinkAction( linkArea, LinkAction::Close ); + } + else + { + // TODO + } + } + break; + + case actionURI: + { + popplerLink = new LinkBrowse( linkArea, ((LinkURI *)a)->getURI()->getCString() ); + } + break; + + case actionMovie: + case actionSound: + case actionRendition: + case actionJavaScript: + case actionOCGState: + break; + + case actionUnknown: + break; + } + } + + if (popplerLink) + { + popplerLinks.append(popplerLink); + } + } + + delete xpdfLinks; +#endif + + return popplerLinks; +} + +} diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-private.cc b/tdefile-plugins/dependencies/poppler-tqt/poppler-private.cc new file mode 100644 index 00000000..7e366014 --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-private.cc @@ -0,0 +1,147 @@ +/* poppler-private.h: qt interface to poppler + * Copyright (C) 2005, Net Integration Technologies, Inc. + * Copyright (C) 2005-2008, Albert Astals Cid <aacid@kde.org> + * Copyright (C) 2006, Kristian Høgsberg <krh@bitplanet.net> + * Copyright (C) 2006, Wilfried Huss <Wilfried.Huss@gmx.at> + * Copyright (C) 2007, Pino Toscano <pino@kde.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, 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 "poppler-private.h" +#include "poppler-link-qt3.h" + +#include <tqstring.h> + +#include <Outline.h> +#include <Link.h> + +namespace Poppler { + +/* borrowed from kpdf */ +TQString unicodeToTQString(Unicode* u, int len) +{ + TQString ret; + ret.setLength(len); + TQChar* qch = (TQChar*) ret.unicode(); + for (;len;--len) + *qch++ = (TQChar) *u++; + return ret; +} + +TQString UnicodeParsedString(GooString *s1) +{ + GBool isUnicode; + int i; + Unicode u; + TQString result; + if ( ( s1->getChar(0) & 0xff ) == 0xfe && ( s1->getChar(1) & 0xff ) == 0xff ) + { + isUnicode = gTrue; + i = 2; + } + else + { + isUnicode = gFalse; + i = 0; + } + while ( i < s1->getLength() ) + { + if ( isUnicode ) + { + u = ( ( s1->getChar(i) & 0xff ) << 8 ) | ( s1->getChar(i+1) & 0xff ); + i += 2; + } + else + { + u = s1->getChar(i) & 0xff; + ++i; + } + result += unicodeToTQString( &u, 1 ); + } + return result; +} + +GooString *TQStringToGooString(const TQString &s) +{ + int len = s.length(); + char *cstring = (char *)gmallocn(s.length(), sizeof(char)); + for (int i = 0; i < len; ++i) + cstring[i] = s.at(i).unicode(); + GooString *ret = new GooString(cstring, len); + gfree(cstring); + return ret; +} + + +void DocumentData::addTocChildren( TQDomDocument * docSyn, TQDomNode * parent, GooList * items ) +{ + int numItems = items->getLength(); + for ( int i = 0; i < numItems; ++i ) + { + // iterate over every object in 'items' + OutlineItem * outlineItem = (OutlineItem *)items->get( i ); + + // 1. create element using outlineItem's title as tagName + TQString name; + Unicode * uniChar = outlineItem->getTitle(); + int titleLength = outlineItem->getTitleLength(); + name = unicodeToTQString(uniChar, titleLength); + if ( name.isEmpty() ) + continue; + + TQDomElement item = docSyn->createElement( name ); + parent->appendChild( item ); + + // 2. find the page the link refers to + ::LinkAction * a = outlineItem->getAction(); + if ( a && ( a->getKind() == actionGoTo || a->getKind() == actionGoToR ) ) + { + // page number is contained/referenced in a LinkGoTo + LinkGoTo * g = static_cast< LinkGoTo * >( a ); + LinkDest * destination = g->getDest(); + if ( !destination && g->getNamedDest() ) + { + // no 'destination' but an internal 'named reference'. we could + // get the destination for the page now, but it's VERY time consuming, + // so better storing the reference and provide the viewport on demand + GooString *s = g->getNamedDest(); + TQChar *charArray = new TQChar[s->getLength()]; + for (int i = 0; i < s->getLength(); ++i) charArray[i] = TQChar(s->getCString()[i]); + TQString aux(charArray, s->getLength()); + item.setAttribute( "DestinationName", aux ); + delete[] charArray; + } + else if ( destination && destination->isOk() ) + { + LinkDestinationData ldd(destination, NULL, this); + item.setAttribute( "Destination", LinkDestination(ldd).toString() ); + } + if ( a->getKind() == actionGoToR ) + { + LinkGoToR * g2 = static_cast< LinkGoToR * >( a ); + item.setAttribute( "ExternalFileName", g2->getFileName()->getCString() ); + } + } + + // 3. recursively descend over children + outlineItem->open(); + GooList * children = outlineItem->getKids(); + if ( children ) + addTocChildren( docSyn, &item, children ); + } +} + +} diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-private.h b/tdefile-plugins/dependencies/poppler-tqt/poppler-private.h new file mode 100644 index 00000000..9e9e3292 --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-private.h @@ -0,0 +1,97 @@ +/* poppler-private.h: qt interface to poppler + * Copyright (C) 2005, Net Integration Technologies, Inc. + * Copyright (C) 2005-2008, Albert Astals Cid <aacid@kde.org> + * Copyright (C) 2006, Kristian Høgsberg <krh@bitplanet.net> + * Copyright (C) 2006, Wilfried Huss <Wilfried.Huss@gmx.at> + * Copyright (C) 2007, Pino Toscano <pino@kde.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, 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 POPPLER_PRIVATE_H +#define POPPLER_PRIVATE_H + +#include <tqdom.h> + +#include <config.h> +#include <Object.h> +#include <PDFDoc.h> +#include <FontInfo.h> +#if defined(HAVE_SPLASH) +#include <SplashOutputDev.h> +#else +class SplashOutputDev; +#endif + +namespace Poppler { + +class DocumentData; + +TQString unicodeToTQString(Unicode* u, int len); + +TQString UnicodeParsedString(GooString *s1); + +GooString *TQStringToGooString(const TQString &s); + +class LinkDestinationData { + public: + LinkDestinationData( LinkDest *l, GooString *nd, Poppler::DocumentData *pdfdoc ) : ld(l), namedDest(nd), doc(pdfdoc) + { + } + + LinkDest *ld; + GooString *namedDest; + Poppler::DocumentData *doc; +}; + +class DocumentData { + public: + DocumentData(GooString *filePath, GooString *password) : doc(filePath,password), m_fontInfoScanner(0), m_outputDev(0) {} + + ~DocumentData() + { +#if defined(HAVE_SPLASH) + delete m_outputDev; +#endif + delete m_fontInfoScanner; + } + + SplashOutputDev *getOutputDev() + { +#if defined(HAVE_SPLASH) + if (!m_outputDev) + { + SplashColor white; + white[0] = 255; + white[1] = 255; + white[2] = 255; + m_outputDev = new SplashOutputDev(splashModeXBGR8, 4, gFalse, white); + m_outputDev->startDoc(doc.getXRef()); + } +#endif + return m_outputDev; + } + + void addTocChildren( TQDomDocument * docSyn, TQDomNode * parent, GooList * items ); + + class PDFDoc doc; + bool locked; + FontInfoScanner *m_fontInfoScanner; + SplashOutputDev *m_outputDev; +}; + +} + +#endif // POPPLER_PRIVATE_H diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-qt.h b/tdefile-plugins/dependencies/poppler-tqt/poppler-qt.h new file mode 100644 index 00000000..9150ee3b --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-qt.h @@ -0,0 +1,310 @@ +/* poppler-qt.h: qt interface to poppler + * Copyright (C) 2005, Net Integration Technologies, Inc. + * Copyright (C) 2005, Tobias Koening <tokoe@kde.org> + * Copyright (C) 2005-2007, Albert Astals Cid <aacid@kde.org> + * Copyright (C) 2005-2006, Stefan Kebekus <stefan.kebekus@math.uni-koeln.de> + * Copyright (C) 2006, Wilfried Huss <Wilfried.Huss@gmx.at> + * + * 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, 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 __POPPLER_TQT_H__ +#define __POPPLER_TQT_H__ + +#include "poppler-link-qt3.h" +#include "poppler-page-transition.h" + +#include <tqcstring.h> +#include <tqdatetime.h> +#include <tqdom.h> +#include <tqpixmap.h> + +namespace Poppler { + +class Document; +class Page; + +/* A rectangle on a page, with coordinates in PDF points. */ +class Rectangle +{ + public: + Rectangle(double x1 = 0, double y1 = 0, double x2 = 0, double y2 = 0) : + m_x1(x1), m_y1(y1), m_x2(x2), m_y2(y2) {} + bool isNull() const { return m_x1 == 0 && m_y1 == 0 && m_x2 == 0 && m_y2 == 0; } + + double m_x1; + double m_y1; + double m_x2; + double m_y2; +}; + +class TextBox +{ + public: + TextBox(const TQString& text, const Rectangle &bBox) : + m_text(text), m_bBox(bBox) {}; + + TQString getText() const { return m_text; }; + Rectangle getBoundingBox() const { return m_bBox; }; + + private: + TQString m_text; + Rectangle m_bBox; +}; + + +/** + Container class for information about a font within a PDF document +*/ +class FontInfoData; +class FontInfo { +public: + enum Type { + unknown, + Type1, + Type1C, + Type1COT, + Type3, + TrueType, + TrueTypeOT, + CIDType0, + CIDType0C, + CIDType0COT, + CIDTrueType, + CIDTrueTypeOT + }; + + /** + Create a new font information container + */ + FontInfo( const TQString &fontName, const bool isEmbedded, + const bool isSubset, Type type ); + + FontInfo(); + + FontInfo( const FontInfo &fi ); + + ~FontInfo(); + + /** + The name of the font. Can be TQString() if the font has no name + */ + const TQString &name() const; + + /** + Whether the font is embedded in the file, or not + + \return true if the font is embedded + */ + bool isEmbedded() const; + + /** + Whether the font provided is only a subset of the full + font or not. This only has meaning if the font is embedded. + + \return true if the font is only a subset + */ + bool isSubset() const; + + /** + The type of font encoding + */ + Type type() const; + + const TQString &typeName() const; + +private: + FontInfoData *data; +}; + +class PageData; +class Page { + friend class Document; + public: + ~Page(); + void renderToPixmap(TQPixmap **q, int x, int y, int w, int h, double xres, double yres, bool doLinks = false) const; + + /** + This is a convenience function that is equivalent to + renderToPixmap() with xres and yres set to 72.0. We keep it + only for binary compatibility + + \sa renderToImage() + */ + void renderToPixmap(TQPixmap **q, int x, int y, int w, int h, bool doLinks = false) const; + + /** + \brief Render the page to a TQImage using the Splash renderer + + This method can be used to render the page to a TQImage. It + uses the "Splash" rendering engine. + + \param xres horizontal resolution of the graphics device, + in dots per inch (defaults to 72 dpi) + + \param yres vertical resolution of the graphics device, in + dots per inch (defaults to 72 dpi) + + \returns a TQImage of the page. + + \sa renderToPixmap() + */ + TQImage renderToImage(double xres = 72.0, double yres = 72.0, bool doLinks = false) const; + + /** + * Returns the size of the page in points + **/ + TQSize pageSize() const; + + /** + * Returns the text that is inside the Rectangle r + * If r is a null Rectangle all text of the page is given + **/ + TQString getText(const Rectangle &r) const; + + TQValueList<TextBox*> textList() const; + + /** + * Returns the transition of this page + **/ + PageTransition *getTransition() const; + + enum Orientation { + Landscape, + Portrait, + Seascape, + UpsideDown + }; + + /** + * The orientation of the page + **/ + Orientation orientation() const; + + /** + Gets the links of the page once it has been rendered if doLinks was true + */ + TQValueList<Link*> links() const; + + private: + Page(const Document *doc, int index); + PageData *data; +}; + +class DocumentData; + +class Document { + friend class Page; + +public: + enum PageMode { + UseNone, + UseOutlines, + UseThumbs, + FullScreen, + UseOC + }; + + static Document *load(const TQString & filePath); + + Page *getPage(int index) const{ return new Page(this, index); } + + int getNumPages() const; + + PageMode getPageMode() const; + + bool unlock(const TQCString &password); + + bool isLocked() const; + + TQDateTime getDate( const TQString & data ) const; + TQString getInfo( const TQString & data ) const; + bool isEncrypted() const; + bool isLinearized() const; + bool okToPrint() const; + bool okToChange() const; + bool okToCopy() const; + bool okToAddNotes() const; + double getPDFVersion() const; + /** + The version of the PDF specification that the document + conforms to + + \param major an optional pointer to a variable where store the + "major" number of the version + \param minor an optional pointer to a variable where store the + "minor" number of the version + + \since 0.12 + */ + void getPdfVersion(int *major, int *minor) const; + + bool print(const TQString &fileName, TQValueList<int> pageList, double hDPI, double vDPI, int rotate); + + // If you are using TQPrinter you can get paper size doing + // TQPrinter dummy(TQPrinter::PrinterResolution); + // dummy.setFullPage(true); + // dummy.setPageSize(thePageSizeYouWant); + // TQPaintDeviceMetrics metrics(&dummy); + // int width = metrics.width(); + // int height = metrics.height(); + bool print(const TQString &fileName, TQValueList<int> pageList, double hDPI, double vDPI, int rotate, int paperWidth, int paperHeight); + + /** + The fonts within the PDF document. + + \note this can take a very long time to run with a large + document. You may wish to use the call below if you have more + than say 20 pages + */ + TQValueList<FontInfo> fonts() const; + + /** + \overload + + \param numPages the number of pages to scan + \param fontList pointer to the list where the font information + should be placed + + \return false if the end of the document has been reached + */ + bool scanForFonts( int numPages, TQValueList<FontInfo> *fontList ) const; + + /** + Gets the TOC of the Document, it is application responsabiliy to delete + it when no longer needed + + * In the tree the tag name is the 'screen' name of the entry. A tag can have + * attributes. Here follows the list of tag attributes with meaning: + * - Destination: A string description of the referred destination + * - DestinationName: A 'named reference' to the viewport that must be converted + * using linkDestination( *destination_name* ) + * - ExternalFileName: A link to a external filename + + \returns NULL if the Document does not have TOC + */ + TQDomDocument *toc() const; + + LinkDestination *linkDestination( const TQString &name ); + + ~Document(); + +private: + DocumentData *data; + Document(DocumentData *dataA); +}; + +} +#endif diff --git a/tdefile-plugins/dependencies/poppler-tqt/poppler-tqt.pc.cmake b/tdefile-plugins/dependencies/poppler-tqt/poppler-tqt.pc.cmake new file mode 100644 index 00000000..86a0a0d5 --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/poppler-tqt.pc.cmake @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@LIB_INSTALL_DIR@ +includedir=@INCLUDE_INSTALL_DIR@ + +Name: poppler-tqt +Description: TQt bindings for poppler +Version: @POPPLER_VERSION@ +Requires: poppler = @POPPLER_VERSION@ + +Libs: -L${libdir} -lpoppler-tqt +Cflags: -I${includedir} diff --git a/tdefile-plugins/dependencies/poppler-tqt/test-poppler-qt.cpp b/tdefile-plugins/dependencies/poppler-tqt/test-poppler-qt.cpp new file mode 100644 index 00000000..d616290d --- /dev/null +++ b/tdefile-plugins/dependencies/poppler-tqt/test-poppler-qt.cpp @@ -0,0 +1,122 @@ +#include <tqapplication.h> +#include <tqpainter.h> +#include <tqpixmap.h> +#include <tqwidget.h> +#include <tqlabel.h> +#include <tqmessagebox.h> +#include <tqfile.h> +#include <ctype.h> +#include <poppler-qt.h> +#include <stdlib.h> + +class PDFDisplay : public TQWidget // picture display widget +{ +public: + PDFDisplay( Poppler::Document *d ); + ~PDFDisplay(); +protected: + void paintEvent( TQPaintEvent * ); + void keyPressEvent( TQKeyEvent * ); +private: + void display(); + + int currentPage; + TQPixmap *pixmap; + Poppler::Document *doc; +}; + +PDFDisplay::PDFDisplay( Poppler::Document *d ) +{ + doc = d; + pixmap = 0; + currentPage = 0; + display(); +} + +PDFDisplay::~PDFDisplay() +{ + delete doc; + delete pixmap; +} + +void PDFDisplay::paintEvent( TQPaintEvent *e ) +{ + TQPainter paint( this ); // paint widget + if (pixmap) + paint.drawPixmap(0, 0, *pixmap); +} + +void PDFDisplay::keyPressEvent( TQKeyEvent *e ) +{ + if (e->key() == TQt::Key_Down) + { + if (currentPage + 1 < doc->getNumPages()) + { + currentPage++; + display(); + } + } + else if (e->key() == TQt::Key_Up) + { + if (currentPage > 0) + { + currentPage--; + display(); + } + } +} + +void PDFDisplay::display() +{ + if (doc) { + Poppler::Page *page = doc->getPage(currentPage); + if (page) { + delete pixmap; + page->renderToPixmap(&pixmap, -1, -1, -1, -1); + delete page; + update(); + } + } else { + printf("doc not loaded\n"); + } +} + +int main( int argc, char **argv ) +{ + TQApplication a( argc, argv ); // TQApplication required! + + if ( argc < 2 || (argc == 3 && strcmp(argv[2], "-extract") != 0) || argc > 3) + { + // use argument as file name + printf("usage: test-poppler-qt filename [-extract]\n"); + exit(1); + } + + Poppler::Document *doc = Poppler::Document::load(argv[1]); + if (!doc) + { + printf("doc not loaded\n"); + exit(1); + } + + if (argc == 2) + { + PDFDisplay test( doc ); // create picture display + a.setMainWidget( &test); // set main widget + test.setCaption("Poppler-TQt Test"); + test.show(); // show it + + return a.exec(); // start event loop + } + else + { + Poppler::Page *page = doc->getPage(0); + + TQLabel *l = new TQLabel(page->getText(Poppler::Rectangle()), 0); + l->show(); + a.setMainWidget(l); // set main widget + delete page; + delete doc; + return a.exec(); + } +} diff --git a/tdefile-plugins/dvi/CMakeLists.txt b/tdefile-plugins/dvi/CMakeLists.txt new file mode 100644 index 00000000..beb5d8e2 --- /dev/null +++ b/tdefile-plugins/dvi/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_dvi.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_dvi (module) ######################### + +tde_add_kpart( tdefile_dvi AUTOMOC + SOURCES tdefile_dvi.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/dvi/Makefile.am b/tdefile-plugins/dvi/Makefile.am new file mode 100644 index 00000000..116d7a0d --- /dev/null +++ b/tdefile-plugins/dvi/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for the dvi file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_dvi.h + +kde_module_LTLIBRARIES = tdefile_dvi.la + +tdefile_dvi_la_SOURCES = tdefile_dvi.cpp +tdefile_dvi_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_dvi_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdefile_dvi.pot + +services_DATA = tdefile_dvi.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/dvi/tdefile_dvi.cpp b/tdefile-plugins/dvi/tdefile_dvi.cpp new file mode 100644 index 00000000..374e5e54 --- /dev/null +++ b/tdefile-plugins/dvi/tdefile_dvi.cpp @@ -0,0 +1,150 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Matthias Witzgall <witzi@gmx.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + + +/* further informations about the dvi file format could be downloaded from: http://www.rpi.edu/~sofkam/DVI/archive/standards/dvistd0.dvi */ + +#include "tdefile_dvi.h" + +#include <kgenericfactory.h> +#include <kdebug.h> +#include <klocale.h> +#include <tdefilemetainfo.h> + +#include <tqstring.h> +#include <tqvariant.h> +#include <tqdatetime.h> +#include <tqfile.h> +#include <tqfileinfo.h> +#include <tqregexp.h> + + +// preprocessormacro K_EXPORT_COMPONENT_FACTORY loads shared library 'tdefile_dvi.so' dynamic if necessary +typedef KGenericFactory<KDviPlugin> DviFactory; +K_EXPORT_COMPONENT_FACTORY(tdefile_dvi, DviFactory("tdefile_dvi")) + +KDviPlugin::KDviPlugin (TQObject * parent, const char * name, const TQStringList & preferredItems) + : KFilePlugin(parent, name, preferredItems) +{ + kdDebug(7034) << "dvi plugin" << endl; + + // set up our mime type + KFileMimeTypeInfo * info = this->addMimeTypeInfo("application/x-dvi"); + + + KFileMimeTypeInfo::GroupInfo * group = this->addGroupInfo(info, "General", "General"); + + this->addItemInfo(group, "3_Created", i18n("Created"), TQVariant::String); + this->addItemInfo(group, "6_Comment", i18n("Comment"), TQVariant::String); + this->addItemInfo(group, "7_Pages", i18n("Pages"), TQVariant::UInt); +} + +bool KDviPlugin::readInfo (KFileMetaInfo & info, uint /* what (unused in this plugin) */) +{ + if ( info.path().isEmpty() ) + return false; + KFileMetaInfoGroup GeneralGroup = appendGroup(info, "General"); + TQFile f(info.path()); + TQFileInfo f_info; + TQ_UINT16 bytes_to_read; + TQ_UINT8 comment_length; + TQString comment; + TQ_UINT16 pages; + TQ_UINT8 buffer[270]; // buffer for reading data; no data is read with more than 270 bytes + TQ_UINT32 ptr; + int i; // running index + + // open file and try to get the comment + f.open(IO_ReadOnly); + + if ( f.isOpen() == false ){ + kdDebug(7034) << "cannot open file" << endl; + return false; + } + + f_info.setFile(f); // create fileinfoobject + bytes_to_read = TQMIN(f_info.size(), 270); // check, if the file size is smaller than 270 bytes + // (if the comment is as large as possible, we don't have to + // read more than 270 bytes) + + if ( f.readBlock((char *)buffer, bytes_to_read) != bytes_to_read ){ // cast to (char *) is necessary + kdDebug(7034) << "read error (1)" << endl; + return false; + } + + if ( (buffer[0] != 247) || (buffer[1] != 2) ){ + // magic numbers are not right + kdDebug(7034) << "wrong file format" << endl;; + return false; + } + + comment_length = buffer[14]; // set up length of comment + comment.setLength(comment_length); // used to avoid permanent reallocation when extracting the comment from buffer + + for ( i = 15; i <= 14+comment_length; ++i ) // extract comment from buffer + comment[i-15] = (char)buffer[i]; + + appendItem(GeneralGroup, "6_Comment", comment.simplifyWhiteSpace() ); + + // comment is ok, now get total number of pages + f.at( f.size() - 13); + if ( f.readBlock((char *)buffer, 13) != 13 ){ + kdDebug(7034) << "read error (2)" << endl; + return false; + } + + i = 12; // reset running index i + while ( buffer[i] == 223 ){ --i; } // skip all trailing bytes + + if ( (buffer[i] != 2) || (i > 8) || (i < 5) ){ + kdDebug(7034) << "wrong file formatx" << endl; + return false; + } + + // now we know the position of the pointer to the beginning of the postamble and we can read it + ptr = buffer[i-4]; + ptr = (ptr << 8) | buffer[i-3]; + ptr = (ptr << 8) | buffer[i-2]; + ptr = (ptr << 8) | buffer[i-1]; + + // bytes for total number of pages have a offset of 27 to the beginning of the postamble + f.at(ptr + 27); + + // now read total number of pages from file + if ( f.readBlock((char *)buffer, 2) != 2 ){ + kdDebug(7034) << "read error (3)" << endl; + return false; + } + pages = buffer[0]; + pages = (pages << 8) | buffer[1]; + + appendItem(GeneralGroup, "7_Pages", TQVariant(pages) ); + + f.close(); + + // now get and set up some basic informations about the file (same informations would be displayed, if there is no dvi-plugin) + appendItem(GeneralGroup, "1_Type", TQVariant( i18n("TeX Device Independent file") ) ); // set up type of file + + appendItem(GeneralGroup, "4_Modified", TQVariant(f_info.lastModified().toString("yyyy-MM-dd hh:mm")) ); + // ISO 8601 date format (without seconds) + + return true; +} + +#include "tdefile_dvi.moc" diff --git a/tdefile-plugins/dvi/tdefile_dvi.desktop b/tdefile-plugins/dvi/tdefile_dvi.desktop new file mode 100644 index 00000000..e3bade83 --- /dev/null +++ b/tdefile-plugins/dvi/tdefile_dvi.desktop @@ -0,0 +1,60 @@ +[Desktop Entry] +Icon= +MimeType=application/x-dvi +Name=DVI Info +Name[ar]=معلومات DVI +Name[br]=Titouroù DVI +Name[ca]=Informació de DVI +Name[cs]=DVI info +Name[cy]=Gwybodaeth DVI +Name[da]=DVI-info +Name[de]=DVI-Info +Name[el]=Πληροφορίες DVI +Name[eo]=DVI-informo +Name[es]=Info DVI +Name[et]=DVI info +Name[fa]=اطلاعات DVI +Name[fi]=DVI-tiedot +Name[fr]=Informations DVI +Name[ga]=Eolas faoi DVI +Name[gl]=Inf. DVI +Name[he]=מידע DVI +Name[hi]=DVI जानकारी +Name[hu]=DVI-jellemzők +Name[is]=DVI upplýsingar +Name[it]=Informazioni DVI +Name[ja]=DVI 情報 +Name[kk]=DVI мәліметі +Name[km]=ព័ត៌មាន DVI +Name[lt]=DVI informacija +Name[ms]=Maklumat DVI +Name[nds]=DVI-Info +Name[ne]=DVI सूचना +Name[nl]=DVI-info +Name[nn]=DVI-info +Name[pa]=DVI ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku DVI +Name[pt]=Informação do DVI +Name[pt_BR]=Informação sobre DVI +Name[ro]=Informaţii DVI +Name[ru]=Информация о DVI +Name[se]=DVI-dieđut +Name[sl]=Podatki o DVI +Name[sr]=DVI информације +Name[sr@Latn]=DVI informacije +Name[sv]=DVI-information +Name[ta]=DVI தகவல் +Name[tg]=Иттилоот оиди DVI +Name[th]=ข้อมูลแฟ้ม DVI +Name[tr]=DVI Bilgisi +Name[uk]=Інформація по DVI +Name[uz]=DVI haqida maʼlumot +Name[uz@cyrillic]=DVI ҳақида маълумот +Name[wa]=Informåcion sol documint DVI +Name[zh_CN]=DVI 信息 +Name[zh_HK]=DVI 資訊 +Name[zh_TW]=DVI 資訊 +ServiceTypes=KFilePlugin +Type=Service +X-TDE-Library=tdefile_dvi +PreferredItems=Title,Author,Subject,Creator,Producer,CreationDate,ModDate,Keywords diff --git a/tdefile-plugins/dvi/tdefile_dvi.h b/tdefile-plugins/dvi/tdefile_dvi.h new file mode 100644 index 00000000..da4bc6fe --- /dev/null +++ b/tdefile-plugins/dvi/tdefile_dvi.h @@ -0,0 +1,38 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Matthias Witzgall <witzi@gmx.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + + +#ifndef __KFILE_DVI_H__ +#define __KFILE_DVI_H__ + +#include <tdefilemetainfo.h> + +class TQStringList; + +class KDviPlugin : public KFilePlugin +{ + Q_OBJECT + +public: + KDviPlugin ( TQObject * parent, const char * name, const TQStringList & preferredItems ); + + virtual bool readInfo (KFileMetaInfo & info, uint what); +}; + +#endif diff --git a/tdefile-plugins/exr/CMakeLists.txt b/tdefile-plugins/exr/CMakeLists.txt new file mode 100644 index 00000000..284c973a --- /dev/null +++ b/tdefile-plugins/exr/CMakeLists.txt @@ -0,0 +1,38 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include( ConfigureChecks.cmake ) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} + ${OPENEXR_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_exr.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_exr (module) ######################### + +tde_add_kpart( tdefile_exr AUTOMOC + SOURCES tdefile_exr.cpp + LINK tdeio-shared ${OPENEXR_LIBRARIES} + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/exr/ConfigureChecks.cmake b/tdefile-plugins/exr/ConfigureChecks.cmake new file mode 100644 index 00000000..193173c2 --- /dev/null +++ b/tdefile-plugins/exr/ConfigureChecks.cmake @@ -0,0 +1,16 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +# OpenEXR +pkg_search_module( OPENEXR OpenEXR ) +if( NOT OPENEXR_FOUND ) + tde_message_fatal( "OpenEXR is required, but was not found on your system" ) +endif( ) diff --git a/tdefile-plugins/exr/Makefile.am b/tdefile-plugins/exr/Makefile.am new file mode 100644 index 00000000..8df4ed64 --- /dev/null +++ b/tdefile-plugins/exr/Makefile.am @@ -0,0 +1,25 @@ +## Makefile.am for EXR file meta info plugin + +KDE_CXXFLAGS = $(USE_EXCEPTIONS) + +# set the include path for X, qt and KDE +INCLUDES = -Drestrict= $(all_includes) $(EXR_FLAGS) +# INCLUDES = $(all_includes) $(EXR_FLAGS) + +# these are the headers for your project +noinst_HEADERS = tdefile_exr.h + +kde_module_LTLIBRARIES = tdefile_exr.la + +tdefile_exr_la_SOURCES = tdefile_exr.cpp +tdefile_exr_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_exr_la_LIBADD = $(LIB_KIO) $(LIB_EXR) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdefile_exr.pot + +services_DATA = tdefile_exr.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/exr/configure.in.in b/tdefile-plugins/exr/configure.in.in new file mode 100644 index 00000000..2a9ff5e5 --- /dev/null +++ b/tdefile-plugins/exr/configure.in.in @@ -0,0 +1,14 @@ +AC_ARG_WITH([openexr], + [AC_HELP_STRING([--with-openexr], + [Enable support for OpenEXR @<:@default=check@:>@])], + [], with_openexr=check) + +if test "x$with_openexr" != xno; then + KDE_FIND_LIBEXR + + if test "x$with_openexr" != xcheck && test -z "$LIB_EXR"; then + AC_MSG_ERROR([--with-openexr was given, but test for OpenEXR failed]) + fi +fi + +AM_CONDITIONAL(include_EXR_MODULES, test -n "$LIB_EXR") diff --git a/tdefile-plugins/exr/tdefile_exr.cpp b/tdefile-plugins/exr/tdefile_exr.cpp new file mode 100644 index 00000000..d8007e3d --- /dev/null +++ b/tdefile-plugins/exr/tdefile_exr.cpp @@ -0,0 +1,393 @@ +// -*- C++;indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*- +/* This file is part of the KDE project + * Copyright (C) 2003 <bradh@frogmouth.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $Id$ + */ + +#include <ImfStandardAttributes.h> +#include <ImathBox.h> +#include <ImfInputFile.h> +#include <ImfBoxAttribute.h> +#include <ImfChannelListAttribute.h> +#include <ImfCompressionAttribute.h> +#include <ImfFloatAttribute.h> +#include <ImfIntAttribute.h> +#include <ImfLineOrderAttribute.h> +#include <ImfStringAttribute.h> +#include <ImfVecAttribute.h> +#include <ImfPreviewImage.h> +#include <ImfVersion.h> +#include <ImfCRgbaFile.h> + +#include <iostream> + +#include <stdlib.h> +#include <string> + +#include <kurl.h> +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kdebug.h> + +#include <tqcstring.h> +#include <tqfile.h> +#include <tqdatetime.h> +#include <tqdict.h> +#include <tqvalidator.h> +#include <tqimage.h> + + +#include "tdefile_exr.h" +using namespace Imf; + +typedef KGenericFactory<KExrPlugin> ExrFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_exr, ExrFactory("tdefile_exr")) + +KExrPlugin::KExrPlugin(TQObject *parent, const char *name, + const TQStringList &args) + : KFilePlugin(parent, name, args) +{ + // set up our mime type + KFileMimeTypeInfo* info = addMimeTypeInfo( "image/x-exr" ); + + KFileMimeTypeInfo::GroupInfo* group = 0; + KFileMimeTypeInfo::ItemInfo* item; + + // info group + group = addGroupInfo( info, "Info", i18n("Information") ); + addItemInfo( group, "Version", i18n("Format Version"), TQVariant::Int ); + addItemInfo( group, "Tiled image", i18n("Tiled Image"), TQVariant::String ); + item = addItemInfo( group, "Dimensions", i18n("Dimensions"), TQVariant::Size ); + setHint( item, KFileMimeTypeInfo::Size ); + setUnit( item, KFileMimeTypeInfo::Pixels ); + item = addItemInfo( group, "ThumbnailDimensions", + i18n("Thumbnail Dimensions"), TQVariant::Size ); + setHint( item, KFileMimeTypeInfo::Size ); + setUnit( item, KFileMimeTypeInfo::Pixels ); + addItemInfo( group, "Comment", i18n("Comment"), TQVariant::String ); + item = addItemInfo( group, "Thumbnail", i18n("Thumbnail"), TQVariant::Image ); + setHint( item, KFileMimeTypeInfo::Thumbnail ); + + // standard attributes group + group = addGroupInfo( info, "Standard", i18n("Standard Attributes") ); + addItemInfo( group, "Owner", i18n("Owner"), TQVariant::String ); + addItemInfo( group, "Comments", i18n("Comments"), TQVariant::String ); + addItemInfo( group, "Capture Date", i18n("Capture Date"), TQVariant::String ); + item = addItemInfo( group, "UTC Offset", i18n("UTC Offset"), TQVariant::String ); + item = addItemInfo( group, "Exposure time", i18n("Exposure Time"), TQVariant::Double); + setUnit( item, KFileMimeTypeInfo::Seconds ); + item = addItemInfo( group, "Focus", i18n("Focus"), TQVariant::Double); + setSuffix( item, i18n("Metres", "m") ); + item = addItemInfo( group, "X Density", i18n("X Density"), TQVariant::Double); + setSuffix( item, i18n("Pixels Per Inch", " ppi") ); + item = addItemInfo( group, "White luminance", i18n("White Luminance"), TQVariant::Double); + setSuffix( item, i18n("Candelas per square metre", " Nits") ); + addItemInfo( group, "Longitude", i18n("Longitude"), TQVariant::String ); + addItemInfo( group, "Latitude", i18n("Latitude"), TQVariant::String ); + item = addItemInfo( group, "Altitude", i18n("Altitude"), TQVariant::String ); + setSuffix( item, i18n("Metres", "m") ); + addItemInfo( group, "ISO speed", i18n("ISO Speed"), TQVariant::Double ); + addItemInfo( group, "Aperture", i18n("Aperture"), TQVariant::Double ); + + // channel group + group = addGroupInfo( info, "Channel", i18n("Channels") ); + addItemInfo( group, "A", i18n("A"), TQVariant::String ); + addItemInfo( group, "R", i18n("R"), TQVariant::String ); + addItemInfo( group, "G", i18n("G"), TQVariant::String ); + addItemInfo( group, "B", i18n("B"), TQVariant::String ); + addItemInfo( group, "Z", i18n("Z"), TQVariant::String ); + addItemInfo( group, "NX", i18n("NX"), TQVariant::String ); + addItemInfo( group, "NY", i18n("NY"), TQVariant::String ); + addItemInfo( group, "NZ", i18n("NZ"), TQVariant::String ); + addItemInfo( group, "R", i18n("R"), TQVariant::String ); + addItemInfo( group, "U", i18n("U"), TQVariant::String ); + addItemInfo( group, "V", i18n("V"), TQVariant::String ); + addItemInfo( group, "materialID", i18n("materialID"), TQVariant::String ); + addItemInfo( group, "objectID", i18n("objectID"), TQVariant::String ); + addItemInfo( group, "renderID", i18n("renderID"), TQVariant::String ); + addItemInfo( group, "pixelCover", i18n("pixelCover"), TQVariant::String ); + addItemInfo( group, "velX", i18n("velX"), TQVariant::String ); + addItemInfo( group, "velY", i18n("velY"), TQVariant::String ); + addItemInfo( group, "packedRGBA", i18n("packedRGBA"), TQVariant::String ); + + + // technical group + group = addGroupInfo( info, "Technical", i18n("Technical Details") ); + addItemInfo( group, "Compression", i18n("Compression"), TQVariant::String ); + addItemInfo( group, "Line Order", i18n("Line Order"), TQVariant::String ); + + // 3dsMax group + // This supports a special plugin for 3D Studio Max + group = addGroupInfo( info, "3dsMax", i18n("3dsMax Details") ); + addItemInfo( group, "Local time", i18n("Local Time"), TQVariant::String ); + addItemInfo( group, "System time", i18n("System Time"), TQVariant::String ); + addItemInfo( group, "Plugin version", i18n("Plugin Version"), TQVariant::String ); + addItemInfo( group, "EXR version", i18n("EXR Version"), TQVariant::String ); + addItemInfo( group, "Computer name", i18n("Computer Name"), TQVariant::String ); +} + +TQCString doType( PixelType pt ) +{ + switch (pt) + { + case UINT: + return TQCString("32-bit unsigned integer"); + break; + case HALF: + return TQCString("16-bit floating-point"); + break; + case FLOAT: + return TQCString("32-bit floating-point"); + break; + default: + return TQCString(); + break; + } +} + +bool KExrPlugin::readInfo( KFileMetaInfo& info, uint what) +{ + try + { + InputFile in ( info.path().ascii() ); + const Header &h = in.header(); + + KFileMetaInfoGroup infogroup = appendGroup(info, "Info"); + KFileMetaInfoGroup stdgroup = appendGroup(info, "Standard"); + KFileMetaInfoGroup channelgroup = appendGroup(info, "Channel"); + KFileMetaInfoGroup techgroup = appendGroup(info, "Technical"); + KFileMetaInfoGroup threedsmaxgroup = appendGroup(info, "3dsMax"); + + appendItem( infogroup, "Version", getVersion(in.version()) ); + if (isTiled(in.version())) { + appendItem( infogroup, "Tiled image", "yes" ); + } else { + appendItem( infogroup, "Tiled image", "no" ); + } + + Imath::Box2i dw = h.dataWindow(); + appendItem( infogroup, "Dimensions", TQSize( (dw.max.x - dw.min.x + 1 ), + (dw.max.y - dw.min.y + 1 ) ) ); + + if ( h.hasPreviewImage() ) { + const PreviewImage &preview = in.header().previewImage(); + appendItem( infogroup, "ThumbnailDimensions", TQSize(preview.width(), preview.height()) ); + TQImage qpreview(preview.width(), preview.height(), 32, 0, TQImage::BigEndian); + for ( unsigned int y=0; y < preview.height(); y++ ) { + for ( unsigned int x=0; x < preview.width(); x++ ) { + const PreviewRgba &q = preview.pixels()[x+(y*preview.width())]; + qpreview.setPixel( x, y, tqRgba(q.r, q.g, q.b, q.a) ); + } + } + appendItem( infogroup, "Thumbnail", qpreview); + } + + const StringAttribute *commentSA = h.findTypedAttribute <StringAttribute> ("comment"); + if (commentSA) { + std::string commentString = commentSA->value(); + TQString qcommentString(commentString.data()); + qcommentString.setLength(commentString.size()); + appendItem( infogroup, "Comment", qcommentString ); + } + + // Standard Attributes we are interested in and can + // meaningfully represent. + if ( hasComments(h) ) { + std::string commentsString = comments(h); + TQString qcommentsString(commentsString.data()); + qcommentsString.setLength(commentsString.size()); + appendItem( stdgroup, "Comments", qcommentsString ); + } + if ( hasOwner(h) ) { + std::string ownerString = owner(h); + TQString qownerString(ownerString.data()); + qownerString.setLength(ownerString.size()); + appendItem( stdgroup, "Owner", qownerString ); + } + if ( hasCapDate(h) ) { + std::string capDateString = capDate(h); + TQString qcapDateString(capDateString.data()); + qcapDateString.setLength(capDateString.size()); + appendItem( stdgroup, "Capture Date", qcapDateString ); + } + // This define was introduced in EXR 1.6.0 +#ifndef IMF_B44_COMPRESSION + // This is the 1.4 and earlier version + if ( hasutcOffset(h) ) { +#else + // This is the 1.6.0 and later version + if ( hasUtcOffset(h) ) { +#endif + TQString UTCOffset; + if (utcOffset(h)>0.0) { + UTCOffset.append(TQString("%1").arg(utcOffset(h)/3600, 0, 'f', 1)); + UTCOffset.append(" hours behind UTC"); + } else { + UTCOffset.append(TQString("%1").arg(-1.0*utcOffset(h)/3600, 0, 'f', 1)); + UTCOffset.append(" hours ahead of UTC"); + } + appendItem( stdgroup, "UTC Offset", UTCOffset); + } + if ( hasExpTime(h) ) { + double exposureTime = expTime(h); + appendItem( stdgroup, "Exposure time", exposureTime ); + } + if ( hasFocus(h) ) { + double focusDistance = focus(h); + appendItem( stdgroup, "Focus", focusDistance ); + } + if ( hasXDensity(h) ) { + double XDensity = xDensity(h); + appendItem( stdgroup, "X Density", XDensity ); + } + if ( hasWhiteLuminance(h) ) { + double WhiteLuminance = whiteLuminance(h); + appendItem( stdgroup, "White luminance", WhiteLuminance ); + } + if ( hasLongitude(h) ) { + TQString Longitude; + if (longitude(h)<0.0) { + Longitude.append(TQString("%1").arg(-1.0*longitude(h),0,'f',3)); + Longitude.append(" deg West"); + } else { + Longitude.append(TQString("%1").arg(longitude(h),0,'f',3)); + Longitude.append(" deg East"); + } + appendItem( stdgroup, "Longitude", Longitude); + } + if ( hasLatitude(h) ) { + TQString Latitude; + if (latitude(h)<0.0) { + Latitude.append(TQString("%1").arg(-1.0*latitude(h),0,'f',3)); + Latitude.append(" deg South"); + } else { + Latitude.append(TQString("%1").arg(latitude(h),0,'f',3)); + Latitude.append(" deg North"); + } + appendItem( stdgroup, "Latitude", Latitude ); + } + if ( hasAltitude(h) ) { + double Altitude = altitude(h); + appendItem( stdgroup, "Altitude", TQString("%1").arg(Altitude,0,'f',1) ); + } + if ( hasIsoSpeed(h) ) { + double IsoSpeed = isoSpeed(h); + appendItem( stdgroup, "ISO speed", IsoSpeed ); + } + if ( hasAperture(h) ) { + double Aperture = aperture(h); + appendItem( stdgroup, "Aperture", Aperture ); + } + + for (Header::ConstIterator i = h.begin(); i != h.end(); ++i) { + const Attribute *a = &i.attribute(); + + if (const CompressionAttribute *ta = dynamic_cast <const CompressionAttribute *> (a)) { + switch ( ta->value() ) + { + case NO_COMPRESSION: + appendItem( techgroup, "Compression", i18n("No compression")); + break; + case RLE_COMPRESSION: + appendItem( techgroup, "Compression", i18n("Run Length Encoding")); + break; + case ZIPS_COMPRESSION: + appendItem( techgroup, "Compression", i18n("zip, individual scanlines")); + break; + case ZIP_COMPRESSION: + appendItem( techgroup, "Compression", i18n("zip, multi-scanline blocks")); + break; + case PIZ_COMPRESSION: + appendItem( techgroup, "Compression", i18n("piz compression")); + break; + default: + break; + } + } else if (const LineOrderAttribute *ta = dynamic_cast <const LineOrderAttribute *> (a)) { + switch (ta->value()) + { + case INCREASING_Y: + appendItem( techgroup, "Line Order", i18n("increasing Y")); + break; + case DECREASING_Y: + appendItem( techgroup, "Line Order", i18n("decreasing Y")); + break; + default: + break; + }; + } else if (const ChannelListAttribute *ta = dynamic_cast <const ChannelListAttribute *> (a)) { + + for (ChannelList::ConstIterator i = ta->value().begin(); i != ta->value().end(); ++i) + { + appendItem( channelgroup, i.name(), doType(i.channel().type) ); + } + } + } + + // This section deals with some special case stuff for a 3D Studio Max + // plugin from Splutterfish. The weird construction is an + // attempt to to deal with class conversion. C++ string handling + // without TQt is a pain... + const StringAttribute *ver3DSM = h.findTypedAttribute <StringAttribute> ("version3dsMax"); + if (ver3DSM) { + std::string ver3DSMstring = ver3DSM->value(); + TQString qver3DSMstring(ver3DSMstring.data()); + qver3DSMstring.setLength(ver3DSMstring.size()); + appendItem( threedsmaxgroup, "Plugin version", qver3DSMstring ); + } + const StringAttribute *verEXR = h.findTypedAttribute <StringAttribute> ("versionEXR"); + if (verEXR) { + std::string verEXRstring = verEXR->value(); + TQString qverEXRstring(verEXRstring.data()); + qverEXRstring.setLength(verEXRstring.size()); + appendItem( threedsmaxgroup, "EXR version", TQString( verEXRstring.data() ) ); + } + const StringAttribute *localTime = h.findTypedAttribute <StringAttribute> ("localTime"); + if (localTime) { + std::string localTimeString = localTime->value(); + TQString qlocalTimeString(localTimeString.data()); + qlocalTimeString.setLength(localTimeString.size()); + appendItem( threedsmaxgroup, "Local time", qlocalTimeString ); + } + const StringAttribute *systemTime = h.findTypedAttribute <StringAttribute> ("systemTime"); + if (systemTime) { + std::string systemTimeString = systemTime->value(); + TQString qsystemTimeString(systemTimeString.data()); + qsystemTimeString.setLength(systemTimeString.size()); + appendItem( threedsmaxgroup, "System time", qsystemTimeString ); + } + const StringAttribute *computerName = h.findTypedAttribute <StringAttribute> ("computerName"); + if (computerName) { + std::string computerNameString = computerName->value(); + TQString qcomputerNameString(computerNameString.data()); + qcomputerNameString.setLength(computerNameString.size()); + appendItem( threedsmaxgroup, "Computer name", qcomputerNameString ); + } + + return true; + } + catch (const std::exception &e) + { + kdDebug(0) << e.what() << endl; + return false; + } +} + +#include "tdefile_exr.moc" diff --git a/tdefile-plugins/exr/tdefile_exr.desktop b/tdefile-plugins/exr/tdefile_exr.desktop new file mode 100644 index 00000000..e9736d67 --- /dev/null +++ b/tdefile-plugins/exr/tdefile_exr.desktop @@ -0,0 +1,57 @@ +[Desktop Entry] +Type=Service +Name=EXR Info +Name[br]=Titouroù EXR +Name[ca]=Informació EXR +Name[cs]=EXR info +Name[cy]=Gwybodaeth EXR +Name[da]=EXR-Info +Name[de]=EXR-Info +Name[el]=Πληροφορίες EXR +Name[eo]=EXR-informo +Name[es]=Info EXR +Name[et]=EXR info +Name[fa]=اطلاعات EXR +Name[fi]=EXR-tiedot +Name[fr]=Informations EXR +Name[ga]=Eolas faoi EXR +Name[gl]=Inf. EXR +Name[he]=מידע EXR +Name[hu]=EXR-jellemzők +Name[is]=EXR upplýsingar +Name[it]=Informazioni EXR +Name[ja]=EXR 情報 +Name[kk]=EXR мәліметі +Name[km]=ព័ត៌មាន EXR +Name[lt]=EXR informacija +Name[ms]=Maklumat EXR +Name[nds]=EXR-Info +Name[ne]=EXR सूचना +Name[nl]=EXR-info +Name[nn]=EXR-info +Name[pa]=EXR ਜਾਣਕਾਰੀ +Name[pl]=Informacja EXR +Name[pt]=Informação do EXR +Name[pt_BR]=Informação sobre EXR +Name[ro]=Informaţii EXR +Name[ru]=Информация о EXR +Name[se]=EXR-dieđut +Name[sl]=Podatki o EXR +Name[sr]=EXR информације +Name[sr@Latn]=EXR informacije +Name[sv]=EXR-information +Name[ta]=EXR தகவல் +Name[tg]=Иттилоот оиди EXR +Name[th]=ข้อมูลแฟ้ม EXR +Name[tr]=EXR Bilgisi +Name[uk]=Інформація по EXR +Name[uz]=EXR haqida maʼlumot +Name[uz@cyrillic]=EXR ҳақида маълумот +Name[zh_CN]=EXR 信息 +Name[zh_HK]=EXR 資訊 +Name[zh_TW]=EXR 資訊 +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_exr +MimeType=image/x-exr +PreferredGroups=Info,Standard,Channels,Technical,3dsMax +PreferredItems=Dimensions,Thumbnail,ThumbnailDimensions,Version,Comments,Owner,Latitude,Longitude,Altitude,Capture Date,UTC Offset diff --git a/tdefile-plugins/exr/tdefile_exr.h b/tdefile-plugins/exr/tdefile_exr.h new file mode 100644 index 00000000..2fd23434 --- /dev/null +++ b/tdefile-plugins/exr/tdefile_exr.h @@ -0,0 +1,40 @@ +/* This file is part of the KDE project + * Copyright (C) 2003 <bradh@frogmouth.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $Id$ + */ + +#ifndef __KFILE_EXR_H__ +#define __KFILE_EXR_H__ + +#include <tdefilemetainfo.h> +#include <kurl.h> + +class TQStringList; + +class KExrPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KExrPlugin( TQObject *parent, const char *name, const TQStringList& preferredItems ); + + virtual bool readInfo( KFileMetaInfo& info, uint ); +}; + +#endif diff --git a/tdefile-plugins/gif/CMakeLists.txt b/tdefile-plugins/gif/CMakeLists.txt new file mode 100644 index 00000000..8e71efbf --- /dev/null +++ b/tdefile-plugins/gif/CMakeLists.txt @@ -0,0 +1,34 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_gif.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_gif (module) ######################### +tde_add_kpart( tdefile_gif AUTOMOC + SOURCES tdefile_gif.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/gif/Makefile.am b/tdefile-plugins/gif/Makefile.am new file mode 100644 index 00000000..d6f8d82c --- /dev/null +++ b/tdefile-plugins/gif/Makefile.am @@ -0,0 +1,24 @@ +## Makefile.am for gif file meta info plugin + +KDE_CXXFLAGS = $(USE_EXCEPTIONS) + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_gif.h + +kde_module_LTLIBRARIES = tdefile_gif.la + +tdefile_gif_la_SOURCES = tdefile_gif.cpp +tdefile_gif_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_gif_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdefile_gif.pot + +services_DATA = tdefile_gif.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/gif/README b/tdefile-plugins/gif/README new file mode 100644 index 00000000..811cbb28 --- /dev/null +++ b/tdefile-plugins/gif/README @@ -0,0 +1,10 @@ +The original README for this file read: +<quote> +Note: Development of this module has been suspended. +Please feel free to contact me, and pick it up. All I ask +is that you preserve both command line and tdefile abilities. Thanks. +bryce@obviously.com +</quote> + +I contacted Bryce, but received no response. The command line code +is unchanged - I just fixed the tdefile code to work, read only. diff --git a/tdefile-plugins/gif/gif-info.1 b/tdefile-plugins/gif/gif-info.1 new file mode 100644 index 00000000..6c36b1c4 --- /dev/null +++ b/tdefile-plugins/gif/gif-info.1 @@ -0,0 +1,25 @@ +.TH gif-info 1 "April 2002" + +.SH NAME +gif-info \- reads gif image info or sets comment. + +.SH SYNOPSIS +.B gif-info +.RB <filename> +['Comment'] + +.SH DESCRIPTION +.LP +.B gif-info +displays information about the given gif (Graphic Interchange Format) image. If a comment is specified, the comment is set instead. +.PP +Write a empty comment ('') to delete the comment block. +.PP +The GIF standard allows any number of 256 byte comment blocks in an image file, but most implementations (including this one) restrict you to just one block. The GIF standard restricts comment blocks to "7 Bit ASCII", but this is widely ignored. You are welcome to store text in your own native language, and are especially encouraged to use comments in utf-8 unicode format. + +.SH "SEE ALSO" +.BR wrjpgcom (1) +.BR rdjpgcom (1) + +.SH AUTHOR +Bryce Nesbitt diff --git a/tdefile-plugins/gif/gif-info.c b/tdefile-plugins/gif/gif-info.c new file mode 100644 index 00000000..2f64a2f2 --- /dev/null +++ b/tdefile-plugins/gif/gif-info.c @@ -0,0 +1,561 @@ +/* +** $Id$ +** +** Minimal GIF parser, for use in extracting and setting metadata. +** Modified for standalone & KDE calling by Bryce Nesbitt +** +** TODO: +** Support gif comments that span more than one comment block. +** Verify that Unicode utf-8 is fully unmolested by this code. +** Implement gif structure verifier. +** +** Based on: GIFtrans v1.12.2 +** Copyright (C) 24.2.94 by Andreas Ley <ley@rz.uni-karlsruhe.de> +** +******************************************************************************* +** +** Original distribution site is +** ftp://ftp.rz.uni-karlsruhe.de/pub/net/www/tools/giftrans/giftrans.c +** A man-page by knordlun@fltxa.helsinki.fi (Kai Nordlund) is at +** ftp://ftp.rz.uni-karlsruhe.de/pub/net/www/tools/giftrans/giftrans.1 +** An online version by taylor@intuitive.com (Dave Taylor) is at +** http://www.intuitive.com/coolweb/Addons/giftrans-doc.html +** To compile for MS-DOS or OS/2, you need getopt: +** ftp://ftp.rz.uni-karlsruhe.de/pub/net/www/tools/giftrans/getopt.c +** MS-DOS executable can be found at +** ftp://ftp.rz.uni-karlsruhe.de/pub/net/www/tools/giftrans/giftrans.exe +** OS/2 executable can be found at +** ftp://ftp.rz.uni-karlsruhe.de/pub/net/www/tools/giftrans/giftrans.os2.exe +** A template rgb.txt for use with the MS-DOS version can be found at +** ftp://ftp.rz.uni-karlsruhe.de/pub/net/www/tools/giftrans/rgb.txt +** Additional info can be found on +** http://melmac.corp.harris.com/transparent_images.html +** +** The GIF file format is documented in +** ftp://ftp.uu.net/doc/literary/obi/Standards/Graphics/Formats/gif89a.doc.Z +** A good quick reference is at: +** http://www.goice.co.jp/member/mo/formats/gif.html +** +******************************************************************************* +** +** 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 <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> + +#define STANDALONE_COMPILE + +extern int set_gif_comment( const char * original_filename, char * comment ); +extern void * get_gif_info( const char * original_filename ); +extern int validate_gif_structure( const char * original_filename ); +int giftrans( FILE * src, FILE * dest); + +#define WARNING_GARBAGE 1 /* Original file had some unspecified content */ +#define ERROR_NOT_A_JPEG 5 /* Original file not a proper jpeg (must be 1st) */ +#define ERROR_TEMP_FILE 6 /* Problem writing temporay file */ +#define ERROR_SCREWUP 7 /* Original file is now damaged. Ooops. */ +#define ERROR_PREMATURE_EOF 8 /* Unexpected end of file */ +#define ERROR_BAD_MARKER 9 /* Marker with illegal length */ +#define ERROR_MARKER_ORDER 10 /* File seems to be mixed up */ + +/*****************************************************************************/ +#ifndef FALSE +#define FALSE (0) /* This is the naked Truth */ +#define TRUE (1) /* and this is the Light */ +#endif + +#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ +#define READ_BINARY "r" +#define WRITE_BINARY "w" +#else +#ifdef VMS /* VMS is very nonstandard */ +#define READ_BINARY "rb", "ctx=stm" +#define WRITE_BINARY "wb", "ctx=stm" +#else /* standard ANSI-compliant case */ +#define READ_BINARY "rb" +#define WRITE_BINARY "wb" +#endif +#endif + +#define SUCCESS (0) +#define FAILURE (1) + +static char skipcomment,list,verbose,output,debug; +char *global_comment; +static long int pos; + +static char true[] = "True"; +static char false[] = "False"; +static char id[] = "$Id$"; + +/*****************************************************************************/ + +#define readword(buffer) ((buffer)[0]+256*(buffer)[1]) +#define readflag(buffer) ((buffer)?true:false) +#define hex(c) ('a'<=(c)&&(c)<='z'?(c)-'a'+10:'A'<=(c)&&(c)<='Z'?(c)-'A'+10:(c)-'0') + +void dump(adr,data,len) +long int adr; +unsigned char *data; +size_t len; +{ + int i; + + while (len>0) { + (void)fprintf(stderr,"%08lx:%*s",adr,(int)((adr%16)*3+(adr%16>8?1:0)),""); + for (i=adr%16;i<16&&len>0;i++,adr++,data++,len--) + (void)fprintf(stderr,"%s%02x",i==8?" ":" ",*data); + (void)fprintf(stderr,"\n"); + } +} + +void writedata(dest,data,len) +FILE *dest; +unsigned char *data; +size_t len; +{ + unsigned char size; + + while (len) { + size=len<256?len:255; + (void)fwrite((void *)&size,1,1,dest); + (void)fwrite((void *)data,(size_t)size,1,dest); + data+=size; + len-=size; + } + size=0; + (void)fwrite((void *)&size,1,1,dest); +} + +void skipdata(src) +FILE *src; +{ + unsigned char size,buffer[256]; + + do { + pos=ftell(src); + (void)fread((void *)&size,1,1,src); + if (debug) + dump(pos,&size,1); + if (debug) { + pos=ftell(src); + (void)fread((void *)buffer,(size_t)size,1,src); + dump(pos,buffer,(size_t)size); + } + else + (void)fseek(src,(long int)size,SEEK_CUR); + } while (!feof(src)&&size>0); +} + +void transblock(src,dest) +FILE *src; +FILE *dest; +{ + unsigned char size,buffer[256]; + + pos=ftell(src); + (void)fread((void *)&size,1,1,src); + if (debug) + dump(pos,&size,1); + if (output) + (void)fwrite((void *)&size,1,1,dest); + pos=ftell(src); + (void)fread((void *)buffer,(size_t)size,1,src); + if (debug) + dump(pos,buffer,(size_t)size); + if (output) + (void)fwrite((void *)buffer,(size_t)size,1,dest); +} + +void dumpcomment(src) +FILE *src; +{ + unsigned char size,buffer[256]; + size_t i; + + pos=ftell(src); + (void)fread((void *)&size,1,1,src); + if (debug) + dump(pos,&size,1); + (void)fread((void *)buffer,(size_t)size,1,src); + if (debug) + dump(pos+1,buffer,(size_t)size); + for (i=0; i<(size_t)size; i++) + { + if ( buffer[i] >= 0x20 || buffer[i] == '\t' || + buffer[i] =='\r' || buffer[i] == '\n') + (void)putc(buffer[i],stderr); + else + (void)fprintf(stderr,"\\%03o",buffer[i]); + } + (void)fseek(src,(long int)pos,SEEK_SET); +} + +void transdata(src,dest) +FILE *src; +FILE *dest; +{ + unsigned char size,buffer[256]; + + do { + pos=ftell(src); + (void)fread((void *)&size,1,1,src); + if (debug) + dump(pos,&size,1); + if (output) + (void)fwrite((void *)&size,1,1,dest); + pos=ftell(src); + (void)fread((void *)buffer,(size_t)size,1,src); + if (debug) + dump(pos,buffer,(size_t)size); + if (output) + (void)fwrite((void *)buffer,(size_t)size,1,dest); + } while (!feof(src)&&size>0); +} + + +/*****************************************************************************/ + +int giftrans(src,dest) +FILE *src; +FILE *dest; +{ + unsigned char buffer[3*256],lsd[7],gct[3*256]; + unsigned int cnt,cols,size,gct_size; + + /* Header */ + pos=ftell(src); + (void)fread((void *)buffer,6,1,src); + if (strncmp((char *)buffer,"GIF",3)) { + (void)fprintf(stderr,"Not GIF file!\n"); + return(1); + } + if (verbose && debug) { + buffer[6]='\0'; + (void)fprintf(stderr,"Header: \"%s\"\n",buffer); + } + if (debug) + dump(pos,buffer,6); + if (output) { + (void)fwrite((void *)buffer,6,1,dest); + } + + /* Logical Screen Descriptor */ + pos=ftell(src); + (void)fread((void *)lsd,7,1,src); + if (verbose) { + //(void)fprintf(stderr,"Logical Screen Descriptor:\n"); + (void)fprintf(stderr,"Size : %dx%d pixels\n",readword(lsd), readword(lsd+2)); + //(void)fprintf(stderr,"Global Color Table Flag: %s\n",readflag(lsd[4]&0x80)); + (void)fprintf(stderr,"Depth : %d bits\n",(lsd[4]&0x70>>4)+1); + //if (lsd[4]&0x80) { + // (void)fprintf(stderr,"\tSort Flag: %s\n",readflag(lsd[4]&0x8)); + // (void)fprintf(stderr,"\tSize of Global Color Table: %d colors\n",2<<(lsd[4]&0x7)); + // (void)fprintf(stderr,"\tBackground Color Index: %d\n",lsd[5]); + //} + if (lsd[6]) + (void)fprintf(stderr,"Pixel Aspect Ratio: %d (Aspect Ratio %f)\n",lsd[6],((double)lsd[6]+15)/64); + } + if (debug) + dump(pos,lsd,7); + if (output) + (void)fwrite((void *)lsd,7,1,dest); + + /* Global Color Table */ + if (lsd[4]&0x80) { + gct_size=2<<(lsd[4]&0x7); + pos=ftell(src); + (void)fread((void *)gct,gct_size,3,src); + if (output) + (void)fwrite((void *)gct,gct_size,3,dest); + } + + do { + pos=ftell(src); + (void)fread((void *)buffer,1,1,src); + switch (buffer[0]) { + case 0x2c: /* Image Descriptor */ + if (verbose && debug) + (void)fprintf(stderr,"Image Descriptor:\n"); + (void)fread((void *)(buffer+1),9,1,src); + if (debug) + dump(pos,buffer,10); + if (output) + (void)fwrite((void *)buffer,10,1,dest); + /* Local Color Table */ + if (buffer[8]&0x80) { + size=2<<(buffer[8]&0x7); + pos=ftell(src); + (void)fread((void *)buffer,size,3,src); + if (verbose && debug) { + (void)fprintf(stderr,"Local Color Table:\n"); + for(cnt=0;cnt<size;cnt++) + (void)fprintf(stderr,"\tColor %d: Red %d, Green %d, Blue %d\n",cnt,buffer[3*cnt],buffer[3*cnt+1],buffer[3*cnt+2]); + } + if (debug) + dump(pos,buffer,size*3); + if (output) + (void)fwrite((void *)buffer,size,3,dest); + } + /* Table Based Image Data */ + pos=ftell(src); + (void)fread((void *)buffer,1,1,src); + if (verbose && debug) { + (void)fprintf(stderr,"Table Based Image Data:\n"); + (void)fprintf(stderr,"\tLZW Minimum Code Size: 0x%02x\n",buffer[0]); + } + if (debug) + dump(pos,buffer,1); + if (output) + (void)fwrite((void *)buffer,1,1,dest); + transdata(src,dest); + break; + case 0x21: /* Extension */ + (void)fread((void *)(buffer+1),1,1,src); + switch (buffer[1]) { + case 0xfe: /* Comment Extension */ + if (verbose) + { + (void)fprintf(stderr,"Comment: "); + dumpcomment(src); + (void)fprintf(stderr,"\n"); + } + if (debug) + dump(pos,buffer,2); + if (skipcomment) + skipdata(src); + else { + if (output) + (void)fwrite((void *)buffer,2,1,dest); + transdata(src,dest); + } + break; + case 0x01: /* Plain Text Extension */ + case 0xf9: /* Graphic Control Extension */ + case 0xff: /* Application Extension */ + default: + if (verbose && debug) + (void)fprintf(stderr,"Extension type: 0x%02x\n",buffer[1]); + if (debug) + dump(pos,buffer,2); + if (output) + (void)fwrite((void *)buffer,2,1,dest); + transblock(src,dest); + transdata(src,dest); + break; + } + break; + case 0x3b: /* Trailer (write comment just before here) */ + if (verbose && debug) + (void)fprintf(stderr,"Trailer %o\n", pos); + if (debug) + dump(pos,buffer,1); + if (global_comment && *global_comment && output) { + (void)fputs("\041\376",dest); + writedata(dest,(unsigned char *)global_comment,strlen(global_comment)); + } + if (output) + (void)fwrite((void *)buffer,1,1,dest); + break; + default: + (void)fprintf(stderr,"0x%08lx: Error, unknown block 0x%02x!\n",ftell(src)-1,buffer[0]); + if (debug) + dump(pos,buffer,1); + return(1); + } + } while (buffer[0]!=0x3b&&!feof(src)); + return(buffer[0]==0x3b?SUCCESS:FAILURE); +} + + +/****************************************************************************/ +extern int validate_gif_structure( const char * original_filename ) +{ +FILE * infile; +int rc; + + if ((infile = fopen(original_filename, READ_BINARY)) == NULL) { + fprintf(stderr, "can't open gif image '%s'\n", original_filename); + return( 1 ); + } + output = FALSE; + verbose = FALSE; + debug = FALSE; + skipcomment = FALSE; + rc = giftrans( infile, NULL ); + fclose( infile ); + return( rc ); +} + + +/****************************************************************************/ +extern void * get_gif_info( const char * original_filename ) +{ +FILE * infile; + + if ((infile = fopen(original_filename, READ_BINARY)) == NULL) { + fprintf(stderr, "can't open gif image '%s'\n", original_filename); + return( NULL ); + } + + output = FALSE; + verbose = TRUE; + debug = FALSE; + skipcomment = FALSE; + giftrans( infile, NULL ); + return( NULL ); +} + + +/***************************************************************************** + Modify the file in place, but be paranoid and safe about it. + It's worth a few extra CPU cycles to make sure we never + destory an original image: + + 1) Validate the input file. + 2) Open a temporary file in same directory (filenameXX). + 3) Copy the data, writing a new comment block. + 4) Sync everything to disc. + 5) Validate the temporary file. + 6) Move the temporary file over the original. +*/ +extern int set_gif_comment( const char * original_filename, char * comment ) +{ +int i; +int rc; +char * temp_filename; +int temp_filename_length; +struct stat statbuf; +FILE * infile; +FILE * outfile; + + + /* + * Make sure we're dealing with a proper input file. Safety first! + */ + if( validate_gif_structure( original_filename ) ) { + fprintf(stderr, "error validating gif image '%s'\n", original_filename); + return(ERROR_NOT_A_JPEG); + } + + /* Get a unique temporary file in the same directory. Hopefully + * if things go wrong, this file will still be left for recovery purposes. + * + * NB: I hate these stupid unsafe string functions in C... + */ + outfile = NULL; + temp_filename_length = strlen( original_filename) + 4; + temp_filename = (char *)calloc( temp_filename_length, 1 ); + for( i=0; i<10; i++ ) { + snprintf( temp_filename, temp_filename_length, "%s%d", original_filename, i ); + if( (stat( temp_filename, &statbuf )) && (outfile = fopen(temp_filename, WRITE_BINARY)) ) { + //fprintf(stderr, "opened temporary file '%s'\n", temp_filename); + break; + } + } + if( !outfile ) { + fprintf(stderr, "failed opening temporary file '%s'\n", temp_filename); + return(ERROR_TEMP_FILE); + } + + if ((infile = fopen(original_filename, READ_BINARY)) == NULL) { + fclose( outfile ); + fprintf(stderr, "can't open gif image '%s'\n", original_filename); + return(ERROR_NOT_A_JPEG); + } + /* Let's do it */ + output = TRUE; + verbose = FALSE; + debug = FALSE; + skipcomment = TRUE; + global_comment = comment; + rc = giftrans( infile, outfile ); + fclose( infile ); + fsync( fileno( outfile) ); /* Flush it to disk. IMPORTANT!! */ + /* We really should also flush the directory */ + + /* If everything is OK, and if the new file validates, move + it over the top of the original */ + if ( fclose( outfile ) || validate_gif_structure( temp_filename ) ) { + fprintf(stderr, "error in temporary file '%s'\n", temp_filename); + return(ERROR_TEMP_FILE); + } + if( rc ) { + unlink( temp_filename ); + return( rc ); + } + if( rename( temp_filename, original_filename ) ) { + fprintf(stderr, "error renaming '%s' to '%s'\n", temp_filename, original_filename); + return(ERROR_TEMP_FILE); + } + + return(0); +} + + +/*****************************************************************************/ +#ifdef STANDALONE_COMPILE +int +main (int argc, char **argv) +{ + char * progname; + char * filename; + char * comment; + FILE * fp; + int error; + + /* Process command line arguments... */ + progname = argv[0]; + if (progname == NULL || progname[0] == 0) + progname = "gif-info"; /* in case C library doesn't provide it */ + if( argc < 2 || argc > 3) { + fprintf(stderr, "Usage: %s <filename> [\"<comment>\"]\nReads gif image info or sets comment.\n", progname); + return(5); + } + filename = argv[1]; + comment = argv[2]; + + + /* Check if file is readable... */ + if ((fp = fopen(filename, READ_BINARY)) == NULL) { + fprintf(stderr, "Error: Can't open file '%s'\n", filename); + return(5); + } + fclose(fp); + + /* Check if we really have a commentable image file here... */ + if( validate_gif_structure( filename ) ) { + fprintf(stderr, "Error: error parsing file '%s' as a gif image\n", filename); + return(5); + } + + if( argc == 2 ) { + get_gif_info( filename ); + } + else { + set_gif_comment( filename, comment ); + } + + return( 0 ); +} +#endif + diff --git a/tdefile-plugins/gif/tdefile_gif.cpp b/tdefile-plugins/gif/tdefile_gif.cpp new file mode 100644 index 00000000..9cc522dc --- /dev/null +++ b/tdefile-plugins/gif/tdefile_gif.cpp @@ -0,0 +1,122 @@ +/* + * This file is part of the KDE project, added by Bryce Nesbitt + * + * This is a plugin for Konqeror/KFile which processes 'extra' information + * contained in a .gif image file (In particular the comment, and resolution). + * + ************************************** + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include <stdlib.h> +#include "tdefile_gif.h" + +#include <kurl.h> +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kdebug.h> + +#include <tqcstring.h> +#include <tqfile.h> +#include <tqdatetime.h> +#include <tqdict.h> +#include <tqvalidator.h> +#include <tqimage.h> + +typedef KGenericFactory<KGifPlugin> GifFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_gif, GifFactory("tdefile_gif")) + +KGifPlugin::KGifPlugin(TQObject *parent, const char *name, + const TQStringList &args) + : KFilePlugin(parent, name, args) +{ + kdDebug(7034) << "gif KFileMetaInfo plugin\n"; + + KFileMimeTypeInfo* info = addMimeTypeInfo( "image/gif" ); + + KFileMimeTypeInfo::GroupInfo* group = 0L; + + group = addGroupInfo(info, "General", i18n("General")); + + KFileMimeTypeInfo::ItemInfo* item; + + item = addItemInfo(group, "Version", i18n("Version"), TQVariant::String); + + item = addItemInfo( group, "Dimensions", i18n("Dimensions"), TQVariant::Size ); + setHint( item, KFileMimeTypeInfo::Size ); + setUnit( item, KFileMimeTypeInfo::Pixels ); + + item = addItemInfo(group, "BitDepth", i18n("Bit Depth"), TQVariant::Int); + setUnit(item, KFileMimeTypeInfo::BitsPerPixel); + +} + +bool KGifPlugin::readInfo( KFileMetaInfo& info, uint what ) +{ + Q_UNUSED( what ); + + kdDebug(7034) << "gif KFileMetaInfo readInfo\n"; + + TQFile file(info.path()); + + if (!file.open(IO_ReadOnly)) { + kdDebug(7034) << "Couldn't open " << TQFile::encodeName(info.path()).data() << endl; + return false; + } + + TQDataStream fstream(&file); + + bool isGIF87a = false; + char magic[7]; + TQ_UINT16 width = 0; + TQ_UINT16 height = 0; + TQ_UINT8 miscInfo = 0; + + fstream.readRawBytes( magic, 6 ); + magic[6] = 0x00; // null terminate + + // I have special requirements... + fstream.setByteOrder( TQDataStream::LittleEndian ); + fstream >> width; + fstream >> height; + fstream >> miscInfo; + + KFileMetaInfoGroup group = appendGroup(info, "General"); + + if ( 0 == strncmp( magic, "GIF89a", 6 ) ) { + appendItem( group, "Version", i18n("GIF Version 89a") ); + } else if ( 0 == strncmp( magic, "GIF87a", 6 ) ) { + appendItem( group, "Version", i18n("GIF Version 87a") ); + isGIF87a = true; + } else { + appendItem( group, "Version", i18n("Unknown") ); + } + + appendItem( group, "Dimensions", TQSize(width, height) ); + + if ( isGIF87a ) { + appendItem( group, "BitDepth", ( (miscInfo & 0x07) + 1) ); + } + + file.close(); + + return true; +} + +#include "tdefile_gif.moc" diff --git a/tdefile-plugins/gif/tdefile_gif.desktop b/tdefile-plugins/gif/tdefile_gif.desktop new file mode 100644 index 00000000..d6e3bfb3 --- /dev/null +++ b/tdefile-plugins/gif/tdefile_gif.desktop @@ -0,0 +1,65 @@ +[Desktop Entry] +Type=Service +Name=GIF Info +Name[af]=Gif Inligting +Name[ar]=معلومات GIF +Name[br]=Titouroù GIF +Name[ca]=Informació de GIF +Name[cs]=GIF info +Name[cy]=Gwybodaeth GIF +Name[da]=GIF-info +Name[de]=GIF-Info +Name[el]=Πληροφορίες GIF +Name[eo]=GIF-informo +Name[es]=Info GIF +Name[et]=GIF info +Name[fa]=اطلاعات GIF +Name[fi]=GIF-tiedot +Name[fr]=Informations GIF +Name[ga]=Eolas faoi GIF +Name[gl]=Inf. Gif +Name[he]=מידע GIF +Name[hi]=GIF जानकारी +Name[hr]=GIF Informacije +Name[hu]=GIF-jellemzők +Name[is]=GIF upplýsingar +Name[it]=Informazioni GIF +Name[ja]=GIF 情報 +Name[kk]=GIF мәліметі +Name[km]=ព័ត៌មាន GIF +Name[lt]=GIF informacija +Name[ms]=Maklumat GIF +Name[nds]=GIF-Info +Name[ne]=GIF सूचना +Name[nl]=GIF-info +Name[nn]=GIF-info +Name[nso]=Tshedimoso ya GIF +Name[pa]=GIF ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku GIF +Name[pt]=Informação do GIF +Name[pt_BR]=Informação sobre GIF +Name[ro]=Informaţii GIF +Name[ru]=Информация о GIF +Name[se]=GIF-dieđut +Name[sl]=Podatki o GIF +Name[sr]=GIF информације +Name[sr@Latn]=GIF informacije +Name[sv]=Gif-information +Name[ta]=GIF தகவல் +Name[tg]=Иттилоот оиди GIF +Name[th]=ข้อมูลแฟ้ม GIF +Name[tr]=GIF Bilgisi +Name[uk]=Інформація по GIF +Name[uz]=GIF haqida maʼlumot +Name[uz@cyrillic]=GIF ҳақида маълумот +Name[ven]=Mafhungo a GIF +Name[wa]=Informåcion sol imådje GIF +Name[xh]=Ulwazi lwe GIF +Name[zh_CN]=GIF 信息 +Name[zh_HK]=GIF 資訊 +Name[zh_TW]=GIF 資訊 +Name[zu]=Ulwazi lwe-GIF +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_gif +MimeType=image/gif +PreferredItems=Comment,Resolution diff --git a/tdefile-plugins/gif/tdefile_gif.h b/tdefile-plugins/gif/tdefile_gif.h new file mode 100644 index 00000000..37588e7a --- /dev/null +++ b/tdefile-plugins/gif/tdefile_gif.h @@ -0,0 +1,38 @@ +/* This file is part of the KDE project + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_GIF_H__ +#define __KFILE_GIF_H__ + +#include <tdefilemetainfo.h> +#include <kurl.h> + +class TQStringList; + +class KGifPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KGifPlugin( TQObject *parent, const char *name, const TQStringList& args ); + + virtual bool readInfo ( KFileMetaInfo& info, uint what ); +}; + +#endif diff --git a/tdefile-plugins/ico/CMakeLists.txt b/tdefile-plugins/ico/CMakeLists.txt new file mode 100644 index 00000000..54d87add --- /dev/null +++ b/tdefile-plugins/ico/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_ico.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_ico (module) ######################## + +tde_add_kpart( tdefile_ico AUTOMOC + SOURCES tdefile_ico.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/ico/Makefile.am b/tdefile-plugins/ico/Makefile.am new file mode 100644 index 00000000..e95cf924 --- /dev/null +++ b/tdefile-plugins/ico/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for ico file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_ico.h + +kde_module_LTLIBRARIES = tdefile_ico.la + +tdefile_ico_la_SOURCES = tdefile_ico.cpp +tdefile_ico_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_ico_la_LIBADD = $(LIB_KSYCOCA) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) tdefile_ico.cpp -o $(podir)/tdefile_ico.pot + +services_DATA = tdefile_ico.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/ico/tdefile_ico.cpp b/tdefile-plugins/ico/tdefile_ico.cpp new file mode 100644 index 00000000..273a5e18 --- /dev/null +++ b/tdefile-plugins/ico/tdefile_ico.cpp @@ -0,0 +1,148 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Shane Wright <me@shanewright.co.uk> + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include <config.h> +#include "tdefile_ico.h" + +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kstringvalidator.h> +#include <kdebug.h> + +#include <tqdict.h> +#include <tqvalidator.h> +#include <tqcstring.h> +#include <tqfile.h> +#include <tqdatetime.h> + +#if !defined(__osf__) +#include <inttypes.h> +#else +typedef unsigned long uint32_t; +typedef unsigned short uint16_t; +typedef unsigned char uint8_t; +#endif + +typedef KGenericFactory<KIcoPlugin> IcoFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_ico, IcoFactory( "tdefile_ico" )) + +KIcoPlugin::KIcoPlugin(TQObject *parent, const char *name, + const TQStringList &args) + + : KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( "image/x-ico" ); + + KFileMimeTypeInfo::GroupInfo* group = 0L; + + group = addGroupInfo(info, "Technical", i18n("Technical Details")); + + KFileMimeTypeInfo::ItemInfo* item; + + item = addItemInfo(group, "Number", i18n("Number of Icons"), TQVariant::Int); + + item = addItemInfo(group, "Dimensions", i18n("Dimensions"), TQVariant::Size); + item = addItemInfo(group, "Colors", i18n("Colors"), TQVariant::Int); + + item = addItemInfo(group, "DimensionsM", i18n("Dimensions (1st icon)"), TQVariant::Size); + item = addItemInfo(group, "ColorsM", i18n("Colors (1st icon)"), TQVariant::Int); +} + + +bool KIcoPlugin::readInfo( KFileMetaInfo& info, uint what) +{ + + + TQFile file(info.path()); + + if (!file.open(IO_ReadOnly)) + { + kdDebug(7034) << "Couldn't open " << TQFile::encodeName(info.path()).data() << endl; + return false; + } + + TQDataStream dstream(&file); + + // ICO files are little-endian + dstream.setByteOrder(TQDataStream::LittleEndian); + + + // read the beginning of the file and make sure it looks ok + uint16_t ico_reserved; + uint16_t ico_type; + uint16_t ico_count; + + dstream >> ico_reserved; + dstream >> ico_type; + dstream >> ico_count; + + if ((ico_reserved != 0) || (ico_type != 1) || (ico_count < 1)) + return false; + + + // now loop through each of the icon entries + uint8_t icoe_width; + uint8_t icoe_height; + uint8_t icoe_colorcount; + uint8_t icoe_reserved; + uint16_t icoe_planes; + uint16_t icoe_bitcount; + uint32_t icoe_bytesinres; + uint32_t icoe_imageoffset; + + // read the data on the 1st icon + dstream >> icoe_width; + dstream >> icoe_height; + dstream >> icoe_colorcount; + dstream >> icoe_reserved; + dstream >> icoe_planes; + dstream >> icoe_bitcount; + dstream >> icoe_bytesinres; + dstream >> icoe_imageoffset; + + + // output the useful bits + KFileMetaInfoGroup group = appendGroup(info, "Technical"); + appendItem(group, "Number", ico_count); + + if (ico_count == 1) { + appendItem(group, "Dimensions", TQSize(icoe_width, icoe_height)); + + if (icoe_colorcount > 0) + appendItem(group, "Colors", icoe_colorcount); + else if (icoe_bitcount > 0) + appendItem(group, "Colors", 2 ^ icoe_bitcount); + + } else { + + appendItem(group, "DimensionsM", TQSize(icoe_width, icoe_height)); + + if (icoe_colorcount > 0) + appendItem(group, "ColorsM", icoe_colorcount); + else if (icoe_bitcount > 0) + appendItem(group, "ColorsM", 2 ^ icoe_bitcount); + + } + + return true; +} + +#include "tdefile_ico.moc" diff --git a/tdefile-plugins/ico/tdefile_ico.desktop b/tdefile-plugins/ico/tdefile_ico.desktop new file mode 100644 index 00000000..66cadb95 --- /dev/null +++ b/tdefile-plugins/ico/tdefile_ico.desktop @@ -0,0 +1,65 @@ +[Desktop Entry] +Type=Service +Name=ICO Info +Name[af]=Ico Inligting +Name[ar]=معلومات ICO +Name[br]=Titouroù ICO +Name[ca]=Informació d'ICO +Name[cs]=ICO info +Name[cy]=Gwybodaeth ICO +Name[da]=ICO-info +Name[de]=ICO-Info +Name[el]=Πληροφορίες ICO +Name[eo]=ICO-informo +Name[es]=Info ICO +Name[et]=ICO info +Name[fa]=اطلاعات ICO +Name[fi]=ICO-tiedot +Name[fr]=Informations ICO +Name[gl]=Inf. ICO +Name[he]=מידע ICO +Name[hi]=ICO जानकारी +Name[hr]=ICO informacije +Name[hu]=ICO-jellemzők +Name[is]=ICO upplýsingar +Name[it]=Informazioni ICO +Name[ja]=ICO 情報 +Name[kk]=ICO мәліметі +Name[km]=ព័ត៌មាន ICO +Name[lt]=ICO informacija +Name[ms]= Maklumat ICO +Name[nds]=ICO-Info +Name[ne]=ICO सूचना +Name[nl]=ICO-info +Name[nn]=ICO-info +Name[nso]=Tshedimoso ya ICO +Name[pa]=ICO ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku ICO +Name[pt]=Informação do ICO +Name[pt_BR]=Informação sobre ICO +Name[ro]=Informaţii ICO +Name[ru]=Информация об ICO +Name[se]=ICO-dieđut +Name[sl]=Podatki o ICO +Name[sr]=ICO информације +Name[sr@Latn]=ICO informacije +Name[sv]=Ico-information +Name[ta]=ICO தகவல் +Name[tg]=Иттилоот оиди ICO +Name[th]=ข้อมูลแฟ้ม ICO +Name[tr]=ICO Bilgisi +Name[uk]=Інформація по ICO +Name[uz]=ICO haqida maʼlumot +Name[uz@cyrillic]=ICO ҳақида маълумот +Name[ven]=Mafhungo a ICO +Name[wa]=Informåcion sol imådjete ICO +Name[xh]=Ulwazi lwe ICO +Name[zh_CN]=ICO 信息 +Name[zh_HK]=ICO 資訊 +Name[zh_TW]=ICO 資訊 +Name[zu]=Ulwazi lwe-ICO +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_ico +MimeType=image/x-ico +PreferredGroups=Technical +PreferredItems=Number,Resolution,Colors,ResolutionM,ColorsM diff --git a/tdefile-plugins/ico/tdefile_ico.h b/tdefile-plugins/ico/tdefile_ico.h new file mode 100644 index 00000000..faa9481e --- /dev/null +++ b/tdefile-plugins/ico/tdefile_ico.h @@ -0,0 +1,38 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Shane Wright <me@shanewright.co.uk> + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_ICO_H__ +#define __KFILE_ICO_H__ + +#include <tdefilemetainfo.h> + +class TQStringList; + +class KIcoPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KIcoPlugin( TQObject *parent, const char *name, const TQStringList& args ); + + virtual bool readInfo( KFileMetaInfo& info, uint what); +}; + +#endif diff --git a/tdefile-plugins/jpeg/CMakeLists.txt b/tdefile-plugins/jpeg/CMakeLists.txt new file mode 100644 index 00000000..3e99eba7 --- /dev/null +++ b/tdefile-plugins/jpeg/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_jpeg.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_jpeg (module) ######################## + +tde_add_kpart( tdefile_jpeg AUTOMOC + SOURCES tdefile_jpeg.cpp exif.cpp tdefile_setcomment.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/jpeg/Makefile.am b/tdefile-plugins/jpeg/Makefile.am new file mode 100644 index 00000000..76e9e32d --- /dev/null +++ b/tdefile-plugins/jpeg/Makefile.am @@ -0,0 +1,24 @@ +## Makefile.am for jpeg file meta info plugin + +KDE_CXXFLAGS = $(USE_EXCEPTIONS) + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_jpeg.h exif.h + +kde_module_LTLIBRARIES = tdefile_jpeg.la + +tdefile_jpeg_la_SOURCES = tdefile_jpeg.cpp exif.cpp tdefile_setcomment.cpp +tdefile_jpeg_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_jpeg_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdefile_jpeg.pot + +services_DATA = tdefile_jpeg.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/jpeg/README b/tdefile-plugins/jpeg/README new file mode 100644 index 00000000..6b714426 --- /dev/null +++ b/tdefile-plugins/jpeg/README @@ -0,0 +1,35 @@ +------------------------------------------------------------------------------- +Thanks to: +Matthias Wandel <matt@rim.net> +jhead (http://www.sentex.net/~mwandel/jhead/) + +Groult Richard <rgroult@jalix.org> +showimg (http://ric.jalix.org/) + +Bryce Nesbitt for setcomment +based on wrjpgcom.c, Copyright (C) 1994-1997, Thomas G. Lane. + +Frank Pieczynski <pieczy@knuut.de> + +EXIF spec: +http://www.pima.net/standards/it10/PIMA15740/exif.htm +http://www.ba.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html + +------------------------------------------------------------------------------- +Bugs: + 0) Just showing the meta info can cause the file to be rewritten!!! + 1) utf-8 paths must be tested and supported. + 2) Display of EXIF comments need to be tested. + Both Unicode & ASCII need testing. + +New features needed: + 1) Should switch to a multi-line editor for comments. Support "\n". + 2) Should autodetect if the jpeg COM is in utf-8 format. + 3) Allow editing the EXIF "Orientation" flag (without rewriting the exif header). + 4) Extract and return the EXIF thumbnail, oriented properly, as an alternative + to the much slower process of generating a new thumbnail. + +Future features: + 1) Allow the user to erase or move comment in either the EXIF or jpeg COM. + 2) Play or return audio files associated with the exif. + diff --git a/tdefile-plugins/jpeg/exif.cpp b/tdefile-plugins/jpeg/exif.cpp new file mode 100644 index 00000000..60c689bd --- /dev/null +++ b/tdefile-plugins/jpeg/exif.cpp @@ -0,0 +1,961 @@ +//-------------------------------------------------------------------------- +// Program to pull the information out of various types of EFIF digital +// camera files and show it in a reasonably consistent way +// +// This module parses the very complicated exif structures. +// +// Matthias Wandel, Dec 1999 - August 2000 +//-------------------------------------------------------------------------- + + +#include "exif.h" +#include <tqwmatrix.h> +#include <kglobal.h> + + +static unsigned char * LastExifRefd; +static int ExifSettingsLength; +static double FocalplaneXRes; +static double FocalplaneUnits; +static int MotorolaOrder = 0; +static int SectionsRead; +//static int HaveAll; + +//-------------------------------------------------------------------------- +// Table of Jpeg encoding process names + +#define M_SOF0 0xC0 // Start Of Frame N +#define M_SOF1 0xC1 // N indicates which compression process +#define M_SOF2 0xC2 // Only SOF0-SOF2 are now in common use +#define M_SOF3 0xC3 +#define M_SOF5 0xC5 // NB: codes C4 and CC are NOT SOF markers +#define M_SOF6 0xC6 +#define M_SOF7 0xC7 +#define M_SOF9 0xC9 +#define M_SOF10 0xCA +#define M_SOF11 0xCB +#define M_SOF13 0xCD +#define M_SOF14 0xCE +#define M_SOF15 0xCF +#define M_SOI 0xD8 // Start Of Image (beginning of datastream) +#define M_EOI 0xD9 // End Of Image (end of datastream) +#define M_SOS 0xDA // Start Of Scan (begins compressed data) +#define M_JFIF 0xE0 // Jfif marker +#define M_EXIF 0xE1 // Exif marker +#define M_COM 0xFE // COMment + + +TagTable_t ProcessTable[] = { + { M_SOF0, "Baseline"}, + { M_SOF1, "Extended sequential"}, + { M_SOF2, "Progressive"}, + { M_SOF3, "Lossless"}, + { M_SOF5, "Differential sequential"}, + { M_SOF6, "Differential progressive"}, + { M_SOF7, "Differential lossless"}, + { M_SOF9, "Extended sequential, arithmetic coding"}, + { M_SOF10, "Progressive, arithmetic coding"}, + { M_SOF11, "Lossless, arithmetic coding"}, + { M_SOF13, "Differential sequential, arithmetic coding"}, + { M_SOF14, "Differential progressive, arithmetic coding"}, + { M_SOF15, "Differential lossless, arithmetic coding"}, + { 0, "Unknown"} +}; + + + +//-------------------------------------------------------------------------- +// Describes format descriptor +static int BytesPerFormat[] = {0,1,1,2,4,8,1,1,2,4,8,4,8}; +#define NUM_FORMATS 12 + +#define FMT_BYTE 1 +#define FMT_STRING 2 +#define FMT_USHORT 3 +#define FMT_ULONG 4 +#define FMT_URATIONAL 5 +#define FMT_SBYTE 6 +#define FMT_UNDEFINED 7 +#define FMT_SSHORT 8 +#define FMT_SLONG 9 +#define FMT_SRATIONAL 10 +#define FMT_SINGLE 11 +#define FMT_DOUBLE 12 + +//-------------------------------------------------------------------------- +// Describes tag values + +#define TAG_EXIF_OFFSET 0x8769 +#define TAG_INTEROP_OFFSET 0xa005 + +#define TAG_MAKE 0x010F +#define TAG_MODEL 0x0110 +#define TAG_ORIENTATION 0x0112 + +#define TAG_EXPOSURETIME 0x829A +#define TAG_FNUMBER 0x829D + +#define TAG_SHUTTERSPEED 0x9201 +#define TAG_APERTURE 0x9202 +#define TAG_MAXAPERTURE 0x9205 +#define TAG_FOCALLENGTH 0x920A + +#define TAG_DATETIME_ORIGINAL 0x9003 +#define TAG_USERCOMMENT 0x9286 + +#define TAG_SUBJECT_DISTANCE 0x9206 +#define TAG_FLASH 0x9209 + +#define TAG_FOCALPLANEXRES 0xa20E +#define TAG_FOCALPLANEUNITS 0xa210 +#define TAG_EXIF_IMAGEWIDTH 0xA002 +#define TAG_EXIF_IMAGELENGTH 0xA003 + +// the following is added 05-jan-2001 vcs +#define TAG_EXPOSURE_BIAS 0x9204 +#define TAG_WHITEBALANCE 0x9208 +#define TAG_METERING_MODE 0x9207 +#define TAG_EXPOSURE_PROGRAM 0x8822 +#define TAG_ISO_EQUIVALENT 0x8827 +#define TAG_COMPRESSION_LEVEL 0x9102 + +#define TAG_THUMBNAIL_OFFSET 0x0201 +#define TAG_THUMBNAIL_LENGTH 0x0202 + + +/*static TagTable_t TagTable[] = { + { 0x100, "ImageWidth"}, + { 0x101, "ImageLength"}, + { 0x102, "BitsPerSample"}, + { 0x103, "Compression"}, + { 0x106, "PhotometricInterpretation"}, + { 0x10A, "FillOrder"}, + { 0x10D, "DocumentName"}, + { 0x10E, "ImageDescription"}, + { 0x10F, "Make"}, + { 0x110, "Model"}, + { 0x111, "StripOffsets"}, + { 0x112, "Orientation"}, + { 0x115, "SamplesPerPixel"}, + { 0x116, "RowsPerStrip"}, + { 0x117, "StripByteCounts"}, + { 0x11A, "XResolution"}, + { 0x11B, "YResolution"}, + { 0x11C, "PlanarConfiguration"}, + { 0x128, "ResolutionUnit"}, + { 0x12D, "TransferFunction"}, + { 0x131, "Software"}, + { 0x132, "DateTime"}, + { 0x13B, "Artist"}, + { 0x13E, "WhitePoint"}, + { 0x13F, "PrimaryChromaticities"}, + { 0x156, "TransferRange"}, + { 0x200, "JPEGProc"}, + { 0x201, "ThumbnailOffset"}, + { 0x202, "ThumbnailLength"}, + { 0x211, "YCbCrCoefficients"}, + { 0x212, "YCbCrSubSampling"}, + { 0x213, "YCbCrPositioning"}, + { 0x214, "ReferenceBlackWhite"}, + { 0x828D, "CFARepeatPatternDim"}, + { 0x828E, "CFAPattern"}, + { 0x828F, "BatteryLevel"}, + { 0x8298, "Copyright"}, + { 0x829A, "ExposureTime"}, + { 0x829D, "FNumber"}, + { 0x83BB, "IPTC/NAA"}, + { 0x8769, "ExifOffset"}, + { 0x8773, "InterColorProfile"}, + { 0x8822, "ExposureProgram"}, + { 0x8824, "SpectralSensitivity"}, + { 0x8825, "GPSInfo"}, + { 0x8827, "ISOSpeedRatings"}, + { 0x8828, "OECF"}, + { 0x9000, "ExifVersion"}, + { 0x9003, "DateTimeOriginal"}, + { 0x9004, "DateTimeDigitized"}, + { 0x9101, "ComponentsConfiguration"}, + { 0x9102, "CompressedBitsPerPixel"}, + { 0x9201, "ShutterSpeedValue"}, + { 0x9202, "ApertureValue"}, + { 0x9203, "BrightnessValue"}, + { 0x9204, "ExposureBiasValue"}, + { 0x9205, "MaxApertureValue"}, + { 0x9206, "SubjectDistance"}, + { 0x9207, "MeteringMode"}, + { 0x9208, "LightSource"}, + { 0x9209, "Flash"}, + { 0x920A, "FocalLength"}, + { 0x927C, "MakerNote"}, + { 0x9286, "UserComment"}, + { 0x9290, "SubSecTime"}, + { 0x9291, "SubSecTimeOriginal"}, + { 0x9292, "SubSecTimeDigitized"}, + { 0xA000, "FlashPixVersion"}, + { 0xA001, "ColorSpace"}, + { 0xA002, "ExifImageWidth"}, + { 0xA003, "ExifImageLength"}, + { 0xA005, "InteroperabilityOffset"}, + { 0xA20B, "FlashEnergy"}, // 0x920B in TIFF/EP + { 0xA20C, "SpatialFrequencyResponse"}, // 0x920C - - + { 0xA20E, "FocalPlaneXResolution"}, // 0x920E - - + { 0xA20F, "FocalPlaneYResolution"}, // 0x920F - - + { 0xA210, "FocalPlaneResolutionUnit"}, // 0x9210 - - + { 0xA214, "SubjectLocation"}, // 0x9214 - - + { 0xA215, "ExposureIndex"}, // 0x9215 - - + { 0xA217, "SensingMethod"}, // 0x9217 - - + { 0xA300, "FileSource"}, + { 0xA301, "SceneType"}, + { 0, NULL} +} ; +*/ + + +//-------------------------------------------------------------------------- +// Parse the marker stream until SOS or EOI is seen; +//-------------------------------------------------------------------------- +int ExifData::ReadJpegSections (TQFile & infile, ReadMode_t ReadMode) +{ + int a; + + a = infile.getch(); + + if (a != 0xff || infile.getch() != M_SOI) { + SectionsRead = 0; + return false; + } + for(SectionsRead = 0; SectionsRead < MAX_SECTIONS-1; ){ + int marker = 0; + int got; + unsigned int ll,lh; + unsigned int itemlen; + uchar * Data; + + for (a=0;a<7;a++){ + marker = infile.getch(); + if (marker != 0xff) break; + + if (a >= 6){ + + kdDebug(7034) << "too many padding bytes\n"; + return false; + + } + } + + if (marker == 0xff){ + // 0xff is legal padding, but if we get that many, something's wrong. + throw FatalError("too many padding bytes!"); + } + + Sections[SectionsRead].Type = marker; + + // Read the length of the section. + lh = (uchar) infile.getch(); + ll = (uchar) infile.getch(); + + itemlen = (lh << 8) | ll; + + if (itemlen < 2) { + throw FatalError("invalid marker"); + } + + Sections[SectionsRead].Size = itemlen; + + Data = (uchar *)malloc(itemlen+1); // Add 1 to allow sticking a 0 at the end. + Sections[SectionsRead].Data = Data; + + // Store first two pre-read bytes. + Data[0] = (uchar)lh; + Data[1] = (uchar)ll; + + got = infile.readBlock((char*)Data+2, itemlen-2); // Read the whole section. + if (( unsigned ) got != itemlen-2){ + throw FatalError("reading from file"); + } + SectionsRead++; + + switch(marker){ + + case M_SOS: // stop before hitting compressed data + // If reading entire image is requested, read the rest of the data. + if (ReadMode & READ_IMAGE){ + unsigned long size; + + size = kMax( 0ul, (unsigned long)(infile.size()-infile.at()) ); + Data = (uchar *)malloc(size); + if (Data == NULL){ + throw FatalError("could not allocate data for entire image"); + } + + got = infile.readBlock((char*)Data, size); + if (( unsigned ) got != size){ + throw FatalError("could not read the rest of the image"); + } + + Sections[SectionsRead].Data = Data; + Sections[SectionsRead].Size = size; + Sections[SectionsRead].Type = PSEUDO_IMAGE_MARKER; + SectionsRead ++; + //HaveAll = 1; + } + return true; + + case M_EOI: // in case it's a tables-only JPEG stream + kdDebug(7034) << "No image in jpeg!\n"; + return false; + + case M_COM: // Comment section + // pieczy 2002-02-12 + // now the User comment goes to UserComment + // so we can store a Comment section also in READ_EXIF mode + process_COM(Data, itemlen); + break; + + case M_JFIF: + // Regular jpegs always have this tag, exif images have the exif + // marker instead, althogh ACDsee will write images with both markers. + // this program will re-create this marker on absence of exif marker. + // hence no need to keep the copy from the file. + free(Sections[--SectionsRead].Data); + break; + + case M_EXIF: + // Seen files from some 'U-lead' software with Vivitar scanner + // that uses marker 31 for non exif stuff. Thus make sure + // it says 'Exif' in the section before treating it as exif. + if ((ReadMode & READ_EXIF) && memcmp(Data+2, "Exif", 4) == 0){ + process_EXIF((uchar *)Data, itemlen); // FIXME: This call + // requires Data to be array of at least 8 bytes. Code + // above only checks for itemlen < 2. + }else{ + // Discard this section. + free(Sections[--SectionsRead].Data); + } + break; + + case M_SOF0: + case M_SOF1: + case M_SOF2: + case M_SOF3: + case M_SOF5: + case M_SOF6: + case M_SOF7: + case M_SOF9: + case M_SOF10: + case M_SOF11: + case M_SOF13: + case M_SOF14: + case M_SOF15: + process_SOFn(Data, marker); //FIXME: This call requires Data to + // be array of at least 8 bytes. Code above only checks for + // itemlen < 2. + break; + default: + break; + } + } + return true; +} + + +//-------------------------------------------------------------------------- +// Discard read data. +//-------------------------------------------------------------------------- +void ExifData::DiscardData(void) +{ + for (int a=0; a < SectionsRead; a++) + free(Sections[a].Data); + SectionsRead = 0; +} + +//-------------------------------------------------------------------------- +// Convert a 16 bit unsigned value from file's native byte order +//-------------------------------------------------------------------------- +int ExifData::Get16u(void * Short) +{ + if (MotorolaOrder){ + return (((uchar *)Short)[0] << 8) | ((uchar *)Short)[1]; + }else{ + return (((uchar *)Short)[1] << 8) | ((uchar *)Short)[0]; + } +} + +//-------------------------------------------------------------------------- +// Convert a 32 bit signed value from file's native byte order +//-------------------------------------------------------------------------- +int ExifData::Get32s(void * Long) +{ + if (MotorolaOrder){ + return ((( char *)Long)[0] << 24) | (((uchar *)Long)[1] << 16) + | (((uchar *)Long)[2] << 8 ) | (((uchar *)Long)[3] << 0 ); + }else{ + return ((( char *)Long)[3] << 24) | (((uchar *)Long)[2] << 16) + | (((uchar *)Long)[1] << 8 ) | (((uchar *)Long)[0] << 0 ); + } +} + +//-------------------------------------------------------------------------- +// Convert a 32 bit unsigned value from file's native byte order +//-------------------------------------------------------------------------- +unsigned ExifData::Get32u(void * Long) +{ + return (unsigned)Get32s(Long) & 0xffffffff; +} + +//-------------------------------------------------------------------------- +// Evaluate number, be it int, rational, or float from directory. +//-------------------------------------------------------------------------- +double ExifData::ConvertAnyFormat(void * ValuePtr, int Format) +{ + double Value; + Value = 0; + + switch(Format){ + case FMT_SBYTE: Value = *(signed char *)ValuePtr; break; + case FMT_BYTE: Value = *(uchar *)ValuePtr; break; + + case FMT_USHORT: Value = Get16u(ValuePtr); break; + + case FMT_ULONG: Value = Get32u(ValuePtr); break; + + case FMT_URATIONAL: + case FMT_SRATIONAL: + { + int Num,Den; + Num = Get32s(ValuePtr); + Den = Get32s(4+(char *)ValuePtr); + if (Den == 0){ + Value = 0; + }else{ + Value = (double)Num/Den; + } + break; + } + + case FMT_SSHORT: Value = (signed short)Get16u(ValuePtr); break; + case FMT_SLONG: Value = Get32s(ValuePtr); break; + + // Not sure if this is correct (never seen float used in Exif format) + case FMT_SINGLE: Value = (double)*(float *)ValuePtr; break; + case FMT_DOUBLE: Value = *(double *)ValuePtr; break; + } + return Value; +} + +//-------------------------------------------------------------------------- +// Process one of the nested EXIF directories. +//-------------------------------------------------------------------------- +void ExifData::ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, unsigned ExifLength, unsigned NestingLevel) +{ + int de; + int a; + int NumDirEntries; + unsigned ThumbnailOffset = 0; + unsigned ThumbnailSize = 0; + + if ( NestingLevel > 4) + throw FatalError("Maximum directory nesting exceeded (corrupt exif header)"); + + NumDirEntries = Get16u(DirStart); + #define DIR_ENTRY_ADDR(Start, Entry) (Start+2+12*(Entry)) + + { + unsigned char * DirEnd; + DirEnd = DIR_ENTRY_ADDR(DirStart, NumDirEntries); + if (DirEnd+4 > (OffsetBase+ExifLength)){ + if (DirEnd+2 == OffsetBase+ExifLength || DirEnd == OffsetBase+ExifLength){ + // Version 1.3 of jhead would truncate a bit too much. + // This also caught later on as well. + }else{ + // Note: Files that had thumbnails trimmed with jhead 1.3 or earlier + // might trigger this. + throw FatalError("Illegally sized directory"); + } + } + if (DirEnd < LastExifRefd) LastExifRefd = DirEnd; + } + + for (de=0;de<NumDirEntries;de++){ + int Tag, Format, Components; + unsigned char * ValuePtr; + unsigned ByteCount; + char * DirEntry; + DirEntry = (char *)DIR_ENTRY_ADDR(DirStart, de); + + Tag = Get16u(DirEntry); + Format = Get16u(DirEntry+2); + Components = Get32u(DirEntry+4); + + if ((Format-1) >= NUM_FORMATS) { + // (-1) catches illegal zero case as unsigned underflows to positive large. + throw FatalError("Illegal format code in EXIF dir"); + } + + if ((unsigned)Components > 0x10000) { + throw FatalError("Illegal number of components for tag"); + continue; + } + + ByteCount = Components * BytesPerFormat[Format]; + + if (ByteCount > 4){ + unsigned OffsetVal; + OffsetVal = Get32u(DirEntry+8); + // If its bigger than 4 bytes, the dir entry contains an offset. + if (OffsetVal+ByteCount > ExifLength){ + // Bogus pointer offset and / or bytecount value + //printf("Offset %d bytes %d ExifLen %d\n",OffsetVal, ByteCount, ExifLength); + + throw FatalError("Illegal pointer offset value in EXIF"); + } + ValuePtr = OffsetBase+OffsetVal; + }else{ + // 4 bytes or less and value is in the dir entry itself + ValuePtr = (unsigned char *)DirEntry+8; + } + + if (LastExifRefd < ValuePtr+ByteCount){ + // Keep track of last byte in the exif header that was actually referenced. + // That way, we know where the discardable thumbnail data begins. + LastExifRefd = ValuePtr+ByteCount; + } + + // Extract useful components of tag + switch(Tag){ + + case TAG_MAKE: + ExifData::CameraMake = TQString::fromLatin1((const char*)ValuePtr, 31); + break; + + case TAG_MODEL: + ExifData::CameraModel = TQString::fromLatin1((const char*)ValuePtr, 39); + break; + + case TAG_ORIENTATION: + Orientation = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_DATETIME_ORIGINAL: + DateTime = TQString::fromLatin1((const char*)ValuePtr, 19); + break; + + case TAG_USERCOMMENT: + // Olympus has this padded with trailing spaces. Remove these first. + for (a=ByteCount;;){ + a--; + if ((ValuePtr)[a] == ' '){ + (ValuePtr)[a] = '\0'; + }else{ + break; + } + if (a == 0) break; + } + + // Copy the comment + if (memcmp(ValuePtr, "ASCII",5) == 0){ + for (a=5;a<10;a++){ + int c; + c = (ValuePtr)[a]; + if (c != '\0' && c != ' '){ + UserComment = TQString::fromLatin1((const char*)(a+ValuePtr), 199); + break; + } + } + }else{ + UserComment = TQString::fromLatin1((const char*)ValuePtr, 199); + } + break; + + case TAG_FNUMBER: + // Simplest way of expressing aperture, so I trust it the most. + // (overwrite previously computd value if there is one) + ExifData::ApertureFNumber = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_APERTURE: + case TAG_MAXAPERTURE: + // More relevant info always comes earlier, so only use this field if we don't + // have appropriate aperture information yet. + if (ExifData::ApertureFNumber == 0){ + ExifData::ApertureFNumber + = (float)exp(ConvertAnyFormat(ValuePtr, Format)*log(2.0)*0.5); + } + break; + + case TAG_FOCALLENGTH: + // Nice digital cameras actually save the focal length as a function + // of how far they are zoomed in. + ExifData::FocalLength = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_SUBJECT_DISTANCE: + // Inidcates the distacne the autofocus camera is focused to. + // Tends to be less accurate as distance increases. + ExifData::Distance = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_EXPOSURETIME: + // Simplest way of expressing exposure time, so I trust it most. + // (overwrite previously computd value if there is one) + ExifData::ExposureTime = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_SHUTTERSPEED: + // More complicated way of expressing exposure time, so only use + // this value if we don't already have it from somewhere else. + if (ExifData::ExposureTime == 0){ + ExifData::ExposureTime + = (float)(1/exp(ConvertAnyFormat(ValuePtr, Format)*log(2.0))); + } + break; + + case TAG_FLASH: + ExifData::FlashUsed = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_EXIF_IMAGELENGTH: + ExifImageLength = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_EXIF_IMAGEWIDTH: + ExifImageWidth = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_FOCALPLANEXRES: + FocalplaneXRes = ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_FOCALPLANEUNITS: + switch((int)ConvertAnyFormat(ValuePtr, Format)){ + case 1: FocalplaneUnits = 25.4; break; // inch + case 2: + // According to the information I was using, 2 means meters. + // But looking at the Cannon powershot's files, inches is the only + // sensible value. + FocalplaneUnits = 25.4; + break; + + case 3: FocalplaneUnits = 10; break; // centimeter + case 4: FocalplaneUnits = 1; break; // milimeter + case 5: FocalplaneUnits = .001; break; // micrometer + } + break; + + // Remaining cases contributed by: Volker C. Schoech (schoech@gmx.de) + + case TAG_EXPOSURE_BIAS: + ExifData::ExposureBias = (float)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_WHITEBALANCE: + ExifData::Whitebalance = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_METERING_MODE: + ExifData::MeteringMode = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_EXPOSURE_PROGRAM: + ExifData::ExposureProgram = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_ISO_EQUIVALENT: + ExifData::ISOequivalent = (int)ConvertAnyFormat(ValuePtr, Format); + if ( ExifData::ISOequivalent < 50 ) ExifData::ISOequivalent *= 200; + break; + + case TAG_COMPRESSION_LEVEL: + ExifData::CompressionLevel = (int)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_THUMBNAIL_OFFSET: + ThumbnailOffset = (unsigned)ConvertAnyFormat(ValuePtr, Format); + break; + + case TAG_THUMBNAIL_LENGTH: + ThumbnailSize = (unsigned)ConvertAnyFormat(ValuePtr, Format); + break; + + } + + if (Tag == TAG_EXIF_OFFSET || Tag == TAG_INTEROP_OFFSET){ + unsigned char * SubdirStart; + SubdirStart = OffsetBase + Get32u(ValuePtr); + if (SubdirStart <= OffsetBase || SubdirStart >= OffsetBase+ExifLength){ + throw FatalError("Illegal subdirectory link"); + } + ProcessExifDir(SubdirStart, OffsetBase, ExifLength, NestingLevel+1); + continue; + } + } + + { + // In addition to linking to subdirectories via exif tags, + // there's also a potential link to another directory at the end of each + // directory. this has got to be the result of a comitee! + unsigned char * SubdirStart; + unsigned Offset; + + if (DIR_ENTRY_ADDR(DirStart, NumDirEntries) + 4 <= OffsetBase+ExifLength){ + Offset = Get32u(DIR_ENTRY_ADDR(DirStart, NumDirEntries)); + // There is at least one jpeg from an HP camera having an Offset of almost MAXUINT. + // Adding OffsetBase to it produces an overflow, so compare with ExifLength here. + // See http://bugs.kde.org/show_bug.cgi?id=54542 + if (Offset && Offset < ExifLength){ + SubdirStart = OffsetBase + Offset; + if (SubdirStart > OffsetBase+ExifLength){ + if (SubdirStart < OffsetBase+ExifLength+20){ + // Jhead 1.3 or earlier would crop the whole directory! + // As Jhead produces this form of format incorrectness, + // I'll just let it pass silently + kdDebug(7034) << "Thumbnail removed with Jhead 1.3 or earlier\n"; + }else{ + throw FatalError("Illegal subdirectory link 2"); + } + }else{ + if (SubdirStart <= OffsetBase+ExifLength){ + ProcessExifDir(SubdirStart, OffsetBase, ExifLength, NestingLevel+1); + } + } + } + }else{ + // The exif header ends before the last next directory pointer. + } + } + + if (ThumbnailSize && ThumbnailOffset){ + if (ThumbnailSize + ThumbnailOffset < ExifLength){ + // The thumbnail pointer appears to be valid. Store it. + Thumbnail.loadFromData(OffsetBase + ThumbnailOffset, ThumbnailSize, "JPEG"); + } + } +} + +//-------------------------------------------------------------------------- +// Process a COM marker. We want to leave the bytes unchanged. The +// progam that displays this text may decide to remove blanks, convert +// newlines, or otherwise modify the text. In particular we want to be +// safe for passing utf-8 text. +//-------------------------------------------------------------------------- +void ExifData::process_COM (const uchar * Data, int length) +{ + Comment = TQString::fromUtf8((char *)Data+2, (length-2)); +} + + +//-------------------------------------------------------------------------- +// Process a SOFn marker. This is useful for the image dimensions +//-------------------------------------------------------------------------- +void ExifData::process_SOFn (const uchar * Data, int marker) +{ + int data_precision, num_components; + + data_precision = Data[2]; + ExifData::Height = Get16m(Data+3); + ExifData::Width = Get16m(Data+5); + num_components = Data[7]; + + if (num_components == 3){ + ExifData::IsColor = 1; + }else{ + ExifData::IsColor = 0; + } + + ExifData::Process = marker; + +} + +//-------------------------------------------------------------------------- +// Get 16 bits motorola order (always) for jpeg header stuff. +//-------------------------------------------------------------------------- +int ExifData::Get16m(const void * Short) +{ + return (((uchar *)Short)[0] << 8) | ((uchar *)Short)[1]; +} + + +//-------------------------------------------------------------------------- +// Process a EXIF marker +// Describes all the drivel that most digital cameras include... +//-------------------------------------------------------------------------- +void ExifData::process_EXIF(unsigned char * CharBuf, unsigned int length) +{ + ExifData::FlashUsed = 0; // If it s from a digicam, and it used flash, it says so. + + FocalplaneXRes = 0; + FocalplaneUnits = 0; + ExifImageWidth = 0; + ExifImageLength = 0; + + { // Check the EXIF header component + static const uchar ExifHeader[] = "Exif\0\0"; + if (memcmp(CharBuf+2, ExifHeader,6)){ + throw FatalError("Incorrect Exif header"); + } + } + + if (memcmp(CharBuf+8,"II",2) == 0){ + // printf("Exif section in Intel order\n"); + MotorolaOrder = 0; + }else{ + if (memcmp(CharBuf+8,"MM",2) == 0){ + // printf("Exif section in Motorola order\n"); + MotorolaOrder = 1; + }else{ + throw FatalError("Invalid Exif alignment marker."); + } + } + + // Check the next two values for correctness. + if (Get16u(CharBuf+10) != 0x2a){ + throw FatalError("Invalid Exif start (1)"); + } + + long IFDoffset = Get32u(CharBuf+12); + + LastExifRefd = CharBuf; + + // First directory starts 16 bytes in. Offsets start at 8 bytes in. + ProcessExifDir(&CharBuf[8+IFDoffset], CharBuf+8, length-6, 0); + + // This is how far the interesting (non thumbnail) part of the exif went. + ExifSettingsLength = LastExifRefd - CharBuf; + + // Compute the CCD width, in milimeters. + if (FocalplaneXRes != 0){ + kdDebug(7034) << "ExifImageWidth " << ExifImageWidth << " FocalplaneUnits " << FocalplaneUnits << " FocalplaneXRes " << FocalplaneXRes << endl; + ExifData::CCDWidth = (float)(ExifImageWidth * FocalplaneUnits / FocalplaneXRes); + } +} + +//-------------------------------------------------------------------------- +// Convert exif time to Unix time structure +//-------------------------------------------------------------------------- +int ExifData::Exif2tm(struct tm * timeptr, char * ExifTime) +{ + int a; + + timeptr->tm_wday = -1; + + // Check for format: YYYY:MM:DD HH:MM:SS format. + a = sscanf(ExifTime, "%d:%d:%d %d:%d:%d", + &timeptr->tm_year, &timeptr->tm_mon, &timeptr->tm_mday, + &timeptr->tm_hour, &timeptr->tm_min, &timeptr->tm_sec); + + if (a == 6){ + timeptr->tm_isdst = -1; + timeptr->tm_mon -= 1; // Adjust for unix zero-based months + timeptr->tm_year -= 1900; // Adjust for year starting at 1900 + return true; // worked. + } + + return false; // Wasn't in Exif date format. +} + +//-------------------------------------------------------------------------- +// Contructor for initialising +//-------------------------------------------------------------------------- +ExifData::ExifData() +{ + ExifData::Whitebalance = -1; + ExifData::MeteringMode = -1; + ExifData::FlashUsed = 0; + Orientation = 0; + Height = 0; + Width = 0; + IsColor = 0; + Process = 0; + FocalLength = 0; + ExposureTime = 0; + ApertureFNumber = 0; + Distance = 0; + CCDWidth = 0; + ExposureBias = 0; + ExposureProgram = 0; + ISOequivalent = 0; + CompressionLevel = 0; +} + +//-------------------------------------------------------------------------- +// process a EXIF jpeg file +//-------------------------------------------------------------------------- +bool ExifData::scan(const TQString & path) +{ + int ret; + + TQFile f(path); + if ( !f.open(IO_ReadOnly) ) + return false; + + try { + // Scan the JPEG headers. + ret = ReadJpegSections(f, READ_EXIF); + } + catch (FatalError& e) { + e.debug_print(); + f.close(); + return false; + } + + if (ret == false){ + kdDebug(7034) << "Not JPEG file!\n"; + DiscardData(); + f.close(); + return false; + } + f.close(); + DiscardData(); + + //now make the strings clean, + // for exmaple my Casio is a "QV-4000 " + CameraMake = CameraMake.stripWhiteSpace(); + CameraModel = CameraModel.stripWhiteSpace(); + UserComment = UserComment.stripWhiteSpace(); + Comment = Comment.stripWhiteSpace(); + return true; +} + +//-------------------------------------------------------------------------- +// Does the embedded thumbnail match the jpeg image? +//-------------------------------------------------------------------------- +#ifndef JPEG_TOL +#define JPEG_TOL 0.02 +#endif +bool ExifData::isThumbnailSane() { + if (Thumbnail.isNull()) return false; + + // check whether thumbnail dimensions match the image + // not foolproof, but catches some altered images (jpegtran -rotate) + if (ExifImageLength != 0 && ExifImageLength != Height) return false; + if (ExifImageWidth != 0 && ExifImageWidth != Width) return false; + if (Thumbnail.width() == 0 || Thumbnail.height() == 0) return false; + if (Height == 0 || Width == 0) return false; + double d = (double)Height/Width*Thumbnail.width()/Thumbnail.height(); + return (1-JPEG_TOL < d) && (d < 1+JPEG_TOL); +} + + +//-------------------------------------------------------------------------- +// return a thumbnail that respects the orientation flag +// only if it seems sane +//-------------------------------------------------------------------------- +TQImage ExifData::getThumbnail() { + if (!isThumbnailSane()) return NULL; + if (!Orientation || Orientation == 1) return Thumbnail; + + // now fix orientation + TQWMatrix M; + TQWMatrix flip= TQWMatrix(-1,0,0,1,0,0); + switch (Orientation) { // notice intentional fallthroughs + case 2: M = flip; break; + case 4: M = flip; + case 3: M.rotate(180); break; + case 5: M = flip; + case 6: M.rotate(90); break; + case 7: M = flip; + case 8: M.rotate(270); break; + default: break; // should never happen + } + return Thumbnail.xForm(M); +} diff --git a/tdefile-plugins/jpeg/exif.h b/tdefile-plugins/jpeg/exif.h new file mode 100644 index 00000000..f8eb13ef --- /dev/null +++ b/tdefile-plugins/jpeg/exif.h @@ -0,0 +1,127 @@ +#ifndef __EXIF_H__ +#define __EXIF_H__ + +/** + exif.h +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <time.h> + +#include "tqstring.h" +#include "tqfile.h" +#include "tqimage.h" +#include <kdebug.h> + +typedef enum { + READ_EXIF = 1, + READ_IMAGE = 2, + READ_ALL = 3 +}ReadMode_t; + +//-------------------------------------------------------------------------- +// This structure is used to store jpeg file sections in memory. +typedef struct { + uchar * Data; + int Type; + unsigned Size; +}Section_t; + +typedef unsigned char uchar; + +typedef struct { + unsigned short Tag; + const char*const Desc; +}TagTable_t; + +#define MAX_SECTIONS 20 +#define PSEUDO_IMAGE_MARKER 0x123; // Extra value. + +class ExifData { + Section_t Sections[MAX_SECTIONS]; + + TQString CameraMake; + TQString CameraModel; + TQString DateTime; + int Orientation; + int Height, Width; + int ExifImageLength, ExifImageWidth; + int IsColor; + int Process; + int FlashUsed; + float FocalLength; + float ExposureTime; + float ApertureFNumber; + float Distance; + int Whitebalance; + int MeteringMode; + float CCDWidth; + float ExposureBias; + int ExposureProgram; + int ISOequivalent; + int CompressionLevel; + TQString UserComment; + TQString Comment; + TQImage Thumbnail; + + int ReadJpegSections (TQFile & infile, ReadMode_t ReadMode); + void DiscardData(void); + int Get16u(void * Short); + int Get32s(void * Long); + unsigned Get32u(void * Long); + double ConvertAnyFormat(void * ValuePtr, int Format); + void ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, unsigned ExifLength, + unsigned NestingLevel); + void process_COM (const uchar * Data, int length); + void process_SOFn (const uchar * Data, int marker); + int Get16m(const void * Short); + void process_EXIF(unsigned char * CharBuf, unsigned int length); + int Exif2tm(struct tm * timeptr, char * ExifTime); + +public: + ExifData(); + bool scan(const TQString &); + TQString getCameraMake() { return CameraMake; } + TQString getCameraModel() { return CameraModel; } + TQString getDateTime() { return DateTime; } + int getOrientation() { return Orientation; } + int getHeight() { return Height; } + int getWidth() { return Width; } + int getIsColor() { return IsColor; } + int getProcess() { return Process; } + int getFlashUsed() { return FlashUsed; } + float getFocalLength() { return FocalLength; } + float getExposureTime() { return ExposureTime; } + float getApertureFNumber() { return ApertureFNumber; } + float getDistance() { return Distance; } + int getWhitebalance() { return Whitebalance; } + int getMeteringMode() { return MeteringMode; } + float getCCDWidth() { return CCDWidth; } + float getExposureBias() { return ExposureBias; } + int getExposureProgram() { return ExposureProgram; } + int getISOequivalent() { return ISOequivalent; } + int getCompressionLevel() { return CompressionLevel; } + TQString getUserComment() { return UserComment; } + TQString getComment() { return Comment; } + TQImage getThumbnail(); + bool isThumbnailSane(); + bool isNullThumbnail() { return !isThumbnailSane(); } +}; + +class FatalError { + const char* ex; +public: + FatalError(const char* s) { ex = s; } + void debug_print() const { kdDebug(7034) << "exception: " << ex << endl; } +}; + +extern TagTable_t ProcessTable[]; + +//-------------------------------------------------------------------------- +// Define comment writing code, impelemented in setcomment.c +extern int safe_copy_and_modify( const char * original_filename, const char * comment ); + +#endif + diff --git a/tdefile-plugins/jpeg/tdefile_jpeg.cpp b/tdefile-plugins/jpeg/tdefile_jpeg.cpp new file mode 100644 index 00000000..c902b99b --- /dev/null +++ b/tdefile-plugins/jpeg/tdefile_jpeg.cpp @@ -0,0 +1,531 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Frank Pieczynski <pieczy@knuut.de>, + * 2002 Carsten Pfeiffer <pfeiffer@kde.org> + * based on the jhead tool of Matthias Wandel (see below) + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + + +#include <stdlib.h> +#include "tdefile_jpeg.h" + +#include <kurl.h> +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kdebug.h> + +#include <tqcstring.h> +#include <tqfile.h> +#include <tqdatetime.h> +#include <tqdict.h> +#include <tqvalidator.h> +#include <tqimage.h> + +#include "exif.h" + +#define EXIFGROUP "Jpeg EXIF Data" + +typedef KGenericFactory<KJpegPlugin> JpegFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_jpeg, JpegFactory("tdefile_jpeg")) + +KJpegPlugin::KJpegPlugin(TQObject *parent, const char *name, + const TQStringList &args ) + : KFilePlugin(parent, name, args) +{ + kdDebug(7034) << "jpeg plugin\n"; + + // + // define all possible meta info items + // + KFileMimeTypeInfo *info = addMimeTypeInfo("image/jpeg"); + KFileMimeTypeInfo::GroupInfo *exifGroup = addGroupInfo( info, EXIFGROUP, + i18n("JPEG Exif") ); + KFileMimeTypeInfo::ItemInfo* item; + + item = addItemInfo( exifGroup, "Comment", i18n("Comment"), TQVariant::String); + setAttributes( item, + KFileMimeTypeInfo::Modifiable | + KFileMimeTypeInfo::Addable | + KFileMimeTypeInfo::MultiLine ); + + item = addItemInfo( exifGroup, "Manufacturer", i18n("Camera Manufacturer"), + TQVariant::String ); + + item = addItemInfo( exifGroup, "Model", i18n("Camera Model"), + TQVariant::String ); + + item = addItemInfo( exifGroup, "Date/time", i18n("Date/Time"), + TQVariant::DateTime ); + + item = addItemInfo( exifGroup, "CreationDate", i18n("Creation Date"), + TQVariant::Date ); + + item = addItemInfo( exifGroup, "CreationTime", i18n("Creation Time"), + TQVariant::Time ); + + item = addItemInfo( exifGroup, "Dimensions", i18n("Dimensions"), + TQVariant::Size ); + setHint( item, KFileMimeTypeInfo::Size ); + setUnit( item, KFileMimeTypeInfo::Pixels ); + + item = addItemInfo( exifGroup, "Orientation", i18n("Orientation"), + TQVariant::Int ); + + item = addItemInfo( exifGroup, "ColorMode", i18n("Color Mode"), + TQVariant::String ); + + item = addItemInfo( exifGroup, "Flash used", i18n("Flash Used"), + TQVariant::String ); + item = addItemInfo( exifGroup, "Focal length", i18n("Focal Length"), + TQVariant::String ); + setUnit( item, KFileMimeTypeInfo::Millimeters ); + + item = addItemInfo( exifGroup, "35mm equivalent", i18n("35mm Equivalent"), + TQVariant::Int ); + setUnit( item, KFileMimeTypeInfo::Millimeters ); + + item = addItemInfo( exifGroup, "CCD width", i18n("CCD Width"), + TQVariant::String ); + setUnit( item, KFileMimeTypeInfo::Millimeters ); + + item = addItemInfo( exifGroup, "Exposure time", i18n("Exposure Time"), + TQVariant::String ); + setHint( item, KFileMimeTypeInfo::Seconds ); + + item = addItemInfo( exifGroup, "Aperture", i18n("Aperture"), + TQVariant::String ); + + item = addItemInfo( exifGroup, "Focus dist.", i18n("Focus Dist."), + TQVariant::String ); + + item = addItemInfo( exifGroup, "Exposure bias", i18n("Exposure Bias"), + TQVariant::String ); + + item = addItemInfo( exifGroup, "Whitebalance", i18n("Whitebalance"), + TQVariant::String ); + + item = addItemInfo( exifGroup, "Metering mode", i18n("Metering Mode"), + TQVariant::String ); + + item = addItemInfo( exifGroup, "Exposure", i18n("Exposure"), + TQVariant::String ); + + item = addItemInfo( exifGroup, "ISO equiv.", i18n("ISO Equiv."), + TQVariant::String ); + + item = addItemInfo( exifGroup, "JPEG quality", i18n("JPEG Quality"), + TQVariant::String ); + + item = addItemInfo( exifGroup, "User comment", i18n("User Comment"), + TQVariant::String ); + setHint(item, KFileMimeTypeInfo::Description); + + item = addItemInfo( exifGroup, "JPEG process", i18n("JPEG Process"), + TQVariant::String ); + + item = addItemInfo( exifGroup, "Thumbnail", i18n("Thumbnail"), + TQVariant::Image ); + setHint( item, KFileMimeTypeInfo::Thumbnail ); + +// ### +// exifGroup.setSupportsVariableKeys(true); +} + +TQValidator* KJpegPlugin::createValidator(const KFileMetaInfoItem& /*item*/, + TQObject */*parent*/, + const char */*name*/ ) const +{ + // no need to return a validator that validates everything as OK :) +// if (item.isEditable()) +// return new TQRegExpValidator(TQRegExp(".*"), parent, name); +// else + return 0L; +} + +bool KJpegPlugin::writeInfo( const KFileMetaInfo& info ) const +{ + TQString comment = info[EXIFGROUP].value("Comment").toString(); + TQString path = info.path(); + + kdDebug(7034) << "exif writeInfo: " << info.path() << " \"" << comment << "\"\n"; + + /* + Do a strictly safe insertion of the comment: + + Scan original to verify it's a proper jpeg + Open a unique temporary file in this directory + Write temporary, replacing all COM blocks with this one. + Scan temporary, to verify it's a proper jpeg + Rename original to another unique name + Rename temporary to original + Unlink original + */ + /* + The jpeg standard does not regulate the contents of the COM block. + I'm assuming the best thing to do here is write as unicode utf-8, + which is fully backwards compatible with readers expecting ascii. + Readers expecting a national character set are out of luck... + */ + if( safe_copy_and_modify( TQFile::encodeName( path ), comment.utf8() ) ) { + return false; + } + return true; +} + +bool KJpegPlugin::readInfo( KFileMetaInfo& info, uint what ) +{ + const TQString path( info.path() ); + if ( path.isEmpty() ) // remote file + return false; + + TQString tag; + ExifData ImageInfo; + + // parse the jpeg file now + try { + if ( !ImageInfo.scan(info.path()) ) { + kdDebug(7034) << "Not a JPEG file!\n"; + return false; + } + } + catch (FatalError& e) { // malformed exif data? + kdDebug(7034) << "Exception caught while parsing Exif data of: " << info.path() << endl; + e.debug_print(); + return false; + } + + KFileMetaInfoGroup exifGroup = appendGroup( info, EXIFGROUP ); + + tag = ImageInfo.getComment(); + if ( tag.length() ) { + kdDebug(7034) << "exif inserting Comment: " << tag << "\n"; + appendItem( exifGroup, "Comment", tag ); + } else { + appendItem( exifGroup, "Comment", tag ); // So user can add new comment + } + + tag = ImageInfo.getCameraMake(); + if (tag.length()) + appendItem( exifGroup, "Manufacturer", tag ); + + tag = ImageInfo.getCameraModel(); + if (tag.length()) + appendItem( exifGroup, "Model", tag ); + + tag = ImageInfo.getDateTime(); + if (tag.length()){ + TQDateTime dt = parseDateTime( tag.stripWhiteSpace() ); + if ( dt.isValid() ) { + appendItem( exifGroup, "Date/time", dt ); + appendItem( exifGroup, "CreationDate", dt.date() ); + appendItem( exifGroup, "CreationTime", dt.time() ); + } + } + + appendItem( exifGroup,"Dimensions", TQSize( ImageInfo.getWidth(), + ImageInfo.getHeight() ) ); + + if ( ImageInfo.getOrientation() ) + appendItem( exifGroup, "Orientation", ImageInfo.getOrientation() ); + + appendItem( exifGroup, "ColorMode", ImageInfo.getIsColor() ? + i18n("Color") : i18n("Black and white") ); + + int flashUsed = ImageInfo.getFlashUsed(); // -1, <set> + if ( flashUsed >= 0 ) { + TQString flash = i18n("Flash", "(unknown)"); + switch ( flashUsed ) { + case 0: flash = i18n("Flash", "No"); + break; + case 1: + case 5: + case 7: + flash = i18n("Flash", "Fired"); + break; + case 9: + case 13: + case 15: + flash = i18n( "Flash", "Fill Fired" ); + break; + case 16: + flash = i18n( "Flash", "Off" ); + break; + case 24: + flash = i18n( "Flash", "Auto Off" ); + break; + case 25: + case 29: + case 31: + flash = i18n( "Flash", "Auto Fired" ); + break; + case 32: + flash = i18n( "Flash", "Not Available" ); + break; + default: + break; + } + appendItem( exifGroup, "Flash used", + flash ); + } + + if (ImageInfo.getFocalLength()){ + appendItem( exifGroup, "Focal length", + TQString(TQString().sprintf("%4.1f", ImageInfo.getFocalLength()) )); + + if (ImageInfo.getCCDWidth()){ + appendItem( exifGroup, "35mm equivalent", + (int)(ImageInfo.getFocalLength()/ImageInfo.getCCDWidth()*35 + 0.5) ); + } + } + + if (ImageInfo.getCCDWidth()){ + appendItem( exifGroup, "CCD width", + TQString(TQString().sprintf("%4.2f", ImageInfo.getCCDWidth()) )); + } + + if (ImageInfo.getExposureTime()){ + tag=TQString().sprintf("%6.3f", ImageInfo.getExposureTime()); + float exposureTime = ImageInfo.getExposureTime(); + if (exposureTime > 0 && exposureTime <= 0.5){ + tag+=TQString().sprintf(" (1/%d)", (int)(0.5 + 1/exposureTime) ); + } + appendItem( exifGroup, "Exposure time", tag ); + } + + if (ImageInfo.getApertureFNumber()){ + appendItem( exifGroup, "Aperture", + TQString(TQString().sprintf("f/%3.1f", + (double)ImageInfo.getApertureFNumber()))); + } + + if (ImageInfo.getDistance()){ + if (ImageInfo.getDistance() < 0){ + tag=i18n("Infinite"); + }else{ + tag=TQString().sprintf("%5.2fm",(double)ImageInfo.getDistance()); + } + appendItem( exifGroup, "Focus dist.", tag ); + } + + if (ImageInfo.getExposureBias()){ + appendItem( exifGroup, "Exposure bias", + TQString(TQString().sprintf("%4.2f", + (double)ImageInfo.getExposureBias()) )); + } + + if (ImageInfo.getWhitebalance() != -1){ + switch(ImageInfo.getWhitebalance()) { + case 0: + tag=i18n("Unknown"); + break; + case 1: + tag=i18n("Daylight"); + break; + case 2: + tag=i18n("Fluorescent"); + break; + case 3: + //tag=i18n("incandescent"); + tag=i18n("Tungsten"); + break; + case 17: + tag=i18n("Standard light A"); + break; + case 18: + tag=i18n("Standard light B"); + break; + case 19: + tag=i18n("Standard light C"); + break; + case 20: + tag=i18n("D55"); + break; + case 21: + tag=i18n("D65"); + break; + case 22: + tag=i18n("D75"); + break; + case 255: + tag=i18n("Other"); + break; + default: + //23 to 254 = reserved + tag=i18n("Unknown"); + } + appendItem( exifGroup, "Whitebalance", tag ); + } + + if (ImageInfo.getMeteringMode() != -1){ + switch(ImageInfo.getMeteringMode()) { + case 0: + tag=i18n("Unknown"); + break; + case 1: + tag=i18n("Average"); + break; + case 2: + tag=i18n("Center weighted average"); + break; + case 3: + tag=i18n("Spot"); + break; + case 4: + tag=i18n("MultiSpot"); + break; + case 5: + tag=i18n("Pattern"); + break; + case 6: + tag=i18n("Partial"); + break; + case 255: + tag=i18n("Other"); + break; + default: + // 7 to 254 = reserved + tag=i18n("Unknown"); + } + appendItem( exifGroup, "Metering mode", tag ); + } + + if (ImageInfo.getExposureProgram()){ + switch(ImageInfo.getExposureProgram()) { + case 0: + tag=i18n("Not defined"); + break; + case 1: + tag=i18n("Manual"); + break; + case 2: + tag=i18n("Normal program"); + break; + case 3: + tag=i18n("Aperture priority"); + break; + case 4: + tag=i18n("Shutter priority"); + break; + case 5: + tag=i18n("Creative program\n(biased toward fast shutter speed)"); + break; + case 6: + tag=i18n("Action program\n(biased toward fast shutter speed)"); + break; + case 7: + tag=i18n("Portrait mode\n(for closeup photos with the background out of focus)"); + break; + case 8: + tag=i18n("Landscape mode\n(for landscape photos with the background in focus)"); + break; + default: + // 9 to 255 = reserved + tag=i18n("Unknown"); + } + appendItem( exifGroup, "Exposure", tag ); + } + + if (ImageInfo.getISOequivalent()){ + appendItem( exifGroup, "ISO equiv.", + TQString(TQString().sprintf("%2d", + (int)ImageInfo.getISOequivalent()) )); + } + + if (ImageInfo.getCompressionLevel()){ + switch(ImageInfo.getCompressionLevel()) { + case 1: + tag=i18n("Basic"); + break; + case 2: + tag=i18n("Normal"); + break; + case 4: + tag=i18n("Fine"); + break; + default: + tag=i18n("Unknown"); + } + appendItem( exifGroup, "JPEG quality", tag ); + } + + tag = ImageInfo.getUserComment(); + if (tag.length()){ + appendItem( exifGroup, "EXIF comment", tag ); + } + + int a; + for (a=0;;a++){ + if (ProcessTable[a].Tag == ImageInfo.getProcess() || ProcessTable[a].Tag == 0){ + appendItem( exifGroup, "JPEG process", + TQString::fromUtf8( ProcessTable[a].Desc) ); + break; + } + } + + if ( what & KFileMetaInfo::Thumbnail && !ImageInfo.isNullThumbnail() ){ + appendItem( exifGroup, "Thumbnail", ImageInfo.getThumbnail() ); + } + + return true; +} + +// format of the string is: +// YYYY:MM:DD HH:MM:SS +TQDateTime KJpegPlugin::parseDateTime( const TQString& string ) +{ + TQDateTime dt; + if ( string.length() != 19 ) + return dt; + + TQString year = string.left( 4 ); + TQString month = string.mid( 5, 2 ); + TQString day = string.mid( 8, 2 ); + TQString hour = string.mid( 11, 2 ); + TQString minute = string.mid( 14, 2 ); + TQString seconds = string.mid( 17, 2 ); + + bool ok; + bool allOk = true; + int y = year.toInt( &ok ); + allOk &= ok; + + int mo = month.toInt( &ok ); + allOk &= ok; + + int d = day.toInt( &ok ); + allOk &= ok; + + int h = hour.toInt( &ok ); + allOk &= ok; + + int mi = minute.toInt( &ok ); + allOk &= ok; + + int s = seconds.toInt( &ok ); + allOk &= ok; + + if ( allOk ) { + dt.setDate( TQDate( y, mo, d ) ); + dt.setTime( TQTime( h, mi, s ) ); + } + + return dt; +} + +#include "tdefile_jpeg.moc" diff --git a/tdefile-plugins/jpeg/tdefile_jpeg.desktop b/tdefile-plugins/jpeg/tdefile_jpeg.desktop new file mode 100644 index 00000000..d2cfa0ff --- /dev/null +++ b/tdefile-plugins/jpeg/tdefile_jpeg.desktop @@ -0,0 +1,64 @@ +[Desktop Entry] +Type=Service +Name=JPEG EXIF Info +Name[ar]=معلومات JPEG EXIF +Name[br]=Titouroù EXIF JPEG +Name[ca]=Informació de JPEG EXIF +Name[cs]=JPEG EXIF info +Name[cy]=Gwybodaeth JPEG EXIF +Name[da]=JPEG EXIF-info +Name[de]=JPEG EXIF-Info +Name[el]=Πληροφορίες JPEG EXIF +Name[eo]=JPEG-EXIF-informo +Name[es]=Info JPEG EXIF +Name[et]=JPEG EXIF info +Name[fa]=اطلاعات JPEG EXIF +Name[fi]=JPEG EXIF -tiedot +Name[fr]=Informations JPEG EXIF +Name[gl]=Inf. JPEG EXIF +Name[he]=מידע JPEG EXIF +Name[hi]=JPEG EXIF जानकारी +Name[hr]=JPEG EXIF Informacije +Name[hu]=JPEG EXIF-jellemzők +Name[is]=JPEG EXIF upplýsingar +Name[it]=Informazioni JPEG EXIF +Name[ja]=JPEG EXIF 情報 +Name[kk]=JPEG EXIF мәліметі +Name[km]=ព័ត៌មាន JPEG EXIF +Name[lt]=JPEG EXIF informacija +Name[ms]=Maklumat JPEG EXIF +Name[nds]=JPEG-EXIF-Info +Name[ne]=JPEG EXIF सूचना +Name[nl]=JPEG EXIF-info +Name[nn]=JPEG EXIF-info +Name[nso]=TshedimoJPEG EXIF Info +Name[pa]=JPEG EXIF ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku JPEG EXIF +Name[pt]=Informação do JPEG EXIF +Name[pt_BR]=Informação sobre JPEG EXIF +Name[ro]=Informaţii EXIF JPEG +Name[ru]=Информация о JPEG EXIF +Name[se]=JPEG EXIF-dieđut +Name[sl]=Podatki o JPEG EXIF +Name[sr]=JPEG EXIF информације +Name[sr@Latn]=JPEG EXIF informacije +Name[sv]=JPEG EXIF-information +Name[ta]=JPEG EXIF தகவல் +Name[tg]=Иттилоот оиди JPEG EXIF +Name[th]=ข้อมูลแฟ้ม JPEG EXIF +Name[tr]=JPEG EXIF Bilgisi +Name[uk]=Інформація про JPEG EXIF +Name[uz]=JPEG EXIF haqida maʼlumot +Name[uz@cyrillic]=JPEG EXIF ҳақида маълумот +Name[ven]=Mafhungo a JPEG EXIF +Name[wa]=Informåcion sol imådje JPEG EXIF +Name[xh]=Ulwazi lwe JPEG EXIF +Name[zh_CN]=JPEG EXIF 信息 +Name[zh_HK]=JPEG EXIF 資訊 +Name[zh_TW]=JPEG EXIF 資訊 +Name[zu]=Ulwazi lwe-JPEG EXIF +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_jpeg +MimeType=image/jpeg +PreferredItems=User comment,CreationDate,CreationTime,Dimensions,Exposure time,JPEG quality,Comment +SupportsThumbnail=true diff --git a/tdefile-plugins/jpeg/tdefile_jpeg.h b/tdefile-plugins/jpeg/tdefile_jpeg.h new file mode 100644 index 00000000..979ae515 --- /dev/null +++ b/tdefile-plugins/jpeg/tdefile_jpeg.h @@ -0,0 +1,44 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Frank Pieczynski + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_JPEG_H__ +#define __KFILE_JPEG_H__ + +#include <tqdatetime.h> +#include <tdefilemetainfo.h> + +class KJpegPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KJpegPlugin( TQObject *parent, const char *name, + const TQStringList& args ); + + virtual bool readInfo ( KFileMetaInfo& info, uint what ); + virtual bool writeInfo( const KFileMetaInfo& info ) const; + virtual TQValidator* createValidator( const KFileMetaInfoItem& item, + TQObject* parent, const char* name) const; + +private: + TQDateTime parseDateTime( const TQString& string ); +}; + +#endif diff --git a/tdefile-plugins/jpeg/tdefile_setcomment.cpp b/tdefile-plugins/jpeg/tdefile_setcomment.cpp new file mode 100644 index 00000000..07dca273 --- /dev/null +++ b/tdefile-plugins/jpeg/tdefile_setcomment.cpp @@ -0,0 +1,536 @@ +/* + * setcomment.cpp + * + * Copyright 2002 Bryce Nesbitt + * + * Based on wrjpgcom.c, Copyright (C) 1994-1997, Thomas G. Lane. + * Part of the Independent JPEG Group's software release 6b of 27-Mar-1998 + * + * This file contains a very simple stand-alone application that inserts + * user-supplied text as a COM (comment) marker in a JPEG/JFIF file. + * This may be useful as an example of the minimum logic needed to parse + * JPEG markers. + * + * There can be an arbitrary number of COM blocks in each jpeg file, with + * up to 64K of data each. We, however, write just one COM and blow away + * the rest. + * + ***************** + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#undef STANDALONE_COMPILE + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <string.h> +#include "config.h" + +extern int safe_copy_and_modify( const char * original_filename, const char * comment ); + +#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ +#define READ_BINARY "r" +#define WRITE_BINARY "w" +#else +#ifdef VMS /* VMS is very nonstandard */ +#define READ_BINARY "rb", "ctx=stm" +#define WRITE_BINARY "wb", "ctx=stm" +#else /* standard ANSI-compliant case */ +#define READ_BINARY "rb" +#define WRITE_BINARY "wb" +#endif +#endif + +#define WARNING_GARBAGE 1 /* Original file had some unspecified content */ +#define ERROR_NOT_A_JPEG 5 /* Original file not a proper jpeg (must be 1st) */ +#define ERROR_TEMP_FILE 6 /* Problem writing temporay file */ +#define ERROR_SCREWUP 7 /* Original file is now damaged. Ooops. */ +#define ERROR_PREMATURE_EOF 8 /* Unexpected end of file */ +#define ERROR_BAD_MARKER 9 /* Marker with illegal length */ +#define ERROR_MARKER_ORDER 10 /* File seems to be mixed up */ + +static int global_error; /* global error flag. Once set, we're dead. */ + +/****************************************************************************/ +/* + * These macros are used to read the input file and write the output file. + * To reuse this code in another application, you might need to change these. + */ +static FILE * infile; /* input JPEG file */ + +/* Return next input byte, or EOF if no more */ +#define NEXTBYTE() getc(infile) + +static FILE * outfile; /* output JPEG file */ + +/* Emit an output byte */ +#define PUTBYTE(x) putc((x), outfile) + + +/****************************************************************************/ +/* Read one byte, testing for EOF */ +static int +read_1_byte (void) +{ + int c; + + c = NEXTBYTE(); + if (c == EOF) { + global_error = ERROR_PREMATURE_EOF; + } + return c; +} + +/* Read 2 bytes, convert to unsigned int */ +/* All 2-byte quantities in JPEG markers are MSB first */ +static unsigned int +read_2_bytes (void) +{ + int c1, c2; + + c1 = NEXTBYTE(); + if (c1 == EOF) + global_error = ERROR_PREMATURE_EOF; + c2 = NEXTBYTE(); + if (c2 == EOF) + global_error = ERROR_PREMATURE_EOF; + return (((unsigned int) c1) << 8) + ((unsigned int) c2); +} + + +/****************************************************************************/ +/* Routines to write data to output file */ +static void +write_1_byte (int c) +{ + PUTBYTE(c); +} + +static void +write_2_bytes (unsigned int val) +{ + PUTBYTE((val >> 8) & 0xFF); + PUTBYTE(val & 0xFF); +} + +static void +write_marker (int marker) +{ + PUTBYTE(0xFF); + PUTBYTE(marker); +} + +static void +copy_rest_of_file (void) +{ + int c; + + while ((c = NEXTBYTE()) != EOF) + PUTBYTE(c); +} + + +/****************************************************************************/ +/* + * JPEG markers consist of one or more 0xFF bytes, followed by a marker + * code byte (which is not an FF). Here are the marker codes of interest + * in this program. (See jdmarker.c for a more complete list.) + */ + +#define M_SOF0 0xC0 /* Start Of Frame N */ +#define M_SOF1 0xC1 /* N indicates which compression process */ +#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ +#define M_SOF3 0xC3 +#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ +#define M_SOF6 0xC6 +#define M_SOF7 0xC7 +#define M_SOF9 0xC9 +#define M_SOF10 0xCA +#define M_SOF11 0xCB +#define M_SOF13 0xCD +#define M_SOF14 0xCE +#define M_SOF15 0xCF +#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ +#define M_EOI 0xD9 /* End Of Image (end of datastream) */ +#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ +#define M_COM 0xFE /* COMment */ + + +/* + * Find the next JPEG marker and return its marker code. + * We expect at least one FF byte, possibly more if the compressor used FFs + * to pad the file. (Padding FFs will NOT be replicated in the output file.) + * There could also be non-FF garbage between markers. The treatment of such + * garbage is unspecified; we choose to skip over it but emit a warning msg. + * NB: this routine must not be used after seeing SOS marker, since it will + * not deal correctly with FF/00 sequences in the compressed image data... + */ +static int +next_marker (void) +{ + int c; + int discarded_bytes = 0; + + /* Find 0xFF byte; count and skip any non-FFs. */ + c = read_1_byte(); + while (c != 0xFF) { + discarded_bytes++; + c = read_1_byte(); + } + /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs + * are legal as pad bytes, so don't count them in discarded_bytes. + */ + do { + c = read_1_byte(); + } while (c == 0xFF); + + if (discarded_bytes != 0) { + global_error = WARNING_GARBAGE; + } + + return c; +} + + +/* + * Most types of marker are followed by a variable-length parameter segment. + * This routine skips over the parameters for any marker we don't otherwise + * want to process. + * Note that we MUST skip the parameter segment explicitly in order not to + * be fooled by 0xFF bytes that might appear within the parameter segment; + * such bytes do NOT introduce new markers. + */ +static void +copy_variable (void) +/* Copy an unknown or uninteresting variable-length marker */ +{ + unsigned int length; + + /* Get the marker parameter length count */ + length = read_2_bytes(); + write_2_bytes(length); + /* Length includes itself, so must be at least 2 */ + if (length < 2) { + global_error = ERROR_BAD_MARKER; + length = 2; + } + length -= 2; + /* Skip over the remaining bytes */ + while (length > 0) { + write_1_byte(read_1_byte()); + length--; + } +} + +static void +skip_variable (void) +/* Skip over an unknown or uninteresting variable-length marker */ +{ + unsigned int length; + + /* Get the marker parameter length count */ + length = read_2_bytes(); + /* Length includes itself, so must be at least 2 */ + if (length < 2) { + global_error = ERROR_BAD_MARKER; + length = 2; + } + length -= 2; + /* Skip over the remaining bytes */ + while (length > 0) { + (void) read_1_byte(); + length--; + } +} + + +static int +scan_JPEG_header (int keep_COM) +/* + * Parse & copy the marker stream until SOFn or EOI is seen; + * copy data to output, but discard COM markers unless keep_COM is true. + */ +{ + int c1, c2; + int marker; + + /* + * Read the initial marker, which should be SOI. + * For a JFIF file, the first two bytes of the file should be literally + * 0xFF M_SOI. To be more general, we could use next_marker, but if the + * input file weren't actually JPEG at all, next_marker might read the whole + * file and then return a misleading error message... + */ + c1 = NEXTBYTE(); + c2 = NEXTBYTE(); + if (c1 != 0xFF || c2 != M_SOI) { + global_error = ERROR_NOT_A_JPEG; + return EOF; + } + + write_marker(M_SOI); + + /* Scan miscellaneous markers until we reach SOFn. */ + for (;;) { + marker = next_marker(); + switch (marker) { + /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, + * treated as SOFn. C4 in particular is actually DHT. + */ + case M_SOF0: /* Baseline */ + case M_SOF1: /* Extended sequential, Huffman */ + case M_SOF2: /* Progressive, Huffman */ + case M_SOF3: /* Lossless, Huffman */ + case M_SOF5: /* Differential sequential, Huffman */ + case M_SOF6: /* Differential progressive, Huffman */ + case M_SOF7: /* Differential lossless, Huffman */ + case M_SOF9: /* Extended sequential, arithmetic */ + case M_SOF10: /* Progressive, arithmetic */ + case M_SOF11: /* Lossless, arithmetic */ + case M_SOF13: /* Differential sequential, arithmetic */ + case M_SOF14: /* Differential progressive, arithmetic */ + case M_SOF15: /* Differential lossless, arithmetic */ + return marker; + + case M_SOS: /* should not see compressed data before SOF */ + global_error = ERROR_MARKER_ORDER; + break; + + case M_EOI: /* in case it's a tables-only JPEG stream */ + return marker; + + case M_COM: /* Existing COM: conditionally discard */ + if (keep_COM) { + write_marker(marker); + copy_variable(); + } else { + skip_variable(); + } + break; + + default: /* Anything else just gets copied */ + write_marker(marker); + copy_variable(); /* we assume it has a parameter count... */ + break; + } + } /* end loop */ +} + + +/****************************************************************************/ +/* + Verify we know how to set the comment on this type of file. + + TODO: The actual check! This should verify + the image size promised in the headers matches the file, + and that all markers are properly formatted. +*/ +static int validate_image_file( const char * filename ) +{ +int status = 1; +int c1, c2; + + if ( (infile = fopen(filename, READ_BINARY)) ) { + c1 = NEXTBYTE(); + c2 = NEXTBYTE(); + if (c1 != 0xFF || c2 != M_SOI) + status = ERROR_NOT_A_JPEG; + else + status = 0; + fclose( infile ); + } + return( status ); +} + + +/****************************************************************************/ +/* + Modify the file in place, but be paranoid and safe about it. + It's worth a few extra CPU cycles to make sure we never + destory an original image: + 1) Validate the input file. + 2) Open a temporary file. + 3) Copy the data, writing a new comment block. + 4) Validate the temporary file. + 5) Move the temporary file over the original. + + To be even more paranoid & safe we could: + 5) Rename the original to a different temporary name. + 6) Rename the temporary to the original. + 7) Delete the original. +*/ +extern int safe_copy_and_modify( const char * original_filename, const char * comment ) +{ +char * temp_filename; +int temp_filename_length; +int comment_length = 0; +int marker; +int i; +struct stat statbuf; + + global_error = 0; + + /* + * Make sure we're dealing with a proper input file. Safety first! + */ + if( validate_image_file( original_filename ) ) { + fprintf(stderr, "error validating original file %s\n", original_filename); + return(ERROR_NOT_A_JPEG); + } + + /* Get a unique temporary file in the same directory. Hopefully + * if things go wrong, this file will still be left for recovery purposes. + * + * NB: I hate these stupid string functions in C... the buffer length is too + * hard to manage... + */ + outfile = NULL; + temp_filename_length = strlen( original_filename) + 4; + temp_filename = (char *)calloc( temp_filename_length, 1 ); + for( i=0; i<10; i++ ) { + snprintf( temp_filename, temp_filename_length, "%s%d", original_filename, i ); + if( stat( temp_filename, &statbuf ) ) { + outfile = fopen(temp_filename, WRITE_BINARY); + break; + } + } + if( !outfile ) { + fprintf(stderr, "failed opening temporary file %s\n", temp_filename); + free(temp_filename); + return(ERROR_TEMP_FILE); + } + + + /* + * Let's rock and roll! + */ + if ((infile = fopen(original_filename, READ_BINARY)) == NULL) { + fprintf(stderr, "can't open input file %s\n", original_filename); + free(temp_filename); + return(ERROR_NOT_A_JPEG); + } + /* Copy JPEG headers until SOFn marker; + * we will insert the new comment marker just before SOFn. + * This (a) causes the new comment to appear after, rather than before, + * existing comments; and (b) ensures that comments come after any JFIF + * or JFXX markers, as required by the JFIF specification. + */ + marker = scan_JPEG_header(0); + /* Insert the new COM marker, but only if nonempty text has been supplied */ + if (comment) { + comment_length = strlen( comment ); + } + if (comment_length > 0) { + write_marker(M_COM); + write_2_bytes(comment_length + 2); + while (comment_length > 0) { + write_1_byte(*comment++); + comment_length--; + } + } + /* Duplicate the remainder of the source file. + * Note that any COM markers occurring after SOF will not be touched. + * + * :TODO: Discard COM markers occurring after SOF + */ + write_marker(marker); + copy_rest_of_file(); + fclose( infile ); + fsync( fileno( outfile) ); /* Make sure its really on disk first. !!!VERY IMPORTANT!!! */ + if ( fclose( outfile ) ) { + fprintf(stderr, "error in temporary file %s\n", temp_filename); + free(temp_filename); + return(ERROR_TEMP_FILE); + } + + + /* + * Make sure we did it right. We've already fsync()'ed the file. Safety first! + */ + if( validate_image_file( temp_filename ) ) { + fprintf(stderr, "error in temporary file %s\n", temp_filename); + free(temp_filename); + return(ERROR_TEMP_FILE); + } + + if( global_error >= ERROR_NOT_A_JPEG ) { + fprintf(stderr, "error %d processing %s\n", global_error, original_filename); + free(temp_filename); + return(ERROR_NOT_A_JPEG); + } + + if( rename( temp_filename, original_filename ) ) { + fprintf(stderr, "error renaming %s to %s\n", temp_filename, original_filename); + free(temp_filename); + return(ERROR_TEMP_FILE); + } + free(temp_filename); + + return(0); +} + + +#ifdef STANDALONE_COMPILE +int +main (int argc, char **argv) +{ + char * progname; /* program name for error messages */ + char * filename; + char * comment; + FILE * fp; + int error; + + /* Process command line arguments... */ + progname = argv[0]; + if (progname == NULL || progname[0] == 0) + progname = "writejpgcomment"; /* in case C library doesn't provide it */ + if( argc != 3) { + fprintf(stderr, "Usage: %s <filename> \"<comment>\"\nOverwrites the comment in a image file with the given comment.\n", progname); + return(5); + } + filename = argv[1]; + comment = argv[2]; + + + /* Check if file is readable... */ + if ((fp = fopen(filename, READ_BINARY)) == NULL) { + fprintf(stderr, "Error: Can't open file %s\n", filename); + fclose(fp); + return(5); + } + fclose(fp); + + /* Check if we really have a commentable image file here... */ + if( validate_image_file( filename ) ) { + fprintf(stderr, "Error: file %s is not of a supported type\n", filename); + return(5); + } + + /* Lets do it... modify the comment in place */ + if ((error = safe_copy_and_modify( filename, comment ) )) { + fprintf(stderr, "Error: %d setting jpg comment\n", error); + return(10); + } + + + /* TODO: Read comment back out of jpg and display it */ + return( 0 ); +} +#endif diff --git a/tdefile-plugins/pcx/CMakeLists.txt b/tdefile-plugins/pcx/CMakeLists.txt new file mode 100644 index 00000000..7eea5125 --- /dev/null +++ b/tdefile-plugins/pcx/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_pcx.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_pcx (module) ######################### + +tde_add_kpart( tdefile_pcx AUTOMOC + SOURCES tdefile_pcx.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/pcx/Makefile.am b/tdefile-plugins/pcx/Makefile.am new file mode 100644 index 00000000..18249bc6 --- /dev/null +++ b/tdefile-plugins/pcx/Makefile.am @@ -0,0 +1,21 @@ +## Makefile.am for PCX file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +noinst_HEADERS = tdefile_pcx.h + +kde_module_LTLIBRARIES = tdefile_pcx.la + +tdefile_pcx_la_SOURCES = tdefile_pcx.cpp +tdefile_pcx_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_pcx_la_LIBADD = $(LIB_KIO) $(LIBTIFF) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdefile_pcx.pot + +services_DATA = tdefile_pcx.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/pcx/tdefile_pcx.cpp b/tdefile-plugins/pcx/tdefile_pcx.cpp new file mode 100644 index 00000000..2c4047a6 --- /dev/null +++ b/tdefile-plugins/pcx/tdefile_pcx.cpp @@ -0,0 +1,122 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Nadeem Hasan <nhasan@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "tdefile_pcx.h" + +#include <kgenericfactory.h> +#include <kdebug.h> + +#include <tqdatastream.h> +#include <tqfile.h> + +typedef KGenericFactory<KPcxPlugin> PcxFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_pcx, PcxFactory("tdefile_pcx")) + +TQDataStream &operator>>( TQDataStream &s, PALETTE &pal ) +{ + for ( int i=0; i<16; ++i ) + s >> pal.p[ i ].r >> pal.p[ i ].g >> pal.p[ i ].b; + + return s; +} + +TQDataStream &operator>>( TQDataStream &s, PCXHEADER &ph ) +{ + s >> ph.Manufacturer; + s >> ph.Version; + s >> ph.Encoding; + s >> ph.Bpp; + s >> ph.XMin >> ph.YMin >> ph.XMax >> ph.YMax; + s >> ph.HDpi >> ph.YDpi; + s >> ph.Palette; + s >> ph.Reserved; + s >> ph.NPlanes; + s >> ph.BytesPerLine; + s >> ph.PaletteInfo; + s >> ph.HScreenSize; + s >> ph.VScreenSize; + + return s; +} + +KPcxPlugin::KPcxPlugin( TQObject *parent, const char *name, + const TQStringList &args ) : KFilePlugin( parent, name, args ) +{ + kdDebug(7034) << "PCX file meta info plugin" << endl; + KFileMimeTypeInfo* info = addMimeTypeInfo( "image/x-pcx" ); + + KFileMimeTypeInfo::GroupInfo* group = + addGroupInfo( info, "General", i18n( "General" ) ); + + KFileMimeTypeInfo::ItemInfo* item; + item = addItemInfo( group, "Dimensions", i18n( "Dimensions" ), + TQVariant::Size ); + setHint( item, KFileMimeTypeInfo::Size ); + setUnit( item, KFileMimeTypeInfo::Pixels ); + item = addItemInfo( group, "BitDepth", i18n( "Bit Depth" ), + TQVariant::Int ); + setUnit( item, KFileMimeTypeInfo::BitsPerPixel ); + item = addItemInfo( group, "Resolution", i18n( "Resolution" ), + TQVariant::Size ); + setUnit( item, KFileMimeTypeInfo::DotsPerInch ); + item = addItemInfo( group, "Compression", i18n( "Compression" ), + TQVariant::String ); +} + +bool KPcxPlugin::readInfo( KFileMetaInfo& info, uint ) +{ + if ( info.path().isEmpty() ) + return false; + + struct PCXHEADER header; + + TQFile f( info.path() ); + if ( !f.open( IO_ReadOnly ) ) + return false; + + TQDataStream s( &f ); + s.setByteOrder( TQDataStream::LittleEndian ); + + s >> header; + + int w = ( header.XMax-header.XMin ) + 1; + int h = ( header.YMax-header.YMin ) + 1; + int bpp = header.Bpp*header.NPlanes; + + KFileMetaInfoGroup group = appendGroup( info, "General" ); + + appendItem( group, "Dimensions", TQSize( w, h ) ); + appendItem( group, "BitDepth", bpp ); + appendItem( group, "Resolution", TQSize( header.HDpi, header.YDpi ) ); + if ( header.Encoding == 1 ) + appendItem( group, "Compression", i18n( "Yes (RLE)" ) ); + else + appendItem( group, "Compression", i18n( "None" ) ); + + f.close(); + + return true; +} + +#include "tdefile_pcx.moc" + +/* vim: et sw=2 ts=2 +*/ + diff --git a/tdefile-plugins/pcx/tdefile_pcx.desktop b/tdefile-plugins/pcx/tdefile_pcx.desktop new file mode 100644 index 00000000..bcf54b6a --- /dev/null +++ b/tdefile-plugins/pcx/tdefile_pcx.desktop @@ -0,0 +1,62 @@ +[Desktop Entry] +Type=Service +Name=PCX File Meta Info +Name[ar]=معلومات ملف PCX +Name[br]=Meta-titouroù ar restr PCX +Name[bs]=PCX meta-podaci +Name[ca]=Metainformació de fitxer PCX +Name[cs]=Metainformace obrázku typu PCX +Name[cy]=Meta-wybodaeth Ffeil PCX +Name[da]=PCX Fil-meta-info +Name[de]=PCX Metainformation +Name[el]=Μετα-πληροφορίες αρχείου PCX +Name[eo]=PCX-dosiera metainformo +Name[es]=Info meta de archivos PCX +Name[et]=PCX faili metainfo +Name[eu]=PCX fitxategi meta info +Name[fa]=فرااطلاعات پروندۀ PCX +Name[fi]=PCX-tiedoston metatiedot +Name[fr]=Méta Informations sur les fichiers PCX +Name[gl]=Inf. metaficheiro PCX +Name[he]=מידע PCX +Name[hi]=PCX फ़ाइल मेटा जानकारी +Name[hu]=PCX-jellemzők +Name[is]=PCX File Meta upplýsingar +Name[it]=Informazioni PCX +Name[ja]=PCX ファイルメタ情報 +Name[kk]=PCX файлдың мета деректері +Name[km]=ព័ត៌មានមេតារបស់ឯកសារ PCX +Name[lt]=PCX bylos meta informacija +Name[ms]=Maklumat Meta Fail PCX +Name[nb]=PCX-filmetainfo +Name[nds]=PCX-Metainfo +Name[ne]=PCX फाइल मेटा सूचना +Name[nl]=PCX meta-info +Name[nn]=PCX-filmetainfo +Name[pl]=Informacja o pliku PCX +Name[pt]=Meta-Informação do Ficheiro PCX +Name[pt_BR]=Informação sobre Meta Arquivo PCX +Name[ro]=Metainformaţii PCX +Name[ru]=Информация о метафайле PCX +Name[se]=PCX-filla metadieđut +Name[sk]=Meta-info o súbore PCX +Name[sl]=Meta podatki o PCX +Name[sr]=Мета информације PCX фајла +Name[sr@Latn]=Meta informacije PCX fajla +Name[sv]=Metainformation om PCX-fil +Name[ta]=PCX File Meta தகவல் +Name[tg]=Иттилоот оиди метафайли PCX +Name[th]=ข้อมูลเมตาแฟ้ม PCX +Name[tr]=PCX Dosya Bilgisi +Name[uk]=Метаінформація про файл PCX +Name[uz]=PCX-faylining meta-maʼlumoti +Name[uz@cyrillic]=PCX-файлининг мета-маълумоти +Name[wa]=Informåcion sol imådje PCX +Name[zh_CN]=PCX 文件元信息 +Name[zh_HK]=PCX 檔案 Meta 資訊 +Name[zh_TW]=PCX 檔案 Meta 資訊 +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_pcx +MimeType=image/x-pcx +PreferredGroups=General +PreferredItems=Dimensions,Resolution,BitDepth,Compression diff --git a/tdefile-plugins/pcx/tdefile_pcx.h b/tdefile-plugins/pcx/tdefile_pcx.h new file mode 100644 index 00000000..c7b62e2e --- /dev/null +++ b/tdefile-plugins/pcx/tdefile_pcx.h @@ -0,0 +1,89 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Nadeem Hasan <nhasan@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_PCX_H_ +#define __KFILE_PCX_H_ + +#include <tdefilemetainfo.h> + +struct PALETTE +{ + struct + { + TQ_UINT8 r; + TQ_UINT8 g; + TQ_UINT8 b; + } p[ 16 ]; +}; + +struct PCXHEADER +{ + TQ_UINT8 Manufacturer; // Constant Flag, 10 = ZSoft .pcx + TQ_UINT8 Version; // Version information + // 0 = Version 2.5 of PC Paintbrush + // 2 = Version 2.8 w/palette information + // 3 = Version 2.8 w/o palette information + // 4 = PC Paintbrush for Windows(Plus for + // Windows uses Ver 5) + // 5 = Version 3.0 and > of PC Paintbrush + // and PC Paintbrush +, includes + // Publisher's Paintbrush . Includes + // 24-bit .PCX files + TQ_UINT8 Encoding; // 1 = .PCX run length encoding + TQ_UINT8 Bpp; // Number of bits to represent a pixel + // (per Plane) - 1, 2, 4, or 8 + TQ_UINT16 XMin; + TQ_UINT16 YMin; + TQ_UINT16 XMax; + TQ_UINT16 YMax; + TQ_UINT16 HDpi; + TQ_UINT16 YDpi; + struct PALETTE Palette; + TQ_UINT8 Reserved; // Should be set to 0. + TQ_UINT8 NPlanes; // Number of color planes + TQ_UINT16 BytesPerLine; // Number of bytes to allocate for a scanline + // plane. MUST be an EVEN number. Do NOT + // calculate from Xmax-Xmin. + TQ_UINT16 PaletteInfo; // How to interpret palette- 1 = Color/BW, + // 2 = Grayscale ( ignored in PB IV/ IV + ) + TQ_UINT16 HScreenSize; //Qt::Horizontal screen size in pixels. New field + // found only in PB IV/IV Plus + TQ_UINT16 VScreenSize; //Qt::Vertical screen size in pixels. New field + // found only in PB IV/IV Plus + TQ_UINT8 Filler[ 54 ]; // Blank to fill out 128 byte header. Set all + // bytes to 0 +}; + +class KPcxPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KPcxPlugin(TQObject *parent, const char *name, const TQStringList& args); + virtual bool readInfo(KFileMetaInfo& info, uint what); + +private: +}; + +#endif + +/* vim: et sw=2 ts=2 +*/ + diff --git a/tdefile-plugins/pdf/CMakeLists.txt b/tdefile-plugins/pdf/CMakeLists.txt new file mode 100644 index 00000000..5a81d453 --- /dev/null +++ b/tdefile-plugins/pdf/CMakeLists.txt @@ -0,0 +1,36 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/tdefile-plugins/dependencies/poppler-tqt +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_pdf.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_pdf (module) ######################### + +tde_add_kpart( tdefile_pdf AUTOMOC + SOURCES tdefile_pdf.cpp + LINK tdeio-shared -L${CMAKE_BINARY_DIR}/tdefile-plugins/dependencies/poppler-tqt -lpoppler-tqt + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/pdf/Makefile.am b/tdefile-plugins/pdf/Makefile.am new file mode 100644 index 00000000..a6f38115 --- /dev/null +++ b/tdefile-plugins/pdf/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for the pdf file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) -I$(top_srcdir)/tdefile-plugins/dependencies/poppler-tqt + +# these are the headers for your project +noinst_HEADERS = tdefile_pdf.h + +kde_module_LTLIBRARIES = tdefile_pdf.la + +tdefile_pdf_la_SOURCES = tdefile_pdf.cpp +tdefile_pdf_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_pdf_la_LIBADD = $(LIB_KIO) -L$(top_builddir)/tdefile-plugins/dependencies/poppler-tqt/ -lpoppler-tqt + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdefile_pdf.pot + +services_DATA = tdefile_pdf.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/pdf/configure.in.in b/tdefile-plugins/pdf/configure.in.in new file mode 100644 index 00000000..ec2fff51 --- /dev/null +++ b/tdefile-plugins/pdf/configure.in.in @@ -0,0 +1,16 @@ +AC_ARG_WITH([poppler], + [AC_HELP_STRING([--with-poppler], + [Enable PDF support through poppler @<:@default=check@:>@])], + [], with_poppler=check) + +## Compile the pdf meta info plugin only if Poppler is available +#if test "x$with_poppler" != xno; then +# PKG_CHECK_MODULES(POPPLER, poppler-qt >= 0.3.1, have_poppler=yes, have_poppler=no) +# +# if test "x$with_poppler" != xcheck && test "x$have_poppler" != xyes; then +# AC_MSG_ERROR([--with-poppler was given, but test for poppler failed]) +# fi +#fi + +have_poppler=yes +AM_CONDITIONAL(include_PDF, test "x$have_poppler" = xyes) diff --git a/tdefile-plugins/pdf/tdefile_pdf.cpp b/tdefile-plugins/pdf/tdefile_pdf.cpp new file mode 100644 index 00000000..b3bacc02 --- /dev/null +++ b/tdefile-plugins/pdf/tdefile_pdf.cpp @@ -0,0 +1,104 @@ +/* This file is part of the KDE project + * Copyright (C) 2001, 2002 Rolf Magnus <ramagnus@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $Id$ + */ + +#include "tdefile_pdf.h" + +#include <kgenericfactory.h> +#include <kdebug.h> + +typedef KGenericFactory<KPdfPlugin> PdfFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_pdf, PdfFactory("tdefile_pdf")) + +KPdfPlugin::KPdfPlugin(TQObject *parent, const char *name, const TQStringList &preferredItems) + : KFilePlugin(parent, name, preferredItems) +{ + kdDebug(7034) << "pdf plugin\n"; + + // set up our mime type + KFileMimeTypeInfo* info = addMimeTypeInfo( "application/pdf" ); + + // general group + KFileMimeTypeInfo::GroupInfo* group = addGroupInfo(info, "General", i18n("General")); + + KFileMimeTypeInfo::ItemInfo* item; + + item = addItemInfo(group, "Title", i18n("Title"), TQVariant::String); + setHint(item, KFileMimeTypeInfo::Name); + item = addItemInfo(group, "Subject", i18n("Subject"), TQVariant::String); + setHint(item, KFileMimeTypeInfo::Description); + item = addItemInfo(group, "Author", i18n("Author"), TQVariant::String); + setHint(item, KFileMimeTypeInfo::Author); + addItemInfo(group, "Keywords", i18n("Key Words"), TQVariant::String); + addItemInfo(group, "Creator", i18n("Creator"), TQVariant::String); + addItemInfo(group, "Producer", i18n("Producer"), TQVariant::String); + addItemInfo(group, "CreationDate", i18n("Creation Date"), TQVariant::DateTime); + addItemInfo(group, "ModificationDate", i18n("Modified"), TQVariant::DateTime); + addItemInfo(group, "Pages", i18n("Pages"), TQVariant::Int); + addItemInfo(group, "Protected", i18n("Protected"), TQVariant::String); + addItemInfo(group, "Linearized", i18n("Linearized"), TQVariant::String); + addItemInfo(group, "Version", i18n("Version"), TQVariant::String); +} + +bool KPdfPlugin::readInfo( KFileMetaInfo& info, uint /* what */) +{ + Poppler::Document *doc = Poppler::Document::load(info.path()); + if (!doc || doc->isLocked()) + { + delete doc; + return false; + } + + KFileMetaInfoGroup generalGroup = appendGroup(info, "General"); + + appendItem(generalGroup, "Title", doc->getInfo("Title") ); + appendItem(generalGroup, "Subject", doc->getInfo("Subject") ); + appendItem(generalGroup, "Author", doc->getInfo("Author") ); + appendItem(generalGroup, "Keywords", doc->getInfo("Keywords") ); + appendItem(generalGroup, "Creator", doc->getInfo("Creator") ); + appendItem(generalGroup, "Producer", doc->getInfo("Producer") ); + + appendItem(generalGroup, "CreationDate", doc->getDate("CreationDate") ); + appendItem(generalGroup, "ModificationDate", doc->getDate("ModDate") ); + appendItem(generalGroup, "Pages", doc->getNumPages() ); + + TQString enc; + if (doc->isEncrypted()) + { + enc = i18n("Yes (Can Print:%1 Can Copy:%2 Can Change:%3 Can Add notes:%4)") + .arg(doc->okToPrint() ? i18n("Yes") : i18n("No")) + .arg(doc->okToCopy() ? i18n("Yes") : i18n("No")) + .arg(doc->okToChange() ? i18n("Yes") : i18n("No")) + .arg(doc->okToAddNotes() ? i18n("Yes") : i18n("No")); + } + else enc = i18n("No"); + + appendItem(generalGroup, "Protected", enc ); + appendItem(generalGroup, "Linearized", doc->isLinearized() ? i18n("Yes") : i18n("No") ); + TQString versionString = TQString("%1").arg( doc->getPDFVersion(), 0, 'f', 1 ); + appendItem(generalGroup, "Version", versionString ); + + delete doc; + + return true; +} + +#include "tdefile_pdf.moc" + diff --git a/tdefile-plugins/pdf/tdefile_pdf.desktop b/tdefile-plugins/pdf/tdefile_pdf.desktop new file mode 100644 index 00000000..41f4d21f --- /dev/null +++ b/tdefile-plugins/pdf/tdefile_pdf.desktop @@ -0,0 +1,64 @@ +[Desktop Entry] +Type=Service +Name=PDF Info +Name[af]=Pdf Inligting +Name[ar]=معلومات PDF +Name[br]=Titouroù PDF +Name[ca]=Informació de PDF +Name[cs]=PDF info +Name[cy]=Gybodaeth PDF +Name[da]=PDF-info +Name[de]=PDF-Info +Name[el]=Πληροφορίες PDF +Name[eo]=PDF-informo +Name[es]=Info PDF +Name[et]=PDF info +Name[fa]=اطلاعات PDF +Name[fi]=PDF-tiedot +Name[fr]=Informations PDF +Name[gl]=Inf. PDF +Name[he]=מידע PDF +Name[hi]=PDF जानकारी +Name[hr]=PDF Informacije +Name[hu]=PDF-jellemzők +Name[is]=PDF upplýsingar +Name[it]=Informazioni PDF +Name[ja]=PDF 情報 +Name[kk]=PDF мәліметі +Name[km]=ព័ត៌មាន PDF +Name[lt]=PDF informacija +Name[ms]=Maklumat PDF +Name[nds]=PDF-Info +Name[ne]=PDF सूचना +Name[nl]=PDF-info +Name[nn]=PDF-info +Name[nso]=Tshedimoso ya PDF +Name[pa]=PDF ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku PDF +Name[pt]=Informação do PDF +Name[pt_BR]=Informação sobre PDF +Name[ro]=Informaţii PDF +Name[ru]=Информация о PDF +Name[se]=PDF-dieđut +Name[sl]=Podatki o PDF +Name[sr]=PDF информације +Name[sr@Latn]=PDF informacije +Name[sv]=PDF-information +Name[ta]=PDF தகவல் +Name[tg]=Иттилоот оиди PDF +Name[th]=ข้อมูลแฟ้ม PDF +Name[tr]=PDF Bilgisi +Name[uk]=Інформація про PDF +Name[uz]=PDF haqida maʼlumot +Name[uz@cyrillic]=PDF ҳақида маълумот +Name[ven]=Mafhungo a PDF +Name[wa]=Informåcion sol documint PDF +Name[xh]=PDF Ulwazi +Name[zh_CN]=PDF 信息 +Name[zh_HK]=PDF 資訊 +Name[zh_TW]=PDF 資訊 +Name[zu]=Ulwazi lwe-PDF +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_pdf +MimeType=application/pdf +PreferredItems=Title,Subject,Author,Keywords,Creator,Producer,CreationDate,ModificationDate,Pages,Protected,Linearized,Version diff --git a/tdefile-plugins/pdf/tdefile_pdf.h b/tdefile-plugins/pdf/tdefile_pdf.h new file mode 100644 index 00000000..d23971c7 --- /dev/null +++ b/tdefile-plugins/pdf/tdefile_pdf.h @@ -0,0 +1,39 @@ +/* This file is part of the KDE project + * Copyright (C) 2001, 2002 Rolf Magnus <ramagnus@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $Id$ + */ + +#ifndef __KFILE_PDF_H__ +#define __KFILE_PDF_H__ + +#include <tdefilemetainfo.h> +#include <poppler-qt.h> + +class TQStringList; + +class KPdfPlugin: public KFilePlugin +{ +Q_OBJECT + +public: + KPdfPlugin( TQObject *parent, const char *name, const TQStringList& preferredItems ); + + virtual bool readInfo(KFileMetaInfo& info, uint what); +}; + +#endif diff --git a/tdefile-plugins/png/CMakeLists.txt b/tdefile-plugins/png/CMakeLists.txt new file mode 100644 index 00000000..7000bcd7 --- /dev/null +++ b/tdefile-plugins/png/CMakeLists.txt @@ -0,0 +1,34 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_png.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_png (module) ######################### +tde_add_kpart( tdefile_png AUTOMOC + SOURCES tdefile_png.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/png/Makefile.am b/tdefile-plugins/png/Makefile.am new file mode 100644 index 00000000..7ce05e86 --- /dev/null +++ b/tdefile-plugins/png/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for png file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_png.h + +kde_module_LTLIBRARIES = tdefile_png.la + +tdefile_png_la_SOURCES = tdefile_png.cpp +tdefile_png_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_png_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdefile_png.pot + +services_DATA = tdefile_png.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/png/tdefile_png.cpp b/tdefile-plugins/png/tdefile_png.cpp new file mode 100644 index 00000000..9766fbc6 --- /dev/null +++ b/tdefile-plugins/png/tdefile_png.cpp @@ -0,0 +1,315 @@ +/* This file is part of the KDE project + * Copyright (C) 2001, 2002 Rolf Magnus <ramagnus@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $Id$ + */ + +#include <stdlib.h> +#include "tdefile_png.h" + +#include <kurl.h> +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kdebug.h> + +#include <tqcstring.h> +#include <tqfile.h> +#include <tqdatetime.h> +#include <tqdict.h> +#include <tqvalidator.h> +#include <zlib.h> + +// some defines to make it easier +// don't tell me anything about preprocessor usage :) +#define CHUNK_SIZE(data, index) ((data[index ]<<24) + (data[index+1]<<16) + \ + (data[index+2]<< 8) + data[index+3]) +#define CHUNK_TYPE(data, index) &data[index+4] +#define CHUNK_HEADER_SIZE 12 +#define CHUNK_DATA(data, index, offset) data[8+index+offset] + +// known translations for common png keys +static const char* knownTranslations[] +#ifdef __GNUC__ +__attribute__((unused)) +#endif + = { + I18N_NOOP("Title"), + I18N_NOOP("Author"), + I18N_NOOP("Description"), + I18N_NOOP("Copyright"), + I18N_NOOP("Creation Time"), + I18N_NOOP("Software"), + I18N_NOOP("Disclaimer"), + I18N_NOOP("Warning"), + I18N_NOOP("Source"), + I18N_NOOP("Comment") +}; + +// and for the colors +static const char* colors[] = { + I18N_NOOP("Grayscale"), + I18N_NOOP("Unknown"), + I18N_NOOP("RGB"), + I18N_NOOP("Palette"), + I18N_NOOP("Grayscale/Alpha"), + I18N_NOOP("Unknown"), + I18N_NOOP("RGB/Alpha") +}; + + // and compressions +static const char* compressions[] = +{ + I18N_NOOP("Deflate") +}; + + // interlaced modes +static const char* interlaceModes[] = { + I18N_NOOP("None"), + I18N_NOOP("Adam7") +}; + +typedef KGenericFactory<KPngPlugin> PngFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_png, PngFactory("tdefile_png")) + +KPngPlugin::KPngPlugin(TQObject *parent, const char *name, + const TQStringList &args) + : KFilePlugin(parent, name, args) +{ + kdDebug(7034) << "png plugin\n"; + + // set up our mime type + KFileMimeTypeInfo* info = addMimeTypeInfo( "image/png" ); + + KFileMimeTypeInfo::GroupInfo* group = 0; + KFileMimeTypeInfo::ItemInfo* item = 0; + + // comment group + group = addGroupInfo(info, "Comment", i18n("Comment")); + addVariableInfo(group, TQVariant::String, 0); + + // technical group + group = addGroupInfo(info, "Technical", i18n("Technical Details")); + + item = addItemInfo(group, "Dimensions", i18n("Dimensions"), TQVariant::Size); + setHint( item, KFileMimeTypeInfo::Size ); + setUnit(item, KFileMimeTypeInfo::Pixels); + + item = addItemInfo(group, "BitDepth", i18n("Bit Depth"), TQVariant::Int); + setUnit(item, KFileMimeTypeInfo::BitsPerPixel); + + addItemInfo(group, "ColorMode", i18n("Color Mode"), TQVariant::String); + addItemInfo(group, "Compression", i18n("Compression"), TQVariant::String); + addItemInfo(group, "InterlaceMode", i18n("Interlace Mode"),TQVariant::String); +} + +bool KPngPlugin::readInfo( KFileMetaInfo& info, uint what) +{ + if ( info.path().isEmpty() ) // remote file + return false; + TQFile f(info.path()); + if ( !f.open(IO_ReadOnly) ) + return false; + + TQIODevice::Offset fileSize = f.size(); + + if (fileSize < 29) return false; + // the technical group will be read from the first 29 bytes. If the file + // is smaller, we can't even read this. + + bool readComments = false; + if (what & (KFileMetaInfo::Fastest | + KFileMetaInfo::DontCare | + KFileMetaInfo::ContentInfo)) readComments = true; + else + fileSize = 29; // No need to read more + + uchar *data = new uchar[fileSize+1]; + f.readBlock(reinterpret_cast<char*>(data), fileSize); + data[fileSize]='\n'; + + // find the start + if (data[0] == 137 && data[1] == 80 && data[2] == 78 && data[3] == 71 && + data[4] == 13 && data[5] == 10 && data[6] == 26 && data[7] == 10 ) + { + // ok + // the IHDR chunk should be the first + if (!strncmp((char*)&data[12], "IHDR", 4)) + { + // we found it, get the dimensions + ulong x,y; + x = (data[16]<<24) + (data[17]<<16) + (data[18]<<8) + data[19]; + y = (data[20]<<24) + (data[21]<<16) + (data[22]<<8) + data[23]; + + uint type = data[25]; + uint bpp = data[24]; + kdDebug(7034) << "dimensions " << x << "*" << y << endl; + + // the bpp are only per channel, so we need to multiply the with + // the channel count + switch (type) + { + case 0: break; // Grayscale + case 2: bpp *= 3; break; // RGB + case 3: break; // palette + case 4: bpp *= 2; break; // grayscale w. alpha + case 6: bpp *= 4; break; // RGBA + + default: // we don't get any sensible value here + bpp = 0; + } + + KFileMetaInfoGroup techgroup = appendGroup(info, "Technical"); + + appendItem(techgroup, "Dimensions", TQSize(x, y)); + appendItem(techgroup, "BitDepth", bpp); + appendItem(techgroup, "ColorMode", + (type < sizeof(colors)/sizeof(colors[0])) + ? i18n(colors[data[25]]) : i18n("Unknown")); + + appendItem(techgroup, "Compression", + (data[26] < sizeof(compressions)/sizeof(compressions[0])) + ? i18n(compressions[data[26]]) : i18n("Unknown")); + + appendItem(techgroup, "InterlaceMode", + (data[28] < sizeof(interlaceModes)/sizeof(interlaceModes[0])) + ? i18n(interlaceModes[data[28]]) : i18n("Unknown")); + } + + // look for a tEXt chunk + if (readComments) + { + uint index = 8; + index += CHUNK_SIZE(data, index) + CHUNK_HEADER_SIZE; + KFileMetaInfoGroup commentGroup = appendGroup(info, "Comment"); + + while(index<fileSize-12) + { + while (index < fileSize - 12 && + strncmp((char*)CHUNK_TYPE(data,index), "tEXt", 4) && + strncmp((char*)CHUNK_TYPE(data,index), "zTXt", 4)) + + { + if (!strncmp((char*)CHUNK_TYPE(data,index), "IEND", 4)) + goto end; + + index += CHUNK_SIZE(data, index) + CHUNK_HEADER_SIZE; + } + + if (index < fileSize - 12) + { + // we found a tEXt or zTXt field + + // get the key, it's a null terminated string at the + // chunk start + + uchar* key = &CHUNK_DATA(data,index,0); + + int keysize=0; + for (;key[keysize]!=0; keysize++) + // look if we reached the end of the file + // (it might be corrupted) + if (8+index+keysize>=fileSize) + goto end; + + TQByteArray arr; + if(!strncmp((char*)CHUNK_TYPE(data,index), "zTXt", 4)) { + kdDebug(7034) << "We found a zTXt field\n"; + // we get the compression method after the key + uchar* compressionMethod = &CHUNK_DATA(data,index,keysize+1); + if ( *compressionMethod != 0x00 ) { + // then it isn't zlib compressed and we are sunk + kdDebug(7034) << "Non-standard compression method." << endl; + goto end; + } + // compressed string after the compression technique spec + uchar* compressedText = &CHUNK_DATA(data, index, keysize+2); + uint compressedTextSize = CHUNK_SIZE(data, index)-keysize-2; + + // security check, also considering overflow wraparound from the addition -- + // we may endup with a /smaller/ index if we wrap all the way around + uint firstIndex = (uint)(compressedText - data); + uint onePastLastIndex = firstIndex + compressedTextSize; + if ( onePastLastIndex > fileSize || onePastLastIndex <= firstIndex) + goto end; + + uLongf uncompressedLen = compressedTextSize * 2; // just a starting point + int zlibResult; + do { + arr.resize(uncompressedLen); + zlibResult = uncompress((Bytef*)arr.data(), &uncompressedLen, + compressedText, compressedTextSize); + if (Z_OK == zlibResult) { + // then it is all OK + arr.resize(uncompressedLen); + } else if (Z_BUF_ERROR == zlibResult) { + // the uncompressedArray needs to be larger + // kdDebug(7034) << "doubling size for decompression" << endl; + uncompressedLen *= 2; + + // DoS protection. can't be bigger than 64k + if ( uncompressedLen > 131072 ) + break; + } else { + // something bad happened + goto end; + } + } while (Z_BUF_ERROR == zlibResult); + + if (Z_OK != zlibResult) + goto end; + } else if (!strncmp((char*)CHUNK_TYPE(data,index), "tEXt", 4)) { + kdDebug(7034) << "We found a tEXt field\n"; + // the text comes after the key, but isn't null terminated + uchar* text = &CHUNK_DATA(data,index, keysize+1); + uint textsize = CHUNK_SIZE(data, index)-keysize-1; + + // security check, also considering overflow wraparound from the addition -- + // we may endup with a /smaller/ index if we wrap all the way around + uint firstIndex = (uint)(text - data); + uint onePastLastIndex = firstIndex + textsize; + + if ( onePastLastIndex > fileSize || onePastLastIndex <= firstIndex) + goto end; + + arr.resize(textsize); + arr = TQByteArray(textsize).duplicate((const char*)text, + textsize); + + } else { + kdDebug(7034) << "We found a field, not expected though\n"; + goto end; + } + appendItem(commentGroup, + TQString(reinterpret_cast<char*>(key)), + TQString(arr)); + + kdDebug(7034) << "adding " << key << " / " + << TQString(arr) << endl; + + index += CHUNK_SIZE(data, index) + CHUNK_HEADER_SIZE; + } + } + } + } +end: + delete[] data; + return true; +} + +#include "tdefile_png.moc" diff --git a/tdefile-plugins/png/tdefile_png.desktop b/tdefile-plugins/png/tdefile_png.desktop new file mode 100644 index 00000000..ad2b98e0 --- /dev/null +++ b/tdefile-plugins/png/tdefile_png.desktop @@ -0,0 +1,65 @@ +[Desktop Entry] +Type=Service +Name=PNG Info +Name[af]=Png Inligting +Name[ar]=معلومات PNG +Name[br]=Titouroù PNG +Name[ca]=Informació de PNG +Name[cs]=PNG info +Name[cy]=Gybodaeth PNG +Name[da]=PNG-info +Name[de]=PNG-Info +Name[el]=Πληροφορίες PNG +Name[eo]=PNG-informo +Name[es]=Info PNG +Name[et]=PNG info +Name[fa]=اطلاعات PNG +Name[fi]=PNG-tiedot +Name[fr]=Informations PNG +Name[gl]=Inf. PNG +Name[he]=מידע PNG +Name[hi]=PNG जानकारी +Name[hr]=PNG Informacije +Name[hu]=PNG-jellemzők +Name[is]=PNG upplýsingar +Name[it]=Informazioni PNG +Name[ja]=PNG 情報 +Name[kk]=PNG мәліметі +Name[km]=ព័ត៌មាន PNG +Name[lt]=PNG informacija +Name[ms]=Maklumat PNG +Name[nds]=PNG-Info +Name[ne]=PNG सूचना +Name[nl]=PNG-Info +Name[nn]=PNG-info +Name[nso]=Tshedimoso ya PNG +Name[pa]=PNG ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku PNG +Name[pt]=Informação do PNG +Name[pt_BR]= Informação sobre PNG +Name[ro]=Informaţii PNG +Name[ru]=Информация о PNG +Name[se]=PNG-dieđut +Name[sl]=Podatki o PNG +Name[sr]=PNG информације +Name[sr@Latn]=PNG informacije +Name[sv]=PNG-information +Name[ta]=PNG தகவல் +Name[tg]=Иттилоот оиди PNG +Name[th]=ข้อมูลแฟ้ม PNG +Name[tr]=PNG Bilgisi +Name[uk]=Інформація про PNG +Name[uz]=PNG haqida maʼlumot +Name[uz@cyrillic]=PNG ҳақида маълумот +Name[ven]=Mafhungo a PNG +Name[wa]=Informåcion sol imådje PNG +Name[xh]=PNG Ulwazi +Name[zh_CN]=PNG 信息 +Name[zh_HK]=PNG 資訊 +Name[zh_TW]=PNG 資訊 +Name[zu]=Ulwazi lwe-PNG +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_png +MimeType=image/png +PreferredGroups=Comment,Technical +PreferredItems=Title,Author,Dimensions,BitDepth,ColorMode,Compression diff --git a/tdefile-plugins/png/tdefile_png.h b/tdefile-plugins/png/tdefile_png.h new file mode 100644 index 00000000..17fa31c8 --- /dev/null +++ b/tdefile-plugins/png/tdefile_png.h @@ -0,0 +1,40 @@ +/* This file is part of the KDE project + * Copyright (C) 2001, 2002 Rolf Magnus <ramagnus@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $Id$ + */ + +#ifndef __KFILE_PNG_H__ +#define __KFILE_PNG_H__ + +#include <tdefilemetainfo.h> +#include <kurl.h> + +class TQStringList; + +class KPngPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KPngPlugin( TQObject *parent, const char *name, const TQStringList& preferredItems ); + + virtual bool readInfo( KFileMetaInfo& info, uint ); +}; + +#endif diff --git a/tdefile-plugins/pnm/CMakeLists.txt b/tdefile-plugins/pnm/CMakeLists.txt new file mode 100644 index 00000000..637fe59d --- /dev/null +++ b/tdefile-plugins/pnm/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_pnm.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_pnm (module) ######################### + +tde_add_kpart( tdefile_pnm AUTOMOC + SOURCES tdefile_pnm.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/pnm/Makefile.am b/tdefile-plugins/pnm/Makefile.am new file mode 100644 index 00000000..f2d9e75e --- /dev/null +++ b/tdefile-plugins/pnm/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for pnm file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_pnm.h + +kde_module_LTLIBRARIES = tdefile_pnm.la + +tdefile_pnm_la_SOURCES = tdefile_pnm.cpp +tdefile_pnm_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_pnm_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdefile_pnm.pot + +services_DATA = tdefile_pnm.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/pnm/tdefile_pnm.cpp b/tdefile-plugins/pnm/tdefile_pnm.cpp new file mode 100644 index 00000000..c9bb065e --- /dev/null +++ b/tdefile-plugins/pnm/tdefile_pnm.cpp @@ -0,0 +1,137 @@ +/* This file is part of the KDE project + * Copyright (C) 2003 Volker Krause <volker.krause@rwth-aachen.de> + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "tdefile_pnm.h" + +#include <math.h> +#include <kgenericfactory.h> +#include <tqfile.h> +#include <tqtextstream.h> + +static const char* formats[] = { + I18N_NOOP("plain"), + I18N_NOOP("raw") +}; + +typedef KGenericFactory<KPnmPlugin> PnmFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_pnm, PnmFactory("tdefile_pnm")) + +KPnmPlugin::KPnmPlugin(TQObject *parent, const char *name, const TQStringList &args) : KFilePlugin(parent, name, args) +{ + makeMimeTypeInfo( "image/x-portable-bitmap" ); + makeMimeTypeInfo( "image/x-portable-greymap" ); + makeMimeTypeInfo( "image/x-portable-pixmap" ); +} + +void KPnmPlugin::makeMimeTypeInfo(const TQString& mimetype) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( mimetype ); + + KFileMimeTypeInfo::GroupInfo* group = 0; + KFileMimeTypeInfo::ItemInfo* item = 0; + + group = addGroupInfo(info, "General", i18n("General")); + + addItemInfo(group, "Format", i18n("Format"), TQVariant::String); + + item = addItemInfo(group, "Dimensions", i18n("Dimensions"), TQVariant::Size); + setUnit(item, KFileMimeTypeInfo::Pixels); + + item = addItemInfo(group, "BitDepth", i18n("Bit Depth"), TQVariant::Int); + setUnit(item, KFileMimeTypeInfo::BitsPerPixel); + + addItemInfo(group, "Comment", i18n("Comment"), TQVariant::String); +} + + +bool KPnmPlugin::readInfo( KFileMetaInfo& info, uint /*what*/) +{ + TQFile f(info.path()); + if(!f.open(IO_ReadOnly)) + return false; + if(f.size() <= 2) + return false; + TQTextStream stream(&f); + + char c; + stream >> c; + if(c != 'P') + return false; + + // image format and type + int n; + stream >> n; + int format = (n - 1) / 3; + if(format != 0 && format != 1) + return false; + int type = (n - 1) % 3; + + TQString comments, buffer; + while(!stream.atEnd()) { + stream >> c; + // comment + if( c == '#') { + buffer = stream.readLine(); + comments += buffer.stripWhiteSpace(); + comments += '\n'; + } + // image size + // unfortunately TQt doesn't have some kind of push-back method for + // TQTextStream, so we need to manually decode the first part of the + // image size. + if( c >= '0' && c <= '9' ) { + buffer = ""; + TQChar tmp(c); + while(!stream.atEnd() && tmp.isDigit()) { + buffer += tmp; + stream >> tmp; + } + break; + } + } + + // image size + int x, y, max; + x = buffer.toInt(); + stream >> y; + stream >> max; + + // bit depth + // PNM doesn't provide a conventional bit depth value, only the highest value + // per pixel. To have comparable values with other formats, we convert it to + // a normal bit depth value. + int bpp = 1; + if(type != 0) + bpp = (int)ceil(log((double)max) / log(2.0)); + if(type == 2) + bpp *= 3; + + KFileMetaInfoGroup group = appendGroup(info, "General"); + appendItem(group, "Format", formats[format]); + appendItem(group, "Dimensions", TQSize(x, y)); + if(!comments.isEmpty()) + appendItem(group, "Comment", comments.stripWhiteSpace()); + appendItem(group, "BitDepth", bpp); + + f.close(); + return true; +} + +#include "tdefile_pnm.moc" diff --git a/tdefile-plugins/pnm/tdefile_pnm.desktop b/tdefile-plugins/pnm/tdefile_pnm.desktop new file mode 100644 index 00000000..1cf4d310 --- /dev/null +++ b/tdefile-plugins/pnm/tdefile_pnm.desktop @@ -0,0 +1,60 @@ +[Desktop Entry] +Type=Service +Name=PNM Info +Name[ar]=معلومات PNM +Name[br]=Titouroù PNM +Name[ca]=Informació de PNM +Name[cs]=PNM info +Name[cy]=Gybodaeth PNM +Name[da]=PNG-info +Name[de]=PNM-Info +Name[el]=Πληροφορίες PNM +Name[eo]=PNM-informo +Name[es]=Info PNM +Name[et]=PNM info +Name[fa]=اطلاعات PNM +Name[fi]=PNM-tiedot +Name[fr]=Informations PNM +Name[gl]=Inf. PNM +Name[he]=מידע PNM +Name[hi]=PNM जानकारी +Name[hu]=PNM-jellemzők +Name[is]=PNM upplýsingar +Name[it]=Informazioni PNM +Name[ja]=PNM 情報 +Name[kk]=PNM мәліметі +Name[km]=ព័ត៌មាន PNM +Name[lt]=PNM informacija +Name[ms]=Maklumat PNM +Name[nb]=PNM-info +Name[nds]=PNM-Info +Name[ne]=PNM सूचना +Name[nl]=PNG-info +Name[nn]=PNM-info +Name[pa]=PNM ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku PNM +Name[pt]=Informação do PNM +Name[pt_BR]=Informação sobre PNG +Name[ro]=Informaţii PNM +Name[ru]=Информация о PNM +Name[se]=PNM-dieđut +Name[sl]=Podatki o PNM +Name[sr]=PNM информације +Name[sr@Latn]=PNM informacije +Name[sv]=PNM-information +Name[ta]=PNM தகவல் +Name[tg]=Иттилоот оиди PNM +Name[th]=ข้อมูลแฟ้ม PNM +Name[tr]=PNM Bilgisi +Name[uk]=Інформація про PNM +Name[uz]=PNM haqida maʼlumot +Name[uz@cyrillic]=PNM ҳақида маълумот +Name[wa]=Informåcion sol imådje PNM +Name[zh_CN]=PNM 信息 +Name[zh_HK]=PNM 資訊 +Name[zh_TW]=PNM 資訊 +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_pnm +MimeType=image/x-portable-bitmap;image/x-portable-greymap;image/x-portable-pixmap +PreferredGroups=General +PreferredItems=Format,Dimensions,BitDepth,Comment diff --git a/tdefile-plugins/pnm/tdefile_pnm.h b/tdefile-plugins/pnm/tdefile_pnm.h new file mode 100644 index 00000000..4b16e4cc --- /dev/null +++ b/tdefile-plugins/pnm/tdefile_pnm.h @@ -0,0 +1,40 @@ +/* This file is part of the KDE project + * Copyright (C) 2003 Volker Krause <volker.krause@rwth-aachen.de> + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_PNM_H__ +#define __KFILE_PNM_H__ + +#include <tdefilemetainfo.h> + +class TQStringList; + +class KPnmPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KPnmPlugin( TQObject *parent, const char *name, const TQStringList& preferredItems ); + virtual bool readInfo( KFileMetaInfo& info, uint ); + +private: + void makeMimeTypeInfo( const TQString&); +}; + +#endif diff --git a/tdefile-plugins/ps/CMakeLists.txt b/tdefile-plugins/ps/CMakeLists.txt new file mode 100644 index 00000000..9a13bcb1 --- /dev/null +++ b/tdefile-plugins/ps/CMakeLists.txt @@ -0,0 +1,46 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/kghostview + ${CMAKE_SOURCE_DIR}/kghostview/dscparse + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_ps.desktop gsthumbnail.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_ps (module) ######################## + +tde_add_kpart( tdefile_ps AUTOMOC + SOURCES tdefile_ps.cpp + LINK dscparse-static tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) + + +##### gsthumbnail (module) ###################### + +tde_add_kpart( gsthumbnail AUTOMOC + SOURCES gscreator.cpp + LINK dscparse-static ${TQT_LIBRARIES} + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/ps/Makefile.am b/tdefile-plugins/ps/Makefile.am new file mode 100644 index 00000000..7e7943c6 --- /dev/null +++ b/tdefile-plugins/ps/Makefile.am @@ -0,0 +1,26 @@ +## Makefile.am for the ps file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = -I$(top_srcdir)/kghostview/dscparse $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_ps.h gscreator.h + +kde_module_LTLIBRARIES = tdefile_ps.la gsthumbnail.la + +tdefile_ps_la_SOURCES = tdefile_ps.cpp +tdefile_ps_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_ps_la_LIBADD = $(LIB_KIO) ../../kghostview/libdscparse.la + +gsthumbnail_la_SOURCES = gscreator.cpp +gsthumbnail_la_LIBADD = $(LIB_TDECORE) ../../kghostview/libdscparse.la +gsthumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdefile_ps.pot + +services_DATA = tdefile_ps.desktop gsthumbnail.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/ps/gscreator.cpp b/tdefile-plugins/ps/gscreator.cpp new file mode 100644 index 00000000..c664947b --- /dev/null +++ b/tdefile-plugins/ps/gscreator.cpp @@ -0,0 +1,619 @@ +/* This file is part of the KDE libraries + Copyright (C) 2001 Malte Starostik <malte@kde.org> + + Handling of EPS previews Copyright (C) 2003 Philipp Hullmann <phull@gmx.de> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +/* This function gets a path of a DVI, EPS, PS or PDF file and + produces a PNG-Thumbnail which is stored as a TQImage + + The program works as follows + + 1. Test if file is a DVI file + + 2. Create a child process (1), in which the + file is to be changed into a PNG + + 3. Child-process (1) : + + 4. If file is DVI continue with 6 + + 5. If file is no DVI continue with 9 + + 6. Create another child process (2), in which the DVI is + turned into PS using dvips + + 7. Parent process (2) : + Turn the recently created PS file into a PNG file using gs + + 8. continue with 10 + + 9. Turn the PS,PDF or EPS file into a PNG file using gs + + 10. Parent process (1) + store data in a TQImage +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + + +#include <assert.h> +#include <ctype.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <signal.h> +#ifdef HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif +#include <sys/time.h> +#include <sys/wait.h> +#include <fcntl.h> +#include <errno.h> +#include <kdemacros.h> + +#include <tqcolor.h> +#include <tqfile.h> +#include <tqimage.h> +#include <tqregexp.h> + + +#include "gscreator.h" +#include "dscparse_adapter.h" +#include "dscparse.h" + +extern "C" +{ + KDE_EXPORT ThumbCreator *new_creator() + { + return new GSCreator; + } +} + +// This PS snippet will be prepended to the actual file so that only +// the first page is output. +static const char *psprolog = + "%!PS-Adobe-3.0\n" + "/.showpage.orig /showpage load def\n" + "/.showpage.firstonly {\n" + " .showpage.orig\n" + " quit\n" + "} def\n" + "/showpage { .showpage.firstonly } def\n"; + +// This is the code recommended by Adobe tech note 5002 for including +// EPS files. +static const char *epsprolog = + "%!PS-Adobe-3.0\n" + "userdict begin /pagelevel save def /showpage { } def\n" + "0 setgray 0 setlinecap 1 setlinewidth 0 setlinejoin 10 setmiterlimit\n" + "[ ] 0 setdash newpath false setoverprint false setstrokeadjust\n"; + +static const char * gsargs_ps[] = { + "gs", + "-sDEVICE=png16m", + "-sOutputFile=-", + "-dSAFER", + "-dPARANOIDSAFER", + "-dNOPAUSE", + "-dFirstPage=1", + "-dLastPage=1", + "-q", + "-", + 0, // file name + "-c", + "showpage", + "-c", + "quit", + 0 +}; + +static const char * gsargs_eps[] = { + "gs", + "-sDEVICE=png16m", + "-sOutputFile=-", + "-dSAFER", + "-dPARANOIDSAFER", + "-dNOPAUSE", + 0, // page size + 0, // resolution + "-q", + "-", + 0, // file name + "-c", + "pagelevel", + "-c", + "restore", + "-c", + "end", + "-c", + "showpage", + "-c", + "quit", + 0 +}; + +static const char *dvipsargs[] = { + "dvips", + "-n", + "1", + "-q", + "-o", + "-", + 0, // file name + 0 +}; + +static bool correctDVI(const TQString& filename); + + +namespace { + bool got_sig_term = false; + void handle_sigterm( int ) { + got_sig_term = true; + } +} + + +bool GSCreator::create(const TQString &path, int width, int height, TQImage &img) +{ +// The code in the loop (when testing whether got_sig_term got set) +// should read some variation of: +// parentJob()->wasKilled() +// +// Unfortunatelly, that's currently impossible without breaking BIC. +// So we need to catch the signal ourselves. +// Otherwise, on certain funny PS files (for example +// http://www.tjhsst.edu/~Eedanaher/pslife/life.ps ) +// gs would run forever after we were dead. +// #### Reconsider for KDE 4 ### +// (24/12/03 - luis_pedro) +// + typedef void ( *sighandler_t )( int ); + // according to linux's "man signal" the above typedef is a gnu extension + sighandler_t oldhandler = signal( SIGTERM, handle_sigterm ); + + int input[2]; + int output[2]; + int dvipipe[2]; + + TQByteArray data(1024); + + bool ok = false; + + // Test if file is DVI + bool no_dvi =!correctDVI(path); + + if (pipe(input) == -1) { + return false; + } + if (pipe(output) == -1) { + close(input[0]); + close(input[1]); + return false; + } + + KDSC dsc; + endComments = false; + dsc.setCommentHandler(this); + + if (no_dvi) + { + FILE* fp = fopen(TQFile::encodeName(path), "r"); + if (fp == 0) return false; + + char buf[4096]; + int count; + while ((count = fread(buf, sizeof(char), 4096, fp)) != 0 + && !endComments) { + dsc.scanData(buf, count); + } + fclose(fp); + + if (dsc.pjl() || dsc.ctrld()) { + // this file is a mess. + return false; + } + } + + const bool is_encapsulated = no_dvi && + (path.find(TQRegExp("\\.epsi?$", false, false)) > 0) && + (dsc.bbox()->width() > 0) && (dsc.bbox()->height() > 0) && + (dsc.page_count() <= 1); + + char translation[64] = ""; + char pagesize[32] = ""; + char resopt[32] = ""; + std::auto_ptr<KDSCBBOX> bbox = dsc.bbox(); + if (is_encapsulated) { + // GhostScript's rendering at the extremely low resolutions + // required for thumbnails leaves something to be desired. To + // get nicer images, we render to four times the required + // resolution and let TQImage scale the result. + const int hres = (width * 72) / bbox->width(); + const int vres = (height * 72) / bbox->height(); + const int resolution = (hres > vres ? vres : hres) * 4; + const int gswidth = ((bbox->urx() - bbox->llx()) * resolution) / 72; + const int gsheight = ((bbox->ury() - bbox->lly()) * resolution) / 72; + + snprintf(pagesize, 31, "-g%ix%i", gswidth, gsheight); + snprintf(resopt, 31, "-r%i", resolution); + snprintf(translation, 63, + " 0 %i sub 0 %i sub translate\n", bbox->llx(), + bbox->lly()); + } + + const CDSC_PREVIEW_TYPE previewType = + static_cast<CDSC_PREVIEW_TYPE>(dsc.preview()); + + switch (previewType) { + case CDSC_TIFF: + case CDSC_WMF: + case CDSC_PICT: + // FIXME: these should take precedence, since they can hold + // color previews, which EPSI can't (or can it?). + break; + case CDSC_EPSI: + { + const int xscale = bbox->width() / width; + const int yscale = bbox->height() / height; + const int scale = xscale < yscale ? xscale : yscale; + if (getEPSIPreview(path, + dsc.beginpreview(), + dsc.endpreview(), + img, + bbox->width() / scale, + bbox->height() / scale)) + return true; + // If the preview extraction routine fails, gs is used to + // create a thumbnail. + } + break; + case CDSC_NOPREVIEW: + default: + // need to run ghostscript in these cases + break; + } + + pid_t pid = fork(); + if (pid == 0) { + // Child process (1) + + // close(STDERR_FILENO); + + // find first zero entry in gsargs and put the filename + // or - (stdin) there, if DVI + const char **gsargs = gsargs_ps; + const char **arg = gsargs; + + if (no_dvi && is_encapsulated) { + gsargs = gsargs_eps; + arg = gsargs; + + // find first zero entry and put page size there + while (*arg) ++arg; + *arg = pagesize; + + // find second zero entry and put resolution there + while (*arg) ++arg; + *arg = resopt; + } + + // find next zero entry and put the filename there + TQCString fname = TQFile::encodeName( path ); + while (*arg) + ++arg; + if( no_dvi ) + *arg = fname.data(); + else + *arg = "-"; + + // find first zero entry in dvipsargs and put the filename there + arg = dvipsargs; + while (*arg) + ++arg; + *arg = fname.data(); + + if( !no_dvi ){ + pipe(dvipipe); + pid_t pid_two = fork(); + if( pid_two == 0 ){ + // Child process (2), reopen stdout on the pipe "dvipipe" and exec dvips + + close(input[0]); + close(input[1]); + close(output[0]); + close(output[1]); + close(dvipipe[0]); + + dup2( dvipipe[1], STDOUT_FILENO); + + execvp(dvipsargs[0], const_cast<char *const *>(dvipsargs)); + exit(1); + } + else if(pid_two != -1){ + close(input[1]); + close(output[0]); + close(dvipipe[1]); + + dup2( dvipipe[0], STDIN_FILENO); + dup2( output[1], STDOUT_FILENO); + + execvp(gsargs[0], const_cast<char *const *>(gsargs)); + exit(1); + } + else{ + // fork() (2) failed, close these + close(dvipipe[0]); + close(dvipipe[1]); + } + + } + else if( no_dvi ){ + // Reopen stdin/stdout on the pipes and exec gs + close(input[1]); + close(output[0]); + + dup2(input[0], STDIN_FILENO); + dup2(output[1], STDOUT_FILENO); + + execvp(gsargs[0], const_cast<char *const *>(gsargs)); + exit(1); + } + } + else if (pid != -1) { + // Parent process, write first-page-only-hack (the hack is not + // used if DVI) and read the png output + close(input[0]); + close(output[1]); + const char *prolog; + if (is_encapsulated) + prolog = epsprolog; + else + prolog = psprolog; + int count = write(input[1], prolog, strlen(prolog)); + if (is_encapsulated) + write(input[1], translation, strlen(translation)); + + close(input[1]); + if (count == static_cast<int>(strlen(prolog))) { + int offset = 0; + while (!ok) { + fd_set fds; + FD_ZERO(&fds); + FD_SET(output[0], &fds); + struct timeval tv; + tv.tv_sec = 20; + tv.tv_usec = 0; + + got_sig_term = false; + if (select(output[0] + 1, &fds, 0, 0, &tv) <= 0) { + if ( ( errno == EINTR || errno == EAGAIN ) && !got_sig_term ) continue; + break; // error, timeout or master wants us to quit (SIGTERM) + } + if (FD_ISSET(output[0], &fds)) { + count = read(output[0], data.data() + offset, 1024); + if (count == -1) + break; + else + if (count) // prepare for next block + { + offset += count; + data.resize(offset + 1024); + } + else // got all data + { + data.resize(offset); + ok = true; + } + } + } + } + if (!ok) // error or timeout, gs probably didn't exit yet + { + kill(pid, SIGTERM); + } + + int status = 0; + if (waitpid(pid, &status, 0) != pid || (status != 0 && status != 256) ) + ok = false; + } + else { + // fork() (1) failed, close these + close(input[0]); + close(input[1]); + close(output[1]); + } + close(output[0]); + + int l = img.loadFromData( data ); + + if ( got_sig_term && + oldhandler != SIG_ERR && + oldhandler != SIG_DFL && + oldhandler != SIG_IGN ) { + oldhandler( SIGTERM ); // propagate the signal. Other things might rely on it + } + if ( oldhandler != SIG_ERR ) signal( SIGTERM, oldhandler ); + + return ok && l; +} + +ThumbCreator::Flags GSCreator::flags() const +{ + return static_cast<Flags>(DrawFrame); +} + +void GSCreator::comment(Name name) +{ + switch (name) { + case EndPreview: + case BeginProlog: + case Page: + endComments = true; + break; + + default: + break; + } +} + +// Quick function to check if the filename corresponds to a valid DVI +// file. Returns true if <filename> is a DVI file, false otherwise. + +static bool correctDVI(const TQString& filename) +{ + TQFile f(filename); + if (!f.open(IO_ReadOnly)) + return FALSE; + + unsigned char test[4]; + if ( f.readBlock( (char *)test,2)<2 || test[0] != 247 || test[1] != 2 ) + return FALSE; + + int n = f.size(); + if ( n < 134 ) // Too short for a dvi file + return FALSE; + f.at( n-4 ); + + unsigned char trailer[4] = { 0xdf,0xdf,0xdf,0xdf }; + + if ( f.readBlock( (char *)test, 4 )<4 || strncmp( (char *)test, (char*) trailer, 4 ) ) + return FALSE; + // We suppose now that the dvi file is complete and OK + return TRUE; +} + +bool GSCreator::getEPSIPreview(const TQString &path, long start, long + end, TQImage &outimg, int imgwidth, int imgheight) +{ + FILE *fp; + fp = fopen(TQFile::encodeName(path), "r"); + if (fp == 0) return false; + + const long previewsize = end - start + 1; + + char *buf = (char *) malloc(previewsize); + fseek(fp, start, SEEK_SET); + int count = fread(buf, sizeof(char), previewsize - 1, fp); + fclose(fp); + buf[previewsize - 1] = 0; + if (count != previewsize - 1) + { + free(buf); + return false; + } + + TQString previewstr = TQString::fromLatin1(buf); + free(buf); + + int offset = 0; + while ((offset < previewsize) && !(previewstr[offset].isDigit())) offset++; + int digits = 0; + while ((offset + digits < previewsize) && previewstr[offset + digits].isDigit()) digits++; + int width = previewstr.mid(offset, digits).toInt(); + offset += digits + 1; + while ((offset < previewsize) && !(previewstr[offset].isDigit())) offset++; + digits = 0; + while ((offset + digits < previewsize) && previewstr[offset + digits].isDigit()) digits++; + int height = previewstr.mid(offset, digits).toInt(); + offset += digits + 1; + while ((offset < previewsize) && !(previewstr[offset].isDigit())) offset++; + digits = 0; + while ((offset + digits < previewsize) && previewstr[offset + digits].isDigit()) digits++; + int depth = previewstr.mid(offset, digits).toInt(); + + // skip over the rest of the BeginPreview comment + while ((offset < previewsize) && + previewstr[offset] != '\n' && + previewstr[offset] != '\r') offset++; + while ((offset < previewsize) && previewstr[offset] != '%') offset++; + + unsigned int imagedepth; + switch (depth) { + case 1: + case 2: + case 4: + case 8: + imagedepth = 8; + break; + case 12: // valid, but not (yet) supported + default: // illegal value + return false; + } + + unsigned int colors = (1U << depth); + TQImage img(width, height, imagedepth, colors); + img.setAlphaBuffer(false); + + if (imagedepth <= 8) { + for (unsigned int gray = 0; gray < colors; gray++) { + unsigned int grayvalue = (255U * (colors - 1 - gray)) / + (colors - 1); + img.setColor(gray, tqRgb(grayvalue, grayvalue, grayvalue)); + } + } + + const unsigned int bits_per_scan_line = width * depth; + unsigned int bytes_per_scan_line = bits_per_scan_line / 8; + if (bits_per_scan_line % 8) bytes_per_scan_line++; + const unsigned int bindatabytes = height * bytes_per_scan_line; + TQMemArray<unsigned char> bindata(bindatabytes); + + for (unsigned int i = 0; i < bindatabytes; i++) { + if (offset >= previewsize) + return false; + + while (!isxdigit(previewstr[offset].latin1()) && + offset < previewsize) + offset++; + + bool ok = false; + bindata[i] = static_cast<unsigned char>(previewstr.mid(offset, 2).toUInt(&ok, 16)); + if (!ok) + return false; + + offset += 2; + } + + for (int scanline = 0; scanline < height; scanline++) { + unsigned char *scanlineptr = img.scanLine(scanline); + + for (int pixelindex = 0; pixelindex < width; pixelindex++) { + unsigned char pixelvalue = 0; + const unsigned int bitoffset = + scanline * bytes_per_scan_line * 8U + pixelindex * depth; + for (int depthindex = 0; depthindex < depth; + depthindex++) { + const unsigned int byteindex = (bitoffset + depthindex) / 8U; + const unsigned int bitindex = + 7 - ((bitoffset + depthindex) % 8U); + const unsigned char bitvalue = + (bindata[byteindex] & static_cast<unsigned char>(1U << bitindex)) >> bitindex; + pixelvalue |= (bitvalue << depthindex); + } + scanlineptr[pixelindex] = pixelvalue; + } + } + + outimg = img.convertDepth(32).smoothScale(imgwidth, imgheight); + + return true; +} diff --git a/tdefile-plugins/ps/gscreator.h b/tdefile-plugins/ps/gscreator.h new file mode 100644 index 00000000..b155bfa7 --- /dev/null +++ b/tdefile-plugins/ps/gscreator.h @@ -0,0 +1,42 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 Malte Starostik <malte@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _GSCREATOR_H_ +#define _GSCREATOR_H_ + +#include <tdeio/thumbcreator.h> +#include "dscparse_adapter.h" + +class GSCreator : public ThumbCreator, public KDSCCommentHandler +{ +public: + GSCreator() {}; + virtual bool create(const TQString &path, int, int, TQImage &img); + virtual Flags flags() const; + void comment(Name name); + +private: + static bool getEPSIPreview(const TQString &path, + long start, long end, + TQImage &outimg, + int imgwidth, int imgheight); + bool endComments; +}; + +#endif diff --git a/tdefile-plugins/ps/gsthumbnail.desktop b/tdefile-plugins/ps/gsthumbnail.desktop new file mode 100644 index 00000000..903f3447 --- /dev/null +++ b/tdefile-plugins/ps/gsthumbnail.desktop @@ -0,0 +1,60 @@ +[Desktop Entry] +Type=Service +Name=PostScript, PDF and DVI Files +Name[ar]=ملفات الــ PostScript ، PDF و DVI +Name[br]=Restroù PostScript, PDF ha DVI +Name[bs]=Postscript, PDF i DVI datoteke +Name[ca]=Fitxers PostScript, PDF i DVI +Name[cs]=Postscriptové, PDF a DVI soubory +Name[cy]=Ffeiliau PostScript, PDF a DVI +Name[da]=PostScript, PDF- og DVI-filer +Name[de]=PostScript-, PDF- und DVI-Dateien +Name[el]=Αρχεία PostScript, PDF και DVI +Name[eo]=Postskriptaj, PDF- kaj DVI-dosieroj +Name[es]=Archivos PostScript, PDF y DVI +Name[et]=PostScript-, PDF- ja DVI-failid +Name[eu]=PostScript, PDF eta DVI fitxategiak +Name[fa]=پروندههای PostScript، PDF و DVI +Name[fi]=PostScript-, PDF- ja DVI-tiedostot +Name[fr]=Fichiers PostScript, PDF et DVI +Name[ga]=Comhaid PostScript, PDF agus DVI +Name[gl]=Ficheiros PostScript, PDF e DVI +Name[he]=קבצי PostScript, PDF ו־DVI +Name[hu]=PostScript-, PDF- és DVI-fájlok +Name[is]=PostScript PDF og DVI skrár +Name[it]=File PostScript, PDF e DVI +Name[ja]=Postscript,PDF,DVIファイル +Name[kk]=PostScript, PDF және DVI файлдары +Name[km]=ឯកសារ PostScript, PDF និង DVI +Name[lt]=Postscript, PDF ir DVI bylos +Name[ms]=PostScript, PDF dan Fail DVI +Name[nb]=PostScript, PDF og DVI filer +Name[nds]=PostScript-, PDF- un DVI-Dateien +Name[ne]=पोष्टस्क्रिप्ट, PDF र DVI फाइल +Name[nl]=PostScript-, DVI- en PDF-bestanden +Name[nn]=PostScript-, PDF- og DVI-filer +Name[pl]=Pliki PostScript, PDF i DVI +Name[pt]=Ficheiros PostScript, PDF e DVI +Name[pt_BR]=Arquivos PostScript, PDF e DVI +Name[ro]=Fişiere PostScript, PDF şi DVI +Name[ru]=Файлы PostScript, PDF и DVI +Name[se]=PostScript-, PDF- ja DVI-fiillat +Name[sk]=PostScript, PDF a DVI súbory +Name[sl]=Datoteke PostScript, PDF in DVI +Name[sr]=PostScript, PDF и DVI фајлови +Name[sr@Latn]=PostScript, PDF i DVI fajlovi +Name[sv]=Postscript, PDF och DVI-filer +Name[ta]= போஸ்ட்கிரிப்ட், பிடிஃப் மற்றும் டிவிஐ கோப்புகள் +Name[tg]=Файлҳои PostScript, PDF ва DVI +Name[th]=แฟ้ม PDF, DVI และ โพสต์สคริปต์ +Name[tr]=PostScript, PDF ve DVI Dosyaları +Name[uk]=Файли PostScript, PDF та DVI +Name[uz]=PostScript, PDF va DVI fayllari +Name[uz@cyrillic]=PostScript, PDF ва DVI файллари +Name[zh_CN]=PostScript、PDF 和 DVI 文件 +Name[zh_HK]=PostScript 、PDF 及 DVI 檔案 +Name[zh_TW]=PostScript,PDF 與 DVI 檔 +ServiceTypes=ThumbCreator +MimeTypes=application/x-dvi,application/postscript,application/pdf,image/x-eps +X-TDE-Library=gsthumbnail +CacheThumbnail=true diff --git a/tdefile-plugins/ps/tdefile_ps.cpp b/tdefile-plugins/ps/tdefile_ps.cpp new file mode 100644 index 00000000..87161176 --- /dev/null +++ b/tdefile-plugins/ps/tdefile_ps.cpp @@ -0,0 +1,124 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Wilco Greven <greven@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $Id$ + */ + +#include "tdefile_ps.h" + +#include <tqfile.h> + +#include <klocale.h> +#include <kgenericfactory.h> +#include <kdebug.h> + +typedef KGenericFactory<KPSPlugin> PSFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_ps, PSFactory("tdefile_ps")) + +KPSPlugin::KPSPlugin(TQObject *parent, const char *name, + const TQStringList &preferredItems) : + KFilePlugin( parent, name, preferredItems ) +{ + kdDebug(7034) << "ps plugin\n"; + + // set up our mimetypes + makeMimeTypeInfo( "application/postscript" ); + makeMimeTypeInfo( "image/x-eps" ); +} + +void KPSPlugin::makeMimeTypeInfo( const char* mimeType ) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( mimeType ); + + // general group + KFileMimeTypeInfo::GroupInfo* group = addGroupInfo(info, "General", i18n("General")); + addItemInfo(group, "Title", i18n("Title"), TQVariant::String); + addItemInfo(group, "Creator", i18n("Creator"), TQVariant::String); + addItemInfo(group, "CreationDate", i18n("Creation Date"), TQVariant::String); + addItemInfo(group, "For", i18n("For"), TQVariant::String); + addItemInfo(group, "Pages", i18n("Pages"), TQVariant::UInt); +} + +bool KPSPlugin::readInfo( KFileMetaInfo& info, uint /* what */) +{ + _info = info; + _group = appendGroup(info, "General"); + _endComments = false; + _setData = 0; + + _dsc = new KDSC; + _dsc->setCommentHandler( this ); + FILE* fp = fopen( TQFile::encodeName( info.path() ), "r" ); + if( fp == 0 ) + return false; + + char buf[4096]; + int count; + while( ( count = fread( buf, sizeof(char), sizeof( buf ), fp ) ) ) { + if ( !_dsc->scanData( buf, count ) ) break; + if ( _endComments || _setData == 5 ) break; // Change if new item scanned + } + fclose( fp ); + delete _dsc; + _dsc = 0; + + return _setData > 0; +} + +void KPSPlugin::comment( Name name ) +{ + switch( name ) + { + case Title: + appendItem(_group, "Title", _dsc->dsc_title()); + ++_setData; + break; + case Creator: + appendItem(_group, "Creator", _dsc->dsc_creator()); + ++_setData; + break; + case CreationDate: + appendItem(_group, "CreationDate", _dsc->dsc_date()); + ++_setData; + break; + case For: + appendItem(_group, "For", _dsc->dsc_for()); + ++_setData; + break; + case Pages: { + int pages = _dsc->page_pages(); + if (pages) + { + appendItem(_group, "Pages", pages); + ++_setData; + } + } + break; + + // Right now we watch for 5 elements: + // Title, Creator, CreationDate, For, Pages + // + // If you add another one(s), please update the 5 in "_setData == 5" above + // + case EndComments: _endComments = true; + default: ; // Ignore + } +} + +#include "tdefile_ps.moc" + diff --git a/tdefile-plugins/ps/tdefile_ps.desktop b/tdefile-plugins/ps/tdefile_ps.desktop new file mode 100644 index 00000000..ec863b8a --- /dev/null +++ b/tdefile-plugins/ps/tdefile_ps.desktop @@ -0,0 +1,66 @@ +[Desktop Entry] +Type=Service +Name=PostScript Info +Name[af]=Postscript Inligting +Name[ar]=معلومات PostScript +Name[br]=Procinfo PostScript +Name[ca]=Informació de PostScript +Name[cs]=PostScript info +Name[cy]=Gwybodaeth PostScript +Name[da]=PostScript-info +Name[de]=PostScript-Info +Name[el]=Πληροφορίες PostScript +Name[eo]=Postskriptinformo +Name[es]=Info PostScript +Name[et]=PostScript info +Name[fa]=اطلاعات PostScript +Name[fi]=PostScript-tiedot +Name[fr]=Informations PostScript +Name[gl]=Inf. PostScript +Name[he]=מידע PostScript +Name[hi]=पोस्टस्क्रिप्ट जानकारी +Name[hr]=Postscript informacije +Name[hu]=PostScript-jellemzők +Name[is]=PostScript upplýsingar +Name[it]=Informazioni PostScript +Name[ja]=PostScript 情報 +Name[kk]=PostScript мәліметі +Name[km]=ព័ត៌មាន PostScript +Name[lt]=PostScript informacija +Name[lv]=Postscript Info +Name[ms]=Maklumat PostScript +Name[nb]=PostScript-info +Name[nds]=PostScript-Info +Name[ne]=पोष्टस्क्रिप्ट सूचना +Name[nl]=PostScript-info +Name[nn]=PostScript-info +Name[nso]=Tshedimoso ya PostScript +Name[pa]=PostScript ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku PostScriptu +Name[pt]=Informação do PostScript +Name[pt_BR]=Informação sobre PostScript +Name[ro]=Informaţii PostScript +Name[ru]=Информация о PostScript +Name[se]=PostScript-dieđut +Name[sl]=Podatki o PostScriptu +Name[sr]=PostScript информације +Name[sr@Latn]=PostScript informacije +Name[sv]=Postscript-information +Name[ta]=முன் எழுத்தாக்க தகவல் +Name[tg]=Иттилоот оиди PostScript +Name[th]=ข้อมูลโพสต์สคริปต์ +Name[tr]=PostScript Bilgisi +Name[uk]=Інформація про PostScript +Name[uz]=PostScript haqida maʼlumot +Name[uz@cyrillic]=PostScript ҳақида маълумот +Name[ven]=Mafhungo a mabammbiri a poso +Name[wa]=Informåcion sol documint PostScript +Name[xh]=Ulwazi Lwe PostScript +Name[zh_CN]=PostScript 信息 +Name[zh_HK]=PostScript 資訊 +Name[zh_TW]=PostScript 資訊 +Name[zu]=Ulwazi Lwesi-PostScript +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_ps +MimeType=application/postscript;image/x-eps +PreferredItems=Title,Creator,CreationDate,For,Pages diff --git a/tdefile-plugins/ps/tdefile_ps.h b/tdefile-plugins/ps/tdefile_ps.h new file mode 100644 index 00000000..1b095bdc --- /dev/null +++ b/tdefile-plugins/ps/tdefile_ps.h @@ -0,0 +1,51 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Wilco Greven <greven@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $Id$ + */ + +#ifndef __KFILE_PS_H__ +#define __KFILE_PS_H__ + +#include <tdefilemetainfo.h> + +#include "dscparse_adapter.h" + +class TQStringList; + +class KPSPlugin: public KFilePlugin, public KDSCCommentHandler +{ + Q_OBJECT + +public: + KPSPlugin( TQObject *parent, const char *name, + const TQStringList& preferredItems ); + + virtual bool readInfo( KFileMetaInfo& info, uint what); + + void comment( Name ); + void makeMimeTypeInfo( const char* mimeType ); + +private: + KFileMetaInfo _info; + KFileMetaInfoGroup _group; + KDSC* _dsc; + bool _endComments; + int _setData; +}; + +#endif diff --git a/tdefile-plugins/raw/CMakeLists.txt b/tdefile-plugins/raw/CMakeLists.txt new file mode 100644 index 00000000..80810e07 --- /dev/null +++ b/tdefile-plugins/raw/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_raw.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_raw (module) ######################### + +tde_add_kpart( tdefile_raw AUTOMOC + SOURCES kcamerarawplugin.cpp parse.c + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/raw/Makefile.am b/tdefile-plugins/raw/Makefile.am new file mode 100644 index 00000000..196aa4bd --- /dev/null +++ b/tdefile-plugins/raw/Makefile.am @@ -0,0 +1,19 @@ +## Makefile.am for the raw thumbnail extration plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = kcamerarawplugin.h + +kde_module_LTLIBRARIES = tdefile_raw.la + +tdefile_raw_la_SOURCES = kcamerarawplugin.cpp parse.c +tdefile_raw_la_LIBADD = $(LIB_KIO) +tdefile_raw_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +services_DATA = tdefile_raw.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/raw/kcamerarawplugin.cpp b/tdefile-plugins/raw/kcamerarawplugin.cpp new file mode 100644 index 00000000..a7a0cb27 --- /dev/null +++ b/tdefile-plugins/raw/kcamerarawplugin.cpp @@ -0,0 +1,141 @@ +/* This file is part of the KDE project + * Copyright (C) Steffen Hansen <hansen@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "kcamerarawplugin.h" + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <klocale.h> +#include <kgenericfactory.h> +#include <kdebug.h> +#include <ktempfile.h> +#include <kimageio.h> +#include <tqfile.h> +#include <tqimage.h> +#include <tqwmatrix.h> +#include <cstdio> + + +typedef KGenericFactory<KCameraRawPlugin> RawFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_raw, RawFactory("tdefile_raw")) + +#ifndef KDE_EXPORT +# define KDE_EXPORT +#endif + +/* Main entry point into raw parser */ +extern "C" { + int extract_thumbnail( FILE*, FILE*, int* ); + extern char make[]; + extern char model[]; +} + +bool KCameraRawPlugin::createPreview(const TQString &path, TQImage &img) +{ + /* Open file and extract thumbnail */ + FILE* input = fopen( TQFile::encodeName(path), "rb" ); + if( !input ) return false; + KTempFile output; + output.setAutoDelete(true); + int orientation = 0; + if( extract_thumbnail( input, output.fstream(), &orientation ) ) { + fclose(input); + return false; + } + fclose(input); + output.close(); + if( !img.load( output.name() ) ) return false; + + if(orientation) { + TQWMatrix M; + TQWMatrix flip= TQWMatrix(-1,0,0,1,0,0); + switch(orientation+1) { // notice intentional fallthroughs + case 2: M = flip; break; + case 4: M = flip; + case 3: M.rotate(180); break; + case 5: M = flip; + case 6: M.rotate(90); break; + case 7: M = flip; + case 8: M.rotate(270); break; + default: break; // should never happen + } + img = img.xForm(M); + } + return true; +} + +KCameraRawPlugin::KCameraRawPlugin(TQObject *parent, const char *name, + const TQStringList &args ) + : KFilePlugin(parent, name, args) +{ + kdDebug(7034) << "KCameraRawPlugin c'tor" << endl; + + // + // define all possible meta info items + // + KFileMimeTypeInfo *info = addMimeTypeInfo("image/x-raw"); + KFileMimeTypeInfo::GroupInfo *group = addGroupInfo( info, "Info", + i18n("Image Info") ); + KFileMimeTypeInfo::ItemInfo* item; + + item = addItemInfo( group, "Manufacturer", i18n("Camera Manufacturer"), + TQVariant::String ); + item = addItemInfo( group, "Model", i18n("Camera Model"), + TQVariant::String ); + item = addItemInfo( group, "Thumbnail", i18n("Thumbnail"), + TQVariant::Image ); + setHint( item, KFileMimeTypeInfo::Thumbnail ); +} + +bool KCameraRawPlugin::readInfo( KFileMetaInfo& info, uint what ) +{ + kdDebug(7034) << "KCameraRawPlugin::readInfo()" << endl; + + const TQString path( info.path() ); + if ( path.isEmpty() ) // remote file + return false; + + KFileMetaInfoGroup group = appendGroup( info, "Info" ); + if ( what & KFileMetaInfo::Thumbnail ){ + TQImage img; + if( createPreview( path,img ) ) { + appendItem( group, "Thumbnail", img ); + kdDebug(7034) << "thumbnail " << path << " created" << endl; + } + } else { + // HACK: We have to extract thumbnail to get any info... + TQImage img; + createPreview( path,img ); + } + kdDebug(7034) << "make=" << make << endl; + kdDebug(7034) << "model=" << model << endl; + if( make[0] ) { + appendItem( group, "Manufacturer", &make[0] ); + } + if( model[0] ) { + appendItem( group, "Model", &model[0] ); + } + + return true; +} + +#include "kcamerarawplugin.moc" diff --git a/tdefile-plugins/raw/kcamerarawplugin.h b/tdefile-plugins/raw/kcamerarawplugin.h new file mode 100644 index 00000000..d16446e8 --- /dev/null +++ b/tdefile-plugins/raw/kcamerarawplugin.h @@ -0,0 +1,39 @@ +/* This file is part of the KDE project + * Copyright (C) 2005 Steffen Hansen <hansen@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef KCAMERARAWPLUGIN_H +#define KCAMERARAWPLUGIN_H + +#include <tdefilemetainfo.h> + +class TQImage; + +class KCameraRawPlugin: public KFilePlugin { + Q_OBJECT + + +public: + KCameraRawPlugin(TQObject *parent, const char *name, const TQStringList& args); + virtual bool readInfo(KFileMetaInfo& info, uint what); + +private: + bool createPreview(const TQString &path, TQImage &img); +}; + +#endif /* KCAMERARAWPLUGIN_H */ diff --git a/tdefile-plugins/raw/parse.c b/tdefile-plugins/raw/parse.c new file mode 100644 index 00000000..a256f04e --- /dev/null +++ b/tdefile-plugins/raw/parse.c @@ -0,0 +1,1080 @@ +/* + Raw Photo Parser + Copyright 2004 by Dave Coffin, dcoffin a cybercom o net + + This program extracts thumbnail images (preferably JPEGs) + from any raw digital camera formats that have them, and + shows table contents. + + $Revision: 1.36 $ + $Date: 2005/05/10 21:43:10 $ + */ + +/* Hacked for thumbnail extraction in KDE by + Steffen Hansen <hansen@kde.org> + + Based on parse.c and parts of dcraw.c by Dave Coffin +*/ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> +#include <time.h> +#include <sys/types.h> + +#ifdef WIN32 +#include <winsock2.h> +typedef __int64 INT64; +#else +#include <netinet/in.h> +typedef long long INT64; +#endif + +/* + TIFF and CIFF data blocks can be quite large. + Display only the first DLEN bytes. + */ +#ifndef DLEN +#define DLEN 768 +#endif + +typedef unsigned char uchar; +/*typedef unsigned short ushort;*/ + +FILE *ifp; +short order; +char *fname; +char make[128], model[128], model2[128], thumb_head[128]; +int width, height, offset, length, bps, is_dng; +int thumb_offset, thumb_length, thumb_layers; +float cam_mul[4], pre_mul[4], coeff[3][4]; +#define camera_red cam_mul[0] +#define camera_blue cam_mul[2] +/*float flash_used, canon_5814;*/ +time_t timestamp; +/*int data_offset, meta_offset*/ +int raw_height, raw_width, top_margin, left_margin; +static int flip = 0; + +struct decode { + struct decode *branch[2]; + int leaf; +} first_decode[640], *free_decode; + +#define CLASS + +#define FORC3 for (c=0; c < 3; c++) +#define FORC4 for (c=0; c < 4; c++) +#define FORCC for (c=0; c < colors; c++) + +/* + Get a 2-byte integer, making no assumptions about CPU byte order. + Nor should we assume that the compiler evaluates left-to-right. + */ +ushort get2() +{ + uchar a, b; + + a = fgetc(ifp); b = fgetc(ifp); + + if (order == 0x4949) /* "II" means little-endian */ + return a | b << 8; + else /* "MM" means big-endian */ + return a << 8 | b; +} + +/* + Same for a 4-byte integer. + */ +int get4() +{ + uchar a, b, c, d; + + a = fgetc(ifp); b = fgetc(ifp); + c = fgetc(ifp); d = fgetc(ifp); + + if (order == 0x4949) + return a | b << 8 | c << 16 | d << 24; + else + return a << 24 | b << 16 | c << 8 | d; +} + +void tiff_dump(int base, int tag, int type, int count, int level) +{ + int save, j, num, den; + uchar c; + int size[] = { 1,1,1,2,4,8,1,1,2,4,8,4,8 }; + + if (count * size[type < 13 ? type:0] > 4) + fseek (ifp, get4()+base, SEEK_SET); + save = ftell(ifp); + fseek (ifp, save, SEEK_SET); +} + +void nikon_decrypt (uchar ci, uchar cj, int tag, int i, int size, uchar *buf) +{ +} + +int parse_tiff_ifd (int base, int level); + +void nef_parse_makernote (base) +{ + int offset=0, entries, tag, type, count, val, save; + unsigned serial=0, key=0; + uchar buf91[630], buf97[608], buf98[31]; + short sorder; + char buf[10]; + +/* + The MakerNote might have its own TIFF header (possibly with + its own byte-order!), or it might just be a table. + */ + sorder = order; + fread (buf, 1, 10, ifp); + if (!strcmp (buf,"Nikon")) { /* starts with "Nikon\0\2\0\0\0" ? */ + base = ftell(ifp); + order = get2(); /* might differ from file-wide byteorder */ + val = get2(); /* should be 42 decimal */ + offset = get4(); + fseek (ifp, offset-8, SEEK_CUR); + } else if (!strncmp (buf,"FUJIFILM",8) || + !strcmp (buf,"Panasonic")) { + order = 0x4949; + fseek (ifp, 2, SEEK_CUR); + } else if (!strcmp (buf,"OLYMP") || + !strcmp (buf,"LEICA") || + !strcmp (buf,"EPSON")) + fseek (ifp, -2, SEEK_CUR); + else if (!strcmp (buf,"AOC")) + fseek (ifp, -4, SEEK_CUR); + else + fseek (ifp, -10, SEEK_CUR); + + entries = get2(); + if (entries > 100) return; + while (entries--) { + save = ftell(ifp); + tag = get2(); + type = get2(); + count= get4(); + tiff_dump (base, tag, type, count, 2); + if (tag == 0x1d) + fscanf (ifp, "%d", &serial); + if (tag == 0x91) + fread (buf91, sizeof buf91, 1, ifp); + if (tag == 0x97) + fread (buf97, sizeof buf97, 1, ifp); + if (tag == 0x98) + fread (buf98, sizeof buf98, 1, ifp); + if (tag == 0xa7) + key = fgetc(ifp)^fgetc(ifp)^fgetc(ifp)^fgetc(ifp); + + if (tag == 0x100 && type == 7 && !strncmp(make,"OLYMPUS",7)) { + thumb_offset = ftell(ifp); + thumb_length = count; + } + if (tag == 0x280 && type == 1) { /* EPSON */ + strncpy (thumb_head, "\xff", sizeof(thumb_head) ); + thumb_offset = ftell(ifp)+1; + thumb_length = count-1; + } + if (strstr(make,"Minolta") || strstr(make,"MINOLTA")) { + switch (tag) { + case 0x81: + thumb_offset = ftell(ifp); + thumb_length = count; + break; + case 0x88: + thumb_offset = get4() + base; + break; + case 0x89: + thumb_length = get4(); + } + } + if (!strcmp (buf,"OLYMP") && tag >> 8 == 0x20) + parse_tiff_ifd (base, 3); + fseek (ifp, save+12, SEEK_SET); + } + nikon_decrypt (serial, key, 0x91, 4, sizeof buf91, buf91); + nikon_decrypt (serial, key, 0x97, 284, sizeof buf97, buf97); + nikon_decrypt (serial, key, 0x98, 4, sizeof buf98, buf98); + order = sorder; +} + +void nef_parse_exif(int base) +{ + int entries, tag, type, count, save; + + entries = get2(); + while (entries--) { + save = ftell(ifp); + tag = get2(); + type = get2(); + count= get4(); + tiff_dump (base, tag, type, count, 1); + if (tag == 0x927c) + nef_parse_makernote (base); + fseek (ifp, save+12, SEEK_SET); + } +} + +int parse_tiff_ifd (int base, int level) +{ + int entries, tag, type, count, slen, save, save2, val, i; + int comp=0; + static const int flip_map[] = { 0,1,3,2,4,6,7,5 }; + + entries = get2(); + if (entries > 255) return 1; + while (entries--) { + save = ftell(ifp); + tag = get2(); + type = get2(); + count= get4(); + slen = count; + if (slen > 128) slen = 128; + + tiff_dump (base, tag, type, count, level); + + save2 = ftell(ifp); + if (type == 3) /* short int */ + val = get2(); + else + val = get4(); + fseek (ifp, save2, SEEK_SET); + + if (tag > 50700 && tag < 50800) + is_dng = 1; + + if (level == 3) { /* Olympus E-1 and E-300 */ + if (type == 4) { + if (tag == 0x101) + thumb_offset = val; + else if (tag == 0x102) + thumb_length = val; + } + goto cont; + } + switch (tag) { + case 0x100: /* ImageWidth */ + if (!width) width = val; + break; + case 0x101: /* ImageHeight */ + if (!height) height = val; + break; + case 0x102: /* Bits per sample */ + if (bps) break; + bps = val; + if (count == 1) + thumb_layers = 1; + break; + case 0x103: /* Compression */ + comp = val; + break; + case 0x10f: /* Make tag */ + fgets (make, slen, ifp); + break; + case 0x110: /* Model tag */ + fgets (model, slen, ifp); + break; + case 33405: /* Model2 tag */ + fgets (model2, slen, ifp); + break; + case 0x111: /* StripOffset */ + if (!offset || is_dng) offset = val; + break; + case 0x112: /* Qt::Orientation */ + flip = flip_map[(val-1) & 7]; + break; + case 0x117: /* StripByteCounts */ + if (!length || is_dng) length = val; + if (offset > val && !strncmp(make,"KODAK",5) && !is_dng) + offset -= val; + break; + case 0x14a: /* SubIFD tag */ + save2 = ftell(ifp); + for (i=0; i < count; i++) { + fseek (ifp, save2 + i*4, SEEK_SET); + fseek (ifp, get4()+base, SEEK_SET); + parse_tiff_ifd (base, level+1); + } + break; + case 0x201: + if (strncmp(make,"OLYMPUS",7) || !thumb_offset) + thumb_offset = val; + break; + case 0x202: + if (strncmp(make,"OLYMPUS",7) || !thumb_length) + thumb_length = val; + break; + case 34665: + fseek (ifp, get4()+base, SEEK_SET); + nef_parse_exif (base); + break; + case 50706: + is_dng = 1; + } +cont: + fseek (ifp, save+12, SEEK_SET); + } + if ((comp == 6 && !strcmp(make,"Canon")) || + (comp == 7 && is_dng)) { + thumb_offset = offset; + thumb_length = length; + } + return 0; +} + +/* + Parse a TIFF file looking for camera model and decompress offsets. + */ +void parse_tiff (int base) +{ + int doff, spp=3, ifd=0; + + width = height = offset = length = bps = is_dng = 0; + fseek (ifp, base, SEEK_SET); + order = get2(); + if (order != 0x4949 && order != 0x4d4d) return; + get2(); + while ((doff = get4())) { + fseek (ifp, doff+base, SEEK_SET); + printf ("IFD #%d:\n", ifd++); + if (parse_tiff_ifd (base, 0)) break; + } + if (is_dng) return; + + if (strncmp(make,"KODAK",5)) + thumb_layers = 0; + if (!strncmp(make,"Kodak",5)) { + fseek (ifp, 12+base, SEEK_SET); + puts ("\nSpecial Kodak image directory:"); + parse_tiff_ifd (base, 0); + } + if (!strncmp(model,"DCS460A",7)) { + spp = 1; + thumb_layers = 0; + } + if (!thumb_length && offset) { + thumb_offset = offset; + sprintf (thumb_head, "P%d %d %d %d\n", + spp > 1 ? 6:5, width, height, (1 << bps) - 1); + thumb_length = width * height * spp * ((bps+7)/8); + } +} + +void parse_minolta() +{ + int data_offset, save, tag, len; + + fseek (ifp, 4, SEEK_SET); + data_offset = get4() + 8; + while ((save=ftell(ifp)) < data_offset) { + tag = get4(); + len = get4(); + printf ("Tag %c%c%c offset %06x length %06x\n", + tag>>16, tag>>8, tag, save, len); + switch (tag) { + case 0x545457: /* TTW */ + parse_tiff (ftell(ifp)); + } + fseek (ifp, save+len+8, SEEK_SET); + } + strncpy (thumb_head, "\xff", sizeof(thumb_head) ); + thumb_offset++; + thumb_length--; +} + +/* + Parse a CIFF file, better known as Canon CRW format. + */ +void parse_ciff (int offset, int length, int level /*unused*/) +{ + int tboff, nrecs, i, c, type, len, roff, aoff, save, wbi=-1; + static const int remap[] = { 1,2,3,4,5,1 }; + static const int remap_10d[] = { 0,1,3,4,5,6,0,0,2,8 }; + static const int remap_s70[] = { 0,1,2,9,4,3,6,7,8,9,10,0,0,0,7,0,0,8 }; + ushort key[] = { 0x410, 0x45f3 }; + + if (strcmp(model,"Canon PowerShot G6") && + strcmp(model,"Canon PowerShot S60") && + strcmp(model,"Canon PowerShot S70") && + strcmp(model,"Canon PowerShot Pro1")) + key[0] = key[1] = 0; + fseek (ifp, offset+length-4, SEEK_SET); + tboff = get4() + offset; + fseek (ifp, tboff, SEEK_SET); + nrecs = get2(); + if (nrecs > 100) return; + for (i = 0; i < nrecs; i++) { + type = get2(); + len = get4(); + roff = get4(); + aoff = offset + roff; + save = ftell(ifp); + if (type == 0x080a) { /* Get the camera make and model */ + fseek (ifp, aoff, SEEK_SET); + fread (make, 64, 1, ifp); + fseek (ifp, aoff+strlen(make)+1, SEEK_SET); + fread (model, 64, 1, ifp); + } + if (type == 0x102a) { /* Find the White Balance index */ + fseek (ifp, aoff+14, SEEK_SET); /* 0=auto, 1=daylight, 2=cloudy ... */ + wbi = get2(); + if (((!strcmp(model,"Canon EOS DIGITAL REBEL") || + !strcmp(model,"Canon EOS 300D DIGITAL"))) && wbi == 6) + wbi++; + } + if (type == 0x102c) { /* Get white balance (G2) */ + if (!strcmp(model,"Canon PowerShot G1") || + !strcmp(model,"Canon PowerShot Pro90 IS")) { + fseek (ifp, aoff+120, SEEK_SET); + FORC4 cam_mul[c ^ 2] = get2(); + } else { + fseek (ifp, aoff+100, SEEK_SET); + goto common; + } + } + if (type == 0x0032) { /* Get white balance (D30 & G3) */ + if (!strcmp(model,"Canon EOS D30")) { + fseek (ifp, aoff+72, SEEK_SET); +common: + camera_red = get2() ^ key[0]; + camera_red =(get2() ^ key[1]) / camera_red; + camera_blue = get2() ^ key[0]; + camera_blue /= get2() ^ key[1]; + } else if (!strcmp(model,"Canon PowerShot G6") || + !strcmp(model,"Canon PowerShot S60") || + !strcmp(model,"Canon PowerShot S70")) { + fseek (ifp, aoff+96 + remap_s70[wbi]*8, SEEK_SET); + goto common; + } else if (!strcmp(model,"Canon PowerShot Pro1")) { + fseek (ifp, aoff+96 + wbi*8, SEEK_SET); + goto common; + } else { + fseek (ifp, aoff+80 + (wbi < 6 ? remap[wbi]*8 : 0), SEEK_SET); + if (!camera_red) + goto common; + } + } + if (type == 0x10a9) { /* Get white balance (D60) */ + if (!strcmp(model,"Canon EOS 10D")) + wbi = remap_10d[wbi]; + fseek (ifp, aoff+2 + wbi*8, SEEK_SET); + camera_red = get2(); + camera_red /= get2(); + camera_blue = get2(); + camera_blue = get2() / camera_blue; + } + /* Skip this for now /steffen */ +#if 0 + if (type == 0x1030 && (wbi == 6 || wbi == 15)) { + fseek (ifp, aoff, SEEK_SET); /* Get white sample */ + ciff_block_1030(); + } +#endif + if (type == 0x1031) { /* Get the raw width and height */ + fseek (ifp, aoff+2, SEEK_SET); + raw_width = get2(); + raw_height = get2(); + } + if (type == 0x180e) { /* Get the timestamp */ + fseek (ifp, aoff, SEEK_SET); + timestamp = get4(); + } + if (type == 0x580e) + timestamp = len; +#if 0 + if (type == 0x5813) + flash_used = *((float *) &len); + if (type == 0x5814) + canon_5814 = *((float *) &len); +#endif + if (type == 0x1810) { /* Get the rotation */ + fseek (ifp, aoff+12, SEEK_SET); + flip = get4(); + } + /* Skip this for now /steffen */ +#if 0 + if (type == 0x1835) { /* Get the decoder table */ + fseek (ifp, aoff, SEEK_SET); + crw_init_tables (get4()); + } +#endif + if (type == 0x2007) { /* Found the JPEG thumbnail */ + thumb_offset = aoff; + thumb_length = len; + } + if (type >> 8 == 0x28 || type >> 8 == 0x30) /* Get sub-tables */ + parse_ciff(aoff, len, level+1); + fseek (ifp, save, SEEK_SET); + } + if (wbi == 0 && !strcmp(model,"Canon EOS D30")) + camera_red = -1; /* Use my auto WB for this photo */ +} + + +void parse_mos(int level) +{ + uchar data[256]; + int i, j, skip, save; + char *cp; + + save = ftell(ifp); + while (1) { + fread (data, 1, 8, ifp); + if (strcmp(data,"PKTS")) break; + strcpy (model, "Valeo"); + fread (data, 1, 40, ifp); + skip = get4(); + if (!strcmp(data,"icc_camera_to_tone_matrix")) { + for (i=0; i < skip/4; i++) { + j = get4(); + } + continue; + } + if (!strcmp(data,"JPEG_preview_data")) { + thumb_head[0] = 0; + thumb_offset = ftell(ifp); + thumb_length = skip; + } + fread (data, 1, sizeof data, ifp); + fseek (ifp, -sizeof data, SEEK_CUR); + data[sizeof data - 1] = 0; + while ((cp=index(data,'\n'))) + *cp = ' '; + parse_mos(level+2); + fseek (ifp, skip, SEEK_CUR); + } + fseek (ifp, save, SEEK_SET); +} + +void parse_rollei() +{ + char line[128], *val; + + fseek (ifp, 0, SEEK_SET); + do { + fgets (line, 128, ifp); + fputs (line, stdout); + if ((val = strchr(line,'='))) + *val++ = 0; + else + val = line + strlen(line); + if (!strcmp(line,"HDR")) + thumb_offset = atoi(val); + if (!strcmp(line,"TX ")) + width = atoi(val); + if (!strcmp(line,"TY ")) + height = atoi(val); + } while (strncmp(line,"EOHD",4)); + strcpy (make, "Rollei"); + strcpy (model, "d530flex"); + thumb_length = width*height*2; +} + +void rollei_decode (FILE *tfp) +{ + ushort data; + int row, col; + + fseek (ifp, thumb_offset, SEEK_SET); + fprintf (tfp, "P6\n%d %d\n255\n", width, height); + for (row=0; row < height; row++) + for (col=0; col < width; col++) { + fread (&data, 2, 1, ifp); + data = ntohs(data); + putc (data << 3, tfp); + putc (data >> 5 << 2, tfp); + putc (data >> 11 << 3, tfp); + } +} + +void get_utf8 (int offset, char *buf, int len) +{ + ushort c; + char *cp; + + fseek (ifp, offset, SEEK_SET); + for (cp=buf; (c = get2()) && cp+3 < buf+len; ) { + if (c < 0x80) + *cp++ = c; + else if (c < 0x800) { + *cp++ = 0xc0 + (c >> 6); + *cp++ = 0x80 + (c & 0x3f); + } else { + *cp++ = 0xe0 + (c >> 12); + *cp++ = 0x80 + (c >> 6 & 0x3f); + *cp++ = 0x80 + (c & 0x3f); + } + } + *cp = 0; +} + +ushort sget2 (uchar *s) +{ + return s[0] + (s[1]<<8); +} + +int sget4 (uchar *s) +{ + return s[0] + (s[1]<<8) + (s[2]<<16) + (s[3]<<24); +} + +void parse_foveon() +{ + int entries, img=0, off, len, tag, save, i, j, k, pent, poff[256][2]; + char name[128], value[128], camf[0x20000], *pos, *cp, *dp; + unsigned val, key, type, num, ndim, dim[3]; + + order = 0x4949; /* Little-endian */ + fseek (ifp, -4, SEEK_END); + fseek (ifp, get4(), SEEK_SET); + if (get4() != 0x64434553) { /* SECd */ + printf ("Bad Section identifier at %6x\n", (int)ftell(ifp)-4); + return; + } + get4(); + entries = get4(); + while (entries--) { + off = get4(); + len = get4(); + tag = get4(); + save = ftell(ifp); + fseek (ifp, off, SEEK_SET); + if (get4() != (0x20434553 | (tag << 24))) { + printf ("Bad Section identifier at %6x\n", off); + goto next; + } + val = get4(); + switch (tag) { + case 0x32414d49: /* IMA2 */ + case 0x47414d49: /* IMAG */ + if (++img == 2) { /* second image */ + thumb_offset = off; + thumb_length = 1; + } + printf ("type %d, " , get4()); + printf ("format %2d, " , get4()); + printf ("columns %4d, " , get4()); + printf ("rows %4d, " , get4()); + printf ("rowsize %d\n" , get4()); + break; + case 0x464d4143: /* CAMF */ + printf ("type %d, ", get4()); + get4(); + for (i=0; i < 4; i++) + putchar(fgetc(ifp)); + val = get4(); + printf (" version %d.%d:\n",val >> 16, val & 0xffff); + key = get4(); + if ((len -= 28) > 0x20000) + len = 0x20000; + fread (camf, 1, len, ifp); + for (i=0; i < len; i++) { + key = (key * 1597 + 51749) % 244944; + val = key * (INT64) 301593171 >> 24; + camf[i] ^= ((((key << 8) - val) >> 1) + val) >> 17; + } + for (pos=camf; (unsigned) (pos-camf) < len; pos += sget4(pos+8)) { + if (strncmp (pos, "CMb", 3)) { + printf("Bad CAMF tag \"%.4s\"\n", pos); + break; + } + val = sget4(pos+4); + printf (" %4.4s version %d.%d: ", pos, val >> 16, val & 0xffff); + switch (pos[3]) { + case 'M': + cp = pos + sget4(pos+16); + type = sget4(cp); + ndim = sget4(cp+4); + dim[0] = dim[1] = dim[2] = 1; + printf ("%d-dimensonal array %s of type %d:\n Key: (", + ndim, pos+sget4(pos+12), sget4(cp)); + dp = pos + sget4(cp+8); + for (i=ndim; i--; ) { + cp += 12; + dim[i] = sget4(cp); + printf ("%s %d%s", pos+sget4(cp+4), dim[i], i ? ", ":")\n"); + } + for (i=0; i < dim[2]; i++) { + for (j=0; j < dim[1]; j++) { + printf (" "); + for (k=0; k < dim[0]; k++) + switch (type) { + case 0: + case 6: + printf ("%7d", sget2(dp)); + dp += 2; + break; + case 1: + case 2: + printf (" %d", sget4(dp)); + dp += 4; + break; + case 3: { + union { int ival; float fval; } __t; + __t.ival = sget4(dp); + printf (" %9f", __t.fval); + dp += 4; + } + } + printf ("\n"); + } + printf ("\n"); + } + break; + case 'P': + val = sget4(pos+16); + num = sget4(pos+val); + printf ("%s, %d parameters:\n", pos+sget4(pos+12), num); + cp = pos+val+8 + num*8; + for (i=0; i < num; i++) { + val += 8; + printf (" %s = %s\n", cp+sget4(pos+val), cp+sget4(pos+val+4)); + } + break; + case 'T': + cp = pos + sget4(pos+16); + printf ("%s = %.*s\n", pos+sget4(pos+12), sget4(cp), cp+4); + break; + default: + printf ("\n"); + } + } + break; + case 0x504f5250: /* PROP */ + printf ("entries %d, ", pent=get4()); + printf ("charset %d, ", get4()); + get4(); + printf ("nchars %d\n", get4()); + off += pent*8 + 24; + if (pent > 256) pent=256; + for (i=0; i < pent*2; i++) + poff[0][i] = off + get4()*2; + for (i=0; i < pent; i++) { + get_utf8 (poff[i][0], name, 128); + get_utf8 (poff[i][1], value, 128); + printf (" %s = %s\n", name, value); + if (!strcmp (name,"CAMMANUF")) + strncpy (make, value, sizeof(make)); + if (!strcmp (name,"CAMMODEL")) + strncpy (model, value, sizeof(value)); + } + } +next: + fseek (ifp, save, SEEK_SET); + } +} + +void foveon_tree (unsigned huff[1024], unsigned code) +{ + struct decode *cur; + int i, len; + + cur = free_decode++; + if (code) { + for (i=0; i < 1024; i++) + if (huff[i] == code) { + cur->leaf = i; + return; + } + } + if ((len = code >> 27) > 26) return; + code = (len+1) << 27 | (code & 0x3ffffff) << 1; + + cur->branch[0] = free_decode; + foveon_tree (huff, code); + cur->branch[1] = free_decode; + foveon_tree (huff, code+1); +} + +void foveon_decode (FILE *tfp) +{ + int bwide, row, col, bit=-1, c, i; + char *buf; + struct decode *dindex; + short pred[3]; + unsigned huff[1024], bitbuf=0; + + fseek (ifp, thumb_offset+16, SEEK_SET); + width = get4(); + height = get4(); + bwide = get4(); + fprintf (tfp, "P6\n%d %d\n255\n", width, height); + if (bwide > 0) { + buf = malloc(bwide); + for (row=0; row < height; row++) { + fread (buf, 1, bwide, ifp); + fwrite (buf, 3, width, tfp); + } + free (buf); + return; + } + for (i=0; i < 256; i++) + huff[i] = get4(); + memset (first_decode, 0, sizeof first_decode); + free_decode = first_decode; + foveon_tree (huff, 0); + + for (row=0; row < height; row++) { + memset (pred, 0, sizeof pred); + if (!bit) get4(); + for (col=bit=0; col < width; col++) { + for (c=0; c < 3; c++) { + for (dindex=first_decode; dindex->branch[0]; ) { + if ((bit = (bit-1) & 31) == 31) + for (i=0; i < 4; i++) + bitbuf = (bitbuf << 8) + fgetc(ifp); + dindex = dindex->branch[bitbuf >> bit & 1]; + } + pred[c] += dindex->leaf; + fputc (pred[c], tfp); + } + } + } +} + +void kodak_yuv_decode (FILE *tfp) +{ + uchar c, blen[384]; + unsigned row, col, len, bits=0; + INT64 bitbuf=0; + int i, li=0, si, diff, six[6], y[4], cb=0, cr=0, rgb[3]; + ushort *out, *op; + + fseek (ifp, thumb_offset, SEEK_SET); + width = (width+1) & -2; + height = (height+1) & -2; + fprintf (tfp, "P6\n%d %d\n65535\n", width, height); + out = malloc (width * 12); + if (!out) { + fprintf (stderr, "kodak_yuv_decode() malloc failed!\n"); + exit(1); + } + + for (row=0; row < height; row+=2) { + for (col=0; col < width; col+=2) { + if ((col & 127) == 0) { + len = (width - col + 1) * 3 & -4; + if (len > 384) len = 384; + for (i=0; i < len; ) { + c = fgetc(ifp); + blen[i++] = c & 15; + blen[i++] = c >> 4; + } + li = bitbuf = bits = y[1] = y[3] = cb = cr = 0; + if (len % 8 == 4) { + bitbuf = fgetc(ifp) << 8; + bitbuf += fgetc(ifp); + bits = 16; + } + } + for (si=0; si < 6; si++) { + len = blen[li++]; + if (bits < len) { + for (i=0; i < 32; i+=8) + bitbuf += (INT64) fgetc(ifp) << (bits+(i^8)); + bits += 32; + } + diff = bitbuf & (0xffff >> (16-len)); + bitbuf >>= len; + bits -= len; + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + six[si] = diff; + } + y[0] = six[0] + y[1]; + y[1] = six[1] + y[0]; + y[2] = six[2] + y[3]; + y[3] = six[3] + y[2]; + cb += six[4]; + cr += six[5]; + for (i=0; i < 4; i++) { + op = out + ((i >> 1)*width + col+(i & 1)) * 3; + rgb[0] = y[i] + 1.40200/2 * cr; + rgb[1] = y[i] - 0.34414/2 * cb - 0.71414/2 * cr; + rgb[2] = y[i] + 1.77200/2 * cb; + for (c=0; c < 3; c++) + if (rgb[c] > 0) op[c] = htons(rgb[c]); + } + } + fwrite (out, sizeof *out, width*6, tfp); + } + free(out); +} + +void parse_phase_one (int base) +{ + unsigned entries, tag, type, len, data, save; + char str[256]; + + fseek (ifp, base + 8, SEEK_SET); + fseek (ifp, base + get4(), SEEK_SET); + entries = get4(); + get4(); + while (entries--) { + tag = get4(); + type = get4(); + len = get4(); + data = get4(); + save = ftell(ifp); + printf ("Phase One tag=0x%x, type=%d, len=%2d, data = 0x%x\n", + tag, type, len, data); + if (type == 1 && len < 256) { + fseek (ifp, base + data, SEEK_SET); + fread (str, 256, 1, ifp); + puts (str); + } + if (tag == 0x110) { + thumb_offset = data + base; + thumb_length = len; + } + fseek (ifp, save, SEEK_SET); + } + strcpy (make, "Phase One"); + strcpy (model, "unknown"); +} + +void parse_jpeg (int offset) +{ + int len, save, hlen; + + fseek (ifp, offset, SEEK_SET); + if (fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) return; + + while (fgetc(ifp) == 0xff && fgetc(ifp) >> 4 != 0xd) { + order = 0x4d4d; + len = get2() - 2; + save = ftell(ifp); + order = get2(); + hlen = get4(); + if (get4() == 0x48454150) /* "HEAP" */ + parse_ciff (save+hlen, len-hlen, 0); + parse_tiff (save+6); + fseek (ifp, save+len, SEEK_SET); + } +} + +char *raw_memmem (char *haystack, size_t haystacklen, + char *needle, size_t needlelen) +{ + char *c; + for (c = haystack; c <= haystack + haystacklen - needlelen; c++) + if (!memcmp (c, needle, needlelen)) + return c; + return NULL; +} + +/* + Identify which camera created this file, and set global variables + accordingly. + Return nonzero if the file cannot be decoded or no thumbnail is found + */ +int identify(FILE* tfp) +{ + char head[32], *thumb, *rgb, *cp; + unsigned hlen, fsize, toff, tlen, lsize, i; + + make[0] = model[0] = model2[0] = is_dng = 0; + thumb_head[0] = thumb_offset = thumb_length = thumb_layers = 0; + order = get2(); + hlen = get4(); + fseek (ifp, 0, SEEK_SET); + fread (head, 1, 32, ifp); + fseek (ifp, 0, SEEK_END); + fsize = ftell(ifp); + if ((cp = raw_memmem (head, 32, "MMMMRawT", 8)) || + (cp = raw_memmem (head, 32, "IIIITwaR", 8))) + parse_phase_one (cp - head); + else if (order == 0x4949 || order == 0x4d4d) { + if (!memcmp(head+6,"HEAPCCDR",8)) { + parse_ciff (hlen, fsize - hlen, 0); + fseek (ifp, hlen, SEEK_SET); + } else + parse_tiff (0); + } else if (!memcmp (head, "\0MRM", 4)) + parse_minolta(); + else if (!memcmp (head, "\xff\xd8\xff\xe1", 4) && + !memcmp (head+6, "Exif", 4)) { + parse_tiff (12); + thumb_length = 0; + } else if (!memcmp (head, "FUJIFILM", 8)) { + fseek (ifp, 84, SEEK_SET); + toff = get4(); + tlen = get4(); + thumb_offset = toff; + thumb_length = tlen; + } else if (!memcmp (head, "DSC-Image", 9)) + parse_rollei(); + else if (!memcmp (head, "FOVb", 4)) + parse_foveon(); + fseek (ifp, 8, SEEK_SET); + parse_mos(0); + fseek (ifp, 3472, SEEK_SET); + parse_mos(0); + parse_jpeg(0); + + if (!thumb_length) { + fprintf (stderr, "Thumbnail image not found\n"); + return -1; + } + + if (is_dng) goto dng_skip; + if (!strncmp(model,"DCS Pro",7)) { + kodak_yuv_decode (tfp); + goto done; + } + if (!strcmp(make,"Rollei")) { + rollei_decode (tfp); + goto done; + } + if (!strcmp(make,"SIGMA")) { + foveon_decode (tfp); + goto done; + } +dng_skip: + thumb = (char *) malloc(thumb_length); + if (!thumb) { + fprintf (stderr, "Cannot allocate %d bytes!!\n", thumb_length); + exit(1); + } + fseek (ifp, thumb_offset, SEEK_SET); + fread (thumb, 1, thumb_length, ifp); + if (thumb_layers && !is_dng) { + rgb = (char *) malloc(thumb_length); + if (!rgb) { + fprintf (stderr, "Cannot allocate %d bytes!!\n", thumb_length); + return -1; + } + lsize = thumb_length/3; + for (i=0; i < thumb_length; i++) + rgb[(i%lsize)*3 + i/lsize] = thumb[i]; + free(thumb); + thumb = rgb; + } + fputs (thumb_head, tfp); + fwrite(thumb, 1, thumb_length, tfp); + free (thumb); +done: + fprintf (stderr, "Thumbnail image written, make=%s, model=%s\n",&(make[0]),&(model[0])); + return 0; +} + +int extract_thumbnail( FILE* input, FILE* output, int* orientation ) +{ + /* Coffin's code has different meaning for orientation + values than TIFF, so we map them to TIFF values */ + static const int flip_map[] = { 0,1,3,2,4,7,5,6 }; + int rc; + ifp = input; + rc = identify(output); + switch ((flip+3600) % 360) { + case 270: flip = 5; break; + case 180: flip = 3; break; + case 90: flip = 6; + } + if( orientation ) *orientation = flip_map[flip%7]; + return rc; +} diff --git a/tdefile-plugins/raw/tdefile_raw.desktop b/tdefile-plugins/raw/tdefile_raw.desktop new file mode 100644 index 00000000..cb9b2a14 --- /dev/null +++ b/tdefile-plugins/raw/tdefile_raw.desktop @@ -0,0 +1,53 @@ +[Desktop Entry] +Type=Service +Name=RAW Camera Files +Name[br]=Restroù kamera kriz +Name[bs]=RAW kamera datoteke +Name[ca]=Fitxers RAW de càmera +Name[cs]=RAW soubory +Name[da]=RAW kamera-filer +Name[de]=RAW Kamera-Dateien +Name[el]=RAW αρχείο κάμερας +Name[es]=Archivos RAW de cámara +Name[et]=Toored kaamerafailid +Name[eu]=RAW kamera-fitxategiak +Name[fa]=پروندههای خام دوربین +Name[fi]=RAW-kuvatiedostot +Name[fr]=Fichiers RAW d'appareil photo numérique +Name[ga]=Comhaid Cheamara RAW +Name[gl]=Ficheiros RAW de Cámara +Name[he]=קבצי מצלמה דיגיטלית גולמיים +Name[hu]=RAW-fájlok +Name[is]=RAW myndavélaskrár +Name[it]=File grezzi fotocamera digitale +Name[ja]=RAW カメラファイル +Name[kk]=Камераның RAW пішімдегі файлдары +Name[km]=ឯកសារចេញពីម៉ាស៊ីនថតរូប +Name[lt]=RAW fotoaparato bylos +Name[nb]=RAW-kamerafiler +Name[nds]=RAW-Kameradateien +Name[ne]=RAW क्यामेरा फाइल +Name[nl]=Rauwe camerabestanden +Name[nn]=RAW-kamerafiler +Name[pa]=RAW ਕੈਮਰਾ ਫਾਇਲਾਂ +Name[pl]=Pliki RAW z aparatów cyfrowych +Name[pt]=Ficheiros de Máquina Fotográfica Digital RAW +Name[pt_BR]=Arquivos de Câmeras +Name[ro]=Fişiere foto brute +Name[ru]=Необработанные Файлы с цифровой камеры (RAW) +Name[sk]=RAW súbory digitálneho fotoaparátu +Name[sl]=Surove datoteke s fotoaparata +Name[sr]=RAW фајлови слика +Name[sr@Latn]=RAW fajlovi slika +Name[sv]=Obehandlade kamerafiler +Name[th]=แฟ้มภาพ RAW จากกล้อง +Name[tr]=RAW Kamera Dosyaları +Name[uk]=Файли цифрової камери RAW +Name[zh_CN]=RAW 相机文件 +Name[zh_HK]=RAW 相機檔案 +Name[zh_TW]=原始相機檔 +ServiceTypes=KFilePlugin +MimeType=image/x-raw +X-TDE-Library=tdefile_raw +CacheThumbnail=false +SupportsThumbnail=true diff --git a/tdefile-plugins/rgb/CMakeLists.txt b/tdefile-plugins/rgb/CMakeLists.txt new file mode 100644 index 00000000..7596f2cb --- /dev/null +++ b/tdefile-plugins/rgb/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_rgb.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_rgb (module) ######################### + +tde_add_kpart( tdefile_rgb AUTOMOC + SOURCES tdefile_rgb.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/rgb/Makefile.am b/tdefile-plugins/rgb/Makefile.am new file mode 100644 index 00000000..aab98d29 --- /dev/null +++ b/tdefile-plugins/rgb/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for rgb file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_rgb.h + +kde_module_LTLIBRARIES = tdefile_rgb.la + +tdefile_rgb_la_SOURCES = tdefile_rgb.cpp +tdefile_rgb_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_rgb_la_LIBADD = $(LIB_KSYCOCA) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) tdefile_rgb.cpp -o $(podir)/tdefile_rgb.pot + +services_DATA = tdefile_rgb.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/rgb/tdefile_rgb.cpp b/tdefile-plugins/rgb/tdefile_rgb.cpp new file mode 100644 index 00000000..e503e438 --- /dev/null +++ b/tdefile-plugins/rgb/tdefile_rgb.cpp @@ -0,0 +1,208 @@ +/* This file is part of the KDE project + * Copyright (C) 2004 Melchior FRANZ <mfranz@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include <config.h> +#include "tdefile_rgb.h" + +#include <tqfile.h> +#include <tqvalidator.h> + +#include <kdebug.h> +#include <kgenericfactory.h> + + +typedef KGenericFactory<KRgbPlugin> RgbFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_rgb, RgbFactory("tdefile_rgb")) + + +KRgbPlugin::KRgbPlugin(TQObject *parent, const char *name, const TQStringList &args) : + KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo("image/x-rgb"); + + KFileMimeTypeInfo::GroupInfo* group = 0; + KFileMimeTypeInfo::ItemInfo* item; + + + group = addGroupInfo(info, "Comment", i18n("Comment")); + + item = addItemInfo(group, "ImageName", i18n("Name"), TQVariant::String); + setAttributes(item, KFileMimeTypeInfo::Modifiable); + setHint(item, KFileMimeTypeInfo::Description); + + + group = addGroupInfo(info, "Technical", i18n("Technical Details")); + + item = addItemInfo(group, "Dimensions", i18n("Dimensions"), TQVariant::Size); + setHint(item, KFileMimeTypeInfo::Size); + setUnit(item, KFileMimeTypeInfo::Pixels); + + item = addItemInfo(group, "BitDepth", i18n("Bit Depth"), TQVariant::Int); + setUnit(item, KFileMimeTypeInfo::BitsPerPixel); + + item = addItemInfo(group, "ColorMode", i18n("Color Mode"), TQVariant::String); + item = addItemInfo(group, "Compression", i18n("Compression"), TQVariant::String); + item = addItemInfo(group, "SharedRows", + i18n("percentage of avoided vertical redundancy (the higher the better)", + "Shared Rows"), TQVariant::String); + +} + + +bool KRgbPlugin::readInfo(KFileMetaInfo& info, uint /*what*/) +{ + TQFile file(info.path()); + + if (!file.open(IO_ReadOnly)) { + kdDebug(7034) << "Couldn't open " << TQFile::encodeName(info.path()).data() << endl; + return false; + } + + TQDataStream dstream(&file); + + TQ_UINT16 magic; + TQ_UINT8 storage; + TQ_UINT8 bpc; + TQ_UINT16 dimension; + TQ_UINT16 xsize; + TQ_UINT16 ysize; + TQ_UINT16 zsize; + TQ_UINT32 pixmin; + TQ_UINT32 pixmax; + TQ_UINT32 dummy; + char imagename[80]; + TQ_UINT32 colormap; + + dstream >> magic; + dstream >> storage; + dstream >> bpc; + dstream >> dimension; + dstream >> xsize; + dstream >> ysize; + dstream >> zsize; + dstream >> pixmin; + dstream >> pixmax; + dstream >> dummy; + dstream.readRawBytes(imagename, 80); + imagename[79] = '\0'; + dstream >> colormap; + TQ_UINT8 u8; + for (uint i = 0; i < 404; i++) + dstream >> u8; + + if (magic != 474) + return false; + + KFileMetaInfoGroup group; + + group = appendGroup(info, "Technical"); + + if (dimension == 1) + ysize = 1; + appendItem(group, "Dimensions", TQSize(xsize, ysize)); + appendItem(group, "BitDepth", zsize * 8 * bpc); + + if (zsize == 1) + appendItem(group, "ColorMode", i18n("Grayscale")); + else if (zsize == 2) + appendItem(group, "ColorMode", i18n("Grayscale/Alpha")); + else if (zsize == 3) + appendItem(group, "ColorMode", i18n("RGB")); + else if (zsize == 4) + appendItem(group, "ColorMode", i18n("RGB/Alpha")); + + if (!storage) + appendItem(group, "Compression", i18n("Uncompressed")); + else if (storage == 1) { + long compressed = file.size() - 512; + long verbatim = xsize * ysize * zsize; + appendItem(group, "Compression", i18n("Runlength Encoded") + + TQString(", %1%").arg(compressed * 100.0 / verbatim, 0, 'f', 1)); + + long k; + TQ_UINT32 offs; + TQMap<TQ_UINT32, uint> map; + TQMap<TQ_UINT32, uint>::Iterator it; + TQMap<TQ_UINT32, uint>::Iterator end = map.end(); + for (k = 0; k < (ysize * zsize); k++) { + dstream >> offs; + if ((it = map.find(offs)) != end) + map.replace(offs, it.data() + 1); + else + map[offs] = 0; + } + for (k = 0, it = map.begin(); it != end; ++it) + k += it.data(); + + if (k) + appendItem(group, "SharedRows", TQString("%1%").arg(k * 100.0 + / (ysize * zsize), 0, 'f', 1)); + else + appendItem(group, "SharedRows", i18n("None")); + } else + appendItem(group, "Compression", i18n("Unknown")); + + + group = appendGroup(info, "Comment"); + appendItem(group, "ImageName", imagename); + + file.close(); + return true; +} + + +bool KRgbPlugin::writeInfo(const KFileMetaInfo& info) const +{ + TQFile file(info.path()); + + if (!file.open(IO_WriteOnly|IO_Raw)) { + kdDebug(7034) << "couldn't open " << TQFile::encodeName(info.path()).data() << endl; + return false; + } + + if (!file.at(24)) { + kdDebug(7034) << "couldn't set offset" << endl; + return false; + } + + TQDataStream dstream(&file); + TQString s = info["Comment"]["ImageName"].value().toString(); + s.truncate(79); + + unsigned i; + for (i = 0; i < s.length(); i++) + dstream << TQ_UINT8(s.latin1()[i]); + for (; i < 80; i++) + dstream << TQ_UINT8(0); + + file.close(); + return true; +} + + +// restrict to 79 ASCII characters +TQValidator* KRgbPlugin::createValidator(const TQString&, const TQString &, + const TQString &, TQObject* parent, const char* name) const +{ + return new TQRegExpValidator(TQRegExp("[\x0020-\x007E]{79}"), parent, name); +} + + +#include "tdefile_rgb.moc" diff --git a/tdefile-plugins/rgb/tdefile_rgb.desktop b/tdefile-plugins/rgb/tdefile_rgb.desktop new file mode 100644 index 00000000..9edecac8 --- /dev/null +++ b/tdefile-plugins/rgb/tdefile_rgb.desktop @@ -0,0 +1,61 @@ +[Desktop Entry] +Type=Service +Name=SGI Image (RGB) +Name[br]=Skeudenn SGI (RGB) +Name[bs]=SGI slika (RGB) +Name[ca]=Imatge SGI (RGB) +Name[cs]=SGI obrázek (RGB) +Name[cy]=Delwedd SGI (RGB) +Name[da]=SGI-billede (RGB) +Name[de]=SGI-Bild (RGB) +Name[el]=Εικόνα SGI (RGB) +Name[es]=Imagen SGI (RGB) +Name[et]=SGI pildifail (RGB) +Name[eu]=SGI irudia RGB) +Name[fa]=تصویر SGI (RGB) +Name[fi]=SGI-kuva (RGB) +Name[fr]=Image SGI (RVB) +Name[ga]=Íomhá SGI (RGB) +Name[gl]=Imaxe SGI (RGB) +Name[he]=תמונת SGI (RGB) +Name[hr]=SGI slika (RGB) +Name[hu]=SGI-kép (RGB) +Name[is]=SGI mynd (TGB) +Name[it]=Immagine SGI (RGB) +Name[ja]=SGI 画像 (RGB) +Name[kk]=SGI кескіні (RGB) +Name[km]=រូបភាព SGI (RGB) +Name[lt]=SGI paveiksliukas (RGB) +Name[ms]=Imej SGI (RGB) +Name[nb]=Bildeindeks +Name[nds]=SGI-Bild (RGB) +Name[ne]=SGI छवि (RGB) +Name[nl]=SGI-afbeelding (RGB) +Name[nn]=SGI-bilete (RGB) +Name[pl]=Obrazek SGI (RGB) +Name[pt]=Imagem SGI (RGB) +Name[pt_BR]=Imagem SGI (RGB) +Name[ro]=Imagine SGI (RGB) +Name[ru]=Изображение SGI (RGB) +Name[rw]=SGI Ishusho (RGB) +Name[se]=SGI-govva (RGB) +Name[sk]=SGI obrázok (RGB) +Name[sl]=Slika SGI (RGB) +Name[sr]=SGI слика (RGB) +Name[sr@Latn]=SGI slika (RGB) +Name[sv]=SGI-bild (RGB) +Name[ta]=எஸ்ஜிஐ படிமம் (RGB) +Name[tg]=Тасвироти SGI (RGB) +Name[th]=ภาพ SGI (RGB) +Name[tr]=SGI Resmi(KYM) +Name[uk]=Зображення SGI (RGB) +Name[uz]=SGI-rasm (RGB) +Name[uz@cyrillic]=SGI-расм (RGB) +Name[zh_CN]=SGI 图像(RGB) +Name[zh_HK]=SGI 圖像 (RGB) +Name[zh_TW]=SGI 影像(RGB) +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_rgb +MimeType=image/x-rgb +PreferredGroups=Comment,Technical +PreferredItems=Dimensions,BitDepth,ColorMode,Compression,SharedRows,ImageName diff --git a/tdefile-plugins/rgb/tdefile_rgb.h b/tdefile-plugins/rgb/tdefile_rgb.h new file mode 100644 index 00000000..6a4e0ae2 --- /dev/null +++ b/tdefile-plugins/rgb/tdefile_rgb.h @@ -0,0 +1,42 @@ +/* This file is part of the KDE project + * Copyright (C) 2004 Melcrhio FRANZ <mfranz@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_RGB_H__ +#define __KFILE_RGB_H__ + +#include <tdefilemetainfo.h> + +class TQStringList; + +class KRgbPlugin : public KFilePlugin +{ + Q_OBJECT + + +public: + KRgbPlugin(TQObject *parent, const char *name, const TQStringList& args); + virtual bool readInfo(KFileMetaInfo& info, uint what); + virtual bool writeInfo(const KFileMetaInfo& info) const; + virtual TQValidator* createValidator(const TQString& mimetype, + const TQString &group, const TQString &key, + TQObject* parent, const char* name) const; + +}; + +#endif diff --git a/tdefile-plugins/tga/CMakeLists.txt b/tdefile-plugins/tga/CMakeLists.txt new file mode 100644 index 00000000..7040c7ca --- /dev/null +++ b/tdefile-plugins/tga/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_tga.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_tga (module) ######################### + +tde_add_kpart( tdefile_tga AUTOMOC + SOURCES tdefile_tga.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/tga/Makefile.am b/tdefile-plugins/tga/Makefile.am new file mode 100644 index 00000000..5aad4b7e --- /dev/null +++ b/tdefile-plugins/tga/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for tga file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_tga.h + +kde_module_LTLIBRARIES = tdefile_tga.la + +tdefile_tga_la_SOURCES = tdefile_tga.cpp +tdefile_tga_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_tga_la_LIBADD = $(LIB_KSYCOCA) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) tdefile_tga.cpp -o $(podir)/tdefile_tga.pot + +services_DATA = tdefile_tga.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/tga/tdefile_tga.cpp b/tdefile-plugins/tga/tdefile_tga.cpp new file mode 100644 index 00000000..36fad13c --- /dev/null +++ b/tdefile-plugins/tga/tdefile_tga.cpp @@ -0,0 +1,165 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Shane Wright <me@shanewright.co.uk> + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include <config.h> +#include "tdefile_tga.h" + +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kstringvalidator.h> +#include <kdebug.h> + +#include <tqdict.h> +#include <tqvalidator.h> +#include <tqcstring.h> +#include <tqfile.h> +#include <tqdatetime.h> + +#if !defined(__osf__) +#include <inttypes.h> +#else +typedef unsigned long uint32_t; +typedef unsigned short uint16_t; +typedef unsigned char uint8_t; +#endif + +typedef KGenericFactory<KTgaPlugin> TgaFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_tga, TgaFactory( "tdefile_tga" )) + +KTgaPlugin::KTgaPlugin(TQObject *parent, const char *name, + const TQStringList &args) + + : KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( "image/x-targa" ); + + KFileMimeTypeInfo::GroupInfo* group = 0L; + + group = addGroupInfo(info, "Technical", i18n("Technical Details")); + + KFileMimeTypeInfo::ItemInfo* item; + + item = addItemInfo(group, "Dimensions", i18n("Dimensions"), TQVariant::Size); + setHint( item, KFileMimeTypeInfo::Size ); + setUnit(item, KFileMimeTypeInfo::Pixels); + + item = addItemInfo(group, "BitDepth", i18n("Bit Depth"), TQVariant::Int); + setUnit(item, KFileMimeTypeInfo::BitsPerPixel); + + item = addItemInfo(group, "ColorMode", i18n("Color Mode"), TQVariant::String); + item = addItemInfo(group, "Compression", i18n("Compression"), TQVariant::String); + +} + +bool KTgaPlugin::readInfo( KFileMetaInfo& info, uint what) +{ + + + TQFile file(info.path()); + + if (!file.open(IO_ReadOnly)) + { + kdDebug(7034) << "Couldn't open " << TQFile::encodeName(info.path()).data() << endl; + return false; + } + + TQDataStream dstream(&file); + + // TGA files are little-endian + dstream.setByteOrder(TQDataStream::LittleEndian); + + // the vars for the image data + uint8_t tga_idlength; + uint8_t tga_colormaptype; + uint8_t tga_imagetype; + uint16_t tga_colormap_fei; + uint16_t tga_colormap_length; + uint8_t tga_colormap_entrysize; + uint16_t tga_imagespec_origin_x; + uint16_t tga_imagespec_origin_y; + uint16_t tga_imagespec_width; + uint16_t tga_imagespec_height; + uint8_t tga_imagespec_depth; + uint8_t tga_imagespec_descriptor; + + // read the image data + dstream >> tga_idlength; + dstream >> tga_colormaptype; + dstream >> tga_imagetype; + dstream >> tga_colormap_fei; + dstream >> tga_colormap_length; + dstream >> tga_colormap_entrysize; + dstream >> tga_imagespec_origin_x; + dstream >> tga_imagespec_origin_y; + dstream >> tga_imagespec_width; + dstream >> tga_imagespec_height; + dstream >> tga_imagespec_depth; + dstream >> tga_imagespec_descriptor; + + // output the useful bits + KFileMetaInfoGroup group = appendGroup(info, "Technical"); + appendItem(group, "Dimensions", TQSize(tga_imagespec_width, tga_imagespec_height)); + appendItem(group, "BitDepth", tga_imagespec_depth); + + switch (tga_imagetype) { + case 1 : + case 9 : + case 32 : + appendItem(group, "ColorMode", i18n("Color-Mapped")); + break; + case 2 : + case 10 : + case 33 : + appendItem(group, "ColorMode", i18n("RGB")); + break; + case 3 : + case 11 : + appendItem(group, "ColorMode", i18n("Black and White")); + break; + default : + appendItem(group, "ColorMode", i18n("Unknown")); + } + + switch (tga_imagetype) { + case 1 : + case 2 : + case 3 : + appendItem(group, "Compression", i18n("Uncompressed")); + break; + case 9 : + case 10 : + case 11 : + appendItem(group, "Compression", i18n("Runlength Encoded")); + break; + case 32 : + appendItem(group, "Compression", i18n("Huffman, Delta & RLE")); + break; + case 33 : + appendItem(group, "Compression", i18n("Huffman, Delta, RLE (4-pass quadtree)")); + break; + default : + appendItem(group, "Compression", i18n("Unknown")); + }; + + return true; +} + +#include "tdefile_tga.moc" diff --git a/tdefile-plugins/tga/tdefile_tga.desktop b/tdefile-plugins/tga/tdefile_tga.desktop new file mode 100644 index 00000000..30a45faf --- /dev/null +++ b/tdefile-plugins/tga/tdefile_tga.desktop @@ -0,0 +1,64 @@ +[Desktop Entry] +Type=Service +Name=Truevision Targa Info +Name[ar]=معلومات Truevision Targa +Name[br]=Gorretaol Truevision Targa +Name[ca]=Informació de Targa Truevision +Name[cs]=Truevision Targa info +Name[cy]=Gwybodaeth Truevision Targa +Name[da]=Truevision Targa-info +Name[de]=Truevision Targa-Info +Name[el]=Πληροφορίες Truevision Targa +Name[eo]=TARGA-informo +Name[es]=Info de Targa visión verdadera +Name[et]=Truevision Targa info +Name[fa]=اطلاعات Truevision Targa +Name[fi]=Truevision Targa -tiedot +Name[fr]=Informations Truevision +Name[gl]=Inf. Truevision Targa +Name[he]=מידע Truevision Targa +Name[hi]=ट्रू-विज़न टाग्रा जानकारी +Name[hr]=Truevision Targa Infomacije +Name[hu]=Truevision/Targa-jellemzők +Name[is]=Truevision Targa upplýsingar +Name[it]=Informazioni Truevision Targa +Name[ja]=TGA (Truevision Targa) 情報 +Name[kk]=Truevision Targa мәліметі +Name[km]=ព័ត៌មាន Truevision Targa +Name[lt]=Truevision Targa informacija +Name[ms]=Maklumat Targa Truevision +Name[nb]=Truevision Targa-info +Name[nds]="Truevision Targa"-Info +Name[ne]=ट्रुभिजन टार्गा सूचना +Name[nl]=Truevision Targa-info +Name[nn]=Truevision Targa-info +Name[nso]=Tshedimoso ya Targa ya pono ya Nnete +Name[pl]=Informacja o pliku Truevision Targa +Name[pt]=Informação do Targa da Truevision +Name[pt_BR]=Informação sobre Truevision Targa +Name[ro]=Informaţii Targa Truevision +Name[ru]=Информация о Truevision Targa +Name[se]=Truevision Targa-dieđut +Name[sl]=Podatki o Truevision Targa +Name[sr]=Truevision Targa информације +Name[sr@Latn]=Truevision Targa informacije +Name[sv]=Information om Truevision Targa +Name[ta]=சரியான பார்வை தார்கா தகவல் +Name[tg]=Иттилоот оиди Truevision Targa +Name[th]=ข้อมูลแฟ้ม Truevision Targa +Name[tr]=Truevision Targa Bilgisi +Name[uk]=Інформація по Truevision Targa +Name[uz]=TGA haqida maʼlumot +Name[uz@cyrillic]=TGA ҳақида маълумот +Name[ven]=Mafhungo a Targa ya mbonalelo ya vhukuma +Name[wa]=Informåcion sol imådje Truevision Targa +Name[xh]=Ulwazi lwe Truevision Targa +Name[zh_CN]=Truevision Targa 信息 +Name[zh_HK]=Truevision Targa 資訊 +Name[zh_TW]=Truevision Targa 資訊 +Name[zu]=Ulwazi lwe-Truevision Targa +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_tga +MimeType=image/x-targa +PreferredGroups=Technical +PreferredItems=Dimensions,BitDepth,ColorMode,Compression diff --git a/tdefile-plugins/tga/tdefile_tga.h b/tdefile-plugins/tga/tdefile_tga.h new file mode 100644 index 00000000..68b0ae1d --- /dev/null +++ b/tdefile-plugins/tga/tdefile_tga.h @@ -0,0 +1,38 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Shane Wright <me@shanewright.co.uk> + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_TGA_H__ +#define __KFILE_TGA_H__ + +#include <tdefilemetainfo.h> + +class TQStringList; + +class KTgaPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KTgaPlugin( TQObject *parent, const char *name, const TQStringList& args ); + + virtual bool readInfo( KFileMetaInfo& info, uint what); +}; + +#endif diff --git a/tdefile-plugins/tiff/CMakeLists.txt b/tdefile-plugins/tiff/CMakeLists.txt new file mode 100644 index 00000000..d3ec9b90 --- /dev/null +++ b/tdefile-plugins/tiff/CMakeLists.txt @@ -0,0 +1,37 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include( ConfigureChecks.cmake ) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_tiff.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_tiff (module) ######################## + +tde_add_kpart( tdefile_tiff AUTOMOC + SOURCES tdefile_tiff.cpp + LINK tdeio-shared ${TIFF_LIBRARY} + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/tiff/ConfigureChecks.cmake b/tdefile-plugins/tiff/ConfigureChecks.cmake new file mode 100644 index 00000000..c7efb9b7 --- /dev/null +++ b/tdefile-plugins/tiff/ConfigureChecks.cmake @@ -0,0 +1,21 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +# libtiff +check_include_file( tiff.h HAVE_TIFF_H ) +if( HAVE_TIFF_H ) + check_library_exists( tiff TIFFOpen "" HAVE_TIFF ) +endif( ) +if( HAVE_TIFF_H AND HAVE_TIFF ) + set( TIFF_LIBRARY tiff ) +else( ) + tde_message_fatal( "libtiff is required, but was not found on your system" ) +endif( ) diff --git a/tdefile-plugins/tiff/Makefile.am b/tdefile-plugins/tiff/Makefile.am new file mode 100644 index 00000000..9807a66c --- /dev/null +++ b/tdefile-plugins/tiff/Makefile.am @@ -0,0 +1,21 @@ +## Makefile.am for Tiff file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +noinst_HEADERS = tdefile_tiff.h + +kde_module_LTLIBRARIES = tdefile_tiff.la + +tdefile_tiff_la_SOURCES = tdefile_tiff.cpp +tdefile_tiff_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_tiff_la_LIBADD = $(LIB_KIO) $(LIBTIFF) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdefile_tiff.pot + +services_DATA = tdefile_tiff.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/tiff/configure.in.in b/tdefile-plugins/tiff/configure.in.in new file mode 100644 index 00000000..e1a9730a --- /dev/null +++ b/tdefile-plugins/tiff/configure.in.in @@ -0,0 +1,3 @@ +# Compile the tiff meta info plugin only if libtiff was detected +AC_FIND_TIFF +AM_CONDITIONAL(include_TIFF, test -n "$LIBTIFF") diff --git a/tdefile-plugins/tiff/tdefile_tiff.cpp b/tdefile-plugins/tiff/tdefile_tiff.cpp new file mode 100644 index 00000000..dfd813a5 --- /dev/null +++ b/tdefile-plugins/tiff/tdefile_tiff.cpp @@ -0,0 +1,299 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Nadeem Hasan <nhasan@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "tdefile_tiff.h" + +#include <kgenericfactory.h> +#include <kdebug.h> + +#include <tqstringlist.h> +#include <tqfile.h> +#include <tqdatetime.h> +#include <tqregexp.h> + +#include <tiff.h> +#include <tiffio.h> + +typedef KGenericFactory<KTiffPlugin> TiffFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_tiff, TiffFactory("tdefile_tiff")) + +KTiffPlugin::KTiffPlugin(TQObject *parent, const char *name, + const TQStringList &args) : KFilePlugin(parent, name, args) +{ + kdDebug(7034) << "TIFF file meta info plugin" << endl; + KFileMimeTypeInfo* info = addMimeTypeInfo( "image/tiff" ); + + KFileMimeTypeInfo::GroupInfo* group = + addGroupInfo(info, "General", i18n("General")); + + KFileMimeTypeInfo::ItemInfo* item; + item = addItemInfo(group, "Description", i18n("Description"), + TQVariant::String); + setHint(item, KFileMimeTypeInfo::Description); + item = addItemInfo(group, "Copyright", i18n("Copyright"), + TQVariant::String); + item = addItemInfo(group, "ColorMode", i18n("Color Mode"), + TQVariant::String); + item = addItemInfo(group, "Dimensions", i18n("Dimensions"), + TQVariant::Size); + setHint(item, KFileMimeTypeInfo::Size); + setUnit(item, KFileMimeTypeInfo::Pixels); + item = addItemInfo(group, "Resolution", i18n("Resolution"), + TQVariant::Size); + setUnit(item, KFileMimeTypeInfo::DotsPerInch); + item = addItemInfo(group, "BitDepth", i18n("Bit Depth"), + TQVariant::Int); + setUnit(item, KFileMimeTypeInfo::BitsPerPixel); + item = addItemInfo(group, "Compression", i18n("Compression"), + TQVariant::String); + item = addItemInfo(group, "Software", i18n("Software"), + TQVariant::String); + item = addItemInfo(group, "DateTime", i18n("Date/Time"), + TQVariant::DateTime); + item = addItemInfo(group, "Artist", i18n("Artist"), + TQVariant::String); + setHint(item, KFileMimeTypeInfo::Author); + item = addItemInfo(group, "FaxPages", i18n("Fax Pages"), + TQVariant::Int); + + group = addGroupInfo(info, "Scanner", i18n("Scanner")); + + item = addItemInfo(group, "Make", i18n("Make"), TQVariant::String); + item = addItemInfo(group, "Model", i18n("Model"), TQVariant::String); + + m_colorMode.setAutoDelete(true); + m_imageCompression.setAutoDelete(true); + + m_colorMode.insert(PHOTOMETRIC_MINISWHITE, + new TQString(I18N_NOOP("Monochrome"))); + m_colorMode.insert(PHOTOMETRIC_MINISBLACK, + new TQString(I18N_NOOP("Monochrome"))); + m_colorMode.insert(PHOTOMETRIC_RGB, + new TQString(I18N_NOOP("RGB"))); + m_colorMode.insert(PHOTOMETRIC_PALETTE, + new TQString(I18N_NOOP("Palette color"))); + m_colorMode.insert(PHOTOMETRIC_MASK, + new TQString(I18N_NOOP("Transparency mask"))); + m_colorMode.insert(PHOTOMETRIC_SEPARATED, + new TQString(I18N_NOOP("Color separations"))); + m_colorMode.insert(PHOTOMETRIC_YCBCR, + new TQString(I18N_NOOP("YCbCr"))); + m_colorMode.insert(PHOTOMETRIC_CIELAB, + new TQString(I18N_NOOP("CIE Lab"))); +#ifdef PHOTOMETRIC_ITULAB + m_colorMode.insert(PHOTOMETRIC_ITULAB, + new TQString(I18N_NOOP("ITU Lab"))); +#endif + m_colorMode.insert(PHOTOMETRIC_LOGL, + new TQString(I18N_NOOP("LOGL"))); + m_colorMode.insert(PHOTOMETRIC_LOGLUV, + new TQString(I18N_NOOP("LOGLUV"))); + + m_imageCompression.insert(COMPRESSION_NONE, + new TQString(I18N_NOOP("None"))); + m_imageCompression.insert(COMPRESSION_CCITTRLE, + new TQString(I18N_NOOP("RLE"))); + m_imageCompression.insert(COMPRESSION_CCITTFAX3, + new TQString(I18N_NOOP("G3 Fax"))); + m_imageCompression.insert(COMPRESSION_CCITTFAX4, + new TQString(I18N_NOOP("G4 Fax"))); + m_imageCompression.insert(COMPRESSION_LZW, + new TQString(I18N_NOOP("LZW"))); + m_imageCompression.insert(COMPRESSION_OJPEG, + new TQString(I18N_NOOP("JPEG"))); + m_imageCompression.insert(COMPRESSION_JPEG, + new TQString(I18N_NOOP("JPEG DCT"))); +#ifdef COMPRESSION_ADOBE_DEFLATE + m_imageCompression.insert(COMPRESSION_ADOBE_DEFLATE, + new TQString(I18N_NOOP("Adobe Deflate"))); +#endif + m_imageCompression.insert(COMPRESSION_NEXT, + new TQString(I18N_NOOP("NeXT 2-bit RLE"))); + m_imageCompression.insert(COMPRESSION_CCITTRLEW, + new TQString(I18N_NOOP("RLE Word"))); + m_imageCompression.insert(COMPRESSION_PACKBITS, + new TQString(I18N_NOOP("Packbits"))); + m_imageCompression.insert(COMPRESSION_THUNDERSCAN, + new TQString(I18N_NOOP("Thunderscan RLE"))); + m_imageCompression.insert(COMPRESSION_IT8CTPAD, + new TQString(I18N_NOOP("IT8 CT w/padding"))); + m_imageCompression.insert(COMPRESSION_IT8LW, + new TQString(I18N_NOOP("IT8 linework RLE"))); + m_imageCompression.insert(COMPRESSION_IT8MP, + new TQString(I18N_NOOP("IT8 monochrome"))); + m_imageCompression.insert(COMPRESSION_IT8BL, + new TQString(I18N_NOOP("IT8 binary lineart"))); + m_imageCompression.insert(COMPRESSION_PIXARFILM, + new TQString(I18N_NOOP("Pixar 10-bit LZW"))); + m_imageCompression.insert(COMPRESSION_PIXARLOG, + new TQString(I18N_NOOP("Pixar 11-bit ZIP"))); + m_imageCompression.insert(COMPRESSION_DEFLATE, + new TQString(I18N_NOOP("Pixar deflate"))); + m_imageCompression.insert(COMPRESSION_DCS, + new TQString(I18N_NOOP("Kodak DCS"))); + m_imageCompression.insert(COMPRESSION_JBIG, + new TQString(I18N_NOOP("ISO JBIG"))); + m_imageCompression.insert(COMPRESSION_SGILOG, + new TQString(I18N_NOOP("SGI log luminance RLE"))); + m_imageCompression.insert(COMPRESSION_SGILOG24, + new TQString(I18N_NOOP("SGI log 24-bit packed"))); +} + +TQDateTime KTiffPlugin::tiffDate(const TQString& s) const +{ + TQDateTime dt; + TQRegExp rxDate("^([0-9]{4}):([0-9]{2}):([0-9]{2})\\s" + "([0-9]{2}):([0-9]{2}):([0-9]{2})$"); + + if (rxDate.search(s) != -1) + { + int year = rxDate.cap(1).toInt(); + int month = rxDate.cap(2).toInt(); + int day = rxDate.cap(3).toInt(); + int hour = rxDate.cap(4).toInt(); + int min = rxDate.cap(5).toInt(); + int sec = rxDate.cap(6).toInt(); + + TQDate d = TQDate(year, month, day); + TQTime t = TQTime(hour, min, sec); + + if (d.isValid() && t.isValid()) + { + dt.setDate(d); + dt.setTime(t); + } + } + + return dt; +} + +bool KTiffPlugin::readInfo(KFileMetaInfo& info, uint) +{ + TIFF *tiff = TIFFOpen(TQFile::encodeName(info.path()), "r"); + if (!tiff) + return false; + + uint32 imageLength=0, imageWidth=0; + uint16 bitsPerSample=0, imageCompression=0, colorMode=0, samplesPerPixel=0, + imageAlpha=0, imageResUnit=0, dummy=0, faxPages=0; + float imageXResolution=0, imageYResolution=0; + char *description=0, *copyright=0, *software=0, *datetime=0, *artist=0, + *scannerMake=0, *scannerModel=0; + + TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &imageLength); + TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &imageWidth); + TIFFGetFieldDefaulted(tiff, TIFFTAG_BITSPERSAMPLE, &bitsPerSample); + TIFFGetFieldDefaulted(tiff, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel); + TIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &colorMode); + TIFFGetFieldDefaulted(tiff, TIFFTAG_COMPRESSION, &imageCompression); + TIFFGetField(tiff, TIFFTAG_MATTEING, &imageAlpha); + TIFFGetField(tiff, TIFFTAG_XRESOLUTION, &imageXResolution); + TIFFGetField(tiff, TIFFTAG_YRESOLUTION, &imageYResolution); + TIFFGetFieldDefaulted(tiff, TIFFTAG_RESOLUTIONUNIT, &imageResUnit); + TIFFGetField(tiff, TIFFTAG_IMAGEDESCRIPTION, &description); + TIFFGetField(tiff, TIFFTAG_SOFTWARE, &software); + TIFFGetField(tiff, TIFFTAG_COPYRIGHT, ©right); + TIFFGetField(tiff, TIFFTAG_DATETIME, &datetime); + TIFFGetField(tiff, TIFFTAG_ARTIST, &artist); + TIFFGetField(tiff, TIFFTAG_PAGENUMBER, &dummy, &faxPages); + TIFFGetField(tiff, TIFFTAG_MAKE, &scannerMake); + TIFFGetField(tiff, TIFFTAG_MODEL, &scannerModel); + + kdDebug(7034) << "Description: " << description << endl; + kdDebug(7034) << "Width: " << imageWidth << endl; + kdDebug(7034) << "Height: " << imageLength << endl; + kdDebug(7034) << "BitDepth: " << bitsPerSample << endl; + kdDebug(7034) << "ColorMode: " << colorMode << endl; + kdDebug(7034) << "Compression: " << imageCompression << endl; + kdDebug(7034) << "SamplesPerPixel: " << samplesPerPixel << endl; + kdDebug(7034) << "ImageAlpha: " << imageAlpha << endl; + kdDebug(7034) << "XResolution: " << imageXResolution << endl; + kdDebug(7034) << "YResolution: " << imageYResolution << endl; + kdDebug(7034) << "ResolutionUnit: " << imageResUnit << endl; + kdDebug(7034) << "FaxPages: " << faxPages << endl; + kdDebug(7034) << "DateTime: " << datetime << endl; + kdDebug(7034) << "Copyright: " << copyright << endl; + kdDebug(7034) << "Software: " << software << endl; + kdDebug(7034) << "Artist: " << artist << endl; + kdDebug(7034) << "Make: " << scannerMake << endl; + kdDebug(7034) << "Model: " << scannerModel << endl; + + if (imageResUnit == RESUNIT_CENTIMETER) + { + imageXResolution *= 2.54; + imageYResolution *= 2.54; + } + else if (imageResUnit == RESUNIT_NONE) + { + imageXResolution = 0; + imageYResolution = 0; + } + + int imageBpp = bitsPerSample*samplesPerPixel; + if (imageAlpha && colorMode==PHOTOMETRIC_RGB) + m_colorMode.replace(PHOTOMETRIC_RGB, new TQString(I18N_NOOP("RGBA"))); + + KFileMetaInfoGroup group = appendGroup(info, "General"); + if (description) + appendItem(group, "Description", TQString(description)); + appendItem(group, "Dimensions", TQSize(imageWidth, imageLength)); + appendItem(group, "BitDepth", imageBpp); + if (imageXResolution>0 && imageYResolution>0) + appendItem(group, "Resolution", TQSize( + static_cast<int>(imageXResolution), + static_cast<int>(imageYResolution))); + if (m_colorMode[colorMode]) + appendItem(group, "ColorMode", *m_colorMode[colorMode]); + if (m_imageCompression[imageCompression]) + appendItem(group, "Compression", *m_imageCompression[imageCompression]); + if (datetime) + { + TQDateTime dt = tiffDate(TQString(datetime)); + if (dt.isValid()) + appendItem(group, "DateTime", dt); + } + if (copyright) + appendItem(group, "Copyright", TQString(copyright)); + if (software) + appendItem(group, "Software", TQString(software)); + if (artist) + appendItem(group, "Artist", TQString(artist)); + + if (faxPages>0 && (imageCompression==COMPRESSION_CCITTFAX3 || + imageCompression==COMPRESSION_CCITTFAX4)) + { + appendItem(group, "FaxPages", faxPages); + } + + if (scannerMake || scannerModel) + { + group = appendGroup(info, "Scanner"); + if (scannerMake) + appendItem(group, "Make", TQString(scannerMake)); + if (scannerModel) + appendItem(group, "Model", TQString(scannerModel)); + } + + TIFFClose(tiff); + + return true; +} + +#include "tdefile_tiff.moc" diff --git a/tdefile-plugins/tiff/tdefile_tiff.desktop b/tdefile-plugins/tiff/tdefile_tiff.desktop new file mode 100644 index 00000000..1309e3a3 --- /dev/null +++ b/tdefile-plugins/tiff/tdefile_tiff.desktop @@ -0,0 +1,67 @@ +[Desktop Entry] +Type=Service +Name=TIFF File Meta Info +Name[af]=Tiff Lêer Meta Inligting +Name[ar]=معلومات ملف TIFF +Name[br]=Meta-titouroù ar restr TIFF +Name[ca]=Metainformació de fitxer TIFF +Name[cs]=Metainformace obrázku typu TIFF +Name[cy]=Meta-wybodaeth Ffeil TIFF +Name[da]=TIFF Fil-meta-info +Name[de]=TIFF-Metainformation +Name[el]=Μετα-πληροφορίες αρχείου TIFF +Name[eo]=TIFF-informo +Name[es]=Info meta de archivos TIFF +Name[et]=TIFF faili metainfo +Name[eu]=TIFF fitxategi meta info +Name[fa]=فرااطلاعات پروندۀ TIFF +Name[fi]=TIFF-metatiedot +Name[fr]=Méta Informations sur les fichiers TIFF +Name[gl]=Inf. metaficheiro TIFF +Name[he]=מידע TIFF +Name[hi]=TIFF फ़ाइल मेटा जानकारी +Name[hr]=TIFF meta informacije +Name[hu]=TIFF-metajellemzők +Name[is]=TIFF File Meta upplýsingar +Name[it]=Informazioni TIFF +Name[ja]=TIFF ファイルメタ情報 +Name[kk]=TIFF файлдың мета деректері +Name[km]=ព័ត៌មានមេតារបស់ឯកសារ TIFF +Name[lt]=TIFF bylos meta informacija +Name[ms]=TIFF Maklumat Meta Fail TIFF +Name[nb]=TIFF-filmetainfo +Name[nds]=TIFF-Metainfo +Name[ne]=TIFF फाइल मेटा सूचना +Name[nl]=TIFF File Meta-info +Name[nn]=TIFF-filmetainfo +Name[nso]=Tshedimoso ya Meta wa Faele ya TIFF +Name[pl]=Informacja o pliku TIFF +Name[pt]=Meta-Informação do Ficheiro TIFF +Name[pt_BR]=Informação sobre Meta Arquivo TIFF +Name[ro]=Metainformaţii TIFF +Name[ru]=Информация о метафайле TIFF +Name[se]=TIFF-filla metadieđut +Name[sk]=Meta-info o súbore TIFF +Name[sl]=Meta podatki o TIFF +Name[sr]=Мета информације TIFF фајла +Name[sr@Latn]=Meta informacije TIFF fajla +Name[sv]=Metainformation om TIFF-fil +Name[ta]=TIFF மீக்கோப்பு தகவல் +Name[tg]=Иттилоот оиди метафайли TIFF +Name[th]=ข้อมูลเมตาแฟ้ม TIFF +Name[tr]=TIFF Dosya Bilgisi +Name[uk]=Метаінформація про файл TIFF +Name[uz]=TIFF-faylining meta-maʼlumoti +Name[uz@cyrillic]=TIFF-файлининг мета-маълумоти +Name[ven]=Mafhungo a Meta faela ya TIFF +Name[wa]=Informåcion sol imådje TIFF +Name[xh]=Ulwazi lwe TIFF Ifayile Esembindini +Name[zh_CN]=TIFF 文件元信息 +Name[zh_HK]=TIFF 檔案 Meta 資訊 +Name[zh_TW]=TIFF 檔案 Meta 資訊 +Name[zu]=Ulwazi Lwefayela yemeta ye-TIFF +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_tiff +MimeType=image/tiff +PreferredGroups=General,Scanner +PreferredItems=Description,Copyright,Type,Dimensions,Resolution,BitDepth,Compression,Software,DateTime,Artist,FaxPages,Make,Model diff --git a/tdefile-plugins/tiff/tdefile_tiff.h b/tdefile-plugins/tiff/tdefile_tiff.h new file mode 100644 index 00000000..e34eef25 --- /dev/null +++ b/tdefile-plugins/tiff/tdefile_tiff.h @@ -0,0 +1,43 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Nadeem Hasan <nhasan@kde.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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_TIFF_H_ +#define __KFILE_TIFF_H_ + +#include <tdefilemetainfo.h> + +#include <tqintdict.h> + +class KTiffPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KTiffPlugin(TQObject *parent, const char *name, const TQStringList& args); + virtual bool readInfo(KFileMetaInfo& info, uint what); + +private: + TQDateTime tiffDate(const TQString&) const; + + TQIntDict<TQString> m_colorMode; + TQIntDict<TQString> m_imageCompression; +}; + +#endif diff --git a/tdefile-plugins/xbm/CMakeLists.txt b/tdefile-plugins/xbm/CMakeLists.txt new file mode 100644 index 00000000..4b96ade8 --- /dev/null +++ b/tdefile-plugins/xbm/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_xbm.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_xbm (module) ######################## + +tde_add_kpart( tdefile_xbm AUTOMOC + SOURCES tdefile_xbm.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/xbm/Makefile.am b/tdefile-plugins/xbm/Makefile.am new file mode 100644 index 00000000..90abdc8e --- /dev/null +++ b/tdefile-plugins/xbm/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for xbm file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_xbm.h + +kde_module_LTLIBRARIES = tdefile_xbm.la + +tdefile_xbm_la_SOURCES = tdefile_xbm.cpp +tdefile_xbm_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_xbm_la_LIBADD = $(LIB_KSYCOCA) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) tdefile_xbm.cpp -o $(podir)/tdefile_xbm.pot + +services_DATA = tdefile_xbm.desktop +servicesdir = $(kde_servicesdir) diff --git a/tdefile-plugins/xbm/tdefile_xbm.cpp b/tdefile-plugins/xbm/tdefile_xbm.cpp new file mode 100644 index 00000000..d4871d6f --- /dev/null +++ b/tdefile-plugins/xbm/tdefile_xbm.cpp @@ -0,0 +1,128 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Shane Wright <me@shanewright.co.uk> + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include <config.h> +#include "tdefile_xbm.h" + +#include <kprocess.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kstringvalidator.h> +#include <kdebug.h> + +#include <tqdict.h> +#include <tqvalidator.h> +#include <tqcstring.h> +#include <tqfile.h> +#include <tqdatetime.h> + +#if !defined(__osf__) +#include <inttypes.h> +#else +typedef unsigned short uint32_t; +#endif + +typedef KGenericFactory<KXbmPlugin> XbmFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_xbm, XbmFactory( "tdefile_xbm" )) + +KXbmPlugin::KXbmPlugin(TQObject *parent, const char *name, + const TQStringList &args) + + : KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( "image/x-xbm" ); + + KFileMimeTypeInfo::GroupInfo* group = 0L; + + group = addGroupInfo(info, "Technical", i18n("Technical Details")); + + KFileMimeTypeInfo::ItemInfo* item; + + item = addItemInfo(group, "Dimensions", i18n("Dimensions"), TQVariant::Size); + setHint( item, KFileMimeTypeInfo::Size ); + setUnit(item, KFileMimeTypeInfo::Pixels); +} + + +unsigned long KXbmPlugin::xbm_processLine(char * linebuf) +{ + const char * fsig = "#define "; + + // check it starts with #define + if (memcmp(linebuf, fsig, 8)) + return 0; + + // scan for the 2nd space and set up a pointer + uint32_t slen = strlen(linebuf); + bool done = false; + uint32_t spos = 0; + unsigned char spacecount = 0; + do { + + if (linebuf[spos] == 0x00) + return 0; + + if (linebuf[spos] == ' ') + ++spacecount; + + if (spacecount == 2) + done = true; + else + ++spos; + + } while (!done); + + return atoi(linebuf + spos); +} + + +bool KXbmPlugin::readInfo( KFileMetaInfo& info, uint what) +{ + + TQFile file(info.path()); + + if (!file.open(IO_ReadOnly)) + { + kdDebug(7034) << "Couldn't open " << TQFile::encodeName(info.path()).data() << endl; + return false; + } + + // we need a buffer for lines + char linebuf[1000]; + + // read the first line + file.readLine(linebuf, sizeof( linebuf )); + uint32_t width = xbm_processLine(linebuf); + + // read the 2nd line + file.readLine(linebuf, sizeof( linebuf )); + uint32_t height = xbm_processLine(linebuf); + + if ((width > 0) && (height > 0)) { + // we have valid looking data + KFileMetaInfoGroup group = appendGroup(info, "Technical"); + appendItem(group, "Dimensions", TQSize(width, height)); + return true; + } + + return false; +} + +#include "tdefile_xbm.moc" diff --git a/tdefile-plugins/xbm/tdefile_xbm.desktop b/tdefile-plugins/xbm/tdefile_xbm.desktop new file mode 100644 index 00000000..76102cea --- /dev/null +++ b/tdefile-plugins/xbm/tdefile_xbm.desktop @@ -0,0 +1,65 @@ +[Desktop Entry] +Type=Service +Name=XBM Info +Name[af]=Xbm Inligting +Name[ar]=معلومات XBM +Name[br]=Titouroù XBM +Name[ca]=Informació d'XBM +Name[cs]=XBM info +Name[cy]=Gwybodaeth XBM +Name[da]=XBM-info +Name[de]=XBM-Info +Name[el]=Πληροφορίες XBM +Name[eo]=XBM-informo +Name[es]=Info XBM +Name[et]=XBM info +Name[fa]=اطلاعات XBM +Name[fi]=XBM-tiedot +Name[fr]=Informations sur XBM +Name[gl]=Inf. XBM +Name[he]=מידע XBM +Name[hi]=XBM जानकारी +Name[hr]=XBM Infoformacije +Name[hu]=XBM-jellemzők +Name[is]=XBM upplýsingar +Name[it]=Informazioni XBM +Name[ja]=XBM 情報 +Name[kk]=XBM мәліметі +Name[km]=ព័ត៌មាន XBM +Name[lt]=XBM informacija +Name[ms]=Maklumat XBM +Name[nds]=XBM-Info +Name[ne]=XBM सूचना +Name[nl]=XBM-info +Name[nn]=XBM-info +Name[nso]=Tshedimoso ya XBM +Name[pa]=XBM ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku XBM +Name[pt]=Informação do XBM +Name[pt_BR]=Informação sobre XBM +Name[ro]=Informaţii XBM +Name[ru]=Информация о XBM +Name[se]=XBM-dieđut +Name[sl]=Podatki o XBM +Name[sr]=XBM информације +Name[sr@Latn]=XBM informacije +Name[sv]=XBM-information +Name[ta]=XBM தகவல் +Name[tg]=Иттилоот оиди XBM +Name[th]=ข้อมูลแฟ้ม XBM +Name[tr]=XBM Bilgisi +Name[uk]=Інформація по XBM +Name[uz]=XBM haqida maʼlumot +Name[uz@cyrillic]=XBM ҳақида маълумот +Name[ven]=Mafhungo a XBM +Name[wa]=Informåcion sol imådje XBM +Name[xh]=Ulwazi lwe XBM +Name[zh_CN]=XBM 信息 +Name[zh_HK]=XBM 資訊 +Name[zh_TW]=XBM 資訊 +Name[zu]=Ulwazi lwe-XBM +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_xbm +MimeType=image/x-xbm +PreferredGroups=Technical +PreferredItems=Resolution diff --git a/tdefile-plugins/xbm/tdefile_xbm.h b/tdefile-plugins/xbm/tdefile_xbm.h new file mode 100644 index 00000000..5e7f6429 --- /dev/null +++ b/tdefile-plugins/xbm/tdefile_xbm.h @@ -0,0 +1,43 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Shane Wright <me@shanewright.co.uk> + * + * 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 version 2. + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef __KFILE_XBM_H__ +#define __KFILE_XBM_H__ + +#include <tdefilemetainfo.h> + +class TQStringList; + +class KXbmPlugin: public KFilePlugin +{ + Q_OBJECT + + +public: + KXbmPlugin( TQObject *parent, const char *name, const TQStringList& args ); + + virtual bool readInfo( KFileMetaInfo& info, uint what); + +private: + + unsigned long xbm_processLine(char * linebuf); + +}; + +#endif diff --git a/tdefile-plugins/xpm/CMakeLists.txt b/tdefile-plugins/xpm/CMakeLists.txt new file mode 100644 index 00000000..5b357416 --- /dev/null +++ b/tdefile-plugins/xpm/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Calvin Morrison +# mutantturkey@gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +#### other data ################################# + +install( FILES tdefile_xpm.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + + +#### tdefile_xpm (module) ######################### + +tde_add_kpart( tdefile_xpm AUTOMOC + SOURCES tdefile_xpm.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdefile-plugins/xpm/Makefile.am b/tdefile-plugins/xpm/Makefile.am new file mode 100644 index 00000000..3a32555e --- /dev/null +++ b/tdefile-plugins/xpm/Makefile.am @@ -0,0 +1,21 @@ +## Makefile.am for xpm file meta info plugin + +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = tdefile_xpm.h + +kde_module_LTLIBRARIES = tdefile_xpm.la + +tdefile_xpm_la_SOURCES = tdefile_xpm.cpp +tdefile_xpm_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdefile_xpm_la_LIBADD = $(LIB_KIO) +tdefile_xpm_la_METASOURCES = tdefile_xpm.moc + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +kde_services_DATA = tdefile_xpm.desktop + +messages: + $(XGETTEXT) *.cpp -o $(podir)/tdefile_xpm.pot diff --git a/tdefile-plugins/xpm/tdefile_xpm.cpp b/tdefile-plugins/xpm/tdefile_xpm.cpp new file mode 100644 index 00000000..46b07e51 --- /dev/null +++ b/tdefile-plugins/xpm/tdefile_xpm.cpp @@ -0,0 +1,71 @@ +/*************************************************************************** + * Copyright (C) 2004 by Martin Koller * + * m.koller@surfeu.at * + * * + * 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 <config.h> +#include <tqimage.h> +#include "tdefile_xpm.h" + +#include <kgenericfactory.h> + +//-------------------------------------------------------------------------------- + +typedef KGenericFactory<xpmPlugin> xpmFactory; + +K_EXPORT_COMPONENT_FACTORY(tdefile_xpm, xpmFactory( "tdefile_xpm" )) + +//-------------------------------------------------------------------------------- + +xpmPlugin::xpmPlugin(TQObject *parent, const char *name, const TQStringList &args) + : KFilePlugin(parent, name, args) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( "image/x-xpm" ); + + // our new group + KFileMimeTypeInfo::GroupInfo* group = 0; + group = addGroupInfo(info, "xpmInfo", i18n("X PixMap File Information")); + + KFileMimeTypeInfo::ItemInfo* item; + + // our new items in the group + item = addItemInfo(group, "Dimension", i18n("Dimension"), TQVariant::Size); + setHint(item, KFileMimeTypeInfo::Size); + setUnit(item, KFileMimeTypeInfo::Pixels); + + item = addItemInfo(group, "BitDepth", i18n("Bit Depth"), TQVariant::Int); + setUnit(item, KFileMimeTypeInfo::BitsPerPixel); +} + +//-------------------------------------------------------------------------------- + +bool xpmPlugin::readInfo(KFileMetaInfo& info, uint /*what*/) +{ + TQImage pix; + + if ( ! pix.load(info.path(), "XPM") ) return false; + + KFileMetaInfoGroup group = appendGroup(info, "xpmInfo"); + + appendItem(group, "Dimension", TQSize(pix.size())); + appendItem(group, "BitDepth", pix.depth()); + + return true; +} + +#include "tdefile_xpm.moc" diff --git a/tdefile-plugins/xpm/tdefile_xpm.desktop b/tdefile-plugins/xpm/tdefile_xpm.desktop new file mode 100644 index 00000000..43c18514 --- /dev/null +++ b/tdefile-plugins/xpm/tdefile_xpm.desktop @@ -0,0 +1,53 @@ +[Desktop Entry] +Type=Service +Name=XPM Info +Name[br]=Titouroù XPM +Name[ca]=Informació de XPM +Name[cs]=XPM info +Name[de]=XPM-Info +Name[el]=Πληροφορίες XPM +Name[eo]=XPM-informo +Name[es]=Información XPM +Name[et]=XPM info +Name[fa]=اطلاعات XPM +Name[fi]=XPM-tiedot +Name[fr]=Informations XPM +Name[gl]=Información XPM +Name[he]=מידע XPM +Name[hu]=XPM-jellemzők +Name[is]=XPM upplýsingar +Name[it]=Informazioni XPM +Name[ja]=XPM 情報 +Name[kk]=XPM мәліметі +Name[km]=ព័ត៌មាន XPM +Name[lt]=XPM informacija +Name[ms]=Maklumat XPM +Name[nb]=XPM-info +Name[nds]=XPM-Info +Name[ne]=XPM सूचना +Name[nl]=XPM-info +Name[nn]=XPM-info +Name[pa]=XPM ਜਾਣਕਾਰੀ +Name[pl]=Informacja o pliku XPM +Name[pt]=Informação do XPM +Name[pt_BR]=Informações Sobre XPM +Name[ro]=Informaţii XPM +Name[ru]=Информация о XPM +Name[sl]=Podatki o XPM +Name[sr]=XPM информације +Name[sr@Latn]=XPM informacije +Name[sv]=XPM-information +Name[ta]=XPM தகவல் +Name[th]=ข้อมูลแฟ้ม XPM +Name[tr]=XPM Bilgisi +Name[uk]=Інформація про XPM +Name[uz]=XPM haqida maʼlumot +Name[uz@cyrillic]=XPM ҳақида маълумот +Name[zh_CN]=XPM 信息 +Name[zh_HK]=XPM 資訊 +Name[zh_TW]=XPM 資訊 +ServiceTypes=KFilePlugin +X-TDE-Library=tdefile_xpm +MimeType=image/x-xpm +PreferredGroups=xpmInfo +PreferredItems=Dimension diff --git a/tdefile-plugins/xpm/tdefile_xpm.h b/tdefile-plugins/xpm/tdefile_xpm.h new file mode 100644 index 00000000..275d3dd7 --- /dev/null +++ b/tdefile-plugins/xpm/tdefile_xpm.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2004 by Martin Koller * + * m.koller@surfeu.at * + * * + * This plugin provides information about the content of a * + * XPM image file. * + * * + * 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 KFILE_XPM_H +#define KFILE_XPM_H + +/** + * Note: For further information look into <$TDEDIR/include/tdefilemetainfo.h> + */ +#include <tdefilemetainfo.h> + +class TQStringList; + +class xpmPlugin: public KFilePlugin +{ + Q_OBJECT + + + public: + xpmPlugin(TQObject *parent, const char *name, const TQStringList& args); + + virtual bool readInfo(KFileMetaInfo& info, uint what); +}; + +#endif + |