summaryrefslogtreecommitdiffstats
path: root/sip/qt/qimage.sip
blob: b1628c5bbfef7879fd2ae6b2b064dcd6b7a73cf8 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
// This is the SIP interface definition for TQImage, TQImageIO and
// TQImageTextKeyLang.
//
// Copyright (c) 2007
// 	Riverbank Computing Limited <[email protected]>
// 
// This file is part of PyTQt.
// 
// This copy of PyTQt is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2, or (at your option) any later
// version.
// 
// PyTQt is supplied in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
// details.
// 
// You should have received a copy of the GNU General Public License along with
// PyTQt; see the file LICENSE.  If not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


%ExportedDoc
<Sect2><Title>TQImage</Title>
<Para>
The Python <Literal>==</Literal> and <Literal>!=</Literal> operators are
supported.
</Para>

<FuncSynopsis>
        <FuncDef><Function>TQImage</Function></FuncDef>
        <ParamDef>const char *<Parameter>xpm</Parameter>[]</ParamDef>
</FuncSynopsis>
<Para>
This takes a list of strings as its parameter.
</Para>

<FuncSynopsis>
        <FuncDef><Function>TQImage</Function></FuncDef>
        <ParamDef>uchar *<Parameter>data</Parameter></ParamDef>
        <ParamDef>int <Parameter>w</Parameter></ParamDef>
        <ParamDef>int <Parameter>h</Parameter></ParamDef>
        <ParamDef>int <Parameter>depth</Parameter></ParamDef>
        <ParamDef>TQRgb *<Parameter>colorTable</Parameter></ParamDef>
        <ParamDef>int <Parameter>numColors</Parameter></ParamDef>
        <ParamDef>Endian <Parameter>bitOrder</Parameter></ParamDef>
</FuncSynopsis>
<Para>
The <Literal>colorTable</Literal> parameter is a list of TQRgb instances or
None.  (TQt v2.1+)
</Para>

<FuncSynopsis>
        <FuncDef>uchar *<Function>bits</Function></FuncDef>
        <ParamDef></ParamDef>
</FuncSynopsis>
<Para>
The return value is a <Literal>sip.voidptr</Literal> object which is only
useful if passed to another Python module.
</Para>

<FuncSynopsis>
        <FuncDef>TQRgb *<Function>colorTable</Function></FuncDef>
        <ParamDef></ParamDef>
</FuncSynopsis>
<Para>
The return value is a <Literal>sip.voidptr</Literal> object which is only
useful if passed to another Python module.
</Para>

<FuncSynopsis>
        <FuncDef>TQImage <Function>convertDepthWithPalette</Function></FuncDef>
        <ParamDef>int</ParamDef>
        <ParamDef>TQRgb *<Parameter>p</Parameter></ParamDef>
        <ParamDef>int <Parameter>pc</Parameter></ParamDef>
        <ParamDef>int <Parameter>cf</Parameter> = 0</ParamDef>
</FuncSynopsis>
<Para>
Not implemented.
</Para>

<FuncSynopsis>
        <FuncDef>uchar **<Function>jumpTable</Function></FuncDef>
        <ParamDef></ParamDef>
</FuncSynopsis>
<Para>
The return value is a <Literal>sip.voidptr</Literal> object which is only
useful if passed to another Python module.
</Para>

<FuncSynopsis>
	<FuncDef>bool <Function>loadFromData</Function></FuncDef>
	<ParamDef>const uchar *<Parameter>buf</Parameter></ParamDef>
	<ParamDef>uint <Parameter>len</Parameter></ParamDef>
	<ParamDef>const char *<Parameter>format</Parameter> = 0</ParamDef>
	<ParamDef>ColorMode <Parameter>mode</Parameter> = Auto</ParamDef>
</FuncSynopsis>
<Para>
<Literal>len</Literal> is derived from <Literal>buf</Literal> and not passed as
a parameter.
</Para>

<FuncSynopsis>
        <FuncDef>uchar *<Function>scanLine</Function></FuncDef>
        <ParamDef>int <Parameter>i</Parameter></ParamDef>
</FuncSynopsis>
<Para>
The return value is a <Literal>sip.voidptr</Literal> object which is only
useful if passed to another Python module.
</Para>
</Sect2>

