Oolite 1.91.0.7604-240417-a536cbe
Loading...
Searching...
No Matches
OOPixMap.h
Go to the documentation of this file.
1/*
2
3OOPixMap.h
4
5Types for low-level pixel map manipulation.
6
7
8Copyright (C) 2010-2013 Jens Ayton
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27
28*/
29
30#import "OOMaths.h"
31
32
33typedef uint_fast32_t OOPixMapDimension; // Note: dimensions are assumed to be less than 1048576 (2^20) pixels.
34
35#define OORoundUpToPowerOf2_PixMap OORoundUpToPowerOf2_32
36
37
45
46
55
56
57extern const OOPixMap kOONullPixMap;
58
59
60OOINLINE BOOL OOIsNullPixMap(OOPixMap pixMap) { return pixMap.pixels == NULL; }
61BOOL OOIsValidPixMap(OOPixMap pixMap);
62OOINLINE size_t OOMinimumPixMapBufferSize(OOPixMap pixMap) { return pixMap.rowBytes * pixMap.height; }
63
64
65/* OOMakePixMap()
66 Stuff an OOPixMap struct. Returns kOONullPixMap if the result would be
67 invalid. If rowBytes or bufferSize are zero, minimum valid values will be
68 used.
69*/
70OOPixMap OOMakePixMap(void *pixels, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize);
71
72/* OOAllocatePixMap()
73 Create an OOPixMap, allocating storage. If rowBytes or bufferSize are zero,
74 minimum valid values will be used.
75*/
76OOPixMap OOAllocatePixMap(OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize);
77
78
79/* OOFreePixMap()
80 Deallocate a pixmap's buffer (with free()), and clear out the struct.
81*/
82void OOFreePixMap(OOPixMap *ioPixMap);
83
84
85/* OODuplicatePixMap()
86 Create a pixmap with the same pixel contents as a source pixmap, and
87 optional padding. If desiredSize is less than the required space for the
88 pixmap, it will be ignored. The contents of padding bytes are unspecified.
89*/
90OOPixMap OODuplicatePixMap(OOPixMap srcPixMap, size_t desiredSize);
91
92
93/* OOResizePixMap()
94 Set the size of a pixmap's buffer. Fails if specified size is smaller than
95 required to fit the current pixels.
96*/
97BOOL OOResizePixMap(OOPixMap *ioPixMap, size_t desiredSize);
98
99
100/* OOCompactPixMap()
101 Remove any trailing space in a pixmap's buffer, if possible.
102*/
104
105
106/* OOExpandPixMap()
107 Expand pixmap to at least desiredSize bytes. Returns false on failure.
108*/
109BOOL OOExpandPixMap(OOPixMap *ioPixMap, size_t desiredSize);
110
111
112#ifndef NDEBUG
113void OODumpPixMap(OOPixMap pixMap, NSString *name);
114#else
115#define OODumpPixMap(p, n) do {} while (0)
116#endif
117
118
120
121
122#ifndef NDEBUG
124#else
126{
127 // Currently, format values are component counts. This is subject to change.
128 return format;
129}
130#endif
131
133{
135}
136
138
#define OOINLINE
#define PURE_FUNC
uint_fast32_t OOPixMapDimension
Definition OOPixMap.h:33
void OOFreePixMap(OOPixMap *ioPixMap)
Definition OOPixMap.m:86
NSString * OOPixMapFormatName(OOPixMapFormat format) PURE_FUNC
Definition OOPixMap.m:217
void OODumpPixMap(OOPixMap pixMap, NSString *name)
Definition OOPixMap.m:145
OOPixMapFormat
Definition OOPixMap.h:39
@ kOOPixMapInvalidFormat
Definition OOPixMap.h:40
@ kOOPixMapGrayscale
Definition OOPixMap.h:41
@ kOOPixMapRGBA
Definition OOPixMap.h:43
@ kOOPixMapGrayscaleAlpha
Definition OOPixMap.h:42
OOINLINE size_t OOMinimumPixMapBufferSize(OOPixMap pixMap)
Definition OOPixMap.h:62
BOOL OOIsValidPixMapFormat(OOPixMapFormat format)
Definition OOPixMap.m:186
unsigned short OOPixMapBytesPerPixelForFormat(OOPixMapFormat format) PURE_FUNC
Definition OOPixMap.m:202
const OOPixMap kOONullPixMap
Definition OOPixMap.m:31
OOPixMap OOAllocatePixMap(OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
Definition OOPixMap.m:73
OOINLINE unsigned short OOPixMapBytesPerPixel(OOPixMap pixMap)
Definition OOPixMap.h:132
OOINLINE BOOL OOIsNullPixMap(OOPixMap pixMap)
Definition OOPixMap.h:60
OOPixMap OOMakePixMap(void *pixels, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
Definition OOPixMap.m:53
BOOL OOResizePixMap(OOPixMap *ioPixMap, size_t desiredSize)
Definition OOPixMap.m:110
BOOL OOIsValidPixMap(OOPixMap pixMap)
Definition OOPixMap.m:42
BOOL OOPixMapFormatHasAlpha(OOPixMapFormat format) PURE_FUNC
Definition OOPixMap.m:232
BOOL OOExpandPixMap(OOPixMap *ioPixMap, size_t desiredSize)
Definition OOPixMap.m:130
OOPixMap OODuplicatePixMap(OOPixMap srcPixMap, size_t desiredSize)
Definition OOPixMap.m:95
OOINLINE void OOCompactPixMap(OOPixMap *ioPixMap)
Definition OOPixMap.h:103
struct OOPixMap OOPixMap
OOPixMapDimension height
Definition OOPixMap.h:50
size_t bufferSize
Definition OOPixMap.h:53
size_t rowBytes
Definition OOPixMap.h:52
void * pixels
Definition OOPixMap.h:49
OOPixMapDimension width
Definition OOPixMap.h:50
OOPixMapFormat format
Definition OOPixMap.h:51