1// qimage.sip generated by MetaSIP 2// 3// This file is part of the QtGui Python extension module. 4// 5// Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com> 6// 7// This file is part of PyQt5. 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 22 23class QImage : QPaintDevice 24{ 25%TypeHeaderCode 26#include <qimage.h> 27%End 28 29public: 30 enum InvertMode 31 { 32 InvertRgb, 33 InvertRgba, 34 }; 35 36 enum Format 37 { 38 Format_Invalid, 39 Format_Mono, 40 Format_MonoLSB, 41 Format_Indexed8, 42 Format_RGB32, 43 Format_ARGB32, 44 Format_ARGB32_Premultiplied, 45 Format_RGB16, 46 Format_ARGB8565_Premultiplied, 47 Format_RGB666, 48 Format_ARGB6666_Premultiplied, 49 Format_RGB555, 50 Format_ARGB8555_Premultiplied, 51 Format_RGB888, 52 Format_RGB444, 53 Format_ARGB4444_Premultiplied, 54%If (Qt_5_2_0 -) 55 Format_RGBX8888, 56%End 57%If (Qt_5_2_0 -) 58 Format_RGBA8888, 59%End 60%If (Qt_5_2_0 -) 61 Format_RGBA8888_Premultiplied, 62%End 63%If (Qt_5_4_0 -) 64 Format_BGR30, 65%End 66%If (Qt_5_4_0 -) 67 Format_A2BGR30_Premultiplied, 68%End 69%If (Qt_5_4_0 -) 70 Format_RGB30, 71%End 72%If (Qt_5_4_0 -) 73 Format_A2RGB30_Premultiplied, 74%End 75%If (Qt_5_5_0 -) 76 Format_Alpha8, 77%End 78%If (Qt_5_5_0 -) 79 Format_Grayscale8, 80%End 81%If (Qt_5_12_0 -) 82 Format_RGBX64, 83%End 84%If (Qt_5_12_0 -) 85 Format_RGBA64, 86%End 87%If (Qt_5_12_0 -) 88 Format_RGBA64_Premultiplied, 89%End 90%If (Qt_5_13_0 -) 91 Format_Grayscale16, 92%End 93%If (Qt_5_14_0 -) 94 Format_BGR888, 95%End 96 }; 97 98 QImage(); 99 QImage(const QSize &size, QImage::Format format); 100 QImage(int width, int height, QImage::Format format); 101 QImage(const uchar *data /KeepReference/, int width, int height, QImage::Format format); 102 QImage(void *data, int width, int height, QImage::Format format) [(uchar *data, int width, int height, QImage::Format format)]; 103 QImage(const uchar *data /KeepReference/, int width, int height, int bytesPerLine, QImage::Format format); 104 QImage(void *data, int width, int height, int bytesPerLine, QImage::Format format) [(uchar *data, int width, int height, int bytesPerLine, QImage::Format format)]; 105 explicit QImage(SIP_PYLIST xpm /TypeHint="List[str]"/) [(const char **xpm)]; 106%MethodCode 107 // The Python interface is a list of strings that make up the image. 108 109 const char **str = QtGui_ListToArray(a0); 110 111 if (str) 112 { 113 sipCpp = new sipQImage(str); 114 QtGui_DeleteArray(str); 115 } 116 else 117 sipIsErr = 1; 118%End 119 120 QImage(const QString &fileName, const char *format = 0) /ReleaseGIL/; 121 QImage(const QImage &); 122 QImage(const QVariant &variant /GetWrapper/) /NoDerived/; 123%MethodCode 124 if (a0->canConvert<QImage>()) 125 sipCpp = new sipQImage(a0->value<QImage>()); 126 else 127 sipError = sipBadCallableArg(0, a0Wrapper); 128%End 129 130 virtual ~QImage(); 131 bool isNull() const; 132 virtual int devType() const; 133 bool operator==(const QImage &) const; 134 bool operator!=(const QImage &) const; 135 void detach(); 136 bool isDetached() const; 137 QImage copy(const QRect &rect = QRect()) const; 138 QImage copy(int x, int y, int w, int h) const; 139 QImage::Format format() const; 140 QImage convertToFormat(QImage::Format f, Qt::ImageConversionFlags flags = Qt::ImageConversionFlag::AutoColor) const; 141 QImage convertToFormat(QImage::Format f, const QVector<unsigned int> &colorTable, Qt::ImageConversionFlags flags = Qt::ImageConversionFlag::AutoColor) const; 142 int width() const; 143 int height() const; 144 QSize size() const; 145 QRect rect() const; 146 int depth() const; 147 QRgb color(int i) const; 148 void setColor(int i, QRgb c); 149 bool allGray() const; 150 bool isGrayscale() const; 151 void *bits() [uchar * ()]; 152 const void *constBits() const [const uchar * ()]; 153 void *scanLine(int) [uchar * (int)]; 154 const void *constScanLine(int) const [const uchar * (int)]; 155 int bytesPerLine() const; 156 bool valid(const QPoint &pt) const; 157 bool valid(int x, int y) const; 158 int pixelIndex(const QPoint &pt) const; 159 int pixelIndex(int x, int y) const; 160 QRgb pixel(const QPoint &pt) const; 161 QRgb pixel(int x, int y) const; 162 void setPixel(const QPoint &pt, uint index_or_rgb); 163 void setPixel(int x, int y, uint index_or_rgb); 164 QVector<unsigned int> colorTable() const; 165 void setColorTable(const QVector<unsigned int> colors); 166 void fill(Qt::GlobalColor color /Constrained/); 167 void fill(const QColor &color); 168 void fill(uint pixel); 169 bool hasAlphaChannel() const; 170 void setAlphaChannel(const QImage &alphaChannel); 171 QImage createAlphaMask(Qt::ImageConversionFlags flags = Qt::ImageConversionFlag::AutoColor) const; 172 QImage createHeuristicMask(bool clipTight = true) const; 173 QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const; 174 QImage scaled(const QSize &size, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const; 175 QImage scaledToWidth(int width, Qt::TransformationMode mode = Qt::FastTransformation) const; 176 QImage scaledToHeight(int height, Qt::TransformationMode mode = Qt::FastTransformation) const; 177 QImage mirrored(bool horizontal = false, bool vertical = true) const; 178 QImage rgbSwapped() const; 179 void invertPixels(QImage::InvertMode mode = QImage::InvertRgb); 180 bool load(QIODevice *device, const char *format) /ReleaseGIL/; 181 bool load(const QString &fileName, const char *format = 0) /ReleaseGIL/; 182 bool loadFromData(const uchar *data /Array/, int len /ArraySize/, const char *format = 0); 183 bool loadFromData(const QByteArray &data, const char *format = 0); 184 bool save(const QString &fileName, const char *format = 0, int quality = -1) const /ReleaseGIL/; 185 bool save(QIODevice *device, const char *format = 0, int quality = -1) const /ReleaseGIL/; 186 static QImage fromData(const uchar *data /Array/, int size /ArraySize/, const char *format = 0); 187 static QImage fromData(const QByteArray &data, const char *format = 0); 188 virtual QPaintEngine *paintEngine() const; 189 int dotsPerMeterX() const; 190 int dotsPerMeterY() const; 191 void setDotsPerMeterX(int); 192 void setDotsPerMeterY(int); 193 QPoint offset() const; 194 void setOffset(const QPoint &); 195 QStringList textKeys() const; 196 QString text(const QString &key = QString()) const; 197 void setText(const QString &key, const QString &value); 198 199protected: 200 virtual int metric(QPaintDevice::PaintDeviceMetric metric) const; 201%If (Qt_5_5_0 -) 202 QImage smoothScaled(int w, int h) const; 203%End 204 205public: 206 QImage createMaskFromColor(QRgb color, Qt::MaskMode mode = Qt::MaskInColor) const; 207 QImage transformed(const QTransform &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const; 208 static QTransform trueMatrix(const QTransform &, int w, int h); 209 qint64 cacheKey() const; 210 int colorCount() const; 211 void setColorCount(int); 212 int byteCount() const; 213 int bitPlaneCount() const; 214 void swap(QImage &other /Constrained/); 215 qreal devicePixelRatio() const; 216 void setDevicePixelRatio(qreal scaleFactor); 217%If (Qt_5_4_0 -) 218 QPixelFormat pixelFormat() const; 219%End 220%If (Qt_5_4_0 -) 221 static QPixelFormat toPixelFormat(QImage::Format format); 222%End 223%If (Qt_5_4_0 -) 224 static QImage::Format toImageFormat(QPixelFormat format); 225%End 226%If (Qt_5_6_0 -) 227 QColor pixelColor(int x, int y) const; 228%End 229%If (Qt_5_6_0 -) 230 QColor pixelColor(const QPoint &pt) const; 231%End 232%If (Qt_5_6_0 -) 233 void setPixelColor(int x, int y, const QColor &c); 234%End 235%If (Qt_5_6_0 -) 236 void setPixelColor(const QPoint &pt, const QColor &c); 237%End 238%If (Qt_5_9_0 -) 239 bool reinterpretAsFormat(QImage::Format f); 240%End 241%If (Qt_5_10_0 -) 242 Py_ssize_t sizeInBytes() const [qsizetype ()]; 243%End 244%If (Qt_5_13_0 -) 245 void convertTo(QImage::Format f, Qt::ImageConversionFlags flags = Qt::ImageConversionFlag::AutoColor); 246%End 247%If (Qt_5_14_0 -) 248 QColorSpace colorSpace() const; 249%End 250%If (Qt_5_14_0 -) 251 QImage convertedToColorSpace(const QColorSpace &) const; 252%End 253%If (Qt_5_14_0 -) 254 void convertToColorSpace(const QColorSpace &); 255%End 256%If (Qt_5_14_0 -) 257 void setColorSpace(const QColorSpace &); 258%End 259%If (Qt_5_14_0 -) 260 void applyColorTransform(const QColorTransform &transform); 261%End 262}; 263 264QDataStream &operator<<(QDataStream &, const QImage & /Constrained/) /ReleaseGIL/; 265QDataStream &operator>>(QDataStream &, QImage & /Constrained/) /ReleaseGIL/; 266 267%ModuleHeaderCode 268const char **QtGui_ListToArray(PyObject *lst); 269void QtGui_DeleteArray(const char **arr); 270%End 271 272%ModuleCode 273// Convert a list of strings to an array of ASCII strings on the heap. Used by 274// QImage and QPixmap. 275const char **QtGui_ListToArray(PyObject *lst) 276{ 277 Py_ssize_t nstr = PyList_Size(lst); 278 const char **arr = new const char *[nstr + 1]; 279 280 for (Py_ssize_t i = 0; i < nstr; ++i) 281 { 282 PyObject *ascii_obj = PyList_GetItem(lst, i); 283 const char *ascii = sipString_AsASCIIString(&ascii_obj); 284 285 if (!ascii) 286 { 287 while (i-- > 0) 288 delete[] arr[i]; 289 290 delete[] arr; 291 292 return 0; 293 } 294 295 // Copy the string. 296 arr[i] = qstrdup(ascii); 297 298 Py_DECREF(ascii_obj); 299 } 300 301 // The sentinal. 302 arr[nstr] = 0; 303 304 return arr; 305} 306 307 308// Return a string array created by QtGui_ListToArray() to the heap. 309void QtGui_DeleteArray(const char **arr) 310{ 311 for (Py_ssize_t i = 0; arr[i]; ++i) 312 delete[] arr[i]; 313 314 delete[] arr; 315} 316%End 317