1//---------------------------------------------------------------------------
2// This file is generated by wxPython's SIP generator.  Do not edit by hand.
3//
4// Copyright: (c) 2018 by Total Control Software
5// License:   wxWindows License
6//
7// This file will be included by _core.sip
8//
9//---------------------------------------------------------------------------
10
11%ModuleHeaderCode
12#include <wx/rawbmp.h>
13typedef wxNativePixelData::Iterator wxNativePixelData_Accessor;
14typedef wxAlphaPixelData::Iterator wxAlphaPixelData_Accessor;
15%End
16
17
18//---------------------------------------------------------------------------
19
20class wxPixelDataBase
21{
22    %Docstring
23        PixelDataBase()
24    %End
25public:
26    wxPoint GetOrigin() const;
27    %Docstring
28        GetOrigin() -> Point
29
30        Return the origin of the area this pixel data represents.
31    %End
32
33    int GetWidth() const;
34    %Docstring
35        GetWidth() -> int
36
37        Return the width of the area this pixel data represents.
38    %End
39
40    int GetHeight() const;
41    %Docstring
42        GetHeight() -> int
43
44        Return the height of the area this pixel data represents.
45    %End
46
47    wxSize GetSize() const;
48    %Docstring
49        GetSize() -> Size
50
51        Return the size of the area this pixel data represents.
52    %End
53
54    int GetRowStride() const;
55    %Docstring
56        GetRowStride() -> int
57
58        Returns the distance between the start of one row to the start of the
59        next row.
60    %End
61
62    public:
63
64
65    %Property(name=Height, get=GetHeight)
66    %Property(name=Origin, get=GetOrigin)
67    %Property(name=RowStride, get=GetRowStride)
68    %Property(name=Size, get=GetSize)
69    %Property(name=Width, get=GetWidth)
70
71protected:
72    wxPixelDataBase();
73
74};  // end of class wxPixelDataBase
75
76
77%Extract(id=pycode_core)
78def _PixelDataBase___iter__(self):
79    """
80    Create and return an iterator/generator object for traversing
81    this pixel data object.
82    """
83    width  = self.GetWidth()
84    height = self.GetHeight()
85    pixels = self.GetPixels() # this is the C++ iterator
86
87    # This class is a facade over the pixels object (using the one
88    # in the enclosing scope) that only allows Get() and Set() to
89    # be called.
90    class PixelFacade(object):
91        def Get(self):
92            return pixels.Get()
93        def Set(self, *args, **kw):
94            return pixels.Set(*args, **kw)
95        def __str__(self):
96            return str(self.Get())
97        def __repr__(self):
98            return 'pixel(%d,%d): %s' % (x,y,self.Get())
99        X = property(lambda self: x)
100        Y = property(lambda self: y)
101
102    import sys
103    rangeFunc = range if sys.version_info >= (3,) else xrange
104
105    pf = PixelFacade()
106    for y in rangeFunc(height):
107        pixels.MoveTo(self, 0, y)
108        for x in rangeFunc(width):
109            # We always generate the same pf instance, but it
110            # accesses the pixels object which we use to iterate
111            # over the pixel buffer.
112            yield pf
113            pixels.nextPixel()
114PixelDataBase.__iter__ = _PixelDataBase___iter__
115del _PixelDataBase___iter__
116%End
117
118class wxNativePixelData : wxPixelDataBase
119{
120    %Docstring
121        NativePixelData(bmp)
122        NativePixelData(bmp, rect)
123        NativePixelData(bmp, pt, sz)
124
125        A class providing direct access to a :class:`wx.Bitmap`'s
126        internal data without alpha channel (RGB).
127    %End
128public:
129    wxNativePixelData(
130        wxBitmap& bmp
131    );
132
133    wxNativePixelData(
134        wxBitmap& bmp,
135        const wxRect& rect
136    );
137
138    wxNativePixelData(
139        wxBitmap& bmp,
140        const wxPoint& pt,
141        const wxSize& sz
142    );
143
144    ~wxNativePixelData();
145
146    wxNativePixelData_Accessor GetPixels() const;
147    %Docstring
148        GetPixels() -> NativePixelData_Accessor
149    %End
150
151    int __nonzero__();
152    %Docstring
153        __nonzero__() -> int
154    %End
155    %MethodCode
156        PyErr_Clear();
157        Py_BEGIN_ALLOW_THREADS
158        sipRes = _wxNativePixelData___nonzero__(sipCpp);
159        Py_END_ALLOW_THREADS
160        if (PyErr_Occurred()) sipIsErr = 1;
161    %End
162    %TypeCode
163    int _wxNativePixelData___nonzero__(wxNativePixelData* self)
164    {
165        return (int)self->operator bool();
166    }
167    %End
168
169    int __bool__();
170    %Docstring
171        __bool__() -> int
172    %End
173    %MethodCode
174        PyErr_Clear();
175        Py_BEGIN_ALLOW_THREADS
176        sipRes = _wxNativePixelData___bool__(sipCpp);
177        Py_END_ALLOW_THREADS
178        if (PyErr_Occurred()) sipIsErr = 1;
179    %End
180    %TypeCode
181    int _wxNativePixelData___bool__(wxNativePixelData* self)
182    {
183        return self->operator bool();
184    }
185    %End
186
187    public:
188
189
190    %Property(name=Pixels, get=GetPixels)
191};  // end of class wxNativePixelData
192
193
194class wxNativePixelData_Accessor
195{
196    %Docstring
197        NativePixelData_Accessor(data)
198        NativePixelData_Accessor(bmp, data)
199        NativePixelData_Accessor()
200    %End
201public:
202    wxNativePixelData_Accessor(
203        wxNativePixelData& data
204    );
205
206    wxNativePixelData_Accessor(
207        wxBitmap& bmp,
208        wxNativePixelData& data
209    );
210
211    wxNativePixelData_Accessor();
212
213    ~wxNativePixelData_Accessor();
214
215    void Reset(
216        const wxNativePixelData& data
217    );
218    %Docstring
219        Reset(data)
220    %End
221
222    bool IsOk() const;
223    %Docstring
224        IsOk() -> bool
225    %End
226
227    int __nonzero__();
228    %Docstring
229        __nonzero__() -> int
230    %End
231    %MethodCode
232        PyErr_Clear();
233        Py_BEGIN_ALLOW_THREADS
234        sipRes = _wxNativePixelData_Accessor___nonzero__(sipCpp);
235        Py_END_ALLOW_THREADS
236        if (PyErr_Occurred()) sipIsErr = 1;
237    %End
238    %TypeCode
239    int _wxNativePixelData_Accessor___nonzero__(wxNativePixelData_Accessor* self)
240    {
241        return (int)self->IsOk();
242    }
243    %End
244
245    int __bool__();
246    %Docstring
247        __bool__() -> int
248    %End
249    %MethodCode
250        PyErr_Clear();
251        Py_BEGIN_ALLOW_THREADS
252        sipRes = _wxNativePixelData_Accessor___bool__(sipCpp);
253        Py_END_ALLOW_THREADS
254        if (PyErr_Occurred()) sipIsErr = 1;
255    %End
256    %TypeCode
257    int _wxNativePixelData_Accessor___bool__(wxNativePixelData_Accessor* self)
258    {
259        return self->IsOk();
260    }
261    %End
262
263    void Offset(
264        const wxNativePixelData& data,
265        int x,
266        int y
267    );
268    %Docstring
269        Offset(data, x, y)
270    %End
271
272    void OffsetX(
273        const wxNativePixelData& data,
274        int x
275    );
276    %Docstring
277        OffsetX(data, x)
278    %End
279
280    void OffsetY(
281        const wxNativePixelData& data,
282        int y
283    );
284    %Docstring
285        OffsetY(data, y)
286    %End
287
288    void MoveTo(
289        const wxNativePixelData& data,
290        int x,
291        int y
292    );
293    %Docstring
294        MoveTo(data, x, y)
295    %End
296
297    void nextPixel();
298    %Docstring
299        nextPixel()
300    %End
301    %MethodCode
302        PyErr_Clear();
303        Py_BEGIN_ALLOW_THREADS
304        _wxNativePixelData_Accessor_nextPixel(sipCpp);
305        Py_END_ALLOW_THREADS
306        if (PyErr_Occurred()) sipIsErr = 1;
307    %End
308    %TypeCode
309    void _wxNativePixelData_Accessor_nextPixel(wxNativePixelData_Accessor* self)
310    {
311        ++(*self);
312    }
313    %End
314
315    void Set(byte red,  byte green,  byte blue);
316    %Docstring
317        Set(red, green, blue)
318    %End
319    %MethodCode
320        PyErr_Clear();
321        Py_BEGIN_ALLOW_THREADS
322        _wxNativePixelData_Accessor_Set(sipCpp, red, green, blue);
323        Py_END_ALLOW_THREADS
324        if (PyErr_Occurred()) sipIsErr = 1;
325    %End
326    %TypeCode
327    void _wxNativePixelData_Accessor_Set(wxNativePixelData_Accessor* self, byte red, byte green, byte blue)
328    {
329        self->Red()   = red;
330        self->Green() = green;
331        self->Blue()  = blue;
332    }
333    %End
334
335    PyObject* Get();
336    %Docstring
337        Get() -> PyObject
338    %End
339    %MethodCode
340        PyErr_Clear();
341        Py_BEGIN_ALLOW_THREADS
342        sipRes = _wxNativePixelData_Accessor_Get(sipCpp);
343        Py_END_ALLOW_THREADS
344        if (PyErr_Occurred()) sipIsErr = 1;
345    %End
346    %TypeCode
347    PyObject* _wxNativePixelData_Accessor_Get(wxNativePixelData_Accessor* self)
348    {
349        wxPyThreadBlocker blocker;
350        PyObject* rv = PyTuple_New(3);
351        PyTuple_SetItem(rv, 0, wxPyInt_FromLong(self->Red()));
352        PyTuple_SetItem(rv, 1, wxPyInt_FromLong(self->Green()));
353        PyTuple_SetItem(rv, 2, wxPyInt_FromLong(self->Blue()));
354        return rv;
355    }
356    %End
357
358};  // end of class wxNativePixelData_Accessor
359
360
361class wxAlphaPixelData : wxPixelDataBase
362{
363    %Docstring
364        AlphaPixelData(bmp)
365        AlphaPixelData(bmp, rect)
366        AlphaPixelData(bmp, pt, sz)
367
368        A class providing direct access to a :class:`wx.Bitmap`'s
369        internal data including the alpha channel (RGBA).
370    %End
371public:
372    wxAlphaPixelData(
373        wxBitmap& bmp
374    );
375
376    wxAlphaPixelData(
377        wxBitmap& bmp,
378        const wxRect& rect
379    );
380
381    wxAlphaPixelData(
382        wxBitmap& bmp,
383        const wxPoint& pt,
384        const wxSize& sz
385    );
386
387    ~wxAlphaPixelData();
388
389    wxAlphaPixelData_Accessor GetPixels() const;
390    %Docstring
391        GetPixels() -> AlphaPixelData_Accessor
392    %End
393
394    int __nonzero__();
395    %Docstring
396        __nonzero__() -> int
397    %End
398    %MethodCode
399        PyErr_Clear();
400        Py_BEGIN_ALLOW_THREADS
401        sipRes = _wxAlphaPixelData___nonzero__(sipCpp);
402        Py_END_ALLOW_THREADS
403        if (PyErr_Occurred()) sipIsErr = 1;
404    %End
405    %TypeCode
406    int _wxAlphaPixelData___nonzero__(wxAlphaPixelData* self)
407    {
408        return (int)self->operator bool();
409    }
410    %End
411
412    int __bool__();
413    %Docstring
414        __bool__() -> int
415    %End
416    %MethodCode
417        PyErr_Clear();
418        Py_BEGIN_ALLOW_THREADS
419        sipRes = _wxAlphaPixelData___bool__(sipCpp);
420        Py_END_ALLOW_THREADS
421        if (PyErr_Occurred()) sipIsErr = 1;
422    %End
423    %TypeCode
424    int _wxAlphaPixelData___bool__(wxAlphaPixelData* self)
425    {
426        return self->operator bool();
427    }
428    %End
429
430    public:
431
432
433    %Property(name=Pixels, get=GetPixels)
434};  // end of class wxAlphaPixelData
435
436
437class wxAlphaPixelData_Accessor
438{
439    %Docstring
440        AlphaPixelData_Accessor(data)
441        AlphaPixelData_Accessor(bmp, data)
442        AlphaPixelData_Accessor()
443    %End
444public:
445    wxAlphaPixelData_Accessor(
446        wxAlphaPixelData& data
447    );
448
449    wxAlphaPixelData_Accessor(
450        wxBitmap& bmp,
451        wxAlphaPixelData& data
452    );
453
454    wxAlphaPixelData_Accessor();
455
456    ~wxAlphaPixelData_Accessor();
457
458    void Reset(
459        const wxAlphaPixelData& data
460    );
461    %Docstring
462        Reset(data)
463    %End
464
465    bool IsOk() const;
466    %Docstring
467        IsOk() -> bool
468    %End
469
470    int __nonzero__();
471    %Docstring
472        __nonzero__() -> int
473    %End
474    %MethodCode
475        PyErr_Clear();
476        Py_BEGIN_ALLOW_THREADS
477        sipRes = _wxAlphaPixelData_Accessor___nonzero__(sipCpp);
478        Py_END_ALLOW_THREADS
479        if (PyErr_Occurred()) sipIsErr = 1;
480    %End
481    %TypeCode
482    int _wxAlphaPixelData_Accessor___nonzero__(wxAlphaPixelData_Accessor* self)
483    {
484        return (int)self->IsOk();
485    }
486    %End
487
488    int __bool__();
489    %Docstring
490        __bool__() -> int
491    %End
492    %MethodCode
493        PyErr_Clear();
494        Py_BEGIN_ALLOW_THREADS
495        sipRes = _wxAlphaPixelData_Accessor___bool__(sipCpp);
496        Py_END_ALLOW_THREADS
497        if (PyErr_Occurred()) sipIsErr = 1;
498    %End
499    %TypeCode
500    int _wxAlphaPixelData_Accessor___bool__(wxAlphaPixelData_Accessor* self)
501    {
502        return self->IsOk();
503    }
504    %End
505
506    void Offset(
507        const wxAlphaPixelData& data,
508        int x,
509        int y
510    );
511    %Docstring
512        Offset(data, x, y)
513    %End
514
515    void OffsetX(
516        const wxAlphaPixelData& data,
517        int x
518    );
519    %Docstring
520        OffsetX(data, x)
521    %End
522
523    void OffsetY(
524        const wxAlphaPixelData& data,
525        int y
526    );
527    %Docstring
528        OffsetY(data, y)
529    %End
530
531    void MoveTo(
532        const wxAlphaPixelData& data,
533        int x,
534        int y
535    );
536    %Docstring
537        MoveTo(data, x, y)
538    %End
539
540    void nextPixel();
541    %Docstring
542        nextPixel()
543    %End
544    %MethodCode
545        PyErr_Clear();
546        Py_BEGIN_ALLOW_THREADS
547        _wxAlphaPixelData_Accessor_nextPixel(sipCpp);
548        Py_END_ALLOW_THREADS
549        if (PyErr_Occurred()) sipIsErr = 1;
550    %End
551    %TypeCode
552    void _wxAlphaPixelData_Accessor_nextPixel(wxAlphaPixelData_Accessor* self)
553    {
554        ++(*self);
555    }
556    %End
557
558    void Set(byte red,  byte green,  byte blue,  byte alpha);
559    %Docstring
560        Set(red, green, blue, alpha)
561    %End
562    %MethodCode
563        PyErr_Clear();
564        Py_BEGIN_ALLOW_THREADS
565        _wxAlphaPixelData_Accessor_Set(sipCpp, red, green, blue, alpha);
566        Py_END_ALLOW_THREADS
567        if (PyErr_Occurred()) sipIsErr = 1;
568    %End
569    %TypeCode
570    void _wxAlphaPixelData_Accessor_Set(wxAlphaPixelData_Accessor* self, byte red, byte green, byte blue, byte alpha)
571    {
572        self->Red()   = wxPy_premultiply(red,   alpha);
573        self->Green() = wxPy_premultiply(green, alpha);
574        self->Blue()  = wxPy_premultiply(blue,  alpha);
575        self->Alpha() = alpha;
576    }
577    %End
578
579    PyObject* Get();
580    %Docstring
581        Get() -> PyObject
582    %End
583    %MethodCode
584        PyErr_Clear();
585        Py_BEGIN_ALLOW_THREADS
586        sipRes = _wxAlphaPixelData_Accessor_Get(sipCpp);
587        Py_END_ALLOW_THREADS
588        if (PyErr_Occurred()) sipIsErr = 1;
589    %End
590    %TypeCode
591    PyObject* _wxAlphaPixelData_Accessor_Get(wxAlphaPixelData_Accessor* self)
592    {
593        wxPyThreadBlocker blocker;
594        PyObject* rv = PyTuple_New(4);
595        int red   = self->Red();
596        int green = self->Green();
597        int blue  = self->Blue();
598        int alpha = self->Alpha();
599
600        PyTuple_SetItem(rv, 0, wxPyInt_FromLong( wxPy_unpremultiply(red,   alpha) ));
601        PyTuple_SetItem(rv, 1, wxPyInt_FromLong( wxPy_unpremultiply(green, alpha) ));
602        PyTuple_SetItem(rv, 2, wxPyInt_FromLong( wxPy_unpremultiply(blue,  alpha) ));
603        PyTuple_SetItem(rv, 3, wxPyInt_FromLong( alpha ));
604        return rv;
605    }
606    %End
607
608};  // end of class wxAlphaPixelData_Accessor
609
610
611
612//---------------------------------------------------------------------------
613
614