[patch] gif kfile plugin support?
Brad Hards
bradh at frogmouth.net
Sat Feb 5 06:51:56 GMT 2005
There is a long-standing item in the feature plan (it was added for 3.2) for a
GIF kfile-metadata plugin. A start has been in
kdegraphics/kfile-plugins/gif/ for a while, but it isn't compiled. I've
updated it, and it now parses. I removed the comments stuff, and done some
simple tests.
This does introduce some new strings - I could avoid that if I didn't return
the GIF version type through.
Thoughts? Comments?
Brad
Index: kfile_gif.h
===================================================================
RCS file: /home/kde/kdegraphics/kfile-plugins/gif/kfile_gif.h,v
retrieving revision 1.3
diff -u -4 -p -r1.3 kfile_gif.h
--- kfile_gif.h 23 Oct 2002 19:36:23 -0000 1.3
+++ kfile_gif.h 5 Feb 2005 06:39:41 -0000
@@ -31,12 +31,7 @@ class KGifPlugin: public KFilePlugin
public:
KGifPlugin( QObject *parent, const char *name, const QStringList& args );
virtual bool readInfo ( KFileMetaInfo& info, uint what );
- virtual bool writeInfo( const KFileMetaInfo& info ) const;
- virtual QValidator* createValidator( const QString& mimetype,
- const QString& group,
- const QString& key,
- QObject* parent, const char* name)
const;
};
#endif
Index: kfile_gif.cpp
===================================================================
RCS file: /home/kde/kdegraphics/kfile-plugins/gif/kfile_gif.cpp,v
retrieving revision 1.5
diff -u -4 -p -r1.5 kfile_gif.cpp
--- kfile_gif.cpp 7 Feb 2004 23:34:57 -0000 1.5
+++ kfile_gif.cpp 5 Feb 2005 06:39:41 -0000
@@ -55,75 +55,68 @@ KGifPlugin::KGifPlugin(QObject *parent,
group = addGroupInfo(info, "General", i18n("General"));
KFileMimeTypeInfo::ItemInfo* item;
- item = addItemInfo(group, "Comment", i18n("Comment"), QVariant::String);
- setAttributes(item, KFileMimeTypeInfo::Modifiable);
- setHint(item, KFileMimeTypeInfo::Description);
+ item = addItemInfo(group, "Version", i18n("Version"), QVariant::String);
- item = addItemInfo(group, "Dimensions", i18n("Dimensions"),
QVariant::Size);
+ item = addItemInfo( group, "Dimensions", i18n("Dimensions"),
QVariant::Size );
setHint( item, KFileMimeTypeInfo::Size );
- setUnit(item, KFileMimeTypeInfo::Pixels);
-}
+ setUnit( item, KFileMimeTypeInfo::Pixels );
+
+ item = addItemInfo(group, "BitDepth", i18n("Bit Depth"), QVariant::Int);
+ setUnit(item, KFileMimeTypeInfo::BitsPerPixel);
-QValidator* KGifPlugin::createValidator( const QString& mimetype,
- const QString& group,
- const QString& key,
- QObject* parent, const char* name)
const
-{
- return new QRegExpValidator(QRegExp(".*"), parent, name);
}
-bool KGifPlugin::writeInfo( const KFileMetaInfo& info ) const
+bool KGifPlugin::readInfo( KFileMetaInfo& info, uint what )
{
- QString comment = info["General"]["Comment"].value().toString();
- QString path = info.path();
+ Q_UNUSED( what );
- kdDebug(7034) << "gif KFileMetaInfo writeInfo: " << info.path() << " \""
<< comment << "\"\n";
+ kdDebug(7034) << "gif KFileMetaInfo readInfo\n";
- /*
- Do a strictly safe insertion of the comment:
+ QFile file(info.path());
- Scan original to verify it's a proper gif
- 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 gif
- Rename original to another unique name
- Rename temporary to original
- Unlink original
- */
- /*
- The gif standard specifies 7 bit ascii for the COM block.
- Rather than inserting national characters here,
- I'm assuming it's better to write unicode utf-8,
- which is fully backwards compatible with readers expecting ascii.
- */
- //if( safe_copy_and_modify( path.latin1(), comment.utf8() ) ) {
- // return false;
- // }
- return true;
-}
+ if (!file.open(IO_ReadOnly)) {
+ kdDebug(7034) << "Couldn't open " << QFile::encodeName(info.path()) <<
endl;
+ return false;
+ }
-bool KGifPlugin::readInfo( KFileMetaInfo& info, uint what )
-{
- QString tag;
+ QDataStream fstream(&file);
- kdDebug(7034) << "gif KFileMetaInfo readInfo\n";
+ bool isGIF87a = false;
+ char magic[7];
+ Q_UINT16 width = 0;
+ Q_UINT16 height = 0;
+ Q_UINT8 miscInfo = 0;
+
+ fstream.readRawBytes( magic, 6 );
+ magic[6] = 0x00; // null terminate
+
+ // I have special requirements...
+ fstream.setByteOrder( QDataStream::LittleEndian );
+ fstream >> width;
+ fstream >> height;
+ fstream >> miscInfo;
KFileMetaInfoGroup group = appendGroup(info, "General");
- // I insert a comment always, so that the user can edit it
- // items can be made addable, so you don't need to insert them if there
- // is none
- tag = "placeholder comment";
- kdDebug(7034) << "gif plugin inserting Comment: " << tag << "\n";
- appendItem(group, "Comment", QString(tag));
-
- tag = "unknown x unknown";
- if (tag.length()) {
- KFileMetaInfoItem item = appendItem(group, "Dimensions",
QSize(123,456));
+
+ 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", QSize(width, height) );
+
+ if ( isGIF87a ) {
+ appendItem( group, "BitDepth", ( (miscInfo & 0x07) + 1) );
}
- //DiscardData();
- return true;
+ file.close();
+
+ return true;
}
#include "kfile_gif.moc"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20050205/33370204/attachment.sig>
More information about the kde-core-devel
mailing list