Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qimage_darwin.mm
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qimage.h"
5
6#include <private/qcore_mac_p.h>
7#include <private/qcoregraphics_p.h>
8
9#import <Foundation/Foundation.h>
10#import <CoreGraphics/CoreGraphics.h>
11
13
62CGImageRef QImage::toCGImage() const
63{
64 if (isNull())
65 return nil;
66
67 CGBitmapInfo bitmapInfo = qt_mac_bitmapInfoForImage(*this);
68
69 // Format not supported: return nil CGImageRef
70 if (bitmapInfo == kCGImageAlphaNone)
71 return nil;
72
73 // Create a data provider that owns a copy of the QImage and references the image data.
74 auto deleter = [](void *image, const void *, size_t)
75 { delete static_cast<QImage *>(image); };
76 QCFType<CGDataProviderRef> dataProvider =
77 CGDataProviderCreateWithData(new QImage(*this), bits(), sizeInBytes(), deleter);
78
79 QCFType<CGColorSpaceRef> colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
80
81 const size_t bitsPerComponent = 8;
82 const size_t bitsPerPixel = 32;
83 const CGFloat *decode = nullptr;
84 const bool shouldInterpolate = false;
85
86 return CGImageCreate(width(), height(), bitsPerComponent, bitsPerPixel,
87 this->bytesPerLine(), colorSpace, bitmapInfo, dataProvider,
88 decode, shouldInterpolate, kCGRenderingIntentDefault);
89}
90
\inmodule QtGui
Definition qimage.h:37
QColorSpace colorSpace() const
Definition qimage.cpp:5155
qsizetype bytesPerLine() const
Returns the number of bytes per image scanline.
Definition qimage.cpp:1560
qsizetype sizeInBytes() const
Definition qimage.cpp:1548
int width() const
Returns the width of the image.
uchar * bits()
Returns a pointer to the first pixel data.
Definition qimage.cpp:1698
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition qimage.cpp:1222
int height() const
Returns the height of the image.
QImage() noexcept
Constructs a null image.
Definition qimage.cpp:791
Combined button and popup list for selecting options.
Definition image.cpp:4
float CGFloat
QT_USE_NAMESPACE QT_BEGIN_NAMESPACE CGBitmapInfo qt_mac_bitmapInfoForImage(const QImage &image)
constexpr QPixelLayout::BPP bitsPerPixel()
#define decode(x)