/usr/include/wx-3.0/wx/wxPython/i_files/_image.i is in python-wxgtk3.0-dev 3.0.2.0+dfsg-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 | /////////////////////////////////////////////////////////////////////////////
// Name: _image.i
// Purpose: SWIG definitions for wxImage and such
//
// Author: Robin Dunn
//
// Created: 25-Sept-2000
// RCS-ID: $Id$
// Copyright: (c) 2003 by Total Control Software
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// Not a %module
//---------------------------------------------------------------------------
%{
#include "wx/wxPython/pyistream.h"
%}
//---------------------------------------------------------------------------
enum {
wxIMAGE_ALPHA_TRANSPARENT,
wxIMAGE_ALPHA_THRESHOLD,
wxIMAGE_ALPHA_OPAQUE
};
// Constants for wxImage::Scale() for determining the level of quality
enum wxImageResizeQuality
{
wxIMAGE_QUALITY_NEAREST,
wxIMAGE_QUALITY_BILINEAR,
wxIMAGE_QUALITY_BICUBIC,
wxIMAGE_QUALITY_BOX_AVERAGE,
wxIMAGE_QUALITY_NORMAL,
wxIMAGE_QUALITY_HIGH,
};
//---------------------------------------------------------------------------
%newgroup
DocStr(wxImageHandler,
"This is the base class for implementing image file loading/saving, and
image creation from data. It is used within `wx.Image` and is not
normally seen by the application.", "");
class wxImageHandler : public wxObject {
public:
// wxImageHandler(); Abstract Base Class
wxString GetName();
wxString GetExtension();
const wxArrayString& GetAltExtensions() const;
wxBitmapType GetType();
wxString GetMimeType();
//bool LoadFile(wxImage* image, wxInputStream& stream);
//bool SaveFile(wxImage* image, wxOutputStream& stream);
//virtual int GetImageCount( wxInputStream& stream );
bool CanRead( const wxString& name );
%Rename(CanReadStream, bool, CanRead( wxInputStream& stream ));
void SetName(const wxString& name);
void SetExtension(const wxString& extension);
void SetAltExtensions(const wxArrayString& exts);
void SetType(wxBitmapType type);
void SetMimeType(const wxString& mimetype);
%property(Extension, GetExtension, SetExtension, doc="See `GetExtension` and `SetExtension`");
%property(AltExtensions, GetAltExtensions, SetAltExtensions);
%property(MimeType, GetMimeType, SetMimeType, doc="See `GetMimeType` and `SetMimeType`");
%property(Name, GetName, SetName, doc="See `GetName` and `SetName`");
%property(Type, GetType, SetType, doc="See `GetType` and `SetType`");
};
//---------------------------------------------------------------------------
DocStr(wxPyImageHandler,
"This is the base class for implementing image file loading/saving, and
image creation from data, all written in Python. To create a custom
image handler derive a new class from wx.PyImageHandler and provide
the following methods::
def DoCanRead(self, stream) --> bool
'''Check if this handler can read the image on the stream'''
def LoadFile(self, image, stream, verbose, index) --> bool
'''Load image data from the stream and load it into image.'''
def SaveFile(self, image, stream, verbose) --> bool
'''Save the iamge data in image to the stream using
this handler's image file format.'''
def GetImageCount(self, stream) --> int
'''If this image format can hold more than one image,
how many does the image on the stream have?'''
To activate your handler create an instance of it and pass it to
`wx.Image_AddHandler`. Be sure to call `SetName`, `SetType`, and
`SetExtension` from your constructor.
", "");
class wxPyImageHandler: public wxImageHandler {
public:
%pythonAppend wxPyImageHandler() "self._SetSelf(self)"
wxPyImageHandler();
void _SetSelf(PyObject *self);
};
//---------------------------------------------------------------------------
class wxImageHistogram /* : public wxImageHistogramBase */
{
public:
wxImageHistogram();
DocStr(MakeKey, "Get the key in the histogram for the given RGB values", "");
static unsigned long MakeKey(byte r,
byte g,
byte b);
DocDeclAStr(
bool, FindFirstUnusedColour(byte *OUTPUT,
byte *OUTPUT,
byte *OUTPUT,
byte startR = 1,
byte startG = 0,
byte startB = 0 ) const,
"FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)",
"Find first colour that is not used in the image and has higher RGB
values than startR, startG, startB. Returns a tuple consisting of a
success flag and rgb values.", "");
%extend {
DocStr(GetCount,
"Returns the pixel count for the given key. Use `MakeKey` to create a
key value from a RGB tripple.", "");
unsigned long GetCount(unsigned long key) {
wxImageHistogramEntry e = (*self)[key];
return e.value;
}
DocStr(GetCountRGB,
"Returns the pixel count for the given RGB values.", "");
unsigned long GetCountRGB(byte r,
byte g,
byte b) {
unsigned long key = wxImageHistogram::MakeKey(r, g, b);
wxImageHistogramEntry e = (*self)[key];
return e.value;
}
DocStr(GetCountColour,
"Returns the pixel count for the given `wx.Colour` value.", "");
unsigned long GetCountColour(const wxColour& colour) {
unsigned long key = wxImageHistogram::MakeKey(colour.Red(),
colour.Green(),
colour.Blue());
wxImageHistogramEntry e = (*self)[key];
return e.value;
}
}
};
//---------------------------------------------------------------------------
DocStr(wxImage,
"A platform-independent image class. An image can be created from
data, or using `wx.Bitmap.ConvertToImage`, or loaded from a file in a
variety of formats. Functions are available to set and get image
bits, so it can be used for basic image manipulation.
A wx.Image cannot be drawn directly to a `wx.DC`. Instead, a
platform-specific `wx.Bitmap` object must be created from it using the
`wx.BitmapFromImage` constructor. This bitmap can then be drawn in a
device context, using `wx.DC.DrawBitmap`.
One colour value of the image may be used as a mask colour which will
lead to the automatic creation of a `wx.Mask` object associated to the
bitmap object.
wx.Image supports alpha channel data, that is in addition to a byte
for the red, green and blue colour components for each pixel it also
stores a byte representing the pixel opacity. An alpha value of 0
corresponds to a transparent pixel (null opacity) while a value of 255
means that the pixel is 100% opaque.
Unlike RGB data, not all images have an alpha channel and before using
`GetAlpha` you should check if this image contains an alpha channel
with `HasAlpha`. Note that currently only images loaded from PNG files
with transparency information will have an alpha channel.", "");
%{
// Pull the nested class out to the top level for SWIG's sake
#define wxImage_RGBValue wxImage::RGBValue
#define wxImage_HSVValue wxImage::HSVValue
%}
DocStr(wxImage_RGBValue,
"An object that contains values for red, green and blue which represent
the value of a color. It is used by `wx.Image.HSVtoRGB` and
`wx.Image.RGBtoHSV`, which converts between HSV color space and RGB
color space.", "");
class wxImage_RGBValue
{
public:
DocCtorStr(
wxImage_RGBValue(byte r=0, byte g=0, byte b=0),
"Constructor.", "");
~wxImage_RGBValue();
byte red;
byte green;
byte blue;
};
DocStr(wxImage_HSVValue,
"An object that contains values for hue, saturation and value which
represent the value of a color. It is used by `wx.Image.HSVtoRGB` and
`wx.Image.RGBtoHSV`, which converts between HSV color space and RGB
color space.", "");
class wxImage_HSVValue
{
public:
DocCtorStr(
wxImage_HSVValue(double h=0.0, double s=0.0, double v=0.0),
"Constructor.", "");
~wxImage_HSVValue();
double hue;
double saturation;
double value;
};
class wxImage : public wxObject {
public:
%typemap(out) wxImage*; // turn off this typemap
DocCtorStr(
wxImage( const wxString& name, wxBitmapType type = wxBITMAP_TYPE_ANY,
int index = -1 ),
"Loads an image from a file.",
"
:param name: Name of the file from which to load the image.
:param type: May be one of the following:
==================== =======================================
wx.BITMAP_TYPE_BMP Load a Windows bitmap file.
wx.BITMAP_TYPE_GIF Load a GIF bitmap file.
wx.BITMAP_TYPE_JPEG Load a JPEG bitmap file.
wx.BITMAP_TYPE_PNG Load a PNG bitmap file.
wx.BITMAP_TYPE_PCX Load a PCX bitmap file.
wx.BITMAP_TYPE_PNM Load a PNM bitmap file.
wx.BITMAP_TYPE_TIF Load a TIFF bitmap file.
wx.BITMAP_TYPE_XPM Load a XPM bitmap file.
wx.BITMAP_TYPE_ICO Load a Windows icon file (ICO).
wx.BITMAP_TYPE_CUR Load a Windows cursor file (CUR).
wx.BITMAP_TYPE_ANI Load a Windows animated cursor file (ANI).
wx.BITMAP_TYPE_ANY Will try to autodetect the format.
==================== =======================================
:param index: Index of the image to load in the case that the
image file contains multiple images. This is only used by GIF,
ICO and TIFF handlers. The default value (-1) means to choose
the default image and is interpreted as the first image (the
one with index=0) by the GIF and TIFF handler and as the
largest and most colourful one by the ICO handler.
:see: `wx.ImageFromMime`, `wx.ImageFromStream`, `wx.ImageFromStreamMime`,
`wx.EmptyImage`, `wx.ImageFromBitmap`, `wx.ImageFromBuffer`,
`wx.ImageFromData`, `wx.ImageFromDataWithAlpha`
");
~wxImage();
// Alternate constructors
DocCtorStrName(
wxImage(const wxString& name, const wxString& mimetype, int index = -1),
"Loads an image from a file, using a MIME type string (such as
'image/jpeg') to specify image type.", "
:see: `wx.Image`",
ImageFromMime);
DocCtorStrName(
wxImage(wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1),
"Loads an image from an input stream, or any readable Python file-like
object.", "
:see: `wx.Image`",
ImageFromStream);
DocCtorStrName(
wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1 ),
"Loads an image from an input stream, or any readable Python file-like
object, specifying the image format with a MIME type string.", "
:see: `wx.Image`",
ImageFromStreamMime);
%extend {
%RenameDocCtor(
EmptyImage,
"Construct an empty image of a given size, optionally setting all
pixels to black.", "
:see: `wx.Image`",
wxImage(int width=0, int height=0, bool clear = true))
{
if (width > 0 && height > 0)
return new wxImage(width, height, clear);
else
return new wxImage;
}
MustHaveApp(wxImage(const wxBitmap &bitmap));
%RenameDocCtor(
ImageFromBitmap,
"Construct an Image from a `wx.Bitmap`.", "
:see: `wx.Image`",
wxImage(const wxBitmap &bitmap))
{
return new wxImage(bitmap.ConvertToImage());
}
%RenameDocCtor(
ImageFromData,
"Construct an Image from a buffer of RGB bytes. Accepts either a
string or a buffer object holding the data and the length of the data
must be width*height*3.", "
:see: `wx.Image`",
wxImage(int width, int height, buffer data, int DATASIZE))
{
if (DATASIZE != width*height*3) {
wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
return NULL;
}
// Copy the source data so the wxImage can clean it up later
buffer copy = (buffer)malloc(DATASIZE);
if (copy == NULL) {
wxPyBLOCK_THREADS(PyErr_NoMemory());
return NULL;
}
memcpy(copy, data, DATASIZE);
return new wxImage(width, height, copy, false);
}
%RenameDocCtor(
ImageFromDataWithAlpha,
"Construct an Image from a buffer of RGB bytes with an Alpha channel.
Accepts either a string or a buffer object holding the data and the
length of the data must be width*height*3 bytes, and the length of the
alpha data must be width*height bytes.", "
:see: `wx.Image`",
wxImage(int width, int height, buffer data, int DATASIZE, buffer alpha, int ALPHASIZE))
{
if (DATASIZE != width*height*3) {
wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
return NULL;
}
if (ALPHASIZE != width*height) {
wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
return NULL;
}
// Copy the source data so the wxImage can clean it up later
buffer dcopy = (buffer)malloc(DATASIZE);
if (dcopy == NULL) {
wxPyBLOCK_THREADS(PyErr_NoMemory());
return NULL;
}
memcpy(dcopy, data, DATASIZE);
buffer acopy = (buffer)malloc(ALPHASIZE);
if (acopy == NULL) {
wxPyBLOCK_THREADS(PyErr_NoMemory());
return NULL;
}
memcpy(acopy, alpha, ALPHASIZE);
return new wxImage(width, height, dcopy, acopy, false);
}
}
// TODO: wxImage( char** xpmData );
// Turn the typemap back on again
%typemap(out) wxImage* { $result = wxPyMake_wxObject($1, $owner); }
DocDeclStr(
void , Create( int width, int height, bool clear=true ),
"Creates a fresh image. If clear is ``True``, the new image will be
initialized to black. Otherwise, the image data will be uninitialized.", "");
DocDeclStr(
void , Destroy(),
"Destroys the image data.", "");
DocDeclStr(
wxImage , Scale( int width, int height,
wxImageResizeQuality quality = wxIMAGE_QUALITY_NORMAL ),
"Returns a scaled version of the image. This is also useful for scaling
bitmaps in general as the only other way to scale bitmaps is to blit a
`wx.MemoryDC` into another `wx.MemoryDC`. The ``quality`` parameter
specifies what method to use for resampling the image. It can be
either wx.IMAGE_QUALITY_NORMAL, which uses the normal default scaling
method of pixel replication, or wx.IMAGE_QUALITY_HIGH which uses
bicubic and box averaging resampling methods for upsampling and
downsampling respectively.", "
It should be noted that although using wx.IMAGE_QUALITY_HIGH produces
much nicer looking results it is a slower method. Downsampling will
use the box averaging method which seems to operate very fast. If you
are upsampling larger images using this method you will most likely
notice that it is a bit slower and in extreme cases it will be quite
substantially slower as the bicubic algorithm has to process a lot of
data.
It should also be noted that the high quality scaling may not work as
expected when using a single mask colour for transparency, as the
scaling will blur the image and will therefore remove the mask
partially. Using the alpha channel will work.
:see: `Rescale`");
wxImage ResampleNearest(int width, int height) const;
wxImage ResampleBox(int width, int height) const;
wxImage ResampleBilinear(int width, int height) const;
wxImage ResampleBicubic(int width, int height) const;
DocDeclStr(
wxImage , Blur(int radius),
"Blurs the image in both horizontal and vertical directions by the
specified pixel ``radius``. This should not be used when using a
single mask colour for transparency.", "");
DocDeclStr(
wxImage , BlurHorizontal(int radius),
"Blurs the image in the horizontal direction only. This should not be
used when using a single mask colour for transparency.
", "");
DocDeclStr(
wxImage , BlurVertical(int radius),
"Blurs the image in the vertical direction only. This should not be
used when using a single mask colour for transparency.", "");
DocDeclStr(
wxImage , ShrinkBy( int xFactor , int yFactor ) const ,
"Return a version of the image scaled smaller by the given factors.", "");
// Accomodate the in-place edits of the next two methods so chaining of
// method calls will work.
%typemap(out) wxImage& { $result = $self; Py_INCREF($result); }
DocDeclStr(
wxImage& , Rescale(int width, int height,
wxImageResizeQuality quality = wxIMAGE_QUALITY_NORMAL),
"Changes the size of the image in-place by scaling it: after a call to
this function, the image will have the given width and height.
Returns the (modified) image itself.", "
:see: `Scale`");
// resizes the image in place
DocDeclStr(
wxImage& , Resize( const wxSize& size, const wxPoint& pos,
int r = -1, int g = -1, int b = -1 ),
"Changes the size of the image in-place without scaling it, by adding
either a border with the given colour or cropping as necessary. The
image is pasted into a new image with the given size and background
colour at the position pos relative to the upper left of the new
image. If red = green = blue = -1 then use either the current mask
colour if set or find, use, and set a suitable mask colour for any
newly exposed areas.
Returns the (modified) image itself.", "
:see: `Size`");
%typemap(out) wxImage&; // turn off this typemap
DocDeclStr(
void , SetRGB( int x, int y, byte r, byte g, byte b ),
"Sets the pixel at the given coordinate. This routine performs
bounds-checks for the coordinate so it can be considered a safe way to
manipulate the data, but in some cases this might be too slow so that
the data will have to be set directly. In that case you will have to
get access to the image data using the `GetData` method.", "");
DocDeclStrName(
void, SetRGB( const wxRect& rect,
byte r, byte g, byte b ),
"Sets the colour of the pixels within the given rectangle. This routine
performs bounds-checks for the rectangle so it can be considered a
safe way to manipulate the data.", "",
SetRGBRect);
DocDeclStr(
byte , GetRed( int x, int y ),
"Returns the red intensity at the given coordinate.", "");
DocDeclStr(
byte , GetGreen( int x, int y ),
"Returns the green intensity at the given coordinate.", "");
DocDeclStr(
byte , GetBlue( int x, int y ),
"Returns the blue intensity at the given coordinate.", "");
DocDeclStr(
void , SetAlpha(int x, int y, byte alpha),
"Sets the alpha value for the given pixel. This function should only be
called if the image has alpha channel data, use `HasAlpha` to check
for this.", "");
DocDeclStr(
byte , GetAlpha(int x, int y),
"Returns the alpha value for the given pixel. This function may only be
called for the images with alpha channel, use `HasAlpha` to check for
this.
The returned value is the *opacity* of the image, i.e. the value of 0
corresponds to the fully transparent pixels while the value of 255 to
the fully opaque pixels.", "");
DocDeclStr(
bool , HasAlpha(),
"Returns true if this image has alpha channel, false otherwise.", "
:see: `GetAlpha`, `SetAlpha`");
DocDeclStr(
void , InitAlpha(),
"Initializes the image alpha channel data. It is an error to call it if
the image already has alpha data. If it doesn't, alpha data will be by
default initialized to all pixels being fully opaque. But if the image
has a a mask colour, all mask pixels will be completely transparent.", "");
void ClearAlpha();
DocDeclStr(
bool , IsTransparent(int x, int y,
byte threshold = wxIMAGE_ALPHA_THRESHOLD) const,
"Returns ``True`` if this pixel is masked or has an alpha value less
than the spcified threshold.", "");
// find first colour that is not used in the image and has higher
// RGB values than <startR,startG,startB>
DocDeclAStr(
bool, FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT,
byte startR = 0, byte startG = 0, byte startB = 0 ) const,
"FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)",
"Find first colour that is not used in the image and has higher RGB
values than startR, startG, startB. Returns a tuple consisting of a
success flag and rgb values.", "");
DocDeclStr(
bool , ConvertAlphaToMask(byte threshold = wxIMAGE_ALPHA_THRESHOLD),
"If the image has alpha channel, this method converts it to mask. All
pixels with alpha value less than ``threshold`` are replaced with the
mask colour and the alpha channel is removed. The mask colour is
chosen automatically using `FindFirstUnusedColour`.
If the image image doesn't have alpha channel, ConvertAlphaToMask does
nothing.", "");
// TODO
//bool ConvertAlphaToMask(unsigned char mr, unsigned char mg, unsigned char mb,
// unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
DocDeclStr(
bool , ConvertColourToAlpha( byte r, byte g, byte b ),
"This method converts an image where the original alpha information is
only available as a shades of a colour (actually shades of grey)
typically when you draw anti-aliased text into a bitmap. The DC
drawing routines draw grey values on the black background although
they actually mean to draw white with differnt alpha values. This
method reverses it, assuming a black (!) background and white text.
The method will then fill up the whole image with the colour given.", "");
DocDeclStr(
bool , SetMaskFromImage(const wxImage & mask,
byte mr, byte mg, byte mb),
"Sets the image's mask so that the pixels that have RGB value of
``(mr,mg,mb)`` in ``mask`` will be masked in this image. This is done
by first finding an unused colour in the image, setting this colour as
the mask colour and then using this colour to draw all pixels in the
image who corresponding pixel in mask has given RGB value.
Returns ``False`` if ``mask`` does not have same dimensions as the
image or if there is no unused colour left. Returns ``True`` if the
mask was successfully applied.
Note that this method involves computing the histogram, which is
computationally intensive operation.", "");
// void DoFloodFill (wxCoord x, wxCoord y,
// const wxBrush & fillBrush,
// const wxColour& testColour,
// int style = wxFLOOD_SURFACE,
// int LogicalFunction = wxCOPY /* currently unused */ ) ;
DocDeclStr(
static bool , CanRead( const wxString& filename ),
"Returns True if the image handlers can read this file.", "");
DocDeclStr(
static int , GetImageCount( const wxString& filename, wxBitmapType type = wxBITMAP_TYPE_ANY ),
"If the image file contains more than one image and the image handler
is capable of retrieving these individually, this function will return
the number of available images.", "");
DocDeclStr(
bool , LoadFile( const wxString& name, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1 ),
"Loads an image from a file. If no handler type is provided, the
library will try to autodetect the format.", "");
DocDeclStrName(
bool , LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ),
"Loads an image from a file, specifying the image type with a MIME type
string.", "",
LoadMimeFile);
DocDeclStr(
bool , SaveFile( const wxString& name, wxBitmapType type ),
"Saves an image in the named file.", "");
DocDeclStrName(
bool , SaveFile( const wxString& name, const wxString& mimetype ),
"Saves an image in the named file.", "",
SaveMimeFile);
DocDeclStrName(
bool , SaveFile( wxOutputStream& stream, wxBitmapType type ),
"Saves an image in the named file.", "",
SaveStream);
DocDeclStrName(
bool , SaveFile( wxOutputStream& stream, const wxString& mimetype ),
"Saves an image in the named file.", "",
SaveMimeStream);
DocDeclStrName(
static bool , CanRead( wxInputStream& stream ),
"Returns True if the image handlers can read an image file from the
data currently on the input stream, or a readable Python file-like
object.", "",
CanReadStream);
DocDeclStrName(
bool , LoadFile( wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1 ),
"Loads an image from an input stream or a readable Python file-like
object. If no handler type is provided, the library will try to
autodetect the format.", "",
LoadStream);
DocDeclStrName(
bool , LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 ),
"Loads an image from an input stream or a readable Python file-like
object, using a MIME type string to specify the image file format.", "",
LoadMimeStream);
DocDeclStr(
bool , IsOk(),
"Returns true if image data is present.", "");
%pythoncode { Ok = IsOk }
DocDeclStr(
int , GetWidth(),
"Gets the width of the image in pixels.", "");
DocDeclStr(
int , GetHeight(),
"Gets the height of the image in pixels.", "");
DocDeclStr(
wxBitmapType , GetType() const,
"Gets the type of image found by LoadFile or specified with SaveFile", "");
DocDeclStr(
void , SetType(wxBitmapType type),
"Set the image type, this is normally only called if the image is being
created from data in the given format but not using LoadFile() (e.g.
wxGIFDecoder uses this)
", "");
DocDeclStr(
wxSize , GetSize(),
"Returns the size of the image in pixels.", "");
DocDeclStr(
wxImage , GetSubImage(const wxRect& rect),
"Returns a sub image of the current one as long as the rect belongs
entirely to the image.", "");
DocDeclStr(
wxImage , Size( const wxSize& size, const wxPoint& pos,
int r = -1, int g = -1, int b = -1 ) const,
"Returns a resized version of this image without scaling it by adding
either a border with the given colour or cropping as necessary. The
image is pasted into a new image with the given size and background
colour at the position ``pos`` relative to the upper left of the new
image. If red = green = blue = -1 then use either the current mask
colour if set or find, use, and set a suitable mask colour for any
newly exposed areas.", "
:see: `Resize`");
DocDeclStr(
void , Clear(unsigned char value = 0),
"initialize the image data with zeroes", "");
DocDeclStr(
wxImage , Copy(),
"Returns an identical copy of the image.", "");
DocDeclStr(
void , Paste( const wxImage &image, int x, int y ),
"Pastes ``image`` into this instance and takes care of the mask colour
and any out of bounds problems.", "");
//unsigned char *GetData();
//void SetData( unsigned char *data );
%extend {
DocStr(GetData,
"Returns a string containing a copy of the RGB bytes of the image.", "");
PyObject* GetData()
{
buffer data = self->GetData();
int len = self->GetWidth() * self->GetHeight() * 3;
PyObject* rv;
wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len));
return rv;
}
DocStr(SetData,
"Resets the Image's RGB data from a buffer of RGB bytes. Accepts
either a string or a buffer object holding the data and the length of
the data must be width*height*3.", "");
void SetData(buffer data, int DATASIZE)
{
if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
return;
}
buffer copy = (buffer)malloc(DATASIZE);
if (copy == NULL) {
wxPyBLOCK_THREADS(PyErr_NoMemory());
return;
}
memcpy(copy, data, DATASIZE);
self->SetData(copy, false);
// wxImage takes ownership of copy...
}
DocStr(GetDataBuffer,
"Returns a writable Python buffer object that is pointing at the RGB
image data buffer inside the wx.Image. You need to ensure that you do
not use this buffer object after the image has been destroyed.", "");
PyObject* GetDataBuffer()
{
buffer data = self->GetData();
int len = self->GetWidth() * self->GetHeight() * 3;
PyObject* rv;
wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
return rv;
}
DocStr(SetDataBuffer,
"Sets the internal image data pointer to point at a Python buffer
object. This can save making an extra copy of the data but you must
ensure that the buffer object lives longer than the wx.Image does.", "");
void SetDataBuffer(buffer data, int DATASIZE)
{
if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
return;
}
self->SetData(data, true);
}
DocStr(GetAlphaData,
"Returns a string containing a copy of the alpha bytes of the image.", "");
PyObject* GetAlphaData() {
buffer data = self->GetAlpha();
if (! data) {
RETURN_NONE();
} else {
int len = self->GetWidth() * self->GetHeight();
PyObject* rv;
wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len) );
return rv;
}
}
DocStr(SetAlphaData,
"Resets the Image's alpha data from a buffer of bytes. Accepts either
a string or a buffer object holding the data and the length of the
data must be width*height.", "");
void SetAlphaData(buffer alpha, int ALPHASIZE)
{
if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
return;
}
buffer acopy = (buffer)malloc(ALPHASIZE);
if (acopy == NULL) {
wxPyBLOCK_THREADS(PyErr_NoMemory());
return;
}
memcpy(acopy, alpha, ALPHASIZE);
self->SetAlpha(acopy, false);
// wxImage takes ownership of acopy...
}
DocStr(GetAlphaBuffer,
"Returns a writable Python buffer object that is pointing at the Alpha
data buffer inside the wx.Image. You need to ensure that you do not
use this buffer object after the image has been destroyed.", "");
PyObject* GetAlphaBuffer()
{
buffer data = self->GetAlpha();
int len = self->GetWidth() * self->GetHeight();
PyObject* rv;
wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
return rv;
}
DocStr(SetAlphaBuffer,
"Sets the internal image alpha pointer to point at a Python buffer
object. This can save making an extra copy of the data but you must
ensure that the buffer object lives as long as the wx.Image does.", "");
void SetAlphaBuffer(buffer alpha, int ALPHASIZE)
{
if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
return;
}
self->SetAlpha(alpha, true);
}
}
DocDeclStr(
void , SetMaskColour( byte r, byte g, byte b ),
"Sets the mask colour for this image (and tells the image to use the
mask).", "");
DocDeclAStr(
/*bool*/ void , GetOrFindMaskColour( byte *OUTPUT,
byte *OUTPUT,
byte *OUTPUT ) const,
"GetOrFindMaskColour() -> (r,g,b)",
"Get the current mask colour or find a suitable colour.", "");
DocDeclStr(
byte , GetMaskRed(),
"Gets the red component of the mask colour.", "");
DocDeclStr(
byte , GetMaskGreen(),
"Gets the green component of the mask colour.", "");
DocDeclStr(
byte , GetMaskBlue(),
"Gets the blue component of the mask colour.", "");
DocDeclStr(
void , SetMask( bool mask = true ),
"Specifies whether there is a mask or not. The area of the mask is
determined by the current mask colour.", "");
DocDeclStr(
bool , HasMask(),
"Returns ``True`` if there is a mask active, ``False`` otherwise.", "");
DocDeclStr(
wxImage , Rotate(double angle, const wxPoint & centre_of_rotation,
bool interpolating = true, wxPoint * offset_after_rotation = NULL) const ,
"Rotates the image about the given point, by ``angle`` radians. Passing
``True`` to ``interpolating`` results in better image quality, but is
slower. If the image has a mask, then the mask colour is used for the
uncovered pixels in the rotated image background. Otherwise, black
will be used as the fill colour.
Returns the rotated image, leaving this image intact.", "");
DocDeclStr(
wxImage , Rotate90( bool clockwise = true ) ,
"Returns a copy of the image rotated 90 degrees in the direction
indicated by ``clockwise``.", "");
wxImage Rotate180() const;
DocDeclStr(
wxImage , Mirror( bool horizontally = true ) ,
"Returns a mirrored copy of the image. The parameter ``horizontally``
indicates the orientation.", "");
DocDeclStr(
void , Replace( byte r1, byte g1, byte b1,
byte r2, byte g2, byte b2 ),
"Replaces the colour specified by ``(r1,g1,b1)`` by the colour
``(r2,g2,b2)``.", "");
%nokwargs ConvertToGreyscale;
wxImage ConvertToGreyscale();
DocDeclStr(
wxImage , ConvertToGreyscale( double lr, double lg, double lb ) const,
"Convert to greyscale image. Uses the luminance component (Y) of the
image. The luma value (YUV) is calculated using (R * lr) + (G * lg) + (B * lb),
defaults to ITU-T BT.601", "");
DocDeclStr(
wxImage , ConvertToMono( byte r, byte g, byte b ) const,
"Returns monochromatic version of the image. The returned image has
white colour where the original has ``(r,g,b)`` colour and black
colour everywhere else.", "");
// Convert to disabled (dimmed) image.
wxImage ConvertToDisabled(unsigned char brightness = 255) const;
DocDeclStr(
void , SetOption(const wxString& name, const wxString& value),
"Sets an image handler defined option. For example, when saving as a
JPEG file, the option ``wx.IMAGE_OPTION_QUALITY`` is used, which is a
number between 0 and 100 (0 is terrible, 100 is very good).", "
================================= ===
wx.IMAGE_OPTION_BMP_FORMAT
wx.IMAGE_OPTION_CUR_HOTSPOT_X
wx.IMAGE_OPTION_CUR_HOTSPOT_Y
wx.IMAGE_OPTION_RESOLUTION
wx.IMAGE_OPTION_RESOLUTIONX
wx.IMAGE_OPTION_RESOLUTIONY
wx.IMAGE_OPTION_RESOLUTIONUNIT
wx.IMAGE_OPTION_QUALITY
wx.IMAGE_OPTION_BITSPERSAMPLE
wx.IMAGE_OPTION_SAMPLESPERPIXEL
wx.IMAGE_OPTION_COMPRESSION
wx.IMAGE_OPTION_IMAGEDESCRIPTOR
wx.IMAGE_OPTION_PNG_FORMAT
wx.IMAGE_OPTION_PNG_BITDEPTH
================================= ===
:see: `HasOption`, `GetOption`, `GetOptionInt`, `SetOptionInt`");
DocDeclStrName(
void, SetOption(const wxString& name, int value),
"Sets an image option as an integer.", "
:see: `HasOption`, `GetOption`, `GetOptionInt`, `SetOption`",
SetOptionInt);
DocDeclStr(
wxString , GetOption(const wxString& name) const,
"Gets the value of an image handler option.", "
:see: `HasOption`, `GetOptionInt`, `SetOption`, `SetOptionInt`");
DocDeclStr(
int , GetOptionInt(const wxString& name) const,
"Gets the value of an image handler option as an integer. If the given
option is not present, the function returns 0.", "
:see: `HasOption`, `GetOption`, `SetOptionInt`, `SetOption`");
DocDeclStr(
bool , HasOption(const wxString& name) const,
"Returns true if the given option is present.", "
:see: `GetOption`, `GetOptionInt`, `SetOption`, `SetOptionInt`");
unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
unsigned long ComputeHistogram( wxImageHistogram& h );
static void AddHandler( wxImageHandler *handler );
static void InsertHandler( wxImageHandler *handler );
static bool RemoveHandler( const wxString& name );
%extend {
static PyObject* GetHandlers() {
wxList& list = wxImage::GetHandlers();
wxList::compatibility_iterator node = list.GetFirst();
wxPyBlock_t blocked = wxPyBeginBlockThreads();
PyObject* pyList = PyList_New(0);
while (node) {
wxObject* wxObj = node->GetData();
PyObject* pyObj = wxPyMake_wxObject(wxObj,false);
PyList_Append(pyList, pyObj);
Py_DECREF(pyObj); // the Append also does an INCREF, that's one more than we need.
node = node->GetNext();
}
wxPyEndBlockThreads(blocked);
return pyList;
}
}
DocDeclStr(
static wxString , GetImageExtWildcard(),
"Iterates all registered wxImageHandler objects, and returns a string
containing file extension masks suitable for passing to file open/save
dialog boxes.", "");
MustHaveApp(ConvertToBitmap);
MustHaveApp(ConvertToMonoBitmap);
%extend {
wxBitmap ConvertToBitmap(int depth=-1) {
wxBitmap bitmap(*self, depth);
return bitmap;
}
wxBitmap ConvertToMonoBitmap( byte red,
byte green,
byte blue ) {
wxImage mono = self->ConvertToMono( red, green, blue );
wxBitmap bitmap( mono, 1 );
return bitmap;
}
}
DocDeclStr(
void , RotateHue(double angle),
"Rotates the hue of each pixel of the image. Hue is a double in the
range -1.0..1.0 where -1.0 is -360 degrees and 1.0 is 360 degrees", "");
DocDeclStr(
static wxImage_HSVValue , RGBtoHSV(wxImage_RGBValue rgb),
"Converts a color in RGB color space to HSV color space.", "");
DocDeclStr(
static wxImage_RGBValue , HSVtoRGB(wxImage_HSVValue hsv),
"Converts a color in HSV color space to RGB color space.", "");
%pythoncode { def __nonzero__(self): return self.IsOk() }
DocStr(AdjustChannels,
"This function muliplies all 4 channels (red, green, blue, alpha) with
a factor (around 1.0). Useful for gamma correction, colour correction
and to add a certain amount of transparency to a image (fade in fade
out effects). If factor_alpha is given but the original image has no
alpha channel then a alpha channel will be added.", "");
%extend {
wxImage AdjustChannels(double factor_red,
double factor_green,
double factor_blue,
double factor_alpha=1.0)
{
wxCHECK_MSG( self->Ok(), wxNullImage, wxT("invalid image") );
wxImage dst_image( self->GetWidth(), self->GetHeight(), false );
unsigned rgblen = 3 * self->GetWidth() * self->GetHeight();
unsigned alphalen = self->GetWidth() * self->GetHeight();
unsigned char* src_data = self->GetData();
unsigned char* src_alpha = self->GetAlpha();
unsigned char* dst_data = dst_image.GetData();
unsigned char* dst_alpha = NULL;
wxCHECK_MSG( dst_data, wxNullImage, wxT("unable to create image") );
// adjust rgb
if ( factor_red == 1.0 && factor_green == 1.0 && factor_blue == 1.0)
{
// nothing to do for RGB
memcpy(dst_data, src_data, rgblen);
}
else
{
// rgb pixel for pixel
for ( unsigned i = 0; i < rgblen; i= i + 3 )
{
dst_data[i] = (unsigned char) wxMin( 255, (int) (factor_red * src_data[i]) );
dst_data[i + 1] = (unsigned char) wxMin( 255, (int) (factor_green * src_data[i + 1]) );
dst_data[i + 2] = (unsigned char) wxMin( 255, (int) (factor_blue * src_data[i + 2]) );
}
}
// adjust the mask colour
if ( self->HasMask() )
{
dst_image.SetMaskColour((unsigned char) wxMin( 255, (int) (factor_red * self->GetMaskRed() ) ),
(unsigned char) wxMin( 255, (int) (factor_green * self->GetMaskGreen() ) ),
(unsigned char) wxMin( 255, (int) (factor_blue * self->GetMaskBlue() ) ) );
}
// adjust the alpha channel
if ( src_alpha )
{
// source image already has alpha information
dst_image.SetAlpha(); // create an empty alpha channel (not initialized)
dst_alpha = dst_image.GetAlpha();
wxCHECK_MSG( dst_alpha, wxNullImage, wxT("unable to create alpha data") );
if ( factor_alpha == 1.0)
{
// no need to adjust
memcpy(dst_alpha, src_alpha, alphalen);
}
else
{
// alpha value for alpha value
for ( unsigned i = 0; i < alphalen; ++i )
{
dst_alpha[i] = (unsigned char) wxMin( 255, (int) (factor_alpha * src_alpha[i]) );
}
}
}
else if ( factor_alpha != 1.0 )
{
// no alpha yet but we want to adjust -> create
dst_image.SetAlpha(); // create an empty alpha channel (not initialized)
dst_alpha = dst_image.GetAlpha();
wxCHECK_MSG( dst_alpha, wxNullImage, wxT("unable to create alpha data") );
for ( unsigned i = 0; i < alphalen; ++i )
{
dst_alpha[i] = (unsigned char) wxMin( 255, (int) (factor_alpha * 255) );
}
}
// do we have an alpha channel and a mask in the new image?
if ( dst_alpha && dst_image.HasMask() )
{
// make the mask transparent honoring the alpha channel
const unsigned char mr = dst_image.GetMaskRed();
const unsigned char mg = dst_image.GetMaskGreen();
const unsigned char mb = dst_image.GetMaskBlue();
for ( unsigned i = 0; i < alphalen; ++i )
{
int n = i * 3;
dst_alpha[i] = ( dst_data[n] == mr && dst_data[n + 1] == mg && dst_data[n + 2] == mb )
? wxIMAGE_ALPHA_TRANSPARENT
: dst_alpha[i];
}
// remove the now mask
dst_image.SetMask(false);
}
return dst_image;
}
}
%property(AlphaBuffer, GetAlphaBuffer, SetAlphaBuffer, doc="See `GetAlphaBuffer` and `SetAlphaBuffer`");
%property(AlphaData, GetAlphaData, SetAlphaData, doc="See `GetAlphaData` and `SetAlphaData`");
%property(Data, GetData, SetData, doc="See `GetData` and `SetData`");
%property(DataBuffer, GetDataBuffer, SetDataBuffer, doc="See `GetDataBuffer` and `SetDataBuffer`");
%property(Height, GetHeight, doc="See `GetHeight`");
%property(MaskBlue, GetMaskBlue, doc="See `GetMaskBlue`");
%property(MaskGreen, GetMaskGreen, doc="See `GetMaskGreen`");
%property(MaskRed, GetMaskRed, doc="See `GetMaskRed`");
%property(Width, GetWidth, doc="See `GetWidth`");
};
// Make an image from buffer objects. Not that this is here instead of in the
// wxImage class (as a constructor) because there is already another one with
// the exact same signature, so there would be ambiguities in the generated
// C++. Doing it as an independent factory function like this accomplishes
// the same thing however.
%newobject _ImageFromBuffer;
%inline %{
wxImage* _ImageFromBuffer(int width, int height,
buffer data, int DATASIZE,
buffer alpha=NULL, int ALPHASIZE=0)
{
if (DATASIZE != width*height*3) {
wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
return NULL;
}
if (alpha != NULL) {
if (ALPHASIZE != width*height) {
wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
return NULL;
}
return new wxImage(width, height, data, alpha, true);
}
return new wxImage(width, height, data, true);
}
%}
%pythoncode {
def ImageFromBuffer(width, height, dataBuffer, alphaBuffer=None):
"""
Creates a `wx.Image` from the data in dataBuffer. The dataBuffer
parameter must be a Python object that implements the buffer interface,
such as a string, array, etc. The dataBuffer object is expected to
contain a series of RGB bytes and be width*height*3 bytes long. A buffer
object can optionally be supplied for the image's alpha channel data, and
it is expected to be width*height bytes long.
The wx.Image will be created with its data and alpha pointers initialized
to the memory address pointed to by the buffer objects, thus saving the
time needed to copy the image data from the buffer object to the wx.Image.
While this has advantages, it also has the shoot-yourself-in-the-foot
risks associated with sharing a C pointer between two objects.
To help alleviate the risk a reference to the data and alpha buffer
objects are kept with the wx.Image, so that they won't get deleted until
after the wx.Image is deleted. However please be aware that it is not
guaranteed that an object won't move its memory buffer to a new location
when it needs to resize its contents. If that happens then the wx.Image
will end up referring to an invalid memory location and could cause the
application to crash. Therefore care should be taken to not manipulate
the objects used for the data and alpha buffers in a way that would cause
them to change size.
"""
image = _core_._ImageFromBuffer(width, height, dataBuffer, alphaBuffer)
image._buffer = dataBuffer
image._alpha = alphaBuffer
return image
}
///void wxInitAllImageHandlers();
%pythoncode {
@wx.deprecated
def InitAllImageHandlers():
"""
The former functionality of InitAllImageHanders is now done internal to
the _core_ extension module and so this function has become a simple NOP.
"""
pass
}
%immutable;
const wxImage wxNullImage;
%mutable;
//---------------------------------------------------------------------------
MAKE_CONST_WXSTRING(IMAGE_OPTION_FILENAME);
MAKE_CONST_WXSTRING(IMAGE_OPTION_BMP_FORMAT);
MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_X);
MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_Y);
MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTION);
MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONX);
MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONY);
MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONUNIT);
MAKE_CONST_WXSTRING(IMAGE_OPTION_QUALITY);
MAKE_CONST_WXSTRING(IMAGE_OPTION_MAX_WIDTH);
MAKE_CONST_WXSTRING(IMAGE_OPTION_MAX_HEIGHT);
MAKE_CONST_WXSTRING(IMAGE_OPTION_ORIGINAL_WIDTH);
MAKE_CONST_WXSTRING(IMAGE_OPTION_ORIGINAL_HEIGHT);
// constants used with wxIMAGE_OPTION_RESOLUTIONUNIT
enum wxImageResolution
{
// Resolution not specified
wxIMAGE_RESOLUTION_NONE = 0,
// Resolution specified in inches
wxIMAGE_RESOLUTION_INCHES = 1,
// Resolution specified in centimeters
wxIMAGE_RESOLUTION_CM = 2
};
MAKE_CONST_WXSTRING(IMAGE_OPTION_BITSPERSAMPLE);
MAKE_CONST_WXSTRING(IMAGE_OPTION_SAMPLESPERPIXEL);
MAKE_CONST_WXSTRING(IMAGE_OPTION_COMPRESSION);
MAKE_CONST_WXSTRING(IMAGE_OPTION_IMAGEDESCRIPTOR);
MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_FORMAT);
MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_BITDEPTH);
enum
{
wxPNG_TYPE_COLOUR = 0,
wxPNG_TYPE_GREY = 2,
wxPNG_TYPE_GREY_RED = 3
};
enum
{
wxBMP_24BPP = 24, // default, do not need to set
//wxBMP_16BPP = 16, // wxQuantize can only do 236 colors?
wxBMP_8BPP = 8, // 8bpp, quantized colors
wxBMP_8BPP_GREY = 9, // 8bpp, rgb averaged to greys
wxBMP_8BPP_GRAY = wxBMP_8BPP_GREY,
wxBMP_8BPP_RED = 10, // 8bpp, red used as greyscale
wxBMP_8BPP_PALETTE = 11, // 8bpp, use the wxImage's palette
wxBMP_4BPP = 4, // 4bpp, quantized colors
wxBMP_1BPP = 1, // 1bpp, quantized "colors"
wxBMP_1BPP_BW = 2 // 1bpp, black & white from red
};
DocStr(wxBMPHandler,
"A `wx.ImageHandler` for \*.bmp bitmap files.", "");
class wxBMPHandler : public wxImageHandler {
public:
wxBMPHandler();
};
DocStr(wxICOHandler,
"A `wx.ImageHandler` for \*.ico icon files.", "");
class wxICOHandler : public wxBMPHandler {
public:
wxICOHandler();
};
DocStr(wxCURHandler,
"A `wx.ImageHandler` for \*.cur cursor files.", "");
class wxCURHandler : public wxICOHandler {
public:
wxCURHandler();
};
DocStr(wxANIHandler,
"A `wx.ImageHandler` for \*.ani animated cursor files.", "");
class wxANIHandler : public wxCURHandler {
public:
wxANIHandler();
};
//---------------------------------------------------------------------------
DocStr(wxPNGHandler,
"A `wx.ImageHandler` for PNG image files.", "");
class wxPNGHandler : public wxImageHandler {
public:
wxPNGHandler();
};
DocStr(wxGIFHandler,
"A `wx.ImageHandler` for GIF image files.", "");
class wxGIFHandler : public wxImageHandler {
public:
wxGIFHandler();
};
DocStr(wxPCXHandler,
"A `wx.ImageHandler` for PCX imager files.", "");
class wxPCXHandler : public wxImageHandler {
public:
wxPCXHandler();
};
DocStr(wxJPEGHandler,
"A `wx.ImageHandler` for JPEG/JPG image files.", "");
class wxJPEGHandler : public wxImageHandler {
public:
wxJPEGHandler();
};
DocStr(wxPNMHandler,
"A `wx.ImageHandler` for PNM image files.", "");
class wxPNMHandler : public wxImageHandler {
public:
wxPNMHandler();
};
DocStr(wxXPMHandler,
"A `wx.ImageHandler` for XPM image.", "");
class wxXPMHandler : public wxImageHandler {
public:
wxXPMHandler();
};
DocStr(wxTIFFHandler,
"A `wx.ImageHandler` for TIFF image files.", "");
class wxTIFFHandler : public wxImageHandler {
public:
wxTIFFHandler();
};
#if 0
%{
#include <wx/imagiff.h>
%}
DocStr(wxIFFHandler,
"A `wx.ImageHandler` for IFF image files.", "");
class wxIFFHandler : public wxImageHandler {
public:
wxIFFHandler();
};
#endif
%{
#include <wx/imagtga.h>
%}
DocStr(wxTGAHandler,
"A `wx.ImageHandler` for TGA image files.", "");
class wxTGAHandler : public wxImageHandler {
public:
wxTGAHandler();
};
//---------------------------------------------------------------------------
%{
#include <wx/quantize.h>
%}
enum {
wxQUANTIZE_INCLUDE_WINDOWS_COLOURS,
// wxQUANTIZE_RETURN_8BIT_DATA,
wxQUANTIZE_FILL_DESTINATION_IMAGE
};
DocStr(wxQuantize,
"Performs quantization, or colour reduction, on a wxImage.", "");
class wxQuantize /*: public wxObject */
{
public:
%extend {
DocStr(
Quantize,
"Reduce the colours in the source image and put the result into the
destination image, setting the palette in the destination if
needed. Both images may be the same, to overwrite the source image.", "
:todo: Create a version that returns the wx.Palette used.");
static bool Quantize(const wxImage& src, wxImage& dest, int desiredNoColours = 236,
int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE)
{
return wxQuantize::Quantize(src, dest,
//NULL, // palette
desiredNoColours,
NULL, // eightBitData
flags);
}
}
};
//---------------------------------------------------------------------------
|