Oolite
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
32typedef uint32_t OOPixMapDimension; // Note: dimensions are assumed to be less than 1048576 (2^20) pixels.
33
34#define OORoundUpToPowerOf2_PixMap OORoundUpToPowerOf2_32
35
42
50
51extern const OOPixMap kOONullPixMap;
52
53OOINLINE BOOL OOIsNullPixMap(OOPixMap pixMap) { return pixMap.pixels == NULL; }
54BOOL OOIsValidPixMap(OOPixMap pixMap);
55OOINLINE size_t OOMinimumPixMapBufferSize(OOPixMap pixMap) { return pixMap.rowBytes * pixMap.height; }
56
57/* OOMakePixMap()
58 Stuff an OOPixMap struct. Returns kOONullPixMap if the result would be
59 invalid. If rowBytes or bufferSize are zero, minimum valid values will be
60 used.
61*/
62OOPixMap OOMakePixMap(void* pixels, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize);
63
64/* OOAllocatePixMap()
65 Create an OOPixMap, allocating storage. If rowBytes or bufferSize are zero,
66 minimum valid values will be used.
67*/
68OOPixMap OOAllocatePixMap(OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize);
69
70/* OOFreePixMap()
71 Deallocate a pixmap's buffer (with free()), and clear out the struct.
72*/
73void OOFreePixMap(OOPixMap* ioPixMap);
74
75/* OODuplicatePixMap()
76 Create a pixmap with the same pixel contents as a source pixmap, and
77 optional padding. If desiredSize is less than the required space for the
78 pixmap, it will be ignored. The contents of padding bytes are unspecified.
79*/
80OOPixMap OODuplicatePixMap(OOPixMap srcPixMap, size_t desiredSize);
81
82/* OOResizePixMap()
83 Set the size of a pixmap's buffer. Fails if specified size is smaller than
84 required to fit the current pixels.
85*/
86BOOL OOResizePixMap(OOPixMap* ioPixMap, size_t desiredSize);
87
88/* OOCompactPixMap()
89 Remove any trailing space in a pixmap's buffer, if possible.
90*/
92
93/* OOExpandPixMap()
94 Expand pixmap to at least desiredSize bytes. Returns false on failure.
95*/
96BOOL OOExpandPixMap(OOPixMap* ioPixMap, size_t desiredSize);
97
98#ifndef NDEBUG
99void OODumpPixMap(OOPixMap pixMap, NSString* name);
100#else
101#define OODumpPixMap(p, n) \
102 do { \
103 } while (0)
104#endif
105
107
108#ifndef NDEBUG
110#else
112{
113 // Currently, format values are component counts. This is subject to change.
114 return format;
115}
116#endif
117
119{
121}
122
124
#define OOINLINE
#define PURE_FUNC
void OOFreePixMap(OOPixMap *ioPixMap)
Definition OOPixMap.m:80
uint32_t OOPixMapDimension
Definition OOPixMap.h:32
NSString * OOPixMapFormatName(OOPixMapFormat format) PURE_FUNC
Definition OOPixMap.m:212
void OODumpPixMap(OOPixMap pixMap, NSString *name)
Definition OOPixMap.m:140
OOPixMapFormat
Definition OOPixMap.h:36
@ kOOPixMapInvalidFormat
Definition OOPixMap.h:37
@ kOOPixMapGrayscale
Definition OOPixMap.h:38
@ kOOPixMapRGBA
Definition OOPixMap.h:40
@ kOOPixMapGrayscaleAlpha
Definition OOPixMap.h:39
OOINLINE size_t OOMinimumPixMapBufferSize(OOPixMap pixMap)
Definition OOPixMap.h:55
BOOL OOIsValidPixMapFormat(OOPixMapFormat format)
Definition OOPixMap.m:180
unsigned short OOPixMapBytesPerPixelForFormat(OOPixMapFormat format) PURE_FUNC
Definition OOPixMap.m:195
const OOPixMap kOONullPixMap
Definition OOPixMap.m:30
OOPixMap OOAllocatePixMap(OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
Definition OOPixMap.m:66
OOINLINE unsigned short OOPixMapBytesPerPixel(OOPixMap pixMap)
Definition OOPixMap.h:118
OOINLINE BOOL OOIsNullPixMap(OOPixMap pixMap)
Definition OOPixMap.h:53
OOPixMap OOMakePixMap(void *pixels, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
Definition OOPixMap.m:44
BOOL OOResizePixMap(OOPixMap *ioPixMap, size_t desiredSize)
Definition OOPixMap.m:106
BOOL OOIsValidPixMap(OOPixMap pixMap)
Definition OOPixMap.m:39
BOOL OOPixMapFormatHasAlpha(OOPixMapFormat format) PURE_FUNC
Definition OOPixMap.m:228
BOOL OOExpandPixMap(OOPixMap *ioPixMap, size_t desiredSize)
Definition OOPixMap.m:125
OOPixMap OODuplicatePixMap(OOPixMap srcPixMap, size_t desiredSize)
Definition OOPixMap.m:89
OOINLINE void OOCompactPixMap(OOPixMap *ioPixMap)
Definition OOPixMap.h:91
OOPixMapDimension height
Definition OOPixMap.h:45
size_t bufferSize
Definition OOPixMap.h:48
size_t rowBytes
Definition OOPixMap.h:47
void * pixels
Definition OOPixMap.h:44
OOPixMapDimension width
Definition OOPixMap.h:45
OOPixMapFormat format
Definition OOPixMap.h:46