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
|
$NetBSD: patch-dg,v 1.2 2005/05/01 04:35:40 markd Exp $
--- kimgio/xview.cpp.orig 2004-11-22 16:52:18.000000000 +1300
+++ kimgio/xview.cpp
@@ -7,6 +7,7 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include <qimage.h>
#include <kdelibs_export.h>
@@ -15,6 +16,9 @@
#define BUFSIZE 1024
+static const int b_255_3[]= {0,85,170,255}, // index*255/3
+ rg_255_7[]={0,36,72,109,145,182,218,255}; // index *255/7
+
KDE_EXPORT void kimgio_xv_read( QImageIO *_imageio )
{
int x=-1;
@@ -50,10 +54,14 @@ KDE_EXPORT void kimgio_xv_read( QImageIO
sscanf(str, "%d %d %d", &x, &y, &maxval);
if (maxval != 255) return;
+ int blocksize = x*y;
+ if(x < 0 || y < 0 || blocksize < x || blocksize < y)
+ return;
// now follows a binary block of x*y bytes.
- int blocksize = x*y;
- char *block = new char[ blocksize ];
+ char *block = (char*) malloc(blocksize);
+ if(!block)
+ return;
if (iodev->readBlock(block, blocksize) != blocksize )
{
@@ -62,6 +70,10 @@ KDE_EXPORT void kimgio_xv_read( QImageIO
// Create the image
QImage image( x, y, 8, maxval + 1, QImage::BigEndian );
+ if( image.isNull()) {
+ free(block);
+ return;
+ }
// how do the color handling? they are absolute 24bpp
// or at least can be calculated as such.
@@ -69,29 +81,9 @@ KDE_EXPORT void kimgio_xv_read( QImageIO
for ( int j = 0; j < 256; j++ )
{
-// ----------- OLIVER EIDEN
-// That is the old-code !
-/* r = ((int) ((j >> 5) & 0x07)) << 5;
- g = ((int) ((j >> 2) & 0x07)) << 5;
- b = ((int) ((j >> 0) & 0x03)) << 6;*/
-
-
-// That is the code-how xv, decode 3-3-2 pixmaps, it is slighly different,
-// but yields much better visuals results
-/* r = (((int) ((j >> 5) & 0x07)) *255) / 7;
- g = (((int) ((j >> 2) & 0x07)) *255) / 7;
- b = (((int) ((j >> 0) & 0x03)) *255) / 3;*/
-
-// This is the same as xv, with multiplications/divisions replaced by indexing
-
-// Look-up table to avoid multiplications and divisons
- static int b_255_3[]= {0,85,170,255}, // index*255/3
- rg_255_7[]={0,36,72,109,145,182,218,255}; // index *255/7
-
r = rg_255_7[((j >> 5) & 0x07)];
g = rg_255_7[((j >> 2) & 0x07)];
b = b_255_3[((j >> 0) & 0x03)];
-// ---------------
image.setColor( j, qRgb( r, g, b ) );
}
@@ -104,7 +96,7 @@ KDE_EXPORT void kimgio_xv_read( QImageIO
_imageio->setImage( image );
_imageio->setStatus( 0 );
- delete [] block;
+ free(block);
return;
}
|