qimage.sip 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. // qimage.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtGui Python extension module.
  4. //
  5. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of PyQt6.
  8. //
  9. // This file may be used under the terms of the GNU General Public License
  10. // version 3.0 as published by the Free Software Foundation and appearing in
  11. // the file LICENSE included in the packaging of this file. Please review the
  12. // following information to ensure the GNU General Public License version 3.0
  13. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  14. //
  15. // If you do not wish to use this file under the terms of the GPL version 3.0
  16. // then you may purchase a commercial license. For more information contact
  17. // info@riverbankcomputing.com.
  18. //
  19. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. %If (Windows)
  22. typedef struct HBITMAP__ *HBITMAP;
  23. %End
  24. %If (Windows)
  25. typedef struct HICON__ *HICON;
  26. %End
  27. class QImage : public QPaintDevice
  28. {
  29. %TypeHeaderCode
  30. #include <qimage.h>
  31. %End
  32. %TypeCode
  33. // The C++ closure that is passed to the QImage ctor.
  34. struct QtGui_QImage_closure
  35. {
  36. PyObject *py_cleanup;
  37. PyObject *py_closure;
  38. };
  39. // Return the optional C++ closure for a QImage ctor.
  40. static QtGui_QImage_closure *QtGui_QImage_buffer(PyObject *py_cleanup,
  41. PyObject *py_closure)
  42. {
  43. // The cleanup callable or nullptr if there isn't one.
  44. if (py_cleanup == Py_None)
  45. py_cleanup = nullptr;
  46. if (!py_cleanup)
  47. return nullptr;
  48. QtGui_QImage_closure *closure = new QtGui_QImage_closure;
  49. Py_INCREF(py_cleanup);
  50. if (!py_closure)
  51. py_closure = Py_None;
  52. Py_INCREF(py_closure);
  53. closure->py_cleanup = py_cleanup;
  54. closure->py_closure = py_closure;
  55. return closure;
  56. }
  57. // The cleanup function for a QImage ctor.
  58. static void QtGui_QImage_cleanup(void *c)
  59. {
  60. SIP_BLOCK_THREADS
  61. QtGui_QImage_closure *closure = reinterpret_cast<QtGui_QImage_closure *>(c);
  62. bool is_exception = false;
  63. PyObject *res = PyObject_CallFunctionObjArgs(closure->py_cleanup,
  64. closure->py_closure, SIP_NULLPTR);
  65. Py_DECREF(closure->py_closure);
  66. Py_DECREF(closure->py_cleanup);
  67. if (res)
  68. Py_DECREF(res);
  69. else
  70. is_exception = true;
  71. delete closure;
  72. if (is_exception)
  73. pyqt6_qtgui_err_print();
  74. SIP_UNBLOCK_THREADS
  75. }
  76. %End
  77. public:
  78. enum InvertMode
  79. {
  80. InvertRgb,
  81. InvertRgba,
  82. };
  83. enum Format
  84. {
  85. Format_Invalid,
  86. Format_Mono,
  87. Format_MonoLSB,
  88. Format_Indexed8,
  89. Format_RGB32,
  90. Format_ARGB32,
  91. Format_ARGB32_Premultiplied,
  92. Format_RGB16,
  93. Format_ARGB8565_Premultiplied,
  94. Format_RGB666,
  95. Format_ARGB6666_Premultiplied,
  96. Format_RGB555,
  97. Format_ARGB8555_Premultiplied,
  98. Format_RGB888,
  99. Format_RGB444,
  100. Format_ARGB4444_Premultiplied,
  101. Format_RGBX8888,
  102. Format_RGBA8888,
  103. Format_RGBA8888_Premultiplied,
  104. Format_BGR30,
  105. Format_A2BGR30_Premultiplied,
  106. Format_RGB30,
  107. Format_A2RGB30_Premultiplied,
  108. Format_Alpha8,
  109. Format_Grayscale8,
  110. Format_RGBX64,
  111. Format_RGBA64,
  112. Format_RGBA64_Premultiplied,
  113. Format_Grayscale16,
  114. Format_BGR888,
  115. %If (Qt_6_2_0 -)
  116. Format_RGBX16FPx4,
  117. %End
  118. %If (Qt_6_2_0 -)
  119. Format_RGBA16FPx4,
  120. %End
  121. %If (Qt_6_2_0 -)
  122. Format_RGBA16FPx4_Premultiplied,
  123. %End
  124. %If (Qt_6_2_0 -)
  125. Format_RGBX32FPx4,
  126. %End
  127. %If (Qt_6_2_0 -)
  128. Format_RGBA32FPx4,
  129. %End
  130. %If (Qt_6_2_0 -)
  131. Format_RGBA32FPx4_Premultiplied,
  132. %End
  133. %If (Qt_6_8_0 -)
  134. Format_CMYK8888,
  135. %End
  136. };
  137. QImage();
  138. QImage(const QSize &size, QImage::Format format);
  139. QImage(int width, int height, QImage::Format format);
  140. QImage(const uchar *data /KeepReference/, int width, int height, QImage::Format format, SIP_PYCALLABLE cleanupFunction /AllowNone/ = 0, SIP_PYOBJECT cleanupInfo /AllowNone/ = 0) [(const uchar *data, int width, int height, QImage::Format format, QImageCleanupFunction cleanupFunction = 0, void *cleanupInfo = 0)];
  141. %MethodCode
  142. QtGui_QImage_closure *closure = QtGui_QImage_buffer(a4, a5);
  143. sipCpp = new sipQImage(a0, a1, a2, a3,
  144. (closure ? QtGui_QImage_cleanup : nullptr), closure);
  145. %End
  146. QImage(const uchar *data /KeepReference/, int width, int height, qsizetype bytesPerLine, QImage::Format format, SIP_PYCALLABLE cleanupFunction /AllowNone/ = 0, SIP_PYOBJECT cleanupInfo /AllowNone/ = 0) [(const uchar *data, int width, int height, qsizetype bytesPerLine, QImage::Format format, QImageCleanupFunction cleanupFunction = 0, void *cleanupInfo = 0)];
  147. %MethodCode
  148. QtGui_QImage_closure *closure = QtGui_QImage_buffer(a5, a6);
  149. sipCpp = new sipQImage(a0, a1, a2, a3, a4,
  150. (closure ? QtGui_QImage_cleanup : nullptr), closure);
  151. %End
  152. QImage(void *data /KeepReference/, int width, int height, QImage::Format format, SIP_PYCALLABLE cleanupFunction /AllowNone/ = 0, SIP_PYOBJECT cleanupInfo /AllowNone/ = 0) /NoTypeHint/ [(uchar *data, int width, int height, QImage::Format format, QImageCleanupFunction cleanupFunction = 0, void *cleanupInfo = 0)];
  153. %MethodCode
  154. QtGui_QImage_closure *closure = QtGui_QImage_buffer(a4, a5);
  155. sipCpp = new sipQImage(reinterpret_cast<uchar *>(a0), a1, a2, a3,
  156. (closure ? QtGui_QImage_cleanup : nullptr), closure);
  157. %End
  158. QImage(void *data /KeepReference/, int width, int height, qsizetype bytesPerLine, QImage::Format format, SIP_PYCALLABLE cleanupFunction /AllowNone/ = 0, SIP_PYOBJECT cleanupInfo /AllowNone/ = 0) /NoTypeHint/ [(uchar *data, int width, int height, qsizetype bytesPerLine, QImage::Format format, QImageCleanupFunction cleanupFunction = 0, void *cleanupInfo = 0)];
  159. %MethodCode
  160. QtGui_QImage_closure *closure = QtGui_QImage_buffer(a5, a6);
  161. sipCpp = new sipQImage(reinterpret_cast<uchar *>(a0), a1, a2, a3, a4,
  162. (closure ? QtGui_QImage_cleanup : nullptr), closure);
  163. %End
  164. explicit QImage(SIP_PYLIST xpm /TypeHint="List[str]"/) [(const char * const *xpm)];
  165. %MethodCode
  166. // The Python interface is a list of ASCII strings that make up the image.
  167. const char **str = QtGui_ListToArray(a0);
  168. if (str)
  169. {
  170. sipCpp = new sipQImage(str);
  171. QtGui_DeleteArray(str);
  172. }
  173. else
  174. sipIsErr = 1;
  175. %End
  176. QImage(const QString &fileName, const char *format = 0) /ReleaseGIL/;
  177. QImage(const QImage &);
  178. QImage(const QVariant &variant /GetWrapper/) /NoDerived/;
  179. %MethodCode
  180. if (a0->canConvert<QImage>())
  181. sipCpp = new sipQImage(a0->value<QImage>());
  182. else
  183. sipError = sipBadCallableArg(0, a0Wrapper);
  184. %End
  185. virtual ~QImage();
  186. bool isNull() const;
  187. bool operator==(const QImage &) const;
  188. bool operator!=(const QImage &) const;
  189. QImage copy(const QRect &rect = QRect()) const;
  190. QImage copy(int x, int y, int w, int h) const;
  191. QImage::Format format() const;
  192. QImage convertToFormat(QImage::Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const;
  193. QImage convertToFormat(QImage::Format f, const QList<unsigned int> &colorTable, Qt::ImageConversionFlags flags = Qt::AutoColor) const;
  194. %If (Windows)
  195. HBITMAP toHBITMAP() const;
  196. %End
  197. %If (Windows)
  198. static QImage fromHBITMAP(HBITMAP hbitmap);
  199. %End
  200. %If (Windows)
  201. HICON toHICON(const QImage &mask = {}) const;
  202. %End
  203. %If (Windows)
  204. static QImage fromHICON(HICON hicon);
  205. %End
  206. int width() const;
  207. int height() const;
  208. QSize size() const;
  209. QRect rect() const;
  210. int depth() const;
  211. QRgb color(int i) const;
  212. void setColor(int i, QRgb c);
  213. bool allGray() const;
  214. bool isGrayscale() const;
  215. void *bits() [uchar * ()];
  216. const void *constBits() const [const uchar * ()];
  217. void *scanLine(int) [uchar * (int)];
  218. const void *constScanLine(int) const [const uchar * (int)];
  219. qsizetype bytesPerLine() const;
  220. bool valid(const QPoint &pt) const;
  221. bool valid(int x, int y) const;
  222. int pixelIndex(const QPoint &pt) const;
  223. int pixelIndex(int x, int y) const;
  224. QRgb pixel(const QPoint &pt) const;
  225. QRgb pixel(int x, int y) const;
  226. void setPixel(const QPoint &pt, uint index_or_rgb);
  227. void setPixel(int x, int y, uint index_or_rgb);
  228. QList<unsigned int> colorTable() const;
  229. void setColorTable(const QList<unsigned int> &colors);
  230. void fill(uint pixel);
  231. void fill(Qt::GlobalColor color /Constrained/);
  232. void fill(const QColor &color);
  233. bool hasAlphaChannel() const;
  234. void setAlphaChannel(const QImage &alphaChannel);
  235. QImage createAlphaMask(Qt::ImageConversionFlags flags = Qt::AutoColor) const;
  236. QImage createHeuristicMask(bool clipTight = true) const;
  237. QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const;
  238. QImage scaled(const QSize &size, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const;
  239. QImage scaledToWidth(int width, Qt::TransformationMode mode = Qt::FastTransformation) const;
  240. QImage scaledToHeight(int height, Qt::TransformationMode mode = Qt::FastTransformation) const;
  241. QImage mirrored(bool horizontal = false, bool vertical = true) const;
  242. void mirror(bool horizontal = false, bool vertical = true);
  243. QImage rgbSwapped() const;
  244. void rgbSwap();
  245. void invertPixels(QImage::InvertMode mode = QImage::InvertRgb);
  246. bool load(QIODevice *device, const char *format) /ReleaseGIL/;
  247. bool load(const QString &fileName, const char *format = 0) /ReleaseGIL/;
  248. bool loadFromData(const uchar *data /Array/, int len /ArraySize/, const char *format = 0);
  249. bool loadFromData(const QByteArray &data, const char *format = 0);
  250. bool save(const QString &fileName, const char *format = 0, int quality = -1) const /ReleaseGIL/;
  251. bool save(QIODevice *device, const char *format = 0, int quality = -1) const /ReleaseGIL/;
  252. static QImage fromData(const uchar *data /Array/, int size /ArraySize/, const char *format = 0);
  253. static QImage fromData(const QByteArray &data, const char *format = 0);
  254. virtual QPaintEngine *paintEngine() const;
  255. int dotsPerMeterX() const;
  256. int dotsPerMeterY() const;
  257. void setDotsPerMeterX(int);
  258. void setDotsPerMeterY(int);
  259. QPoint offset() const;
  260. void setOffset(const QPoint &);
  261. QStringList textKeys() const;
  262. QString text(const QString &key = QString()) const;
  263. void setText(const QString &key, const QString &value);
  264. QImage createMaskFromColor(QRgb color, Qt::MaskMode mode = Qt::MaskInColor) const;
  265. QImage transformed(const QTransform &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const;
  266. static QTransform trueMatrix(const QTransform &, int w, int h);
  267. qint64 cacheKey() const;
  268. int colorCount() const;
  269. void setColorCount(int);
  270. int bitPlaneCount() const;
  271. void swap(QImage &other /Constrained/);
  272. qreal devicePixelRatio() const;
  273. void setDevicePixelRatio(qreal scaleFactor);
  274. QPixelFormat pixelFormat() const;
  275. static QPixelFormat toPixelFormat(QImage::Format format);
  276. static QImage::Format toImageFormat(QPixelFormat format);
  277. QColor pixelColor(int x, int y) const;
  278. QColor pixelColor(const QPoint &pt) const;
  279. void setPixelColor(int x, int y, const QColor &c);
  280. void setPixelColor(const QPoint &pt, const QColor &c);
  281. bool reinterpretAsFormat(QImage::Format f);
  282. qsizetype sizeInBytes() const;
  283. QImage convertedTo(QImage::Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const;
  284. void convertTo(QImage::Format f, Qt::ImageConversionFlags flags = Qt::AutoColor);
  285. QColorSpace colorSpace() const;
  286. void setColorSpace(const QColorSpace &);
  287. QImage convertedToColorSpace(const QColorSpace &) const;
  288. %If (Qt_6_8_0 -)
  289. QImage convertedToColorSpace(const QColorSpace &colorSpace, QImage::Format format, Qt::ImageConversionFlags flags = Qt::AutoColor);
  290. %End
  291. void convertToColorSpace(const QColorSpace &);
  292. %If (Qt_6_8_0 -)
  293. void convertToColorSpace(const QColorSpace &colorSpace, QImage::Format format, Qt::ImageConversionFlags flags = Qt::AutoColor);
  294. %End
  295. void applyColorTransform(const QColorTransform &transform);
  296. %If (Qt_6_8_0 -)
  297. void applyColorTransform(const QColorTransform &transform, QImage::Format format, Qt::ImageConversionFlags flags = Qt::AutoColor);
  298. %End
  299. %If (Qt_6_2_0 -)
  300. QSizeF deviceIndependentSize() const;
  301. %End
  302. %If (Qt_6_4_0 -)
  303. QImage colorTransformed(const QColorTransform &transform) const;
  304. %End
  305. %If (Qt_6_8_0 -)
  306. QImage colorTransformed(const QColorTransform &transform, QImage::Format format, Qt::ImageConversionFlags flags = Qt::AutoColor);
  307. %End
  308. %If (Qt_6_9_0 -)
  309. QImage flipped(Qt::Orientations orient = Qt::Vertical) const;
  310. %End
  311. %If (Qt_6_9_0 -)
  312. void flip(Qt::Orientations orient = Qt::Vertical);
  313. %End
  314. };
  315. QDataStream &operator<<(QDataStream &, const QImage &) /ReleaseGIL/;
  316. QDataStream &operator>>(QDataStream &, QImage & /Constrained/) /ReleaseGIL/;
  317. %ModuleHeaderCode
  318. // Helpers for QImage and QPixmap ctors.
  319. const char **QtGui_ListToArray(PyObject *lst);
  320. void QtGui_DeleteArray(const char **arr);
  321. // Imports from QtCore.
  322. typedef void (*pyqt6_qtgui_err_print_t)();
  323. extern pyqt6_qtgui_err_print_t pyqt6_qtgui_err_print;
  324. %End
  325. %ModuleCode
  326. // Convert a list of strings to an array of ASCII strings on the heap. Used by
  327. // QImage and QPixmap.
  328. const char **QtGui_ListToArray(PyObject *lst)
  329. {
  330. Py_ssize_t nstr = PyList_Size(lst);
  331. const char **arr = new const char *[nstr + 1];
  332. for (Py_ssize_t i = 0; i < nstr; ++i)
  333. {
  334. PyObject *ascii_obj = PyList_GetItem(lst, i);
  335. const char *ascii = sipString_AsASCIIString(&ascii_obj);
  336. if (!ascii)
  337. {
  338. while (i-- > 0)
  339. delete[] arr[i];
  340. delete[] arr;
  341. return 0;
  342. }
  343. // Copy the string.
  344. arr[i] = qstrdup(ascii);
  345. Py_DECREF(ascii_obj);
  346. }
  347. // The sentinal.
  348. arr[nstr] = 0;
  349. return arr;
  350. }
  351. // Return a string array created by QtGui_ListToArray() to the heap.
  352. void QtGui_DeleteArray(const char **arr)
  353. {
  354. for (Py_ssize_t i = 0; arr[i]; ++i)
  355. delete[] arr[i];
  356. delete[] arr;
  357. }
  358. // Imports from QtCore.
  359. pyqt6_qtgui_err_print_t pyqt6_qtgui_err_print;
  360. %End
  361. %PostInitialisationCode
  362. // Imports from QtCore.
  363. pyqt6_qtgui_err_print = (pyqt6_qtgui_err_print_t)sipImportSymbol("pyqt6_err_print");
  364. Q_ASSERT(pyqt6_qtgui_err_print);
  365. %End