<Sect2><Title>TQImageIO</Title>
<FuncSynopsis>
	<FuncDef>static void <Function>defineIOHandler</Function></FuncDef>
	<ParamDef>const char *<Parameter>format</Parameter></ParamDef>
	<ParamDef>const char *<Parameter>header</Parameter></ParamDef>
	<ParamDef>const char *<Parameter>flags</Parameter></ParamDef>
	<ParamDef>image_io_handler <Parameter>read_image</Parameter></ParamDef>
	<ParamDef>image_io_handler <Parameter>write_image</Parameter></ParamDef>
</FuncSynopsis>
<Para>
Not implemented.
</Para>
</Sect2>

<Sect2><Title>TQImageTextKeyLang</Title>
<Para>
<Literal>TQImageTextKeyLang</Literal> is fully implemented.
</Para>
</Sect2>
%End


class TQImage
{
%TypeHeaderCode
#include <tqimage.h>
%End

public:
	enum Endian {
		IgnoreEndian,
		BigEndian,
		LittleEndian
	};

	TQImage();
	TQImage(int,int,int,int = 0,Endian = IgnoreEndian);
	TQImage(const TQSize &,int,int = 0,Endian = IgnoreEndian);
	TQImage(const TQString &,char * = 0);

	TQImage(SIP_PYLIST) [(const char **)];
%MethodCode
		// The Python interface is a list of strings that make up the
		// image.

		const char **str;

		if ((str = PyTQt_qt_ListToArray(a0)) == NULL)
			sipIsErr = 1;
		else
		{
			// There is no wrapper class for TQImage.

			Py_BEGIN_ALLOW_THREADS
			sipCpp = new TQImage(str);
			Py_END_ALLOW_THREADS

			sipFree((void *)str);
		}
%End

	TQImage(const TQByteArray &);

	TQImage(uchar *,int,int,int,SIP_PYLIST /AllowNone/,int,Endian) [(uchar *,int,int,int,int,TQRgb *,int,Endian)];
%MethodCode
		// The Python interface takes a list of TQRgb instances.

		TQRgb *coltab;

		if (a4 == Py_None)
			coltab = 0;
		else
		{
			int len = PyList_Size(a4);

			if (a5 > len)
				a5 = len;

			coltab = new TQRgb[len];

			PyErr_Clear();

			for (int i = 0; i < a5; ++i)
			{
				coltab[i] = PyLong_AsUnsignedLong(PyList_GetItem(a4,i));

				if (PyErr_Occurred())
				{
					delete[] coltab;
					sipIsErr = 1;
					break;
				}
			}
		}

		if (!sipIsErr)
		{
			// There is no wrapper class for TQImage.

			Py_BEGIN_ALLOW_THREADS
			sipCpp = new TQImage(a0,a1,a2,a3,0,a5,(TQImage::Endian)a6);

			if (coltab)
			{
				// Now set the colours using the TQImage's self
				// allocated colour table.  If we had passed in
				// coltab as the colour table then we couldn't
				// have freed it and it would leak.
				for (int i = 0; i < a5; ++i)
					sipCpp -> setColor(i,coltab[i]);

				delete[] coltab;
			}
			Py_END_ALLOW_THREADS
		}
%End

	TQImage(const TQImage &);

	bool operator==(const TQImage &) const;
	bool operator!=(const TQImage &) const;

	void detach();
	TQImage copy() const;
	TQImage copy(int,int,int,int,int = 0) const;
	TQImage copy(const TQRect &) const;
	static TQImage fromMimeSource(const TQString &);
	bool isNull() const;

	int width() const;
	int height() const;
	TQSize size() const;
	TQRect rect() const;
	int depth() const;
	int numColors() const;
	Endian bitOrder() const;

	TQRgb color(int) const;
	void setColor(int,TQRgb);
	void setNumColors(int);

	bool hasAlphaBuffer() const;
	void setAlphaBuffer(bool);

	bool allGray() const;
	bool isGrayscale() const;

	// Actually returns uchar *.
	void *bits() const;
	// Actually returns uchar *.
	void *scanLine(int) const;
	// Actually returns uchar **.
	void *jumpTable() const;
	// Actually returns TQRgb *.
	void *colorTable() const;
	int numBytes() const;
	int bytesPerLine() const;

	bool create(int,int,int,int = 0,Endian = IgnoreEndian);
	bool create(const TQSize &,int,int = 0,Endian = IgnoreEndian);
	void reset();

	void fill(uint);
	void invertPixels(bool = 1);

	TQImage convertDepth(int) const;
//	TQImage convertDepthWithPalette(int,TQRgb *,int,int = 0) const;
	TQImage convertDepth(int,int) const;
	TQImage convertBitOrder(Endian) const;

