13 #include <tdelibs_export.h>
19 static const int b_255_3[]= {0,85,170,255},
20 rg_255_7[]={0,36,72,109,145,182,218,255};
22 TDE_EXPORT
void kimgio_xv_read( TQImageIO *_imageio )
27 TQIODevice *iodev = _imageio->ioDevice();
32 iodev->readLine( str, BUFSIZE );
33 if (strncmp(str,
"P7 332",6))
return;
36 iodev->readLine( str, BUFSIZE );
37 if (strncmp(str,
"#XVVERSION", 10))
42 iodev->readLine( str, BUFSIZE );
43 if (strncmp(str,
"#IMGINFO:", 9))
47 iodev->readLine( str, BUFSIZE );
48 if (strncmp(str,
"#END_OF", 7))
53 iodev->readLine( str, BUFSIZE );
54 sscanf(str,
"%d %d %d", &x, &y, &maxval);
56 if (maxval != 255)
return;
58 if(x < 0 || y < 0 || blocksize < x || blocksize < y)
62 char *block = (
char*) malloc(blocksize);
66 if (iodev->readBlock(block, blocksize) != blocksize )
72 TQImage image( x, y, 8, maxval + 1, TQImage::BigEndian );
82 for (
int j = 0; j < 256; j++ )
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 ) );
90 for (
int py = 0; py < y; py++ )
92 uchar *data = image.scanLine( py );
93 memcpy( data, block + py * x, x );
96 _imageio->setImage( image );
97 _imageio->setStatus( 0 );
103 TDE_EXPORT
void kimgio_xv_write( TQImageIO *imageio )
105 TQIODevice& f = *( imageio->ioDevice() );
109 const TQImage& image = imageio->image();
110 int w = image.width(), h = image.height();
115 f.writeBlock(
"P7 332\n", 7 );
118 f.writeBlock(
"#XVVERSION:\n", 12 );
122 f.writeBlock(
"#IMGINFO:\n", 10 );
125 f.writeBlock(
"#END_OF_COMMENTS:\n", 18 );
128 sprintf( str,
"%i %i 255\n", w, h );
129 f.writeBlock( str, strlen( str ) );
132 if ( image.depth() == 1 )
134 image.convertDepth( 8 );
137 uchar* buffer =
new uchar[ w ];
139 for (
int py = 0; py < h; py++ )
141 uchar *data =
const_cast<TQImage&
>(image).scanLine( py );
142 for (
int px = 0; px < w; px++ )
145 if ( image.depth() == 32 )
147 TQRgb *data32 = (TQRgb*) data;
148 r = tqRed( *data32 ) >> 5;
149 g = tqGreen( *data32 ) >> 5;
150 b = tqBlue( *data32 ) >> 6;
151 data +=
sizeof( TQRgb );
155 TQRgb color = image.color( *data );
156 r = tqRed( color ) >> 5;
157 g = tqGreen( color ) >> 5;
158 b = tqBlue( color ) >> 6;
161 buffer[ px ] = ( r << 5 ) | ( g << 2 ) | b;
163 f.writeBlock( (
const char*)buffer, w );
167 imageio->setStatus( 0 );