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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>KSquirrel: development</title>
<meta name='Author' content='Baryshev Dmitry/Krasu'>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<link rel='stylesheet' href='styles.css' type='text/css'>
</head>
<body>
When SQ_LibraryHandler loaded all found libraries, KSquirrel obtains the ability to decode any supported image format.
Here is a sample code to decode some image with library. Error handling is turned <b>off</b>. You can find real examples in
source distribution of ksquirrel-libs.
<p><b><u>Sample</u></b>
<table cellpadding="2" cellspacing="2" width="70%" align="center">
<tbody>
<tr>
<td valign="top" bgcolor="#CCCCCC">
<pre>
int i, j, current = 0;
fmt_info finfo;
RGBA *image = NULL, *scan;
fmt_codec_base *codeK;
TQString file = "/home/krasu/animation1.gif";
<b>Determine the library and codec</b>
codeK = SQ_LibraryHandler::instance()->libraryForFile(file)->codec;
<b>Init: open file, etc.</b>
codeK->read_init(file.ascii());
while(true)
{
i = codeK->read_next();
<b>Break, if we've decoded all available images in file</b>
if(i == SQE_NOTOK)
break;
<b>Obtain the latest information (current image dimensions, etc.)</b>
finfo = codeK->information();
<b>realloc memory for new image</b>
image = (RGBA *)realloc(image, finfo.image[current].w * finfo.image[current].h * sizeof(RGBA));
<b>fill with white color (RGBA(255,255,255,255))</b>
memset(image, 255, finfo.image[current].w * finfo.image[current].h * sizeof(RGBA));
for(int pass = 0;pass < finfo.image[current].passes;pass++)
{
codeK->read_next_pass();
for(j = 0;j < finfo.image[current].h;j++)
{
scan = image + j * finfo.image[current].w;
codeK->read_scanline(scan);
}
}
<b>Do something with decoded image here.
...</b>
current++;
}
codeK->read_close();
free(image);
</pre>
</td>
</tr>
</tbody>
</table>
</body>
</html>
|