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

kimgio

  • kimgio
tiffr.cpp
1// This library is distributed under the conditions of the GNU LGPL.
2
3#include "config.h"
4
5#ifdef HAVE_LIBTIFF
6
7#include <tiffio.h>
8
9#include <tqimage.h>
10#include <tqfile.h>
11#include <tdelibs_export.h>
12
13#include <assert.h>
14
15#include "tiffr.h"
16
17static tsize_t tiff_read( thandle_t handle, tdata_t buf, tsize_t size )
18{
19 TQIODevice *dev = reinterpret_cast<TQIODevice *>( handle );
20 return dev->readBlock( reinterpret_cast<char *>( buf ), size );
21}
22
23static tsize_t tiff_write( thandle_t, tdata_t, tsize_t )
24{
25 return 0;
26}
27
28static toff_t tiff_seek( thandle_t handle, toff_t off, int whence )
29{
30 TQIODevice *dev = reinterpret_cast<TQIODevice *>( handle );
31
32 if ( whence == SEEK_CUR )
33 off += dev->at();
34 else if ( whence == SEEK_END )
35 off += dev->size();
36
37 if ( !dev->at( off ) )
38 return ( toff_t )-1;
39
40 return dev->at();
41}
42
43static toff_t tiff_size( thandle_t handle )
44{
45 TQIODevice *dev = reinterpret_cast<TQIODevice *>( handle );
46 return dev->size();
47}
48
49static int tiff_close( thandle_t )
50{
51 return 0;
52}
53
54static int tiff_map( thandle_t, tdata_t *, toff_t * )
55{
56 return 0;
57}
58
59static void tiff_unmap( thandle_t, tdata_t, toff_t )
60{
61}
62
63TDE_EXPORT void kimgio_tiff_read( TQImageIO *io )
64{
65 TIFF *tiff;
66 uint32 width, height;
67 uint32 *data;
68
69 // FIXME: use qdatastream
70
71 // open file
72 tiff = TIFFClientOpen( TQFile::encodeName( io->fileName() ), "r",
73 ( thandle_t )io->ioDevice(),
74 tiff_read, tiff_write, tiff_seek, tiff_close,
75 tiff_size, tiff_map, tiff_unmap );
76
77 if( tiff == 0 ) {
78 return;
79 }
80
81 // create image with loaded dimensions
82 if( TIFFGetField( tiff, TIFFTAG_IMAGEWIDTH, &width ) != 1
83 || TIFFGetField( tiff, TIFFTAG_IMAGELENGTH, &height ) != 1 )
84 return;
85
86 TQImage image( width, height, 32 );
87 if( image.isNull()) {
88 TIFFClose( tiff );
89 return;
90 }
91 data = (uint32 *)image.bits();
92
93 //Sven: changed to %ld for 64bit machines
94 //debug( "unsigned size: %ld, uint32 size: %ld",
95 // (long)sizeof(unsigned), (long)sizeof(uint32) );
96
97 // read data
98 bool stat =TIFFReadRGBAImage( tiff, width, height, data );
99
100 if( stat == 0 ) {
101 TIFFClose( tiff );
102 return;
103 }
104
105 // reverse red and blue
106 for( unsigned i = 0; i < width * height; ++i )
107 {
108 uint32 red = ( 0x00FF0000 & data[i] ) >> 16;
109 uint32 blue = ( 0x000000FF & data[i] ) << 16;
110 data[i] &= 0xFF00FF00;
111 data[i] += red + blue;
112 }
113
114 // reverse image (it's upside down)
115 for( unsigned ctr = 0; ctr < (height>>1); ) {
116 unsigned *line1 = (unsigned *)image.scanLine( ctr );
117 unsigned *line2 = (unsigned *)image.scanLine( height
118 - ( ++ctr ) );
119
120 for( unsigned x = 0; x < width; x++ ) {
121 int temp = *line1;
122 *line1 = *line2;
123 *line2 = temp;
124 line1++;
125 line2++;
126 }
127
128 // swap rows
129 }
130
131 // set channel order to Qt order
132 // FIXME: Right now they are the same, but will it change?
133
134// for( int ctr = (image.numBytes() / sizeof(uint32))+1; ctr ; ctr-- ) {
135// // TODO: manage alpha with TIFFGetA
136// *data = tqRgb( TIFFGetR( *data ),
137// TIFFGetG( *data ), TIFFGetB( *data ) );
138// data++;
139// }
140 TIFFClose( tiff );
141
142 io->setImage( image );
143 io->setStatus ( 0 );
144}
145
146TDE_EXPORT void kimgio_tiff_write( TQImageIO * )
147{
148 // TODO: stub
149}
150
151#endif

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kimgio by doxygen 1.9.4
This website is maintained by Timothy Pearson.