Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
14/*!
15 \fn CGImageRef QImage::toCGImage() const
16
17 Creates a \c CGImage equivalent to this QImage, and returns a \c CGImageRef
18 handle.
19
20 The returned CGImageRef partakes in the QImage implicit sharing,
21 and holds a reference to the QImage data. CGImage is immutable
22 and will never detach the QImage. Writing to the QImage will detach
23 as usual.
24
25 This function is fast, and does not copy or convert image data.
26
27 If the image format can not be converted a null CGImageRef will
28 be returned. Users of this function may then convert the QImage
29 to a supported format first, for example Format_ARGB32_Premultiplied.
30
31 If the image does not have a color space set the resulting
32 CGImageRef color space is set to the sRGB color space.
33
34 \ingroup platform-type-conversions
35*/
36CGImageRef QImage::toCGImage() const
37{
38 if (isNull())
39 return nil;
40
41 auto cgImageFormat = qt_mac_cgImageFormatForImage(*this);
42 if (!cgImageFormat)
43 return nil;
44
45 // Create a data provider that owns a copy of the QImage and references the image data.
46 auto deleter = [](void *image, const void *, size_t)
47 { delete static_cast<QImage *>(image); };
48 QCFType<CGDataProviderRef> dataProvider =
49 CGDataProviderCreateWithData(new QImage(*this), bits(), sizeInBytes(), deleter);
50
51 static constexpr bool shouldInterpolate = false;
52 static constexpr CGFloat *decodeArray = nullptr;
53
54 return CGImageCreate(width(), height(),
55 cgImageFormat->bitsPerComponent, cgImageFormat->bitsPerPixel,
56 this->bytesPerLine(), cgImageFormat->colorSpace,
57 cgImageFormat->bitmapInfo, dataProvider, decodeArray,
58 shouldInterpolate, kCGRenderingIntentDefault
59 );
60}
61
62QT_END_NAMESPACE
Combined button and popup list for selecting options.