Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2017 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qimage.h" |
41 | |
42 | #include <private/qcore_mac_p.h> |
43 | #include <private/qcoregraphics_p.h> |
44 | |
45 | #import <Foundation/Foundation.h> |
46 | #import <CoreGraphics/CoreGraphics.h> |
47 | |
48 | QT_BEGIN_NAMESPACE |
49 | |
50 | /*! |
51 | Creates a \c CGImage equivalent to this QImage. Returns a |
52 | \c CGImageRef handle. |
53 | |
54 | The returned CGImageRef partakes in the QImage implicit sharing, |
55 | and holds a reference to the QImage data. CGImage is immutable |
56 | and will never detach the QImage. Writing to the QImage will detach |
57 | as usual. |
58 | |
59 | This function is fast, and does not copy or convert image data. |
60 | |
61 | The following image formats are supported, and will be mapped to |
62 | a corresponding native image type: |
63 | |
64 | \table |
65 | \header |
66 | \li Qt |
67 | \li CoreGraphics |
68 | \row |
69 | \li Format_ARGB32 |
70 | \li kCGImageAlphaFirst | kCGBitmapByteOrder32Host |
71 | \row |
72 | \li Format_RGB32 |
73 | \li kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host |
74 | \row |
75 | \li Format_RGBA8888_Premultiplied |
76 | \li kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big |
77 | \row |
78 | \li Format_RGBA8888 |
79 | \li kCGImageAlphaLast | kCGBitmapByteOrder32Big |
80 | \row |
81 | \li Format_RGBX8888 |
82 | \li kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Big |
83 | \row |
84 | \li Format_ARGB32_Premultiplied |
85 | \li kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host |
86 | \endtable |
87 | |
88 | Other formats are not supported; this function returns a null |
89 | CGImageRef for those cases. Users of this function may then |
90 | convert the QImage to a supported formate first, for example |
91 | Format_ARGB32_Premultiplied. |
92 | |
93 | The CGImageRef color space is set to the sRGB color space. |
94 | |
95 | \sa QtMac::toNSImage() |
96 | */ |
97 | CGImageRef QImage::toCGImage() const |
98 | { |
99 | if (isNull()) |
100 | return nil; |
101 | |
102 | CGBitmapInfo bitmapInfo = qt_mac_bitmapInfoForImage(*this); |
103 | |
104 | // Format not supported: return nil CGImageRef |
105 | if (bitmapInfo == kCGImageAlphaNone) |
106 | return nil; |
107 | |
108 | // Create a data provider that owns a copy of the QImage and references the image data. |
109 | auto deleter = [](void *image, const void *, size_t) |
110 | { delete static_cast<QImage *>(image); }; |
111 | QCFType<CGDataProviderRef> dataProvider = |
112 | CGDataProviderCreateWithData(new QImage(*this), bits(), sizeInBytes(), deleter); |
113 | |
114 | QCFType<CGColorSpaceRef> colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); |
115 | |
116 | const size_t bitsPerComponent = 8; |
117 | const size_t bitsPerPixel = 32; |
118 | const CGFloat *decode = nullptr; |
119 | const bool shouldInterpolate = false; |
120 | |
121 | return CGImageCreate(width(), height(), bitsPerComponent, bitsPerPixel, |
122 | this->bytesPerLine(), colorSpace, bitmapInfo, dataProvider, |
123 | decode, shouldInterpolate, kCGRenderingIntentDefault); |
124 | } |
125 | |
126 | QT_END_NAMESPACE |
127 |
Warning: That file was not part of the compilation database. It may have many parsing errors.