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.
209 lines
5.4 KiB
209 lines
5.4 KiB
15 years ago
|
/* 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>
|
||
12 years ago
|
#include "tdefile_rgb.h"
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqfile.h>
|
||
|
#include <tqvalidator.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
#include <kgenericfactory.h>
|
||
|
|
||
|
|
||
|
typedef KGenericFactory<KRgbPlugin> RgbFactory;
|
||
|
|
||
12 years ago
|
K_EXPORT_COMPONENT_FACTORY(tdefile_rgb, RgbFactory("tdefile_rgb"))
|
||
15 years ago
|
|
||
|
|
||
14 years ago
|
KRgbPlugin::KRgbPlugin(TQObject *parent, const char *name, const TQStringList &args) :
|
||
|
KFilePlugin(parent, name, args)
|
||
15 years ago
|
{
|
||
|
KFileMimeTypeInfo* info = addMimeTypeInfo("image/x-rgb");
|
||
|
|
||
|
KFileMimeTypeInfo::GroupInfo* group = 0;
|
||
|
KFileMimeTypeInfo::ItemInfo* item;
|
||
|
|
||
|
|
||
|
group = addGroupInfo(info, "Comment", i18n("Comment"));
|
||
|
|
||
15 years ago
|
item = addItemInfo(group, "ImageName", i18n("Name"), TQVariant::String);
|
||
15 years ago
|
setAttributes(item, KFileMimeTypeInfo::Modifiable);
|
||
|
setHint(item, KFileMimeTypeInfo::Description);
|
||
|
|
||
|
|
||
|
group = addGroupInfo(info, "Technical", i18n("Technical Details"));
|
||
|
|
||
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);
|
||
|
|
||
15 years ago
|
item = addItemInfo(group, "ColorMode", i18n("Color Mode"), TQVariant::String);
|
||
|
item = addItemInfo(group, "Compression", i18n("Compression"), TQVariant::String);
|
||
15 years ago
|
item = addItemInfo(group, "SharedRows",
|
||
|
i18n("percentage of avoided vertical redundancy (the higher the better)",
|
||
15 years ago
|
"Shared Rows"), TQVariant::String);
|
||
15 years ago
|
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KRgbPlugin::readInfo(KFileMetaInfo& info, uint /*what*/)
|
||
|
{
|
||
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 dstream(&file);
|
||
15 years ago
|
|
||
14 years ago
|
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;
|
||
15 years ago
|
char imagename[80];
|
||
14 years ago
|
TQ_UINT32 colormap;
|
||
15 years ago
|
|
||
|
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;
|
||
14 years ago
|
TQ_UINT8 u8;
|
||
15 years ago
|
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;
|
||
15 years ago
|
appendItem(group, "Dimensions", TQSize(xsize, ysize));
|
||
15 years ago
|
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")
|
||
13 years ago
|
+ TQString(", %1%").arg(compressed * 100.0 / verbatim, 0, 'f', 1));
|
||
15 years ago
|
|
||
|
long k;
|
||
14 years ago
|
TQ_UINT32 offs;
|
||
|
TQMap<TQ_UINT32, uint> map;
|
||
|
TQMap<TQ_UINT32, uint>::Iterator it;
|
||
|
TQMap<TQ_UINT32, uint>::Iterator end = map.end();
|
||
15 years ago
|
for (k = 0; k < (ysize * zsize); k++) {
|
||
|
dstream >> offs;
|
||
14 years ago
|
if ((it = map.find(offs)) != end)
|
||
|
map.replace(offs, it.data() + 1);
|
||
15 years ago
|
else
|
||
|
map[offs] = 0;
|
||
|
}
|
||
|
for (k = 0, it = map.begin(); it != end; ++it)
|
||
|
k += it.data();
|
||
|
|
||
|
if (k)
|
||
13 years ago
|
appendItem(group, "SharedRows", TQString("%1%").arg(k * 100.0
|
||
15 years ago
|
/ (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
|
||
|
{
|
||
15 years ago
|
TQFile file(info.path());
|
||
15 years ago
|
|
||
|
if (!file.open(IO_WriteOnly|IO_Raw)) {
|
||
14 years ago
|
kdDebug(7034) << "couldn't open " << TQFile::encodeName(info.path()).data() << endl;
|
||
15 years ago
|
return false;
|
||
|
}
|
||
|
|
||
|
if (!file.at(24)) {
|
||
|
kdDebug(7034) << "couldn't set offset" << endl;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDataStream dstream(&file);
|
||
|
TQString s = info["Comment"]["ImageName"].value().toString();
|
||
15 years ago
|
s.truncate(79);
|
||
|
|
||
|
unsigned i;
|
||
|
for (i = 0; i < s.length(); i++)
|
||
14 years ago
|
dstream << TQ_UINT8(s.latin1()[i]);
|
||
15 years ago
|
for (; i < 80; i++)
|
||
14 years ago
|
dstream << TQ_UINT8(0);
|
||
15 years ago
|
|
||
|
file.close();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
// restrict to 79 ASCII characters
|
||
15 years ago
|
TQValidator* KRgbPlugin::createValidator(const TQString&, const TQString &,
|
||
14 years ago
|
const TQString &, TQObject* parent, const char* name) const
|
||
15 years ago
|
{
|
||
14 years ago
|
return new TQRegExpValidator(TQRegExp("[\x0020-\x007E]{79}"), parent, name);
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
12 years ago
|
#include "tdefile_rgb.moc"
|