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.
119 lines
3.3 KiB
119 lines
3.3 KiB
15 years ago
|
/* 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.
|
||
|
*
|
||
|
*/
|
||
|
|
||
12 years ago
|
#include "tdefile_pcx.h"
|
||
15 years ago
|
|
||
|
#include <kgenericfactory.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
15 years ago
|
#include <tqdatastream.h>
|
||
|
#include <tqfile.h>
|
||
15 years ago
|
|
||
|
typedef KGenericFactory<KPcxPlugin> PcxFactory;
|
||
|
|
||
12 years ago
|
K_EXPORT_COMPONENT_FACTORY(tdefile_pcx, PcxFactory("tdefile_pcx"))
|
||
15 years ago
|
|
||
15 years ago
|
TQDataStream &operator>>( TQDataStream &s, PALETTE &pal )
|
||
15 years ago
|
{
|
||
|
for ( int i=0; i<16; ++i )
|
||
|
s >> pal.p[ i ].r >> pal.p[ i ].g >> pal.p[ i ].b;
|
||
|
|
||
|
return s;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDataStream &operator>>( TQDataStream &s, PCXHEADER &ph )
|
||
15 years ago
|
{
|
||
|
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;
|
||
|
}
|
||
|
|
||
13 years ago
|
KPcxPlugin::KPcxPlugin( TQObject *parent, const char *name,
|
||
|
const TQStringList &args ) : KFilePlugin( parent, name, args )
|
||
15 years ago
|
{
|
||
|
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" ),
|
||
15 years ago
|
TQVariant::Size );
|
||
15 years ago
|
setHint( item, KFileMimeTypeInfo::Size );
|
||
|
setUnit( item, KFileMimeTypeInfo::Pixels );
|
||
|
item = addItemInfo( group, "BitDepth", i18n( "Bit Depth" ),
|
||
15 years ago
|
TQVariant::Int );
|
||
15 years ago
|
setUnit( item, KFileMimeTypeInfo::BitsPerPixel );
|
||
|
item = addItemInfo( group, "Resolution", i18n( "Resolution" ),
|
||
15 years ago
|
TQVariant::Size );
|
||
15 years ago
|
setUnit( item, KFileMimeTypeInfo::DotsPerInch );
|
||
|
item = addItemInfo( group, "Compression", i18n( "Compression" ),
|
||
15 years ago
|
TQVariant::String );
|
||
15 years ago
|
}
|
||
|
|
||
|
bool KPcxPlugin::readInfo( KFileMetaInfo& info, uint )
|
||
|
{
|
||
|
if ( info.path().isEmpty() )
|
||
|
return false;
|
||
|
|
||
|
struct PCXHEADER header;
|
||
|
|
||
15 years ago
|
TQFile f( info.path() );
|
||
15 years ago
|
if ( !f.open( IO_ReadOnly ) )
|
||
|
return false;
|
||
|
|
||
15 years ago
|
TQDataStream s( &f );
|
||
|
s.setByteOrder( TQDataStream::LittleEndian );
|
||
15 years ago
|
|
||
|
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" );
|
||
|
|
||
15 years ago
|
appendItem( group, "Dimensions", TQSize( w, h ) );
|
||
15 years ago
|
appendItem( group, "BitDepth", bpp );
|
||
15 years ago
|
appendItem( group, "Resolution", TQSize( header.HDpi, header.YDpi ) );
|
||
15 years ago
|
if ( header.Encoding == 1 )
|
||
|
appendItem( group, "Compression", i18n( "Yes (RLE)" ) );
|
||
|
else
|
||
|
appendItem( group, "Compression", i18n( "None" ) );
|
||
|
|
||
|
f.close();
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdefile_pcx.moc"
|