• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kimgio
 

kimgio

  • kimgio
xview.cpp
1 // Oliver Eiden <o.eiden@pop.ruhr.de>
2 // 23.3.99
3 // changed the mapping from 3-3-2 decoded pixels to 8-8-8 decoded true-color pixels
4 // now it uses the same mapping as xv, this leads to better visual results
5 // Patch merged in HEAD by Chris Spiegel <matrix@xirtam.org>
6 // This library is distributed under the conditions of the GNU LGPL.
7 
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <tqimage.h>
12 
13 #include <tdelibs_export.h>
14 
15 #include "xview.h"
16 
17 #define BUFSIZE 1024
18 
19 static const int b_255_3[]= {0,85,170,255}, // index*255/3
20  rg_255_7[]={0,36,72,109,145,182,218,255}; // index *255/7
21 
22 KDE_EXPORT void kimgio_xv_read( TQImageIO *_imageio )
23 {
24  int x=-1;
25  int y=-1;
26  int maxval=-1;
27  TQIODevice *iodev = _imageio->ioDevice();
28 
29  char str[ BUFSIZE ];
30 
31  // magic number must be "P7 332"
32  iodev->readLine( str, BUFSIZE );
33  if (strncmp(str,"P7 332",6)) return;
34 
35  // next line #XVVERSION
36  iodev->readLine( str, BUFSIZE );
37  if (strncmp(str, "#XVVERSION", 10))
38  return;
39 
40  // now it gets interesting, #BUILTIN means we are out.
41  // if IMGINFO comes, we are happy!
42  iodev->readLine( str, BUFSIZE );
43  if (strncmp(str, "#IMGINFO:", 9))
44  return;
45 
46  // after this an #END_OF_COMMENTS signals everything to be ok!
47  iodev->readLine( str, BUFSIZE );
48  if (strncmp(str, "#END_OF", 7))
49  return;
50 
51  // now a last line with width, height, maxval which is
52  // supposed to be 255
53  iodev->readLine( str, BUFSIZE );
54  sscanf(str, "%d %d %d", &x, &y, &maxval);
55 
56  if (maxval != 255) return;
57  int blocksize = x*y;
58  if(x < 0 || y < 0 || blocksize < x || blocksize < y)
59  return;
60 
61  // now follows a binary block of x*y bytes.
62  char *block = (char*) malloc(blocksize);
63  if(!block)
64  return;
65 
66  if (iodev->readBlock(block, blocksize) != blocksize )
67  {
68  return;
69  }
70 
71  // Create the image
72  TQImage image( x, y, 8, maxval + 1, TQImage::BigEndian );
73  if( image.isNull()) {
74  free(block);
75  return;
76  }
77 
78  // how do the color handling? they are absolute 24bpp
79  // or at least can be calculated as such.
80  int r,g,b;
81 
82  for ( int j = 0; j < 256; j++ )
83  {
84  r = rg_255_7[((j >> 5) & 0x07)];
85  g = rg_255_7[((j >> 2) & 0x07)];
86  b = b_255_3[((j >> 0) & 0x03)];
87  image.setColor( j, tqRgb( r, g, b ) );
88  }
89 
90  for ( int py = 0; py < y; py++ )
91  {
92  uchar *data = image.scanLine( py );
93  memcpy( data, block + py * x, x );
94  }
95 
96  _imageio->setImage( image );
97  _imageio->setStatus( 0 );
98 
99  free(block);
100  return;
101 }
102 
103 KDE_EXPORT void kimgio_xv_write( TQImageIO *imageio )
104 {
105  TQIODevice& f = *( imageio->ioDevice() );
106 
107  // Removed "f.open(...)" and "f.close()" (tanghus)
108 
109  const TQImage& image = imageio->image();
110  int w = image.width(), h = image.height();
111 
112  char str[ 1024 ];
113 
114  // magic number must be "P7 332"
115  f.writeBlock( "P7 332\n", 7 );
116 
117  // next line #XVVERSION
118  f.writeBlock( "#XVVERSION:\n", 12 );
119 
120  // now it gets interesting, #BUILTIN means we are out.
121  // if IMGINFO comes, we are happy!
122  f.writeBlock( "#IMGINFO:\n", 10 );
123 
124  // after this an #END_OF_COMMENTS signals everything to be ok!
125  f.writeBlock( "#END_OF_COMMENTS:\n", 18 );
126 
127  // now a last line with width, height, maxval which is supposed to be 255
128  sprintf( str, "%i %i 255\n", w, h );
129  f.writeBlock( str, strlen( str ) );
130 
131 
132  if ( image.depth() == 1 )
133  {
134  image.convertDepth( 8 );
135  }
136 
137  uchar* buffer = new uchar[ w ];
138 
139  for ( int py = 0; py < h; py++ )
140  {
141  uchar *data = const_cast<TQImage&>(image).scanLine( py );
142  for ( int px = 0; px < w; px++ )
143  {
144  int r, g, b;
145  if ( image.depth() == 32 )
146  {
147  QRgb *data32 = (QRgb*) data;
148  r = tqRed( *data32 ) >> 5;
149  g = tqGreen( *data32 ) >> 5;
150  b = tqBlue( *data32 ) >> 6;
151  data += sizeof( QRgb );
152  }
153  else
154  {
155  QRgb color = image.color( *data );
156  r = tqRed( color ) >> 5;
157  g = tqGreen( color ) >> 5;
158  b = tqBlue( color ) >> 6;
159  data++;
160  }
161  buffer[ px ] = ( r << 5 ) | ( g << 2 ) | b;
162  }
163  f.writeBlock( (const char*)buffer, w );
164  }
165  delete[] buffer;
166 
167  imageio->setStatus( 0 );
168 }
169 

kimgio

Skip menu "kimgio"
  • Main Page
  • File List
  • Related Pages

kimgio

Skip menu "kimgio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kimgio by doxygen 1.8.8
This website is maintained by Timothy Pearson.