ObjFW
 
Loading...
Searching...
No Matches
OFImage.h
1/*
2 * Copyright (c) 2008-2026 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#import "OFObject.h"
21#import "OFString.h"
22
23OF_ASSUME_NONNULL_BEGIN
24
25@class OFColor;
26@class OFColorSpace;
27@class OFDictionary OF_GENERIC(KeyType, ObjectType);
28@class OFMutableImage;
29@class OFSeekableStream;
30
36typedef enum {
37 /* Private */
38 _OFPixelFormatInt8 = 0x10000,
39 _OFPixelFormatInt16 = 0x20000,
40 _OFPixelFormatInt32 = 0x30000,
41 _OFPixelFormatFP16 = 0x50000,
42 _OFPixelFormatFP32 = 0x60000,
43
45 OFPixelFormatUnknown = 0,
47 OFPixelFormatRGB888 = _OFPixelFormatInt8,
49 OFPixelFormatBGR888,
51 OFPixelFormatRGB565 = _OFPixelFormatInt16,
53 OFPixelFormatRGBA8888 = _OFPixelFormatInt32,
55 OFPixelFormatARGB8888,
57 OFPixelFormatABGR8888,
59 OFPixelFormatBGRA8888,
61 OFPixelFormatRGBA16161616FP = _OFPixelFormatFP16 + 2,
63 OFPixelFormatRGBA32323232FP = _OFPixelFormatFP32 + 2
64} OFPixelFormat;
65
77typedef OFConstantString *OFImageFormat;
78
79#ifdef __cplusplus
80extern "C" {
81#endif
85extern const OFImageFormat OFImageFormatBMP;
86
90extern const OFImageFormat OFImageFormatGIF;
91
95extern const OFImageFormat OFImageFormatJPEG;
96
100extern const OFImageFormat OFImageFormatPNG;
101
105extern const OFImageFormat OFImageFormatQOI;
106#ifdef __cplusplus
107}
108#endif
109
116{
117 void *_pixels;
118 OFPixelFormat _pixelFormat;
119 OFSize _size;
120 OFColorSpace *_colorSpace;
121 bool _freeWhenDone;
122 OFSize _dotsPerInch;
123 OF_RESERVE_IVARS(OFImage, 4)
124}
125
129@property (readonly, nonatomic) const void *pixels OF_RETURNS_INNER_POINTER;
130
134@property (readonly, nonatomic) OFPixelFormat pixelFormat;
135
139@property (readonly, nonatomic) OFSize size;
140
147@property (readonly, retain, nonatomic) OFColorSpace *colorSpace;
148
152@property (readonly, nonatomic) unsigned int bitsPerPixel;
153
157@property (readonly, nonatomic) OFSize dotsPerInch;
158
175+ (OFMutableImage *)imageWithStream: (OFSeekableStream *)stream
176 imageFormat: (OFImageFormat)format;
177
188+ (instancetype)imageWithPixels: (const void *)pixels
189 pixelFormat: (OFPixelFormat)pixelFormat
190 size: (OFSize)size;
191
203+ (instancetype)imageWithPixels: (const void *)pixels
204 pixelFormat: (OFPixelFormat)pixelFormat
205 size: (OFSize)size
206 colorSpace: (OFColorSpace *)colorSpace;
207
221+ (instancetype)imageWithPixelsNoCopy: (const void *)pixels
222 pixelFormat: (OFPixelFormat)pixelFormat
223 size: (OFSize)size
224 freeWhenDone: (bool)freeWhenDone;
225
240+ (instancetype)imageWithPixelsNoCopy: (const void *)pixels
241 pixelFormat: (OFPixelFormat)pixelFormat
242 size: (OFSize)size
243 colorSpace: (OFColorSpace *)colorSpace
244 freeWhenDone: (bool)freeWhenDone;
245
246- (instancetype)init OF_UNAVAILABLE;
247
258- (instancetype)initWithPixels: (const void *)pixels
259 pixelFormat: (OFPixelFormat)pixelFormat
260 size: (OFSize)size;
261
274- (instancetype)initWithPixels: (const void *)pixels
275 pixelFormat: (OFPixelFormat)pixelFormat
276 size: (OFSize)size
277 colorSpace: (OFColorSpace *)colorSpace;
278
292- (instancetype)initWithPixelsNoCopy: (const void *)pixels
293 pixelFormat: (OFPixelFormat)pixelFormat
294 size: (OFSize)size
295 freeWhenDone: (bool)freeWhenDone;
296
312- (instancetype)initWithPixelsNoCopy: (const void *)pixels
313 pixelFormat: (OFPixelFormat)pixelFormat
314 size: (OFSize)size
315 colorSpace: (OFColorSpace *)colorSpace
316 freeWhenDone: (bool)freeWhenDone;
317
332- (OFColor *)colorAtPoint: (OFPoint)point;
333
343- (OFImage *)imageUsingPixelFormat: (OFPixelFormat)pixelFormat
344 colorSpace: (OFColorSpace *)colorSpace;
345
358- (void)
359 writeToStream: (OFSeekableStream *)stream
360 imageFormat: (OFImageFormat)format
361 options: (nullable OFDictionary OF_GENERIC(OFString *, id) *)options;
362@end
363
364OF_ASSUME_NONNULL_END
365
366#import "OFMutableImage.h"
A class representing a color space.
Definition OFColorSpace.h:51
A class for storing a color.
Definition OFColor.h:31
A class for storing constant strings using the @"" literal.
Definition OFConstantString.h:42
An abstract class for storing objects in a dictionary.
Definition OFDictionary.h:84
A class representing an image.
Definition OFImage.h:117
A class representing a mutable image.
Definition OFMutableImage.h:30
The root class for all other classes inside ObjFW.
Definition OFObject.h:956
A stream that supports seeking.
Definition OFSeekableStream.h:75
A class for handling strings.
Definition OFString.h:143
A protocol for the creation of copies.
Definition OFObject.h:1618
A protocol for the creation of mutable copies.
Definition OFObject.h:1639
A point in 2D space.
Definition OFObject.h:251
A size.
Definition OFObject.h:297