summaryrefslogtreecommitdiffstats
path: root/kfile-plugins/pcx/kfile_pcx.cpp
blob: 5dceec9d87b1f7a14c3bfc34ba3a76125314e6ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* This file is part of the KDE project
 * Copyright (C) 2002 Nadeem Hasan <[email protected]>
 *
 * 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 "kfile_pcx.h"

#include <kgenericfactory.h>
#include <kdebug.h>

#include <tqdatastream.h>
#include <tqfile.h>

typedef KGenericFactory<KPcxPlugin> PcxFactory;

K_EXPORT_COMPONENT_FACTORY(kfile_pcx, PcxFactory("kfile_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 "kfile_pcx.moc"

/* vim: et sw=2 ts=2
*/