	enum ScaleMode {
		ScaleFree,
		ScaleMin,
		ScaleMax
	};

	TQImage smoothScale(int,int,ScaleMode = ScaleFree) const;
	TQImage smoothScale(const TQSize &,ScaleMode = ScaleFree) const;
	TQImage scale(int,int,ScaleMode = ScaleFree) const;
	TQImage scale(const TQSize &,ScaleMode = ScaleFree) const;
	TQImage scaleWidth(int) const;
	TQImage scaleHeight(int) const;
	TQImage xForm(const TQWMatrix &) const;

	TQImage createAlphaMask(int = 0) const;
	TQImage createHeuristicMask(bool = 1) const;
	TQImage mirror() const;
	TQImage mirror(bool,bool) const;
	TQImage swapRGB() const;

	static Endian systemBitOrder();
	static Endian systemByteOrder();

	static const char *imageFormat(const TQString &);
	static TQStrList inputFormats();
	static TQStrList outputFormats();
	static TQStringList inputFormatList();
	static TQStringList outputFormatList();
	bool load(const TQString &,const char * = 0);
	bool loadFromData(const uchar * /Array/,uint /ArraySize/,
			  const char * = 0);
	bool loadFromData(TQByteArray,char * = 0);
	bool save(const TQString &,const char *,int = -1) const;
	bool save(TQIODevice *,const char *,int = -1) const;

	bool valid(int,int) const;
	int pixelIndex(int,int) const;
	TQRgb pixel(int,int) const;
	void setPixel(int,int,uint);

	int dotsPerMeterX() const;
	int dotsPerMeterY() const;
	void setDotsPerMeterX(int);
	void setDotsPerMeterY(int);
	TQPoint offset() const;
	void setOffset(const TQPoint &);
%If (TQt_IMAGE_TEXT)
	TQValueList<TQImageTextKeyLang> textList() const;
	TQStringList textLanguages() const;
	TQStringList textKeys() const;
	TQString text(const char *,const char * = 0) const;
	TQString text(const TQImageTextKeyLang &) const;
	void setText(const char *,const char *,const TQString &);
%End
};


void bitBlt(TQImage *,int,int,const TQImage *,int = 0,int = 0,int = -1,int = -1,
	    int = 0);


class TQImageIO
{
%TypeHeaderCode
#include <tqimage.h>
%End

public:
	TQImageIO();
	TQImageIO(TQIODevice *,const char *);
	TQImageIO(const TQString &,const char *);

	const TQImage &image() const;
	int status() const;
	const char *format() const;
	TQIODevice *ioDevice() const;
	TQString fileName() const;
	int quality() const;
	TQString description() const;
	const char *parameters() const;
	float gamma() const;

	void setImage(const TQImage &);
	void setStatus(int);
	void setFormat(const char *);
	void setIODevice(TQIODevice *);
	void setFileName(const TQString &);
	void setQuality(int);
	void setDescription(const TQString &);
	void setParameters(const char *);
	void setGamma(float);

	bool read();
	bool write();

	static const char *imageFormat(const TQString &);
	static const char *imageFormat(TQIODevice *);
	static TQStrList inputFormats();
	static TQStrList outputFormats();

//	static void defineIOHandler(const char *,const char *,const char *,
//				    image_io_handler,image_io_handler);

private:
	TQImageIO(const TQImageIO &);
};


%If (TQt_IMAGE_TEXT)

class TQImageTextKeyLang
{
%TypeHeaderCode
#include <tqimage.h>
%End

public:
	TQImageTextKeyLang(const char *,const char *);
	TQImageTextKeyLang();

	TQCString key;
	TQCString lang;
};

%End


%ModuleHeaderCode
const char **PyTQt_qt_ListToArray(PyObject *lst);
%End


%ModuleCode
// Convert a list of strings to an array of strings on the heap.  Also used by
// TQPixmap.
const char **PyTQt_qt_ListToArray(PyObject *lst)
{
	SIP_SSIZE_T nstr;
	const char **str, **sp;

	nstr = PyList_Size(lst);

	if ((str = (const char **)sipMalloc(nstr * sizeof (char *))) == NULL)
		return NULL;

	// Convert the list.
	sp = str;

	for (int i = 0; i < nstr; ++i)
	{
		PyObject *item = PyList_GetItem(lst, i);
		const char *item_ascii = sipString_AsASCIIString(&item);

		if (item_ascii == NULL)
		{
			sipFree((void *)str);
			return NULL;
		}

		*sp++ = item_ascii;
	}

	return str;
}
%End