/[gentoo-alt]/trunk/kde-base/kdelibs/files/post-3.4.0-kdelibs-kimgio-2.diff
Gentoo

Contents of /trunk/kde-base/kdelibs/files/post-3.4.0-kdelibs-kimgio-2.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 381 - (show annotations) (download)
Sun May 22 15:43:41 2005 UTC (9 years, 6 months ago) by flameeyes
File MIME type: text/plain
File size: 29977 byte(s)
Added kde-base ebuild needed to satisfy dependency for kde. Still trouble with qt for now.

1 diff -u -3 -d -p -r1.4 -r1.4.2.1
2 --- exr.cpp 22 Nov 2004 03:48:27 -0000 1.4
3 +++ exr.cpp 19 Apr 2005 10:48:00 -0000 1.4.2.1
4 @@ -136,6 +136,8 @@ KDE_EXPORT void kimgio_exr_read( QImageI
5 file.readPixels (dw.min.y, dw.max.y);
6
7 QImage image(width, height, 32, 0, QImage::BigEndian);
8 + if( image.isNull())
9 + return;
10
11 // somehow copy pixels into image
12 for ( int y=0; y < height; y++ ) {
13 diff -u -3 -d -p -r1.4 -r1.4.2.1
14 --- g3r.cpp 22 Nov 2004 03:48:27 -0000 1.4
15 +++ g3r.cpp 18 Apr 2005 13:08:44 -0000 1.4.2.1
16 @@ -28,7 +28,7 @@ KDE_EXPORT void kimgio_g3_read( QImageIO
17
18 QImage image(width, height, 1, 0, QImage::BigEndian);
19
20 - if (scanlength != image.bytesPerLine())
21 + if (image.isNull() || scanlength != image.bytesPerLine())
22 {
23 TIFFClose(tiff);
24 return;
25 diff -u -3 -d -p -r1.14 -r1.14.2.1
26 --- jp2.cpp 22 Nov 2004 03:48:27 -0000 1.14
27 +++ jp2.cpp 19 Apr 2005 10:48:00 -0000 1.14.2.1
28 @@ -157,8 +157,9 @@ namespace {
29 void
30 draw_view_gray( gs_t& gs, QImage& qti )
31 {
32 - qti.create( jas_image_width( gs.image ), jas_image_height( gs.image ),
33 - 8, 256 );
34 + if( !qti.create( jas_image_width( gs.image ), jas_image_height( gs.image ),
35 + 8, 256 ))
36 + return;
37 for( int i = 0; i < 256; ++i )
38 qti.setColor( i, qRgb( i, i, i ) );
39
40 diff -u -3 -d -p -r1.12 -r1.12.2.2
41 --- pcx.cpp 22 Nov 2004 03:48:27 -0000 1.12
42 +++ pcx.cpp 19 Apr 2005 10:48:00 -0000 1.12.2.2
43 @@ -1,5 +1,5 @@
44 /* This file is part of the KDE project
45 - Copyright (C) 2002-2003 Nadeem Hasan <nhasan@kde.org>
46 + Copyright (C) 2002-2005 Nadeem Hasan <nhasan@kde.org>
47
48 This program is free software; you can redistribute it and/or
49 modify it under the terms of the GNU Lesser General Public
50 @@ -44,6 +44,11 @@ static QDataStream &operator>>( QDataStr
51 s >> ph.HScreenSize;
52 s >> ph.VScreenSize;
53
54 + // Skip the rest of the header
55 + Q_UINT8 byte;
56 + while ( s.device()->at() < 128 )
57 + s >> byte;
58 +
59 return s;
60 }
61
62 @@ -85,25 +90,22 @@ static QDataStream &operator<<( QDataStr
63 return s;
64 }
65
66 -static PCXHEADER header;
67 -static QImage img;
68 -static Q_UINT16 w, h;
69 -
70 -void PCXHEADER::reset()
71 +PCXHEADER::PCXHEADER()
72 {
73 + // Initialize all data to zero
74 QByteArray dummy( 128 );
75 dummy.fill( 0 );
76 QDataStream s( dummy, IO_ReadOnly );
77 s >> *this;
78 }
79
80 -static void readLine( QDataStream &s, QByteArray &buf )
81 +static void readLine( QDataStream &s, QByteArray &buf, const PCXHEADER &header )
82 {
83 Q_UINT32 i=0;
84 Q_UINT32 size = buf.size();
85 Q_UINT8 byte, count;
86
87 - if ( header.Encoding == 1 )
88 + if ( header.isCompressed() )
89 {
90 // Uncompress the image data
91 while ( i < size )
92 @@ -130,13 +132,14 @@ static void readLine( QDataStream &s, QB
93 }
94 }
95
96 -static void readImage1( QDataStream &s )
97 +static void readImage1( QImage &img, QDataStream &s, const PCXHEADER &header )
98 {
99 QByteArray buf( header.BytesPerLine );
100
101 - img.create( w, h, 1, 2, QImage::BigEndian );
102 + if(!img.create( header.width(), header.height(), 1, 2, QImage::BigEndian ))
103 + return;
104
105 - for ( int y=0; y<h; ++y )
106 + for ( int y=0; y<header.height(); ++y )
107 {
108 if ( s.atEnd() )
109 {
110 @@ -144,10 +147,11 @@ static void readImage1( QDataStream &s )
111 return;
112 }
113
114 - readLine( s, buf );
115 -
116 - for ( int x=0; x<header.BytesPerLine; ++x )
117 - *( img.scanLine( y )+x ) = buf[ x ];
118 + readLine( s, buf, header );
119 + uchar *p = img.scanLine( y );
120 + unsigned int bpl = QMIN((header.width()+7)/8, header.BytesPerLine);
121 + for ( unsigned int x=0; x< bpl; ++x )
122 + p[ x ] = buf[x];
123 }
124
125 // Set the color palette
126 @@ -155,14 +159,15 @@ static void readImage1( QDataStream &s )
127 img.setColor( 1, qRgb( 255, 255, 255 ) );
128 }
129
130 -static void readImage4( QDataStream &s )
131 +static void readImage4( QImage &img, QDataStream &s, const PCXHEADER &header )
132 {
133 QByteArray buf( header.BytesPerLine*4 );
134 - QByteArray pixbuf( w );
135 + QByteArray pixbuf( header.width() );
136
137 - img.create( w, h, 8, 16, QImage::IgnoreEndian );
138 + if(!img.create( header.width(), header.height(), 8, 16 ))
139 + return;
140
141 - for ( int y=0; y<h; ++y )
142 + for ( int y=0; y<header.height(); ++y )
143 {
144 if ( s.atEnd() )
145 {
146 @@ -171,20 +176,19 @@ static void readImage4( QDataStream &s )
147 }
148
149 pixbuf.fill( 0 );
150 - readLine( s, buf );
151 + readLine( s, buf, header );
152
153 for ( int i=0; i<4; i++ )
154 {
155 Q_UINT32 offset = i*header.BytesPerLine;
156 - for ( int x=0; x<w; ++x )
157 + for ( unsigned int x=0; x<header.width(); ++x )
158 if ( buf[ offset + ( x/8 ) ] & ( 128 >> ( x%8 ) ) )
159 pixbuf[ x ] += ( 1 << i );
160 }
161
162 uchar *p = img.scanLine( y );
163 -
164 - for ( int x=0; x<w; ++x )
165 - *p++ = pixbuf[ x ];
166 + for ( unsigned int x=0; x<header.width(); ++x )
167 + p[ x ] = pixbuf[ x ];
168 }
169
170 // Read the palette
171 @@ -192,13 +196,14 @@ static void readImage4( QDataStream &s )
172 img.setColor( i, header.ColorMap.color( i ) );
173 }
174
175 -static void readImage8( QDataStream &s )
176 +static void readImage8( QImage &img, QDataStream &s, const PCXHEADER &header )
177 {
178 QByteArray buf( header.BytesPerLine );
179
180 - img.create( w, h, 8, 256, QImage::IgnoreEndian );
181 + if(!img.create( header.width(), header.height(), 8, 256 ))
182 + return;
183
184 - for ( int y=0; y<h; ++y )
185 + for ( int y=0; y<header.height(); ++y )
186 {
187 if ( s.atEnd() )
188 {
189 @@ -206,19 +211,19 @@ static void readImage8( QDataStream &s )
190 return;
191 }
192
193 - readLine( s, buf );
194 + readLine( s, buf, header );
195
196 uchar *p = img.scanLine( y );
197 -
198 - for ( int x=0; x<header.BytesPerLine; ++x )
199 - *p++ = buf[ x ];
200 + unsigned int bpl = QMIN(header.BytesPerLine, header.width());
201 + for ( unsigned int x=0; x<bpl; ++x )
202 + p[ x ] = buf[ x ];
203 }
204
205 Q_UINT8 flag;
206 s >> flag;
207 - kdDebug() << "Flag: " << flag << endl;
208 + kdDebug( 399 ) << "Palette Flag: " << flag << endl;
209
210 - if ( flag == 12 && header.Version == 5 )
211 + if ( flag == 12 && ( header.Version == 5 || header.Version == 2 ) )
212 {
213 // Read the palette
214 Q_UINT8 r, g, b;
215 @@ -230,15 +235,16 @@ static void readImage8( QDataStream &s )
216 }
217 }
218
219 -static void readImage24( QDataStream &s )
220 +static void readImage24( QImage &img, QDataStream &s, const PCXHEADER &header )
221 {
222 QByteArray r_buf( header.BytesPerLine );
223 QByteArray g_buf( header.BytesPerLine );
224 QByteArray b_buf( header.BytesPerLine );
225
226 - img.create( w, h, 32 );
227 + if(!img.create( header.width(), header.height(), 32 ))
228 + return;
229
230 - for ( int y=0; y<h; ++y )
231 + for ( int y=0; y<header.height(); ++y )
232 {
233 if ( s.atEnd() )
234 {
235 @@ -246,14 +252,13 @@ static void readImage24( QDataStream &s
236 return;
237 }
238
239 - readLine( s, r_buf );
240 - readLine( s, g_buf );
241 - readLine( s, b_buf );
242 + readLine( s, r_buf, header );
243 + readLine( s, g_buf, header );
244 + readLine( s, b_buf, header );
245
246 uint *p = ( uint * )img.scanLine( y );
247 -
248 - for ( int x=0; x<header.BytesPerLine; ++x )
249 - *p++ = qRgb( r_buf[ x ], g_buf[ x ], b_buf[ x ] );
250 + for ( unsigned int x=0; x<header.width(); ++x )
251 + p[ x ] = qRgb( r_buf[ x ], g_buf[ x ], b_buf[ x ] );
252 }
253 }
254
255 @@ -268,6 +273,8 @@ KDE_EXPORT void kimgio_pcx_read( QImageI
256 return;
257 }
258
259 + PCXHEADER header;
260 +
261 s >> header;
262
263 if ( header.Manufacturer != 10 || s.atEnd())
264 @@ -276,10 +283,8 @@ KDE_EXPORT void kimgio_pcx_read( QImageI
265 return;
266 }
267
268 - w = ( header.XMax-header.XMin ) + 1;
269 - h = ( header.YMax-header.YMin ) + 1;
270 -
271 - img.reset();
272 + int w = header.width();
273 + int h = header.height();
274
275 kdDebug( 399 ) << "Manufacturer: " << header.Manufacturer << endl;
276 kdDebug( 399 ) << "Version: " << header.Version << endl;
277 @@ -288,30 +293,27 @@ KDE_EXPORT void kimgio_pcx_read( QImageI
278 kdDebug( 399 ) << "Width: " << w << endl;
279 kdDebug( 399 ) << "Height: " << h << endl;
280 kdDebug( 399 ) << "Window: " << header.XMin << "," << header.XMax << ","
281 - << header.YMin << "," << header.YMax << endl;
282 + << header.YMin << "," << header.YMax << endl;
283 kdDebug( 399 ) << "BytesPerLine: " << header.BytesPerLine << endl;
284 kdDebug( 399 ) << "NPlanes: " << header.NPlanes << endl;
285
286 - // Skip the rest of the header
287 - Q_UINT8 byte;
288 - while ( s.device()->at() < 128 )
289 - s >> byte;
290 + QImage img;
291
292 if ( header.Bpp == 1 && header.NPlanes == 1 )
293 {
294 - readImage1( s );
295 + readImage1( img, s, header );
296 }
297 else if ( header.Bpp == 1 && header.NPlanes == 4 )
298 {
299 - readImage4( s );
300 + readImage4( img, s, header );
301 }
302 else if ( header.Bpp == 8 && header.NPlanes == 1 )
303 {
304 - readImage8( s );
305 + readImage8( img, s, header );
306 }
307 else if ( header.Bpp == 8 && header.NPlanes == 3 )
308 {
309 - readImage24( s );
310 + readImage24( img, s, header );
311 }
312
313 kdDebug( 399 ) << "Image Bytes: " << img.numBytes() << endl;
314 @@ -359,7 +361,7 @@ static void writeLine( QDataStream &s, Q
315 }
316 }
317
318 -static void writeImage1( QDataStream &s )
319 +static void writeImage1( QImage &img, QDataStream &s, PCXHEADER &header )
320 {
321 img = img.convertBitOrder( QImage::BigEndian );
322
323 @@ -367,29 +369,27 @@ static void writeImage1( QDataStream &s
324 header.NPlanes = 1;
325 header.BytesPerLine = img.bytesPerLine();
326
327 - header.ColorMap.setColor( 0, qRgb( 0, 0, 0 ) );
328 - header.ColorMap.setColor( 1, qRgb( 255, 255, 255 ) );
329 -
330 s << header;
331
332 QByteArray buf( header.BytesPerLine );
333
334 - for ( int y=0; y<h; ++y )
335 + for ( int y=0; y<header.height(); ++y )
336 {
337 Q_UINT8 *p = img.scanLine( y );
338
339 + // Invert as QImage uses reverse palette for monochrome images?
340 for ( int i=0; i<header.BytesPerLine; ++i )
341 - buf[ i ] = p[ i ];
342 + buf[ i ] = ~p[ i ];
343
344 writeLine( s, buf );
345 }
346 }
347
348 -static void writeImage4( QDataStream &s )
349 +static void writeImage4( QImage &img, QDataStream &s, PCXHEADER &header )
350 {
351 header.Bpp = 1;
352 header.NPlanes = 4;
353 - header.BytesPerLine = w/8;
354 + header.BytesPerLine = header.width()/8;
355
356 for ( int i=0; i<16; ++i )
357 header.ColorMap.setColor( i, img.color( i ) );
358 @@ -401,14 +401,14 @@ static void writeImage4( QDataStream &s
359 for ( int i=0; i<4; ++i )
360 buf[ i ].resize( header.BytesPerLine );
361
362 - for ( int y=0; y<h; ++y )
363 + for ( int y=0; y<header.height(); ++y )
364 {
365 Q_UINT8 *p = img.scanLine( y );
366
367 for ( int i=0; i<4; ++i )
368 buf[ i ].fill( 0 );
369
370 - for ( int x=0; x<w; ++x )
371 + for ( unsigned int x=0; x<header.width(); ++x )
372 {
373 for ( int i=0; i<4; ++i )
374 if ( *( p+x ) & ( 1 << i ) )
375 @@ -420,7 +420,7 @@ static void writeImage4( QDataStream &s
376 }
377 }
378
379 -static void writeImage8( QDataStream &s )
380 +static void writeImage8( QImage &img, QDataStream &s, PCXHEADER &header )
381 {
382 header.Bpp = 8;
383 header.NPlanes = 1;
384 @@ -430,7 +430,7 @@ static void writeImage8( QDataStream &s
385
386 QByteArray buf( header.BytesPerLine );
387
388 - for ( int y=0; y<h; ++y )
389 + for ( int y=0; y<header.height(); ++y )
390 {
391 Q_UINT8 *p = img.scanLine( y );
392
393 @@ -449,23 +449,23 @@ static void writeImage8( QDataStream &s
394 s << RGB( img.color( i ) );
395 }
396
397 -static void writeImage24( QDataStream &s )
398 +static void writeImage24( QImage &img, QDataStream &s, PCXHEADER &header )
399 {
400 header.Bpp = 8;
401 header.NPlanes = 3;
402 - header.BytesPerLine = w;
403 + header.BytesPerLine = header.width();
404
405 s << header;
406
407 - QByteArray r_buf( w );
408 - QByteArray g_buf( w );
409 - QByteArray b_buf( w );
410 + QByteArray r_buf( header.width() );
411 + QByteArray g_buf( header.width() );
412 + QByteArray b_buf( header.width() );
413
414 - for ( int y=0; y<h; ++y )
415 + for ( int y=0; y<header.height(); ++y )
416 {
417 uint *p = ( uint * )img.scanLine( y );
418
419 - for ( int x=0; x<w; ++x )
420 + for ( unsigned int x=0; x<header.width(); ++x )
421 {
422 QRgb rgb = *p++;
423 r_buf[ x ] = qRed( rgb );
424 @@ -484,10 +484,10 @@ KDE_EXPORT void kimgio_pcx_write( QImage
425 QDataStream s( io->ioDevice() );
426 s.setByteOrder( QDataStream::LittleEndian );
427
428 - img = io->image();
429 + QImage img = io->image();
430
431 - w = img.width();
432 - h = img.height();
433 + int w = img.width();
434 + int h = img.height();
435
436 kdDebug( 399 ) << "Width: " << w << endl;
437 kdDebug( 399 ) << "Height: " << h << endl;
438 @@ -495,6 +495,8 @@ KDE_EXPORT void kimgio_pcx_write( QImage
439 kdDebug( 399 ) << "BytesPerLine: " << img.bytesPerLine() << endl;
440 kdDebug( 399 ) << "Num Colors: " << img.numColors() << endl;
441
442 + PCXHEADER header;
443 +
444 header.Manufacturer = 10;
445 header.Version = 5;
446 header.Encoding = 1;
447 @@ -509,19 +511,19 @@ KDE_EXPORT void kimgio_pcx_write( QImage
448
449 if ( img.depth() == 1 )
450 {
451 - writeImage1( s );
452 + writeImage1( img, s, header );
453 }
454 else if ( img.depth() == 8 && img.numColors() <= 16 )
455 {
456 - writeImage4( s );
457 + writeImage4( img, s, header );
458 }
459 else if ( img.depth() == 8 )
460 {
461 - writeImage8( s );
462 + writeImage8( img, s, header );
463 }
464 else if ( img.depth() == 32 )
465 {
466 - writeImage24( s );
467 + writeImage24( img, s, header );
468 }
469
470 io->setStatus( 0 );
471 Index: pcx.h
472 ===================================================================
473 RCS file: /home/kde/kdelibs/kimgio/pcx.h,v
474 retrieving revision 1.4
475 retrieving revision 1.4.8.1
476 diff -u -3 -d -p -r1.4 -r1.4.8.1
477 --- pcx.h 4 Jan 2003 00:48:25 -0000 1.4
478 +++ pcx.h 19 Apr 2005 10:48:00 -0000 1.4.8.1
479 @@ -49,7 +49,7 @@ class Palette
480 rgb[ i ] = RGB( color );
481 }
482
483 - QRgb color( int i )
484 + QRgb color( int i ) const
485 {
486 return qRgb( rgb[ i ].r, rgb[ i ].g, rgb[ i ].b );
487 }
488 @@ -60,12 +60,11 @@ class Palette
489 class PCXHEADER
490 {
491 public:
492 - PCXHEADER()
493 - {
494 - reset();
495 - }
496 + PCXHEADER();
497
498 - void reset();
499 + inline int width() const { return ( XMax-XMin ) + 1; }
500 + inline int height() const { return ( YMax-YMin ) + 1; }
501 + inline bool isCompressed() const { return ( Encoding==1 ); }
502
503 Q_UINT8 Manufacturer; // Constant Flag, 10 = ZSoft .pcx
504 Q_UINT8 Version; // Version informationĚ
505 @@ -99,7 +98,7 @@ class PCXHEADER
506 // found only in PB IV/IV Plus
507 Q_UINT16 VScreenSize; // Vertical screen size in pixels. New field
508 // found only in PB IV/IV Plus
509 -};
510 +} KDE_PACKED;
511
512 #endif // PCX_H
513
514 diff -u -3 -d -p -r1.1 -r1.1.2.1
515 --- psd.cpp 16 Dec 2004 09:59:07 -0000 1.1
516 +++ psd.cpp 19 Apr 2005 10:48:00 -0000 1.1.2.1
517 @@ -66,6 +66,19 @@ namespace { // Private.
518 s >> header.color_mode;
519 return s;
520 }
521 + static bool seekBy(QDataStream& s, unsigned int bytes)
522 + {
523 + char buf[4096];
524 + while (bytes) {
525 + unsigned int num= QMIN(bytes,sizeof(buf));
526 + unsigned int l = num;
527 + s.readRawBytes(buf, l);
528 + if(l != num)
529 + return false;
530 + bytes -= num;
531 + }
532 + return true;
533 + }
534
535 // Check that the header is a valid PSD.
536 static bool IsValid( const PSDHeader & header )
537 @@ -149,10 +162,8 @@ namespace { // Private.
538 if( compression ) {
539
540 // Skip row lengths.
541 - ushort w;
542 - for(uint i = 0; i < header.height * header.channel_count; i++) {
543 - s >> w;
544 - }
545 + if(!seekBy(s, header.height*header.channel_count*sizeof(ushort)))
546 + return false;
547
548 // Read RLE data.
549 for(uint channel = 0; channel < channel_num; channel++) {
550 @@ -162,6 +173,8 @@ namespace { // Private.
551 uint count = 0;
552 while( count < pixel_count ) {
553 uchar c;
554 + if(s.atEnd())
555 + return false;
556 s >> c;
557 uint len = c;
558
559 @@ -169,6 +182,9 @@ namespace { // Private.
560 // Copy next len+1 bytes literally.
561 len++;
562 count += len;
563 + if ( count > pixel_count )
564 + return false;
565 +
566 while( len != 0 ) {
567 s >> *ptr;
568 ptr += 4;
569 @@ -181,6 +197,8 @@ namespace { // Private.
570 len ^= 0xFF;
571 len += 2;
572 count += len;
573 + if(s.atEnd() || count > pixel_count)
574 + return false;
575 uchar val;
576 s >> val;
577 while( len != 0 ) {
578 diff -u -3 -d -p -r1.31 -r1.31.2.1
579 --- rgb.cpp 10 Jan 2005 19:54:19 -0000 1.31
580 +++ rgb.cpp 19 Apr 2005 10:48:00 -0000 1.31.2.1
581 @@ -87,7 +87,9 @@ bool SGIImage::getRow(uchar *dest)
582 int n, i;
583 if (!m_rle) {
584 for (i = 0; i < m_xsize; i++) {
585 - *dest++ = uchar(*m_pos);
586 + if(m_pos >= m_data.end())
587 + return false;
588 + dest[i] = uchar(*m_pos);
589 m_pos += m_bpc;
590 }
591 return true;
592 @@ -120,7 +122,7 @@ bool SGIImage::readData(QImage& img)
593 {
594 QRgb *c;
595 Q_UINT32 *start = m_starttab;
596 - QCString lguard(m_xsize);
597 + QByteArray lguard(m_xsize);
598 uchar *line = (uchar *)lguard.data();
599 unsigned x, y;
600
601 @@ -128,7 +130,7 @@ bool SGIImage::readData(QImage& img)
602 m_pos = m_data.begin();
603
604 for (y = 0; y < m_ysize; y++) {
605 - c = reinterpret_cast<QRgb *>(img.scanLine(m_ysize - y - 1));
606 + c = (QRgb *) img.scanLine(m_ysize - y - 1);
607 if (m_rle)
608 m_pos = m_data.begin() + *start++;
609 if (!getRow(line))
610 @@ -166,11 +168,11 @@ bool SGIImage::readData(QImage& img)
611 }
612
613 for (y = 0; y < m_ysize; y++) {
614 - c = reinterpret_cast<QRgb *>(img.scanLine(m_ysize - y - 1));
615 if (m_rle)
616 m_pos = m_data.begin() + *start++;
617 if (!getRow(line))
618 return false;
619 + c = (QRgb*) img.scanLine(m_ysize - y - 1);
620 for (x = 0; x < m_xsize; x++, c++)
621 *c = qRgba(qRed(*c), qGreen(*c), qBlue(*c), line[x]);
622 }
623 diff -u -3 -d -p -r1.14 -r1.14.2.1
624 --- tiffr.cpp 22 Nov 2004 03:52:18 -0000 1.14
625 +++ tiffr.cpp 19 Apr 2005 10:48:00 -0000 1.14.2.1
626 @@ -84,6 +84,10 @@ KDE_EXPORT void kimgio_tiff_read( QImage
627 return;
628
629 QImage image( width, height, 32 );
630 + if( image.isNull()) {
631 + TIFFClose( tiff );
632 + return;
633 + }
634 data = (uint32 *)image.bits();
635
636 //Sven: changed to %ld for 64bit machines
637 diff -u -3 -d -p -r1.3 -r1.3.2.1
638 --- xcf.cpp 22 Nov 2004 03:48:27 -0000 1.3
639 +++ xcf.cpp 19 Apr 2005 10:48:00 -0000 1.3.2.1
640 @@ -234,10 +234,10 @@ bool XCFImageFormat::loadImageProperties
641 property.readBytes(tag, size);
642
643 Q_UINT32 flags;
644 - char* data;
645 + char* data=0;
646 property >> flags >> data;
647
648 - if (strcmp(tag, "gimp-comment") == 0)
649 + if (tag && strncmp(tag, "gimp-comment", strlen("gimp-comment")) == 0)
650 xcf_image.image.setText("Comment", 0, data);
651
652 delete[] tag;
653 @@ -257,6 +257,9 @@ bool XCFImageFormat::loadImageProperties
654
655 case PROP_COLORMAP:
656 property >> xcf_image.num_colors;
657 + if(xcf_image.num_colors < 0 || xcf_image.num_colors > 65535)
658 + return false;
659 +
660 xcf_image.palette.reserve(xcf_image.num_colors);
661
662 for (int i = 0; i < xcf_image.num_colors; i++) {
663 @@ -307,6 +310,9 @@ bool XCFImageFormat::loadProperty(QDataS
664 return false;
665 }
666
667 + if(size > 65535 || size < 4)
668 + return false;
669 +
670 size = 3 * (size - 4) + 4;
671 data = new char[size];
672
673 @@ -336,19 +342,21 @@ bool XCFImageFormat::loadProperty(QDataS
674 }
675
676 size = 0;
677 - } else
678 - xcf_io.readBytes(data, size);
679 + } else {
680 + xcf_io >> size;
681 + if(size >256000)
682 + return false;
683 + data = new char[size];
684 + xcf_io.readRawBytes(data, size);
685 + }
686
687 if (xcf_io.device()->status() != IO_Ok) {
688 kdDebug(399) << "XCF: read failure on property " << type << " data, size " << size << endl;
689 return false;
690 }
691
692 - if (size != 0) {
693 - bytes.resize(size);
694 - for (uint i = 0; i < size; i++)
695 - bytes[i] = data[i];
696 - delete[] data;
697 + if (size != 0 && data) {
698 + bytes.assign(data,size);
699 }
700
701 return true;
702 @@ -401,7 +409,8 @@ bool XCFImageFormat::loadLayer(QDataStre
703 // Allocate the individual tile QImages based on the size and type
704 // of this layer.
705
706 - composeTiles(xcf_image);
707 + if( !composeTiles(xcf_image))
708 + return false;
709 xcf_io.device()->at(layer.hierarchy_offset);
710
711 // As tiles are loaded, they are copied into the layers tiles by
712 @@ -425,7 +434,8 @@ bool XCFImageFormat::loadLayer(QDataStre
713 // of the QImage.
714
715 if (!xcf_image.initialized) {
716 - initializeImage(xcf_image);
717 + if( !initializeImage(xcf_image))
718 + return false;
719 copyLayerToImage(xcf_image);
720 xcf_image.initialized = true;
721 } else
722 @@ -516,7 +526,7 @@ bool XCFImageFormat::loadLayerProperties
723 * QImage structures for each of them.
724 * \param xcf_image contains the current layer.
725 */
726 -void XCFImageFormat::composeTiles(XCFImage& xcf_image)
727 +bool XCFImageFormat::composeTiles(XCFImage& xcf_image)
728 {
729 Layer& layer(xcf_image.layer);
730
731 @@ -556,48 +566,67 @@ void XCFImageFormat::composeTiles(XCFIma
732 switch (layer.type) {
733 case RGB_GIMAGE:
734 layer.image_tiles[j][i] = QImage(tile_width, tile_height, 32, 0);
735 + if( layer.image_tiles[j][i].isNull())
736 + return false;
737 layer.image_tiles[j][i].setAlphaBuffer(false);
738 break;
739
740 case RGBA_GIMAGE:
741 layer.image_tiles[j][i] = QImage(tile_width, tile_height, 32, 0);
742 + if( layer.image_tiles[j][i].isNull())
743 + return false;
744 layer.image_tiles[j][i].setAlphaBuffer(true);
745 break;
746
747 case GRAY_GIMAGE:
748 layer.image_tiles[j][i] = QImage(tile_width, tile_height, 8, 256);
749 + if( layer.image_tiles[j][i].isNull())
750 + return false;
751 setGrayPalette(layer.image_tiles[j][i]);
752 break;
753
754 case GRAYA_GIMAGE:
755 layer.image_tiles[j][i] = QImage(tile_width, tile_height, 8, 256);
756 + if( layer.image_tiles[j][i].isNull())
757 + return false;
758 setGrayPalette(layer.image_tiles[j][i]);
759
760 layer.alpha_tiles[j][i] = QImage( tile_width, tile_height, 8, 256);
761 + if( layer.alpha_tiles[j][i].isNull())
762 + return false;
763 setGrayPalette(layer.alpha_tiles[j][i]);
764 break;
765
766 case INDEXED_GIMAGE:
767 layer.image_tiles[j][i] = QImage(tile_width, tile_height, 8,
768 xcf_image.num_colors);
769 + if( layer.image_tiles[j][i].isNull())
770 + return false;
771 setPalette(xcf_image, layer.image_tiles[j][i]);
772 break;
773
774 case INDEXEDA_GIMAGE:
775 layer.image_tiles[j][i] = QImage(tile_width, tile_height,8,
776 xcf_image.num_colors);
777 + if( layer.image_tiles[j][i].isNull())
778 + return false;
779 setPalette(xcf_image, layer.image_tiles[j][i]);
780
781 layer.alpha_tiles[j][i] = QImage(tile_width, tile_height, 8, 256);
782 + if( layer.alpha_tiles[j][i].isNull())
783 + return false;
784 setGrayPalette(layer.alpha_tiles[j][i]);
785 }
786
787 if (layer.mask_offset != 0) {
788 layer.mask_tiles[j][i] = QImage(tile_width, tile_height, 8, 256);
789 + if( layer.mask_tiles[j][i].isNull())
790 + return false;
791 setGrayPalette(layer.mask_tiles[j][i]);
792 }
793 }
794 }
795 + return true;
796 }
797
798
799 @@ -1072,7 +1101,7 @@ void XCFImageFormat::assignMaskBytes(Lay
800 * For indexed images, translucency is an all or nothing effect.
801 * \param xcf_image contains image info and bottom-most layer.
802 */
803 -void XCFImageFormat::initializeImage(XCFImage& xcf_image)
804 +bool XCFImageFormat::initializeImage(XCFImage& xcf_image)
805 {
806 // (Aliases to make the code look a little better.)
807 Layer& layer(xcf_image.layer);
808 @@ -1082,12 +1111,16 @@ void XCFImageFormat::initializeImage(XCF
809 case RGB_GIMAGE:
810 if (layer.opacity == OPAQUE_OPACITY) {
811 image.create( xcf_image.width, xcf_image.height, 32);
812 + if( image.isNull())
813 + return false;
814 image.fill(qRgb(255, 255, 255));
815 break;
816 } // else, fall through to 32-bit representation
817
818 case RGBA_GIMAGE:
819 image.create(xcf_image.width, xcf_image.height, 32);
820 + if( image.isNull())
821 + return false;
822 image.fill(qRgba(255, 255, 255, 0));
823 // Turning this on prevents fill() from affecting the alpha channel,
824 // by the way.
825 @@ -1097,6 +1130,8 @@ void XCFImageFormat::initializeImage(XCF
826 case GRAY_GIMAGE:
827 if (layer.opacity == OPAQUE_OPACITY) {
828 image.create(xcf_image.width, xcf_image.height, 8, 256);
829 + if( image.isNull())
830 + return false;
831 setGrayPalette(image);
832 image.fill(255);
833 break;
834 @@ -1104,6 +1139,8 @@ void XCFImageFormat::initializeImage(XCF
835
836 case GRAYA_GIMAGE:
837 image.create(xcf_image.width, xcf_image.height, 32);
838 + if( image.isNull())
839 + return false;
840 image.fill(qRgba(255, 255, 255, 0));
841 image.setAlphaBuffer(true);
842 break;
843 @@ -1125,12 +1162,16 @@ void XCFImageFormat::initializeImage(XCF
844 image.create(xcf_image.width, xcf_image.height,
845 1, xcf_image.num_colors,
846 QImage::LittleEndian);
847 + if( image.isNull())
848 + return false;
849 image.fill(0);
850 setPalette(xcf_image, image);
851 } else if (xcf_image.num_colors <= 256) {
852 image.create(xcf_image.width, xcf_image.height,
853 8, xcf_image.num_colors,
854 QImage::LittleEndian);
855 + if( image.isNull())
856 + return false;
857 image.fill(0);
858 setPalette(xcf_image, image);
859 }
860 @@ -1147,6 +1188,8 @@ void XCFImageFormat::initializeImage(XCF
861 image.create(xcf_image.width, xcf_image.height,
862 1, xcf_image.num_colors,
863 QImage::LittleEndian);
864 + if( image.isNull())
865 + return false;
866 image.fill(0);
867 setPalette(xcf_image, image);
868 image.setAlphaBuffer(true);
869 @@ -1160,6 +1203,8 @@ void XCFImageFormat::initializeImage(XCF
870 xcf_image.palette[0] = qRgba(255, 255, 255, 0);
871 image.create( xcf_image.width, xcf_image.height,
872 8, xcf_image.num_colors);
873 + if( image.isNull())
874 + return false;
875 image.fill(0);
876 setPalette(xcf_image, image);
877 image.setAlphaBuffer(true);
878 @@ -1168,6 +1213,8 @@ void XCFImageFormat::initializeImage(XCF
879 // true color. (There is no equivalent PNG representation output
880 // from The GIMP as of v1.2.)
881 image.create(xcf_image.width, xcf_image.height, 32);
882 + if( image.isNull())
883 + return false;
884 image.fill(qRgba(255, 255, 255, 0));
885 image.setAlphaBuffer(true);
886 }
887 @@ -1176,6 +1223,7 @@ void XCFImageFormat::initializeImage(XCF
888
889 image.setDotsPerMeterX((int)(xcf_image.x_resolution * INCHESPERMETER));
890 image.setDotsPerMeterY((int)(xcf_image.y_resolution * INCHESPERMETER));
891 + return true;
892 }
893
894
895 Index: xcf.h
896 ===================================================================
897 RCS file: /home/kde/kdelibs/kimgio/xcf.h,v
898 retrieving revision 1.1
899 retrieving revision 1.1.2.1
900 diff -u -3 -d -p -r1.1 -r1.1.2.1
901 --- xcf.h 13 Aug 2004 18:31:44 -0000 1.1
902 +++ xcf.h 19 Apr 2005 10:48:00 -0000 1.1.2.1
903 @@ -176,7 +176,7 @@ private:
904 bool loadProperty(QDataStream& xcf_io, PropType& type, QByteArray& bytes);
905 bool loadLayer(QDataStream& xcf_io, XCFImage& xcf_image);
906 bool loadLayerProperties(QDataStream& xcf_io, Layer& layer);
907 - void composeTiles(XCFImage& xcf_image);
908 + bool composeTiles(XCFImage& xcf_image);
909 void setGrayPalette(QImage& image);
910 void setPalette(XCFImage& xcf_image, QImage& image);
911 static void assignImageBytes(Layer& layer, uint i, uint j);
912 @@ -185,7 +185,7 @@ private:
913 static void assignMaskBytes(Layer& layer, uint i, uint j);
914 bool loadMask(QDataStream& xcf_io, Layer& layer);
915 bool loadChannelProperties(QDataStream& xcf_io, Layer& layer);
916 - void initializeImage(XCFImage& xcf_image);
917 + bool initializeImage(XCFImage& xcf_image);
918 bool loadTileRLE(QDataStream& xcf_io, uchar* tile, int size,
919 int data_length, Q_INT32 bpp);
920 static void copyLayerToImage(XCFImage& xcf_image);
921 diff -u -3 -d -p -r1.12 -r1.12.2.1
922 --- xview.cpp 22 Nov 2004 03:52:18 -0000 1.12
923 +++ xview.cpp 19 Apr 2005 10:48:00 -0000 1.12.2.1
924 @@ -7,6 +7,7 @@
925
926 #include <stdio.h>
927 #include <string.h>
928 +#include <stdlib.h>
929 #include <qimage.h>
930
931 #include <kdelibs_export.h>
932 @@ -15,6 +16,9 @@
933
934 #define BUFSIZE 1024
935
936 +static const int b_255_3[]= {0,85,170,255}, // index*255/3
937 + rg_255_7[]={0,36,72,109,145,182,218,255}; // index *255/7
938 +
939 KDE_EXPORT void kimgio_xv_read( QImageIO *_imageio )
940 {
941 int x=-1;
942 @@ -50,10 +54,14 @@ KDE_EXPORT void kimgio_xv_read( QImageIO
943 sscanf(str, "%d %d %d", &x, &y, &maxval);
944
945 if (maxval != 255) return;
946 + int blocksize = x*y;
947 + if(x < 0 || y < 0 || blocksize < x || blocksize < y)
948 + return;
949
950 // now follows a binary block of x*y bytes.
951 - int blocksize = x*y;
952 - char *block = new char[ blocksize ];
953 + char *block = (char*) malloc(blocksize);
954 + if(!block)
955 + return;
956
957 if (iodev->readBlock(block, blocksize) != blocksize )
958 {
959 @@ -62,6 +70,10 @@ KDE_EXPORT void kimgio_xv_read( QImageIO
960
961 // Create the image
962 QImage image( x, y, 8, maxval + 1, QImage::BigEndian );
963 + if( image.isNull()) {
964 + free(block);
965 + return;
966 + }
967
968 // how do the color handling? they are absolute 24bpp
969 // or at least can be calculated as such.
970 @@ -69,29 +81,9 @@ KDE_EXPORT void kimgio_xv_read( QImageIO
971
972 for ( int j = 0; j < 256; j++ )
973 {
974 -// ----------- OLIVER EIDEN
975 -// That is the old-code !
976 -/* r = ((int) ((j >> 5) & 0x07)) << 5;
977 - g = ((int) ((j >> 2) & 0x07)) << 5;
978 - b = ((int) ((j >> 0) & 0x03)) << 6;*/
979 -
980 -
981 -// That is the code-how xv, decode 3-3-2 pixmaps, it is slighly different,
982 -// but yields much better visuals results
983 -/* r = (((int) ((j >> 5) & 0x07)) *255) / 7;
984 - g = (((int) ((j >> 2) & 0x07)) *255) / 7;
985 - b = (((int) ((j >> 0) & 0x03)) *255) / 3;*/
986 -
987 -// This is the same as xv, with multiplications/divisions replaced by indexing
988 -
989 -// Look-up table to avoid multiplications and divisons
990 - static int b_255_3[]= {0,85,170,255}, // index*255/3
991 - rg_255_7[]={0,36,72,109,145,182,218,255}; // index *255/7
992 -
993 r = rg_255_7[((j >> 5) & 0x07)];
994 g = rg_255_7[((j >> 2) & 0x07)];
995 b = b_255_3[((j >> 0) & 0x03)];
996 -// ---------------
997 image.setColor( j, qRgb( r, g, b ) );
998 }
999
1000 @@ -104,7 +96,7 @@ KDE_EXPORT void kimgio_xv_read( QImageIO
1001 _imageio->setImage( image );
1002 _imageio->setStatus( 0 );
1003
1004 - delete [] block;
1005 + free(block);
1006 return;
1007 }
1008

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20