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/imaggif.h> 13 #include <wx/imagiff.h> 14 #include <wx/imagjpeg.h> 15 #include <wx/imagpcx.h> 16 #include <wx/imagpng.h> 17 #include <wx/imagpnm.h> 18 #include <wx/imagtga.h> 19 #include <wx/imagtiff.h> 20 #include <wx/imagxpm.h> 21 22#include <wx/anidecod.h> 23%End 24 25 26//--------------------------------------------------------------------------- 27 28enum wxImageResolution 29{ 30 wxIMAGE_RESOLUTION_NONE, 31 wxIMAGE_RESOLUTION_INCHES, 32 wxIMAGE_RESOLUTION_CM 33}; 34 35enum wxImageResizeQuality 36{ 37 wxIMAGE_QUALITY_NEAREST, 38 wxIMAGE_QUALITY_BILINEAR, 39 wxIMAGE_QUALITY_BICUBIC, 40 wxIMAGE_QUALITY_BOX_AVERAGE, 41 wxIMAGE_QUALITY_NORMAL, 42 wxIMAGE_QUALITY_HIGH 43}; 44 45enum wxImagePNGType 46{ 47 wxPNG_TYPE_COLOUR, 48 wxPNG_TYPE_GREY, 49 wxPNG_TYPE_GREY_RED, 50 wxPNG_TYPE_PALETTE 51}; 52 53enum 54{ 55 wxBMP_24BPP, 56 wxBMP_8BPP, 57 wxBMP_8BPP_GREY, 58 wxBMP_8BPP_GRAY, 59 wxBMP_8BPP_RED, 60 wxBMP_8BPP_PALETTE, 61 wxBMP_4BPP, 62 wxBMP_1BPP, 63 wxBMP_1BPP_BW 64}; 65 66const unsigned char wxIMAGE_ALPHA_TRANSPARENT /PyInt/; 67 68const unsigned char wxIMAGE_ALPHA_OPAQUE /PyInt/; 69 70const unsigned char wxIMAGE_ALPHA_THRESHOLD /PyInt/; 71 72class wxImage : wxObject 73{ 74 %Docstring 75 Image() 76 Image(width, height, clear=True) 77 Image(sz, clear=True) 78 Image(name, type=BITMAP_TYPE_ANY, index=-1) 79 Image(name, mimetype, index=-1) 80 Image(stream, type=BITMAP_TYPE_ANY, index=-1) 81 Image(stream, mimetype, index=-1) 82 Image(width, height, data) 83 Image(width, height, data, alpha) 84 Image(size, data) 85 Image(size, data, alpha) 86 87 This class encapsulates a platform-independent image. 88 %End 89 %TypeHeaderCode 90 #include <wx/image.h> 91 %End 92 93public: 94public: 95 class HSVValue 96 { 97 %Docstring 98 HSVValue(h=0.0, s=0.0, v=0.0) 99 100 A simple class which stores hue, saturation and value as doubles in 101 the range 0.0-1.0. 102 %End 103 %TypeHeaderCode 104 #include <wx/image.h> 105 %End 106 107 public: 108 HSVValue( 109 double h = 0.0, 110 double s = 0.0, 111 double v = 0.0 112 ); 113 114 double hue; 115 116 double saturation; 117 118 double value; 119 120 }; // end of class HSVValue 121 122 123public: 124 class RGBValue 125 { 126 %Docstring 127 RGBValue(r=0, g=0, b=0) 128 129 A simple class which stores red, green and blue values as 8 bit 130 unsigned integers in the range of 0-255. 131 %End 132 %TypeHeaderCode 133 #include <wx/image.h> 134 %End 135 136 public: 137 RGBValue( 138 unsigned char r /PyInt/ = 0, 139 unsigned char g /PyInt/ = 0, 140 unsigned char b /PyInt/ = 0 141 ); 142 143 unsigned char red /PyInt/; 144 145 unsigned char green /PyInt/; 146 147 unsigned char blue /PyInt/; 148 149 }; // end of class RGBValue 150 151 152 wxImage(); 153 154 wxImage( 155 int width, 156 int height, 157 bool clear = true 158 ); 159 160 wxImage( 161 const wxSize & sz, 162 bool clear = true 163 ); 164 165 wxImage( 166 const wxString & name, 167 wxBitmapType type = wxBITMAP_TYPE_ANY, 168 int index = -1 169 ); 170 %PreMethodCode 171 if (!wxPyCheckForApp()) return NULL; 172 %End 173 174 wxImage( 175 const wxString & name, 176 const wxString & mimetype, 177 int index = -1 178 ); 179 180 wxImage( 181 wxInputStream & stream, 182 wxBitmapType type = wxBITMAP_TYPE_ANY, 183 int index = -1 184 ); 185 186 wxImage( 187 wxInputStream & stream, 188 const wxString & mimetype, 189 int index = -1 190 ); 191 192 wxImage(int width, int height, wxPyBuffer* data) /NoDerived/; 193 %MethodCode 194 if (! data->checkSize(width*height*3)) 195 return NULL; 196 void* copy = data->copy(); 197 if (! copy) 198 return NULL; 199 sipCpp = new sipwxImage; 200 sipCpp->Create(width, height, (byte*)copy); 201 %End 202 203 wxImage(int width, int height, wxPyBuffer* data, wxPyBuffer* alpha) /NoDerived/; 204 %MethodCode 205 void* dcopy; void* acopy; 206 if (!data->checkSize(width*height*3) || !alpha->checkSize(width*height)) 207 return NULL; 208 if ((dcopy = data->copy()) == NULL || (acopy = alpha->copy()) == NULL) 209 return NULL; 210 sipCpp = new sipwxImage; 211 sipCpp->Create(width, height, (byte*)dcopy, (byte*)acopy, false); 212 %End 213 214 wxImage(const wxSize& size, wxPyBuffer* data) /NoDerived/; 215 %MethodCode 216 if (! data->checkSize(size->x*size->y*3)) 217 return NULL; 218 void* copy = data->copy(); 219 if (! copy) 220 return NULL; 221 sipCpp = new sipwxImage; 222 sipCpp->Create(size->x, size->y, (byte*)copy, false); 223 %End 224 225 wxImage(const wxSize& size, wxPyBuffer* data, wxPyBuffer* alpha) /NoDerived/; 226 %MethodCode 227 void* dcopy; void* acopy; 228 if (!data->checkSize(size->x*size->y*3) || !alpha->checkSize(size->x*size->y)) 229 return NULL; 230 if ((dcopy = data->copy()) == NULL || (acopy = alpha->copy()) == NULL) 231 return NULL; 232 sipCpp = new sipwxImage; 233 sipCpp->Create(size->x, size->y, (byte*)dcopy, (byte*)acopy, false); 234 %End 235 236 virtual 237 ~wxImage(); 238 239 wxImage Copy() const; 240 %Docstring 241 Copy() -> Image 242 243 Returns an identical copy of this image. 244 %End 245 246 bool Create( 247 int width, 248 int height, 249 bool clear = true 250 ); 251 %Docstring 252 Create(width, height, clear=True) -> bool 253 Create(sz, clear=True) -> bool 254 Create(width, height, data) -> bool 255 Create(width, height, data, alpha) -> bool 256 Create(size, data) -> bool 257 Create(size, data, alpha) -> bool 258 259 Creates a fresh image. 260 %End 261 262 bool Create( 263 const wxSize & sz, 264 bool clear = true 265 ); 266 267 bool Create(int width, int height, wxPyBuffer* data); 268 %MethodCode 269 PyErr_Clear(); 270 Py_BEGIN_ALLOW_THREADS 271 sipRes = _wxImage_Create(sipCpp, width, height, data); 272 Py_END_ALLOW_THREADS 273 if (PyErr_Occurred()) sipIsErr = 1; 274 %End 275 %TypeCode 276 bool _wxImage_Create(wxImage* self, int width, int height, wxPyBuffer* data) 277 { 278 if (! data->checkSize(width*height*3)) 279 return false; 280 void* copy = data->copy(); 281 if (! copy) 282 return false; 283 return self->Create(width, height, (byte*)copy); 284 } 285 %End 286 287 bool Create(int width, int height, wxPyBuffer* data, wxPyBuffer* alpha); 288 %MethodCode 289 PyErr_Clear(); 290 Py_BEGIN_ALLOW_THREADS 291 sipRes = _wxImage_Create(sipCpp, width, height, data, alpha); 292 Py_END_ALLOW_THREADS 293 if (PyErr_Occurred()) sipIsErr = 1; 294 %End 295 %TypeCode 296 bool _wxImage_Create(wxImage* self, int width, int height, wxPyBuffer* data, wxPyBuffer* alpha) 297 { 298 void* dcopy; void* acopy; 299 if (!data->checkSize(width*height*3) || !alpha->checkSize(width*height)) 300 return false; 301 if ((dcopy = data->copy()) == NULL || (acopy = alpha->copy()) == NULL) 302 return false; 303 return self->Create(width, height, (byte*)dcopy, (byte*)acopy); 304 } 305 %End 306 307 bool Create(const wxSize& size, wxPyBuffer* data); 308 %MethodCode 309 PyErr_Clear(); 310 Py_BEGIN_ALLOW_THREADS 311 sipRes = _wxImage_Create(sipCpp, size, data); 312 Py_END_ALLOW_THREADS 313 if (PyErr_Occurred()) sipIsErr = 1; 314 %End 315 %TypeCode 316 bool _wxImage_Create(wxImage* self, const wxSize* size, wxPyBuffer* data) 317 { 318 if (! data->checkSize(size->x*size->y*3)) 319 return false; 320 void* copy = data->copy(); 321 if (! copy) 322 return false; 323 return self->Create(size->x, size->y, (byte*)copy); 324 } 325 %End 326 327 bool Create(const wxSize& size, wxPyBuffer* data, wxPyBuffer* alpha); 328 %MethodCode 329 PyErr_Clear(); 330 Py_BEGIN_ALLOW_THREADS 331 sipRes = _wxImage_Create(sipCpp, size, data, alpha); 332 Py_END_ALLOW_THREADS 333 if (PyErr_Occurred()) sipIsErr = 1; 334 %End 335 %TypeCode 336 bool _wxImage_Create(wxImage* self, const wxSize* size, wxPyBuffer* data, wxPyBuffer* alpha) 337 { 338 void* dcopy; void* acopy; 339 if (!data->checkSize(size->x*size->y*3) || !alpha->checkSize(size->x*size->y)) 340 return false; 341 if ((dcopy = data->copy()) == NULL || (acopy = alpha->copy()) == NULL) 342 return false; 343 return self->Create(size->x, size->y, (byte*)dcopy, (byte*)acopy); 344 } 345 %End 346 347 void Clear( 348 unsigned char value = 0 349 ); 350 %Docstring 351 Clear(value=0) 352 353 Initialize the image data with zeroes (the default) or with the byte 354 value given as value. 355 %End 356 357 void Destroy(); 358 %Docstring 359 Destroy() 360 361 Destroys the image data. 362 %End 363 364 void InitAlpha(); 365 %Docstring 366 InitAlpha() 367 368 Initializes the image alpha channel data. 369 %End 370 371 wxImage Blur( 372 int blurRadius 373 ) const; 374 %Docstring 375 Blur(blurRadius) -> Image 376 377 Blurs the image in both horizontal and vertical directions by the 378 specified pixel blurRadius. 379 %End 380 381 wxImage BlurHorizontal( 382 int blurRadius 383 ) const; 384 %Docstring 385 BlurHorizontal(blurRadius) -> Image 386 387 Blurs the image in the horizontal direction only. 388 %End 389 390 wxImage BlurVertical( 391 int blurRadius 392 ) const; 393 %Docstring 394 BlurVertical(blurRadius) -> Image 395 396 Blurs the image in the vertical direction only. 397 %End 398 399 wxImage Mirror( 400 bool horizontally = true 401 ) const; 402 %Docstring 403 Mirror(horizontally=True) -> Image 404 405 Returns a mirrored copy of the image. 406 %End 407 408 void Paste( 409 const wxImage & image, 410 int x, 411 int y 412 ); 413 %Docstring 414 Paste(image, x, y) 415 416 Copy the data of the given image to the specified position in this 417 image. 418 %End 419 420 void Replace( 421 unsigned char r1 /PyInt/, 422 unsigned char g1 /PyInt/, 423 unsigned char b1 /PyInt/, 424 unsigned char r2 /PyInt/, 425 unsigned char g2 /PyInt/, 426 unsigned char b2 /PyInt/ 427 ); 428 %Docstring 429 Replace(r1, g1, b1, r2, g2, b2) 430 431 Replaces the colour specified by r1,g1,b1 by the colour r2,g2,b2. 432 %End 433 434 wxImage & Rescale( 435 int width, 436 int height, 437 wxImageResizeQuality quality = wxIMAGE_QUALITY_NORMAL 438 ); 439 %Docstring 440 Rescale(width, height, quality=IMAGE_QUALITY_NORMAL) -> Image 441 442 Changes the size of the image in-place by scaling it: after a call to 443 this function,the image will have the given width and height. 444 %End 445 446 wxImage & Resize( 447 const wxSize & size, 448 const wxPoint & pos, 449 int red = -1, 450 int green = -1, 451 int blue = -1 452 ); 453 %Docstring 454 Resize(size, pos, red=-1, green=-1, blue=-1) -> Image 455 456 Changes the size of the image in-place without scaling it by adding 457 either a border with the given colour or cropping as necessary. 458 %End 459 460 wxImage Rotate( 461 double angle, 462 const wxPoint & rotationCentre, 463 bool interpolating = true, 464 wxPoint * offsetAfterRotation = NULL 465 ) const; 466 %Docstring 467 Rotate(angle, rotationCentre, interpolating=True, offsetAfterRotation=None) -> Image 468 469 Rotates the image about the given point, by angle radians. 470 %End 471 472 wxImage Rotate90( 473 bool clockwise = true 474 ) const; 475 %Docstring 476 Rotate90(clockwise=True) -> Image 477 478 Returns a copy of the image rotated 90 degrees in the direction 479 indicated by clockwise. 480 %End 481 482 wxImage Rotate180() const; 483 %Docstring 484 Rotate180() -> Image 485 486 Returns a copy of the image rotated by 180 degrees. 487 %End 488 489 void RotateHue( 490 double angle 491 ); 492 %Docstring 493 RotateHue(angle) 494 495 Rotates the hue of each pixel in the image by angle, which is a double 496 in the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees 497 and +1.0 corresponds to +360 degrees. 498 %End 499 500 wxImage Scale( 501 int width, 502 int height, 503 wxImageResizeQuality quality = wxIMAGE_QUALITY_NORMAL 504 ) const; 505 %Docstring 506 Scale(width, height, quality=IMAGE_QUALITY_NORMAL) -> Image 507 508 Returns a scaled version of the image. 509 %End 510 511 wxImage Size( 512 const wxSize & size, 513 const wxPoint & pos, 514 int red = -1, 515 int green = -1, 516 int blue = -1 517 ) const; 518 %Docstring 519 Size(size, pos, red=-1, green=-1, blue=-1) -> Image 520 521 Returns a resized version of this image without scaling it by adding 522 either a border with the given colour or cropping as necessary. 523 %End 524 525 bool ConvertAlphaToMask( 526 unsigned char threshold /PyInt/ = wxIMAGE_ALPHA_THRESHOLD 527 ); 528 %Docstring 529 ConvertAlphaToMask(threshold=IMAGE_ALPHA_THRESHOLD) -> bool 530 ConvertAlphaToMask(mr, mg, mb, threshold=IMAGE_ALPHA_THRESHOLD) -> bool 531 532 If the image has alpha channel, this method converts it to mask. 533 %End 534 535 bool ConvertAlphaToMask( 536 unsigned char mr /PyInt/, 537 unsigned char mg /PyInt/, 538 unsigned char mb /PyInt/, 539 unsigned char threshold /PyInt/ = wxIMAGE_ALPHA_THRESHOLD 540 ); 541 542 wxImage ConvertToGreyscale( 543 double weight_r, 544 double weight_g, 545 double weight_b 546 ) const; 547 %Docstring 548 ConvertToGreyscale(weight_r, weight_g, weight_b) -> Image 549 ConvertToGreyscale() -> Image 550 551 Returns a greyscale version of the image. 552 %End 553 554 wxImage ConvertToGreyscale() const; 555 556 wxImage ConvertToMono( 557 unsigned char r /PyInt/, 558 unsigned char g /PyInt/, 559 unsigned char b /PyInt/ 560 ) const; 561 %Docstring 562 ConvertToMono(r, g, b) -> Image 563 564 Returns monochromatic version of the image. 565 %End 566 567 wxImage ConvertToDisabled( 568 unsigned char brightness /PyInt/ = 255 569 ) const; 570 %Docstring 571 ConvertToDisabled(brightness=255) -> Image 572 573 Returns disabled (dimmed) version of the image. 574 %End 575 576 unsigned long ComputeHistogram( 577 wxImageHistogram & histogram 578 ) const; 579 %Docstring 580 ComputeHistogram(histogram) -> unsignedlong 581 582 Computes the histogram of the image. 583 %End 584 585 void FindFirstUnusedColour( 586 unsigned char * r /Out, PyInt/, 587 unsigned char * g /Out, PyInt/, 588 unsigned char * b /Out, PyInt/, 589 unsigned char startR /PyInt/ = 1, 590 unsigned char startG /PyInt/ = 0, 591 unsigned char startB /PyInt/ = 0 592 ) const; 593 %Docstring 594 FindFirstUnusedColour(startR=1, startG=0, startB=0) -> (r, g, b) 595 596 Finds the first colour that is never used in the image. 597 %End 598 599 unsigned char GetAlpha( 600 int x, 601 int y 602 ) const /PyInt/; 603 %Docstring 604 GetAlpha(x, y) -> unsignedchar 605 GetAlpha() -> PyObject 606 607 Return alpha value at given pixel location. 608 %End 609 610 PyObject* GetAlpha(); 611 %MethodCode 612 PyErr_Clear(); 613 Py_BEGIN_ALLOW_THREADS 614 sipRes = _wxImage_GetAlpha(sipCpp); 615 Py_END_ALLOW_THREADS 616 if (PyErr_Occurred()) sipIsErr = 1; 617 %End 618 %TypeCode 619 PyObject* _wxImage_GetAlpha(wxImage* self) 620 { 621 byte* data = self->GetAlpha(); 622 Py_ssize_t len = self->GetWidth() * self->GetHeight(); 623 PyObject* rv = NULL; 624 wxPyBLOCK_THREADS( rv = PyByteArray_FromStringAndSize((const char*)data, len)); 625 return rv; 626 } 627 %End 628 629 PyObject* GetData(); 630 %Docstring 631 GetData() -> PyObject 632 633 Returns a copy of the RGB bytes of the image. 634 %End 635 %MethodCode 636 PyErr_Clear(); 637 Py_BEGIN_ALLOW_THREADS 638 sipRes = _wxImage_GetData(sipCpp); 639 Py_END_ALLOW_THREADS 640 if (PyErr_Occurred()) sipIsErr = 1; 641 %End 642 %TypeCode 643 PyObject* _wxImage_GetData(wxImage* self) 644 { 645 byte* data = self->GetData(); 646 Py_ssize_t len = self->GetWidth() * self->GetHeight() * 3; 647 PyObject* rv = NULL; 648 wxPyBLOCK_THREADS( rv = PyByteArray_FromStringAndSize((const char*)data, len)); 649 return rv; 650 } 651 %End 652 653 unsigned char GetRed( 654 int x, 655 int y 656 ) const /PyInt/; 657 %Docstring 658 GetRed(x, y) -> unsignedchar 659 660 Returns the red intensity at the given coordinate. 661 %End 662 663 unsigned char GetGreen( 664 int x, 665 int y 666 ) const /PyInt/; 667 %Docstring 668 GetGreen(x, y) -> unsignedchar 669 670 Returns the green intensity at the given coordinate. 671 %End 672 673 unsigned char GetBlue( 674 int x, 675 int y 676 ) const /PyInt/; 677 %Docstring 678 GetBlue(x, y) -> unsignedchar 679 680 Returns the blue intensity at the given coordinate. 681 %End 682 683 unsigned char GetMaskRed() const /PyInt/; 684 %Docstring 685 GetMaskRed() -> unsignedchar 686 687 Gets the red value of the mask colour. 688 %End 689 690 unsigned char GetMaskGreen() const /PyInt/; 691 %Docstring 692 GetMaskGreen() -> unsignedchar 693 694 Gets the green value of the mask colour. 695 %End 696 697 unsigned char GetMaskBlue() const /PyInt/; 698 %Docstring 699 GetMaskBlue() -> unsignedchar 700 701 Gets the blue value of the mask colour. 702 %End 703 704 int GetWidth() const; 705 %Docstring 706 GetWidth() -> int 707 708 Gets the width of the image in pixels. 709 %End 710 711 int GetHeight() const; 712 %Docstring 713 GetHeight() -> int 714 715 Gets the height of the image in pixels. 716 %End 717 718 wxSize GetSize() const; 719 %Docstring 720 GetSize() -> Size 721 722 Returns the size of the image in pixels. 723 %End 724 725 wxString GetOption( 726 const wxString & name 727 ) const; 728 %Docstring 729 GetOption(name) -> String 730 731 Gets a user-defined string-valued option. 732 %End 733 734 int GetOptionInt( 735 const wxString & name 736 ) const; 737 %Docstring 738 GetOptionInt(name) -> int 739 740 Gets a user-defined integer-valued option. 741 %End 742 743 void GetOrFindMaskColour( 744 unsigned char * r /Out, PyInt/, 745 unsigned char * g /Out, PyInt/, 746 unsigned char * b /Out, PyInt/ 747 ) const; 748 %Docstring 749 GetOrFindMaskColour() -> (r, g, b) 750 751 Get the current mask colour or find a suitable unused colour that 752 could be used as a mask colour. 753 %End 754 755 const wxPalette & GetPalette() const; 756 %Docstring 757 GetPalette() -> Palette 758 759 Returns the palette associated with the image. 760 %End 761 762 wxImage GetSubImage( 763 const wxRect & rect 764 ) const; 765 %Docstring 766 GetSubImage(rect) -> Image 767 768 Returns a sub image of the current one as long as the rect belongs 769 entirely to the image. 770 %End 771 772 wxBitmapType GetType() const; 773 %Docstring 774 GetType() -> BitmapType 775 776 Gets the type of image found by LoadFile() or specified with 777 SaveFile(). 778 %End 779 780 bool HasAlpha() const; 781 %Docstring 782 HasAlpha() -> bool 783 784 Returns true if this image has alpha channel, false otherwise. 785 %End 786 787 bool HasMask() const; 788 %Docstring 789 HasMask() -> bool 790 791 Returns true if there is a mask active, false otherwise. 792 %End 793 794 bool HasOption( 795 const wxString & name 796 ) const; 797 %Docstring 798 HasOption(name) -> bool 799 800 Returns true if the given option is present. 801 %End 802 803 bool IsOk() const; 804 %Docstring 805 IsOk() -> bool 806 807 Returns true if image data is present. 808 %End 809 810 bool IsTransparent( 811 int x, 812 int y, 813 unsigned char threshold /PyInt/ = wxIMAGE_ALPHA_THRESHOLD 814 ) const; 815 %Docstring 816 IsTransparent(x, y, threshold=IMAGE_ALPHA_THRESHOLD) -> bool 817 818 Returns true if the given pixel is transparent, i.e. either has the 819 mask colour if this image has a mask or if this image has alpha 820 channel and alpha value of this pixel is strictly less than threshold. 821 %End 822 823 virtual 824 bool LoadFile( 825 wxInputStream & stream, 826 wxBitmapType type = wxBITMAP_TYPE_ANY, 827 int index = -1 828 ); 829 %Docstring 830 LoadFile(stream, type=BITMAP_TYPE_ANY, index=-1) -> bool 831 LoadFile(name, type=BITMAP_TYPE_ANY, index=-1) -> bool 832 LoadFile(name, mimetype, index=-1) -> bool 833 LoadFile(stream, mimetype, index=-1) -> bool 834 835 Loads an image from an input stream. 836 %End 837 838 virtual 839 bool LoadFile( 840 const wxString & name, 841 wxBitmapType type = wxBITMAP_TYPE_ANY, 842 int index = -1 843 ); 844 845 virtual 846 bool LoadFile( 847 const wxString & name, 848 const wxString & mimetype, 849 int index = -1 850 ); 851 852 virtual 853 bool LoadFile( 854 wxInputStream & stream, 855 const wxString & mimetype, 856 int index = -1 857 ); 858 859 virtual 860 bool SaveFile( 861 wxOutputStream & stream, 862 const wxString & mimetype 863 ) const; 864 %Docstring 865 SaveFile(stream, mimetype) -> bool 866 SaveFile(name, type) -> bool 867 SaveFile(name, mimetype) -> bool 868 SaveFile(name) -> bool 869 SaveFile(stream, type) -> bool 870 871 Saves an image in the given stream. 872 %End 873 874 virtual 875 bool SaveFile( 876 const wxString & name, 877 wxBitmapType type 878 ) const; 879 880 virtual 881 bool SaveFile( 882 const wxString & name, 883 const wxString & mimetype 884 ) const; 885 886 virtual 887 bool SaveFile( 888 const wxString & name 889 ) const; 890 891 virtual 892 bool SaveFile( 893 wxOutputStream & stream, 894 wxBitmapType type 895 ) const; 896 897 void SetAlpha( 898 int x, 899 int y, 900 unsigned char alpha /PyInt/ 901 ); 902 %Docstring 903 SetAlpha(x, y, alpha) 904 SetAlpha(alpha) 905 906 Sets the alpha value for the given pixel. 907 %End 908 909 void SetAlpha(wxPyBuffer* alpha); 910 %MethodCode 911 PyErr_Clear(); 912 Py_BEGIN_ALLOW_THREADS 913 _wxImage_SetAlpha(sipCpp, alpha); 914 Py_END_ALLOW_THREADS 915 if (PyErr_Occurred()) sipIsErr = 1; 916 %End 917 %TypeCode 918 void _wxImage_SetAlpha(wxImage* self, wxPyBuffer* alpha) 919 { 920 if (!alpha->checkSize(self->GetWidth()*self->GetHeight())) 921 return; 922 void* copy = alpha->copy(); 923 if (!copy) 924 return; 925 self->SetAlpha((byte*)copy, false); 926 } 927 %End 928 929 void ClearAlpha(); 930 %Docstring 931 ClearAlpha() 932 933 Removes the alpha channel from the image. 934 %End 935 936 void SetData(wxPyBuffer* data); 937 %Docstring 938 SetData(data) 939 SetData(data, new_width, new_height) 940 941 Sets the image data without performing checks. 942 %End 943 %MethodCode 944 PyErr_Clear(); 945 Py_BEGIN_ALLOW_THREADS 946 _wxImage_SetData(sipCpp, data); 947 Py_END_ALLOW_THREADS 948 if (PyErr_Occurred()) sipIsErr = 1; 949 %End 950 %TypeCode 951 void _wxImage_SetData(wxImage* self, wxPyBuffer* data) 952 { 953 if (!data->checkSize(self->GetWidth()*self->GetHeight()*3)) 954 return; 955 void* copy = data->copy(); 956 if (!copy) 957 return; 958 self->SetData((byte*)copy, false); 959 } 960 %End 961 962 void SetData(wxPyBuffer* data, int new_width, int new_height); 963 %MethodCode 964 PyErr_Clear(); 965 Py_BEGIN_ALLOW_THREADS 966 _wxImage_SetData(sipCpp, data, new_width, new_height); 967 Py_END_ALLOW_THREADS 968 if (PyErr_Occurred()) sipIsErr = 1; 969 %End 970 %TypeCode 971 void _wxImage_SetData(wxImage* self, wxPyBuffer* data, int new_width, int new_height) 972 { 973 if (!data->checkSize(new_width*new_height*3)) 974 return; 975 void* copy = data->copy(); 976 if (!copy) 977 return; 978 self->SetData((byte*)copy, new_width, new_height, false); 979 } 980 %End 981 982 void SetMask( 983 bool hasMask = true 984 ); 985 %Docstring 986 SetMask(hasMask=True) 987 988 Specifies whether there is a mask or not. 989 %End 990 991 void SetMaskColour( 992 unsigned char red /PyInt/, 993 unsigned char green /PyInt/, 994 unsigned char blue /PyInt/ 995 ); 996 %Docstring 997 SetMaskColour(red, green, blue) 998 999 Sets the mask colour for this image (and tells the image to use the 1000 mask). 1001 %End 1002 1003 bool SetMaskFromImage( 1004 const wxImage & mask, 1005 unsigned char mr /PyInt/, 1006 unsigned char mg /PyInt/, 1007 unsigned char mb /PyInt/ 1008 ); 1009 %Docstring 1010 SetMaskFromImage(mask, mr, mg, mb) -> bool 1011 1012 Sets image's mask so that the pixels that have RGB value of mr,mg,mb 1013 in mask will be masked in the image. 1014 %End 1015 1016 void SetOption( 1017 const wxString & name, 1018 const wxString & value 1019 ); 1020 %Docstring 1021 SetOption(name, value) 1022 SetOption(name, value) 1023 1024 Sets a user-defined option. 1025 %End 1026 1027 void SetOption( 1028 const wxString & name, 1029 int value 1030 ); 1031 1032 void SetPalette( 1033 const wxPalette & palette 1034 ); 1035 %Docstring 1036 SetPalette(palette) 1037 1038 Associates a palette with the image. 1039 %End 1040 1041 void SetRGB( 1042 int x, 1043 int y, 1044 unsigned char r /PyInt/, 1045 unsigned char g /PyInt/, 1046 unsigned char b /PyInt/ 1047 ); 1048 %Docstring 1049 SetRGB(x, y, r, g, b) 1050 SetRGB(rect, red, green, blue) 1051 1052 Set the color of the pixel at the given x and y coordinate. 1053 %End 1054 1055 void SetRGB( 1056 const wxRect & rect, 1057 unsigned char red /PyInt/, 1058 unsigned char green /PyInt/, 1059 unsigned char blue /PyInt/ 1060 ); 1061 1062 void SetType( 1063 wxBitmapType type 1064 ); 1065 %Docstring 1066 SetType(type) 1067 1068 Set the type of image returned by GetType(). 1069 %End 1070 1071 static 1072 void AddHandler( 1073 wxImageHandler * handler 1074 ); 1075 %Docstring 1076 AddHandler(handler) 1077 1078 Register an image handler. 1079 %End 1080 1081 static 1082 void CleanUpHandlers(); 1083 %Docstring 1084 CleanUpHandlers() 1085 1086 Deletes all image handlers. 1087 %End 1088 1089 static 1090 wxImageHandler * FindHandler( 1091 const wxString & name 1092 ); 1093 %Docstring 1094 FindHandler(name) -> ImageHandler 1095 FindHandler(extension, imageType) -> ImageHandler 1096 FindHandler(imageType) -> ImageHandler 1097 1098 Finds the handler with the given name. 1099 %End 1100 1101 static 1102 wxImageHandler * FindHandler( 1103 const wxString & extension, 1104 wxBitmapType imageType 1105 ); 1106 1107 static 1108 wxImageHandler * FindHandler( 1109 wxBitmapType imageType 1110 ); 1111 1112 static 1113 wxImageHandler * FindHandlerMime( 1114 const wxString & mimetype 1115 ); 1116 %Docstring 1117 FindHandlerMime(mimetype) -> ImageHandler 1118 1119 Finds the handler associated with the given MIME type. 1120 %End 1121 1122 static 1123 void InitStandardHandlers(); 1124 %Docstring 1125 InitStandardHandlers() 1126 1127 Internal use only. 1128 %End 1129 1130 static 1131 void InsertHandler( 1132 wxImageHandler * handler 1133 ); 1134 %Docstring 1135 InsertHandler(handler) 1136 1137 Adds a handler at the start of the static list of format handlers. 1138 %End 1139 1140 static 1141 bool RemoveHandler( 1142 const wxString & name 1143 ); 1144 %Docstring 1145 RemoveHandler(name) -> bool 1146 1147 Finds the handler with the given name, and removes it. 1148 %End 1149 1150 static 1151 int GetImageCount( 1152 const wxString & filename, 1153 wxBitmapType type = wxBITMAP_TYPE_ANY 1154 ); 1155 %Docstring 1156 GetImageCount(filename, type=BITMAP_TYPE_ANY) -> int 1157 GetImageCount(stream, type=BITMAP_TYPE_ANY) -> int 1158 1159 If the image file contains more than one image and the image handler 1160 is capable of retrieving these individually, this function will return 1161 the number of available images. 1162 %End 1163 1164 static 1165 int GetImageCount( 1166 wxInputStream & stream, 1167 wxBitmapType type = wxBITMAP_TYPE_ANY 1168 ); 1169 1170 static 1171 bool CanRead( 1172 const wxString & filename 1173 ); 1174 %Docstring 1175 CanRead(filename) -> bool 1176 CanRead(stream) -> bool 1177 1178 Returns true if at least one of the available image handlers can read 1179 the file with the given name. 1180 %End 1181 1182 static 1183 bool CanRead( 1184 wxInputStream & stream 1185 ); 1186 1187 static 1188 wxString GetImageExtWildcard(); 1189 %Docstring 1190 GetImageExtWildcard() -> String 1191 1192 Iterates all registered wxImageHandler objects, and returns a string 1193 containing file extension masks suitable for passing to file open/save 1194 dialog boxes. 1195 %End 1196 1197 static 1198 wxImage::HSVValue RGBtoHSV( 1199 const wxImage::RGBValue & rgb 1200 ); 1201 %Docstring 1202 RGBtoHSV(rgb) -> Image.HSVValue 1203 1204 Converts a color in RGB color space to HSV color space. 1205 %End 1206 1207 static 1208 wxImage::RGBValue HSVtoRGB( 1209 const wxImage::HSVValue & hsv 1210 ); 1211 %Docstring 1212 HSVtoRGB(hsv) -> Image.RGBValue 1213 1214 Converts a color in HSV color space to RGB color space. 1215 %End 1216 1217 PyObject* GetDataBuffer(); 1218 %Docstring 1219 GetDataBuffer() -> PyObject 1220 1221 Returns a writable Python buffer object that is pointing at the RGB 1222 image data buffer inside the :class:`Image`. You need to ensure that 1223 you do 1224 not use this buffer object after the image has been destroyed. 1225 %End 1226 %MethodCode 1227 PyErr_Clear(); 1228 Py_BEGIN_ALLOW_THREADS 1229 sipRes = _wxImage_GetDataBuffer(sipCpp); 1230 Py_END_ALLOW_THREADS 1231 if (PyErr_Occurred()) sipIsErr = 1; 1232 %End 1233 %TypeCode 1234 PyObject* _wxImage_GetDataBuffer(wxImage* self) 1235 { 1236 byte* data = self->GetData(); 1237 Py_ssize_t len = self->GetWidth() * self->GetHeight() * 3; 1238 PyObject* rv; 1239 wxPyThreadBlocker blocker; 1240 rv = wxPyMakeBuffer(data, len); 1241 return rv; 1242 } 1243 %End 1244 1245 PyObject* GetAlphaBuffer(); 1246 %Docstring 1247 GetAlphaBuffer() -> PyObject 1248 1249 Returns a writable Python buffer object that is pointing at the Alpha 1250 data buffer inside the :class:`Image`. You need to ensure that you do 1251 not use this buffer object after the image has been destroyed. 1252 %End 1253 %MethodCode 1254 PyErr_Clear(); 1255 Py_BEGIN_ALLOW_THREADS 1256 sipRes = _wxImage_GetAlphaBuffer(sipCpp); 1257 Py_END_ALLOW_THREADS 1258 if (PyErr_Occurred()) sipIsErr = 1; 1259 %End 1260 %TypeCode 1261 PyObject* _wxImage_GetAlphaBuffer(wxImage* self) 1262 { 1263 byte* data = self->GetAlpha(); 1264 Py_ssize_t len = self->GetWidth() * self->GetHeight(); 1265 PyObject* rv; 1266 wxPyThreadBlocker blocker; 1267 rv = wxPyMakeBuffer(data, len); 1268 return rv; 1269 } 1270 %End 1271 1272 void SetDataBuffer(wxPyBuffer* data); 1273 %Docstring 1274 SetDataBuffer(data) 1275 SetDataBuffer(data, new_width, new_height) 1276 1277 Sets the internal image data pointer to point at a Python buffer 1278 object. This can save making an extra copy of the data but you must 1279 ensure that the buffer object lives lives at least as long as the 1280 :class:`Image` does. 1281 %End 1282 %MethodCode 1283 PyErr_Clear(); 1284 Py_BEGIN_ALLOW_THREADS 1285 _wxImage_SetDataBuffer(sipCpp, data); 1286 Py_END_ALLOW_THREADS 1287 if (PyErr_Occurred()) sipIsErr = 1; 1288 %End 1289 %TypeCode 1290 void _wxImage_SetDataBuffer(wxImage* self, wxPyBuffer* data) 1291 { 1292 if (!data->checkSize(self->GetWidth() * self->GetHeight() * 3)) 1293 return; 1294 // True means don't free() the pointer 1295 self->SetData((byte*)data->m_ptr, true); 1296 } 1297 %End 1298 1299 void SetDataBuffer(wxPyBuffer* data, int new_width, int new_height); 1300 %MethodCode 1301 PyErr_Clear(); 1302 Py_BEGIN_ALLOW_THREADS 1303 _wxImage_SetDataBuffer(sipCpp, data, new_width, new_height); 1304 Py_END_ALLOW_THREADS 1305 if (PyErr_Occurred()) sipIsErr = 1; 1306 %End 1307 %TypeCode 1308 void _wxImage_SetDataBuffer(wxImage* self, wxPyBuffer* data, int new_width, int new_height) 1309 { 1310 if (!data->checkSize(new_width * new_height * 3)) 1311 return; 1312 // True means don't free() the pointer 1313 self->SetData((byte*)data->m_ptr, new_width, new_height, true); 1314 } 1315 %End 1316 1317 void SetAlphaBuffer(wxPyBuffer* alpha); 1318 %Docstring 1319 SetAlphaBuffer(alpha) 1320 1321 Sets the internal image alpha pointer to point at a Python buffer 1322 object. This can save making an extra copy of the data but you must 1323 ensure that the buffer object lives lives at least as long as the 1324 :class:`Image` does. 1325 %End 1326 %MethodCode 1327 PyErr_Clear(); 1328 Py_BEGIN_ALLOW_THREADS 1329 _wxImage_SetAlphaBuffer(sipCpp, alpha); 1330 Py_END_ALLOW_THREADS 1331 if (PyErr_Occurred()) sipIsErr = 1; 1332 %End 1333 %TypeCode 1334 void _wxImage_SetAlphaBuffer(wxImage* self, wxPyBuffer* alpha) 1335 { 1336 if (!alpha->checkSize(self->GetWidth() * self->GetHeight())) 1337 return; 1338 // True means don't free() the pointer 1339 self->SetAlpha((byte*)alpha->m_ptr, true); 1340 } 1341 %End 1342 1343 int __nonzero__(); 1344 %Docstring 1345 __nonzero__() -> int 1346 %End 1347 %MethodCode 1348 PyErr_Clear(); 1349 Py_BEGIN_ALLOW_THREADS 1350 sipRes = _wxImage___nonzero__(sipCpp); 1351 Py_END_ALLOW_THREADS 1352 if (PyErr_Occurred()) sipIsErr = 1; 1353 %End 1354 %TypeCode 1355 int _wxImage___nonzero__(wxImage* self) 1356 { 1357 return self->IsOk(); 1358 } 1359 %End 1360 1361 int __bool__(); 1362 %Docstring 1363 __bool__() -> int 1364 %End 1365 %MethodCode 1366 PyErr_Clear(); 1367 Py_BEGIN_ALLOW_THREADS 1368 sipRes = _wxImage___bool__(sipCpp); 1369 Py_END_ALLOW_THREADS 1370 if (PyErr_Occurred()) sipIsErr = 1; 1371 %End 1372 %TypeCode 1373 int _wxImage___bool__(wxImage* self) 1374 { 1375 return self->IsOk(); 1376 } 1377 %End 1378 1379 wxImage* AdjustChannels(double factor_red, double factor_green, double factor_blue, double factor_alpha=1.0) /Factory/; 1380 %Docstring 1381 AdjustChannels(factor_red, factor_green, factor_blue, factor_alpha=1.0) -> Image 1382 1383 This function muliplies all 4 channels (red, green, blue, alpha) with 1384 a factor (around 1.0). Useful for gamma correction, colour correction 1385 and to add a certain amount of transparency to a image (fade in fade 1386 out effects). If factor_alpha is given but the original image has no 1387 alpha channel then a alpha channel will be added. 1388 %End 1389 %MethodCode 1390 PyErr_Clear(); 1391 Py_BEGIN_ALLOW_THREADS 1392 sipRes = _wxImage_AdjustChannels(sipCpp, factor_red, factor_green, factor_blue, factor_alpha); 1393 Py_END_ALLOW_THREADS 1394 if (PyErr_Occurred()) sipIsErr = 1; 1395 %End 1396 %TypeCode 1397 wxImage* _wxImage_AdjustChannels(wxImage* self, double factor_red, double factor_green, double factor_blue, double factor_alpha) 1398 { 1399 wxCHECK_MSG( self->Ok(), NULL, wxT("invalid image") ); 1400 1401 wxImage* dest = new wxImage( self->GetWidth(), self->GetHeight(), false ); 1402 wxCHECK_MSG( dest && dest->IsOk(), NULL, wxT("unable to create image") ); 1403 1404 unsigned rgblen = 3 * self->GetWidth() * self->GetHeight(); 1405 unsigned alphalen = self->GetWidth() * self->GetHeight(); 1406 byte* src_data = self->GetData(); 1407 byte* src_alpha = self->GetAlpha(); 1408 byte* dst_data = dest->GetData(); 1409 byte* dst_alpha = NULL; 1410 1411 // adjust rgb 1412 if ( factor_red == 1.0 && factor_green == 1.0 && factor_blue == 1.0) 1413 { 1414 // nothing to do for RGB 1415 memcpy(dst_data, src_data, rgblen); 1416 } 1417 else 1418 { 1419 // rgb pixel for pixel 1420 for ( unsigned i = 0; i < rgblen; i= i + 3 ) 1421 { 1422 dst_data[i] = (byte) wxMin( 255, (int) (factor_red * src_data[i]) ); 1423 dst_data[i + 1] = (byte) wxMin( 255, (int) (factor_green * src_data[i + 1]) ); 1424 dst_data[i + 2] = (byte) wxMin( 255, (int) (factor_blue * src_data[i + 2]) ); 1425 } 1426 } 1427 1428 // adjust the mask colour 1429 if ( self->HasMask() ) 1430 { 1431 dest->SetMaskColour((byte) wxMin( 255, (int) (factor_red * self->GetMaskRed() ) ), 1432 (byte) wxMin( 255, (int) (factor_green * self->GetMaskGreen() ) ), 1433 (byte) wxMin( 255, (int) (factor_blue * self->GetMaskBlue() ) ) ); 1434 } 1435 1436 // adjust the alpha channel 1437 if ( src_alpha ) 1438 { 1439 // source image already has alpha information 1440 dest->SetAlpha(); // create an empty alpha channel (not initialized) 1441 dst_alpha = dest->GetAlpha(); 1442 1443 wxCHECK_MSG( dst_alpha, NULL, wxT("unable to create alpha data") ); 1444 1445 if ( factor_alpha == 1.0) 1446 { 1447 // no need to adjust 1448 memcpy(dst_alpha, src_alpha, alphalen); 1449 } 1450 else 1451 { 1452 // alpha value for alpha value 1453 for ( unsigned i = 0; i < alphalen; ++i ) 1454 { 1455 dst_alpha[i] = (byte) wxMin( 255, (int) (factor_alpha * src_alpha[i]) ); 1456 } 1457 } 1458 } 1459 else if ( factor_alpha != 1.0 ) 1460 { 1461 // no alpha yet but we want to adjust -> create 1462 dest->SetAlpha(); // create an empty alpha channel (not initialized) 1463 dst_alpha = dest->GetAlpha(); 1464 1465 wxCHECK_MSG( dst_alpha, NULL, wxT("unable to create alpha data") ); 1466 1467 for ( unsigned i = 0; i < alphalen; ++i ) 1468 { 1469 dst_alpha[i] = (byte) wxMin( 255, (int) (factor_alpha * 255) ); 1470 } 1471 } 1472 1473 // do we have an alpha channel and a mask in the new image? 1474 if ( dst_alpha && dest->HasMask() ) 1475 { 1476 // make the mask transparent honoring the alpha channel 1477 const byte mr = dest->GetMaskRed(); 1478 const byte mg = dest->GetMaskGreen(); 1479 const byte mb = dest->GetMaskBlue(); 1480 1481 for ( unsigned i = 0; i < alphalen; ++i ) 1482 { 1483 int n = i * 3; 1484 dst_alpha[i] = ( dst_data[n] == mr && dst_data[n + 1] == mg && dst_data[n + 2] == mb ) 1485 ? wxIMAGE_ALPHA_TRANSPARENT 1486 : dst_alpha[i]; 1487 } 1488 1489 // remove the mask now 1490 dest->SetMask(false); 1491 } 1492 1493 return dest; 1494 } 1495 %End 1496 1497 %Property(name=Width, get=GetWidth) 1498 %Property(name=Height, get=GetHeight) 1499 %Property(name=MaskBlue, get=GetMaskBlue) 1500 %Property(name=MaskGreen, get=GetMaskGreen) 1501 %Property(name=MaskRed, get=GetMaskRed) 1502 %Property(name=Type, get=GetType, set=SetType) 1503}; // end of class wxImage 1504 1505 1506%Extract(id=pycode_core) 1507def _Image_ConvertToBitmap(self, depth=-1): 1508 """ 1509 ConvertToBitmap(depth=-1) -> Bitmap 1510 1511 Convert the image to a :class:`wx.Bitmap`. 1512 """ 1513 bmp = wx.Bitmap(self, depth) 1514 return bmp 1515Image.ConvertToBitmap = _Image_ConvertToBitmap 1516del _Image_ConvertToBitmap 1517%End 1518 1519%Extract(id=pycode_core) 1520def _Image_ConvertToMonoBitmap(self, red, green, blue): 1521 """ 1522 ConvertToMonoBitmap(red, green, blue) -> Bitmap 1523 1524 Creates a monochrome version of the image and returns it as a :class:`wx.Bitmap`. 1525 """ 1526 mono = self.ConvertToMono( red, green, blue ) 1527 bmp = wx.Bitmap( mono, 1 ) 1528 return bmp 1529Image.ConvertToMonoBitmap = _Image_ConvertToMonoBitmap 1530del _Image_ConvertToMonoBitmap 1531%End 1532 1533class wxImageHistogram 1534{ 1535 %Docstring 1536 ImageHistogram() 1537 %End 1538 %TypeHeaderCode 1539 #include <wx/image.h> 1540 %End 1541 1542public: 1543 wxImageHistogram(); 1544 1545 void FindFirstUnusedColour( 1546 unsigned char * r /Out, PyInt/, 1547 unsigned char * g /Out, PyInt/, 1548 unsigned char * b /Out, PyInt/, 1549 unsigned char startR /PyInt/ = 1, 1550 unsigned char startG /PyInt/ = 0, 1551 unsigned char startB /PyInt/ = 0 1552 ) const; 1553 %Docstring 1554 FindFirstUnusedColour(startR=1, startG=0, startB=0) -> (r, g, b) 1555 %End 1556 1557 static 1558 unsigned long MakeKey( 1559 unsigned char r /PyInt/, 1560 unsigned char g /PyInt/, 1561 unsigned char b /PyInt/ 1562 ); 1563 %Docstring 1564 MakeKey(r, g, b) -> unsignedlong 1565 %End 1566 1567}; // end of class wxImageHistogram 1568 1569 1570class wxImageHandler : wxObject 1571{ 1572 %Docstring 1573 ImageHandler() 1574 1575 This is the base class for implementing image file loading/saving, and 1576 image creation from data. 1577 %End 1578 %TypeHeaderCode 1579 #include <wx/image.h> 1580 %End 1581 1582public: 1583 wxImageHandler(); 1584 1585 virtual 1586 ~wxImageHandler(); 1587 1588 bool CanRead( 1589 wxInputStream & stream 1590 ); 1591 %Docstring 1592 CanRead(stream) -> bool 1593 CanRead(filename) -> bool 1594 1595 Returns true if this handler supports the image format contained in 1596 the given stream. 1597 %End 1598 1599 bool CanRead( 1600 const wxString & filename 1601 ); 1602 1603 const wxString & GetExtension() const; 1604 %Docstring 1605 GetExtension() -> String 1606 1607 Gets the preferred file extension associated with this handler. 1608 %End 1609 1610 const wxArrayString & GetAltExtensions() const; 1611 %Docstring 1612 GetAltExtensions() -> ArrayString 1613 1614 Returns the other file extensions associated with this handler. 1615 %End 1616 1617 int GetImageCount( 1618 wxInputStream & stream 1619 ); 1620 %Docstring 1621 GetImageCount(stream) -> int 1622 1623 If the image file contains more than one image and the image handler 1624 is capable of retrieving these individually, this function will return 1625 the number of available images. 1626 %End 1627 1628 const wxString & GetMimeType() const; 1629 %Docstring 1630 GetMimeType() -> String 1631 1632 Gets the MIME type associated with this handler. 1633 %End 1634 1635 const wxString & GetName() const; 1636 %Docstring 1637 GetName() -> String 1638 1639 Gets the name of this handler. 1640 %End 1641 1642 wxBitmapType GetType() const; 1643 %Docstring 1644 GetType() -> BitmapType 1645 1646 Gets the image type associated with this handler. 1647 %End 1648 1649 virtual 1650 bool LoadFile( 1651 wxImage * image, 1652 wxInputStream & stream, 1653 bool verbose = true, 1654 int index = -1 1655 ); 1656 %Docstring 1657 LoadFile(image, stream, verbose=True, index=-1) -> bool 1658 1659 Loads a image from a stream, putting the resulting data into image. 1660 %End 1661 1662 virtual 1663 bool SaveFile( 1664 wxImage * image, 1665 wxOutputStream & stream, 1666 bool verbose = true 1667 ); 1668 %Docstring 1669 SaveFile(image, stream, verbose=True) -> bool 1670 1671 Saves a image in the output stream. 1672 %End 1673 1674 void SetExtension( 1675 const wxString & extension 1676 ); 1677 %Docstring 1678 SetExtension(extension) 1679 1680 Sets the preferred file extension associated with this handler. 1681 %End 1682 1683 void SetAltExtensions( 1684 const wxArrayString & extensions 1685 ); 1686 %Docstring 1687 SetAltExtensions(extensions) 1688 1689 Sets the alternative file extensions associated with this handler. 1690 %End 1691 1692 void SetMimeType( 1693 const wxString & mimetype 1694 ); 1695 %Docstring 1696 SetMimeType(mimetype) 1697 1698 Sets the handler MIME type. 1699 %End 1700 1701 void SetName( 1702 const wxString & name 1703 ); 1704 %Docstring 1705 SetName(name) 1706 1707 Sets the handler name. 1708 %End 1709 1710 void SetType( 1711 wxBitmapType type 1712 ); 1713 %Docstring 1714 SetType(type) 1715 1716 Sets the bitmap type for the handler. 1717 %End 1718 1719 private: 1720 wxImageHandler(const wxImageHandler&); 1721 1722 1723 public: 1724 1725 1726 %Property(name=AltExtensions, get=GetAltExtensions, set=SetAltExtensions) 1727 %Property(name=Extension, get=GetExtension, set=SetExtension) 1728 %Property(name=MimeType, get=GetMimeType, set=SetMimeType) 1729 %Property(name=Name, get=GetName, set=SetName) 1730 %Property(name=Type, get=GetType, set=SetType) 1731 1732protected: 1733 virtual 1734 int DoGetImageCount( 1735 wxInputStream & stream 1736 ); 1737 %Docstring 1738 DoGetImageCount(stream) -> int 1739 1740 Called to get the number of images available in a multi-image file 1741 type, if supported. 1742 %End 1743 1744 virtual 1745 bool DoCanRead( 1746 wxInputStream & stream 1747 ) = 0; 1748 %Docstring 1749 DoCanRead(stream) -> bool 1750 1751 Called to test if this handler can read an image from the given 1752 stream. 1753 %End 1754 1755}; // end of class wxImageHandler 1756 1757 1758class wxTIFFHandler : wxImageHandler 1759{ 1760 %Docstring 1761 TIFFHandler() 1762 1763 This is the image handler for the TIFF format. 1764 %End 1765 %TypeHeaderCode 1766 #include <wx/imagtiff.h> 1767 %End 1768 1769public: 1770 wxTIFFHandler(); 1771 1772 virtual 1773 bool LoadFile( 1774 wxImage * image, 1775 wxInputStream & stream, 1776 bool verbose = true, 1777 int index = -1 1778 ); 1779 %Docstring 1780 LoadFile(image, stream, verbose=True, index=-1) -> bool 1781 1782 Loads a image from a stream, putting the resulting data into image. 1783 %End 1784 1785 1786protected: 1787 virtual 1788 bool DoCanRead( 1789 wxInputStream & stream 1790 ); 1791 %Docstring 1792 DoCanRead(stream) -> bool 1793 1794 Called to test if this handler can read an image from the given 1795 stream. 1796 %End 1797 1798}; // end of class wxTIFFHandler 1799 1800 1801class wxGIFHandler : wxImageHandler 1802{ 1803 %Docstring 1804 GIFHandler() 1805 1806 This is the image handler for the GIF format. 1807 %End 1808 %TypeHeaderCode 1809 #include <wx/imaggif.h> 1810 %End 1811 1812public: 1813 wxGIFHandler(); 1814 1815 virtual 1816 bool LoadFile( 1817 wxImage * image, 1818 wxInputStream & stream, 1819 bool verbose = true, 1820 int index = -1 1821 ); 1822 %Docstring 1823 LoadFile(image, stream, verbose=True, index=-1) -> bool 1824 1825 Loads a image from a stream, putting the resulting data into image. 1826 %End 1827 1828 virtual 1829 bool SaveFile( 1830 wxImage * image, 1831 wxOutputStream & stream, 1832 bool verbose = true 1833 ); 1834 %Docstring 1835 SaveFile(image, stream, verbose=True) -> bool 1836 1837 Saves a image in the output stream. 1838 %End 1839 1840 bool SaveAnimation( 1841 const wxImageArray & images, 1842 wxOutputStream * stream, 1843 bool verbose = true, 1844 int delayMilliSecs = 1000 1845 ); 1846 %Docstring 1847 SaveAnimation(images, stream, verbose=True, delayMilliSecs=1000) -> bool 1848 1849 Save the animated gif. 1850 %End 1851 1852 1853protected: 1854 virtual 1855 bool DoCanRead( 1856 wxInputStream & stream 1857 ); 1858 %Docstring 1859 DoCanRead(stream) -> bool 1860 1861 Called to test if this handler can read an image from the given 1862 stream. 1863 %End 1864 1865}; // end of class wxGIFHandler 1866 1867 1868class wxIFFHandler : wxImageHandler 1869{ 1870 %Docstring 1871 IFFHandler() 1872 1873 This is the image handler for the IFF format. 1874 %End 1875 %TypeHeaderCode 1876 #include <wx/imagiff.h> 1877 %End 1878 1879public: 1880 wxIFFHandler(); 1881 1882 virtual 1883 bool LoadFile( 1884 wxImage * image, 1885 wxInputStream & stream, 1886 bool verbose = true, 1887 int index = -1 1888 ); 1889 %Docstring 1890 LoadFile(image, stream, verbose=True, index=-1) -> bool 1891 1892 Loads a image from a stream, putting the resulting data into image. 1893 %End 1894 1895 virtual 1896 bool SaveFile( 1897 wxImage * image, 1898 wxOutputStream & stream, 1899 bool verbose = true 1900 ); 1901 %Docstring 1902 SaveFile(image, stream, verbose=True) -> bool 1903 1904 Saves a image in the output stream. 1905 %End 1906 1907 1908protected: 1909 virtual 1910 bool DoCanRead( 1911 wxInputStream & stream 1912 ); 1913 %Docstring 1914 DoCanRead(stream) -> bool 1915 1916 Called to test if this handler can read an image from the given 1917 stream. 1918 %End 1919 1920}; // end of class wxIFFHandler 1921 1922 1923class wxJPEGHandler : wxImageHandler 1924{ 1925 %Docstring 1926 JPEGHandler() 1927 1928 This is the image handler for the JPEG format. 1929 %End 1930 %TypeHeaderCode 1931 #include <wx/imagjpeg.h> 1932 %End 1933 1934public: 1935 wxJPEGHandler(); 1936 1937 virtual 1938 bool LoadFile( 1939 wxImage * image, 1940 wxInputStream & stream, 1941 bool verbose = true, 1942 int index = -1 1943 ); 1944 %Docstring 1945 LoadFile(image, stream, verbose=True, index=-1) -> bool 1946 1947 Loads a image from a stream, putting the resulting data into image. 1948 %End 1949 1950 virtual 1951 bool SaveFile( 1952 wxImage * image, 1953 wxOutputStream & stream, 1954 bool verbose = true 1955 ); 1956 %Docstring 1957 SaveFile(image, stream, verbose=True) -> bool 1958 1959 Saves a image in the output stream. 1960 %End 1961 1962 static 1963 wxVersionInfo GetLibraryVersionInfo(); 1964 %Docstring 1965 GetLibraryVersionInfo() -> VersionInfo 1966 1967 Retrieve the version information about the JPEG library used by this 1968 handler. 1969 %End 1970 1971 1972protected: 1973 virtual 1974 bool DoCanRead( 1975 wxInputStream & stream 1976 ); 1977 %Docstring 1978 DoCanRead(stream) -> bool 1979 1980 Called to test if this handler can read an image from the given 1981 stream. 1982 %End 1983 1984}; // end of class wxJPEGHandler 1985 1986 1987class wxPCXHandler : wxImageHandler 1988{ 1989 %Docstring 1990 PCXHandler() 1991 1992 This is the image handler for the PCX format. 1993 %End 1994 %TypeHeaderCode 1995 #include <wx/imagpcx.h> 1996 %End 1997 1998public: 1999 wxPCXHandler(); 2000 2001 virtual 2002 bool LoadFile( 2003 wxImage * image, 2004 wxInputStream & stream, 2005 bool verbose = true, 2006 int index = -1 2007 ); 2008 %Docstring 2009 LoadFile(image, stream, verbose=True, index=-1) -> bool 2010 2011 Loads a image from a stream, putting the resulting data into image. 2012 %End 2013 2014 virtual 2015 bool SaveFile( 2016 wxImage * image, 2017 wxOutputStream & stream, 2018 bool verbose = true 2019 ); 2020 %Docstring 2021 SaveFile(image, stream, verbose=True) -> bool 2022 2023 Saves a image in the output stream. 2024 %End 2025 2026 2027protected: 2028 virtual 2029 bool DoCanRead( 2030 wxInputStream & stream 2031 ); 2032 %Docstring 2033 DoCanRead(stream) -> bool 2034 2035 Called to test if this handler can read an image from the given 2036 stream. 2037 %End 2038 2039}; // end of class wxPCXHandler 2040 2041 2042class wxPNGHandler : wxImageHandler 2043{ 2044 %Docstring 2045 PNGHandler() 2046 2047 This is the image handler for the PNG format. 2048 %End 2049 %TypeHeaderCode 2050 #include <wx/imagpng.h> 2051 %End 2052 2053public: 2054 wxPNGHandler(); 2055 2056 virtual 2057 bool LoadFile( 2058 wxImage * image, 2059 wxInputStream & stream, 2060 bool verbose = true, 2061 int index = -1 2062 ); 2063 %Docstring 2064 LoadFile(image, stream, verbose=True, index=-1) -> bool 2065 2066 Loads a image from a stream, putting the resulting data into image. 2067 %End 2068 2069 virtual 2070 bool SaveFile( 2071 wxImage * image, 2072 wxOutputStream & stream, 2073 bool verbose = true 2074 ); 2075 %Docstring 2076 SaveFile(image, stream, verbose=True) -> bool 2077 2078 Saves a image in the output stream. 2079 %End 2080 2081 2082protected: 2083 virtual 2084 bool DoCanRead( 2085 wxInputStream & stream 2086 ); 2087 %Docstring 2088 DoCanRead(stream) -> bool 2089 2090 Called to test if this handler can read an image from the given 2091 stream. 2092 %End 2093 2094}; // end of class wxPNGHandler 2095 2096 2097class wxPNMHandler : wxImageHandler 2098{ 2099 %Docstring 2100 PNMHandler() 2101 2102 This is the image handler for the PNM format. 2103 %End 2104 %TypeHeaderCode 2105 #include <wx/imagpnm.h> 2106 %End 2107 2108public: 2109 wxPNMHandler(); 2110 2111 virtual 2112 bool LoadFile( 2113 wxImage * image, 2114 wxInputStream & stream, 2115 bool verbose = true, 2116 int index = -1 2117 ); 2118 %Docstring 2119 LoadFile(image, stream, verbose=True, index=-1) -> bool 2120 2121 Loads a image from a stream, putting the resulting data into image. 2122 %End 2123 2124 virtual 2125 bool SaveFile( 2126 wxImage * image, 2127 wxOutputStream & stream, 2128 bool verbose = true 2129 ); 2130 %Docstring 2131 SaveFile(image, stream, verbose=True) -> bool 2132 2133 Saves a image in the output stream. 2134 %End 2135 2136 2137protected: 2138 virtual 2139 bool DoCanRead( 2140 wxInputStream & stream 2141 ); 2142 %Docstring 2143 DoCanRead(stream) -> bool 2144 2145 Called to test if this handler can read an image from the given 2146 stream. 2147 %End 2148 2149}; // end of class wxPNMHandler 2150 2151 2152class wxTGAHandler : wxImageHandler 2153{ 2154 %Docstring 2155 TGAHandler() 2156 2157 This is the image handler for the TGA format. 2158 %End 2159 %TypeHeaderCode 2160 #include <wx/imagtga.h> 2161 %End 2162 2163public: 2164 wxTGAHandler(); 2165 2166 virtual 2167 bool LoadFile( 2168 wxImage * image, 2169 wxInputStream & stream, 2170 bool verbose = true, 2171 int index = -1 2172 ); 2173 %Docstring 2174 LoadFile(image, stream, verbose=True, index=-1) -> bool 2175 2176 Loads a image from a stream, putting the resulting data into image. 2177 %End 2178 2179 virtual 2180 bool SaveFile( 2181 wxImage * image, 2182 wxOutputStream & stream, 2183 bool verbose = true 2184 ); 2185 %Docstring 2186 SaveFile(image, stream, verbose=True) -> bool 2187 2188 Saves a image in the output stream. 2189 %End 2190 2191 2192protected: 2193 virtual 2194 bool DoCanRead( 2195 wxInputStream & stream 2196 ); 2197 %Docstring 2198 DoCanRead(stream) -> bool 2199 2200 Called to test if this handler can read an image from the given 2201 stream. 2202 %End 2203 2204}; // end of class wxTGAHandler 2205 2206 2207class wxXPMHandler : wxImageHandler 2208{ 2209 %Docstring 2210 XPMHandler() 2211 2212 This is the image handler for the XPM format. 2213 %End 2214 %TypeHeaderCode 2215 #include <wx/imagxpm.h> 2216 %End 2217 2218public: 2219 wxXPMHandler(); 2220 2221 virtual 2222 bool LoadFile( 2223 wxImage * image, 2224 wxInputStream & stream, 2225 bool verbose = true, 2226 int index = -1 2227 ); 2228 %Docstring 2229 LoadFile(image, stream, verbose=True, index=-1) -> bool 2230 2231 Loads a image from a stream, putting the resulting data into image. 2232 %End 2233 2234 virtual 2235 bool SaveFile( 2236 wxImage * image, 2237 wxOutputStream & stream, 2238 bool verbose = true 2239 ); 2240 %Docstring 2241 SaveFile(image, stream, verbose=True) -> bool 2242 2243 Saves a image in the output stream. 2244 %End 2245 2246 2247protected: 2248 virtual 2249 bool DoCanRead( 2250 wxInputStream & stream 2251 ); 2252 %Docstring 2253 DoCanRead(stream) -> bool 2254 2255 Called to test if this handler can read an image from the given 2256 stream. 2257 %End 2258 2259}; // end of class wxXPMHandler 2260 2261 2262void wxInitAllImageHandlers(); 2263%Docstring 2264 InitAllImageHandlers() 2265 2266 Initializes all available image handlers. 2267%End 2268 2269wxImage wxNullImage; 2270 2271%Extract(id=pycode_core) 2272@wx.deprecatedMsg("Use :class:`Image` instead.") 2273def EmptyImage(width=0, height=0, clear=True): 2274 """ 2275 A compatibility wrapper for the wx.Image(width, height) constructor 2276 """ 2277 return Image(width, height, clear) 2278 2279%End 2280 2281%Extract(id=pycode_core) 2282@wx.deprecatedMsg("Use bitmap.ConvertToImage instead.") 2283def ImageFromBitmap(bitmap): 2284 """ 2285 Create a :class:`Image` from a :class:`wx.Bitmap` 2286 """ 2287 return bitmap.ConvertToImage() 2288 2289%End 2290 2291%Extract(id=pycode_core) 2292@wx.deprecatedMsg("Use :class:`Image` instead.") 2293def ImageFromStream(stream, type=BITMAP_TYPE_ANY, index=-1): 2294 """ 2295 Load an image from a stream (file-like object) 2296 """ 2297 return wx.Image(stream, type, index) 2298 2299%End 2300 2301%Extract(id=pycode_core) 2302@wx.deprecatedMsg("Use :class:`Image` instead.") 2303def ImageFromData(width, height, data): 2304 """ 2305 Compatibility wrapper for creating an image from RGB data 2306 """ 2307 return Image(width, height, data) 2308 2309%End 2310 2311%Extract(id=pycode_core) 2312@wx.deprecatedMsg("Use :class:`Image` instead.") 2313def ImageFromDataWithAlpha(width, height, data, alpha): 2314 """ 2315 Compatibility wrapper for creating an image from RGB and Alpha data 2316 """ 2317 return Image(width, height, data, alpha) 2318 2319%End 2320 2321%Extract(id=pycode_core) 2322def ImageFromBuffer(width, height, dataBuffer, alphaBuffer=None): 2323 """ 2324 Creates a :class:`Image` from the data in `dataBuffer`. The `dataBuffer` 2325 parameter must be a Python object that implements the buffer interface, 2326 such as a string, array, etc. The `dataBuffer` object is expected to 2327 contain a series of RGB bytes and be width*height*3 bytes long. A buffer 2328 object can optionally be supplied for the image's alpha channel data, and 2329 it is expected to be width*height bytes long. 2330 2331 The :class:`Image` will be created with its data and alpha pointers initialized 2332 to the memory address pointed to by the buffer objects, thus saving the 2333 time needed to copy the image data from the buffer object to the :class:`Image`. 2334 While this has advantages, it also has the shoot-yourself-in-the-foot 2335 risks associated with sharing a C pointer between two objects. 2336 2337 To help alleviate the risk a reference to the data and alpha buffer 2338 objects are kept with the :class:`Image`, so that they won't get deleted until 2339 after the wx.Image is deleted. However please be aware that it is not 2340 guaranteed that an object won't move its memory buffer to a new location 2341 when it needs to resize its contents. If that happens then the :class:`Image` 2342 will end up referring to an invalid memory location and could cause the 2343 application to crash. Therefore care should be taken to not manipulate 2344 the objects used for the data and alpha buffers in a way that would cause 2345 them to change size. 2346 """ 2347 img = Image(width, height) 2348 img.SetDataBuffer(dataBuffer) 2349 if alphaBuffer: 2350 img.SetAlphaBuffer(alphaBuffer) 2351 img._buffer = dataBuffer 2352 img._alpha = alphaBuffer 2353 return img 2354 2355%End 2356 2357class wxImageArray 2358{ 2359public: 2360 SIP_SSIZE_T __len__(); 2361 %MethodCode 2362 sipRes = sipCpp->GetCount(); 2363 %End 2364 2365 wxImage& __getitem__(long index); 2366 %MethodCode 2367 if (0 > index) 2368 index += sipCpp->GetCount(); 2369 2370 if ((index < sipCpp->GetCount()) && (0 <= index)) { 2371 sipRes = &sipCpp->Item(index); 2372 } 2373 else { 2374 wxPyErr_SetString(PyExc_IndexError, "sequence index out of range"); 2375 sipError = sipErrorFail; 2376 } 2377 %End 2378 2379 2380 int __contains__(wxImage& obj); 2381 %MethodCode 2382 int idx = sipCpp->Index(*obj, false); 2383 sipRes = idx != wxNOT_FOUND; 2384 %End 2385 2386 void append(wxImage& obj); 2387 %MethodCode 2388 sipCpp->Add(*obj); 2389 %End 2390 2391 // TODO: add support for index(value, [start, [stop]]) 2392 int index(wxImage& obj); 2393 %MethodCode 2394 int idx = sipCpp->Index(*obj, false); 2395 if (idx == wxNOT_FOUND) { 2396 sipError = sipErrorFail; 2397 wxPyErr_SetString(PyExc_ValueError, 2398 "sequence.index(x): x not in sequence"); 2399 } 2400 sipRes = idx; 2401 %End 2402}; 2403 2404%Extract(id=pycode_core) 2405def _ImageArray___repr__(self): 2406 return "ImageArray: " + repr(list(self)) 2407ImageArray.__repr__ = _ImageArray___repr__ 2408del _ImageArray___repr__ 2409%End 2410 2411 2412%Extract(id=pycode_core) 2413IMAGE_OPTION_QUALITY = "quality" 2414IMAGE_OPTION_FILENAME = "FileName" 2415IMAGE_OPTION_RESOLUTION = "Resolution" 2416IMAGE_OPTION_RESOLUTIONX = "ResolutionX" 2417IMAGE_OPTION_RESOLUTIONY = "ResolutionY" 2418IMAGE_OPTION_RESOLUTIONUNIT = "ResolutionUnit" 2419IMAGE_OPTION_MAX_WIDTH = "MaxWidth" 2420IMAGE_OPTION_MAX_HEIGHT = "MaxHeight" 2421IMAGE_OPTION_ORIGINAL_WIDTH = "OriginalWidth" 2422IMAGE_OPTION_ORIGINAL_HEIGHT = "OriginalHeight" 2423IMAGE_OPTION_BMP_FORMAT = "wxBMP_FORMAT" 2424IMAGE_OPTION_CUR_HOTSPOT_X = "HotSpotX" 2425IMAGE_OPTION_CUR_HOTSPOT_Y = "HotSpotY" 2426IMAGE_OPTION_GIF_COMMENT = "GifComment" 2427IMAGE_OPTION_PNG_FORMAT = "PngFormat" 2428IMAGE_OPTION_PNG_BITDEPTH = "PngBitDepth" 2429IMAGE_OPTION_PNG_FILTER = "PngF" 2430IMAGE_OPTION_PNG_COMPRESSION_LEVEL = "PngZL" 2431IMAGE_OPTION_PNG_COMPRESSION_MEM_LEVEL = "PngZM" 2432IMAGE_OPTION_PNG_COMPRESSION_STRATEGY = "PngZS" 2433IMAGE_OPTION_PNG_COMPRESSION_BUFFER_SIZE = "PngZB" 2434IMAGE_OPTION_TIFF_BITSPERSAMPLE = "BitsPerSample" 2435IMAGE_OPTION_TIFF_SAMPLESPERPIXEL = "SamplesPerPixel" 2436IMAGE_OPTION_TIFF_COMPRESSION = "Compression" 2437IMAGE_OPTION_TIFF_PHOTOMETRIC = "Photometric" 2438IMAGE_OPTION_TIFF_IMAGEDESCRIPTOR = "ImageDescriptor" 2439IMAGE_OPTION_TIFF_BITSPERSAMPLE = "BitsPerSample" 2440IMAGE_OPTION_TIFF_SAMPLESPERPIXEL = "SamplesPerPixel" 2441IMAGE_OPTION_TIFF_COMPRESSION = "Compression" 2442IMAGE_OPTION_TIFF_PHOTOMETRIC = "Photometric" 2443IMAGE_OPTION_TIFF_IMAGEDESCRIPTOR = "ImageDescriptor" 2444IMAGE_OPTION_GIF_COMMENT = "GifComment" 2445IMAGE_OPTION_PNG_FORMAT = "PngFormat" 2446IMAGE_OPTION_PNG_BITDEPTH = "PngBitDepth" 2447IMAGE_OPTION_PNG_FILTER = "PngF" 2448IMAGE_OPTION_PNG_COMPRESSION_LEVEL = "PngZL" 2449IMAGE_OPTION_PNG_COMPRESSION_MEM_LEVEL = "PngZM" 2450IMAGE_OPTION_PNG_COMPRESSION_STRATEGY = "PngZS" 2451IMAGE_OPTION_PNG_COMPRESSION_BUFFER_SIZE = "PngZB" 2452 2453%End 2454 2455 2456//--------------------------------------------------------------------------- 2457 2458