You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
3.4 KiB
123 lines
3.4 KiB
15 years ago
|
/*
|
||
|
* 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>
|
||
12 years ago
|
#include "tdefile_gif.h"
|
||
15 years ago
|
|
||
|
#include <kurl.h>
|
||
|
#include <kprocess.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kgenericfactory.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
15 years ago
|
#include <tqcstring.h>
|
||
|
#include <tqfile.h>
|
||
|
#include <tqdatetime.h>
|
||
|
#include <tqdict.h>
|
||
|
#include <tqvalidator.h>
|
||
|
#include <tqimage.h>
|
||
15 years ago
|
|
||
|
typedef KGenericFactory<KGifPlugin> GifFactory;
|
||
|
|
||
12 years ago
|
K_EXPORT_COMPONENT_FACTORY(tdefile_gif, GifFactory("tdefile_gif"))
|
||
15 years ago
|
|
||
13 years ago
|
KGifPlugin::KGifPlugin(TQObject *parent, const char *name,
|
||
15 years ago
|
const TQStringList &args)
|
||
13 years ago
|
: KFilePlugin(parent, name, args)
|
||
15 years ago
|
{
|
||
|
kdDebug(7034) << "gif KFileMetaInfo plugin\n";
|
||
|
|
||
|
KFileMimeTypeInfo* info = addMimeTypeInfo( "image/gif" );
|
||
|
|
||
|
KFileMimeTypeInfo::GroupInfo* group = 0L;
|
||
|
|
||
|
group = addGroupInfo(info, "General", i18n("General"));
|
||
|
|
||
|
KFileMimeTypeInfo::ItemInfo* item;
|
||
|
|
||
15 years ago
|
item = addItemInfo(group, "Version", i18n("Version"), TQVariant::String);
|
||
15 years ago
|
|
||
15 years ago
|
item = addItemInfo( group, "Dimensions", i18n("Dimensions"), TQVariant::Size );
|
||
15 years ago
|
setHint( item, KFileMimeTypeInfo::Size );
|
||
|
setUnit( item, KFileMimeTypeInfo::Pixels );
|
||
|
|
||
15 years ago
|
item = addItemInfo(group, "BitDepth", i18n("Bit Depth"), TQVariant::Int);
|
||
15 years ago
|
setUnit(item, KFileMimeTypeInfo::BitsPerPixel);
|
||
|
|
||
|
}
|
||
|
|
||
|
bool KGifPlugin::readInfo( KFileMetaInfo& info, uint what )
|
||
|
{
|
||
|
Q_UNUSED( what );
|
||
|
|
||
|
kdDebug(7034) << "gif KFileMetaInfo readInfo\n";
|
||
|
|
||
15 years ago
|
TQFile file(info.path());
|
||
15 years ago
|
|
||
|
if (!file.open(IO_ReadOnly)) {
|
||
14 years ago
|
kdDebug(7034) << "Couldn't open " << TQFile::encodeName(info.path()).data() << endl;
|
||
15 years ago
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDataStream fstream(&file);
|
||
15 years ago
|
|
||
|
bool isGIF87a = false;
|
||
|
char magic[7];
|
||
14 years ago
|
TQ_UINT16 width = 0;
|
||
|
TQ_UINT16 height = 0;
|
||
|
TQ_UINT8 miscInfo = 0;
|
||
15 years ago
|
|
||
|
fstream.readRawBytes( magic, 6 );
|
||
|
magic[6] = 0x00; // null terminate
|
||
|
|
||
|
// I have special requirements...
|
||
15 years ago
|
fstream.setByteOrder( TQDataStream::LittleEndian );
|
||
15 years ago
|
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") );
|
||
|
}
|
||
|
|
||
15 years ago
|
appendItem( group, "Dimensions", TQSize(width, height) );
|
||
15 years ago
|
|
||
|
if ( isGIF87a ) {
|
||
|
appendItem( group, "BitDepth", ( (miscInfo & 0x07) + 1) );
|
||
|
}
|
||
|
|
||
|
file.close();
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdefile_gif.moc"
|