Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOPixMap.h File Reference
import "OOMaths.h"
+ Include dependency graph for OOPixMap.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  OOPixMap
 

Macros

#define OORoundUpToPowerOf2_PixMap   OORoundUpToPowerOf2_32
 

Typedefs

typedef uint_fast32_t OOPixMapDimension
 
typedef struct OOPixMap OOPixMap
 

Enumerations

enum  OOPixMapFormat { kOOPixMapInvalidFormat = 0 , kOOPixMapGrayscale = 1 , kOOPixMapGrayscaleAlpha = 2 , kOOPixMapRGBA = 4 }
 

Functions

OOINLINE BOOL OOIsNullPixMap (OOPixMap pixMap)
 
BOOL OOIsValidPixMap (OOPixMap pixMap)
 
OOINLINE size_t OOMinimumPixMapBufferSize (OOPixMap pixMap)
 
OOPixMap OOMakePixMap (void *pixels, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
 
OOPixMap OOAllocatePixMap (OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
 
void OOFreePixMap (OOPixMap *ioPixMap)
 
OOPixMap OODuplicatePixMap (OOPixMap srcPixMap, size_t desiredSize)
 
BOOL OOResizePixMap (OOPixMap *ioPixMap, size_t desiredSize)
 
OOINLINE void OOCompactPixMap (OOPixMap *ioPixMap)
 
BOOL OOExpandPixMap (OOPixMap *ioPixMap, size_t desiredSize)
 
void OODumpPixMap (OOPixMap pixMap, NSString *name)
 
BOOL OOIsValidPixMapFormat (OOPixMapFormat format)
 
unsigned short OOPixMapBytesPerPixelForFormat (OOPixMapFormat format) PURE_FUNC
 
OOINLINE unsigned short OOPixMapBytesPerPixel (OOPixMap pixMap)
 
NSString * OOPixMapFormatName (OOPixMapFormat format) PURE_FUNC
 
BOOL OOPixMapFormatHasAlpha (OOPixMapFormat format) PURE_FUNC
 

Variables

const OOPixMap kOONullPixMap
 

Macro Definition Documentation

◆ OORoundUpToPowerOf2_PixMap

#define OORoundUpToPowerOf2_PixMap   OORoundUpToPowerOf2_32

Definition at line 35 of file OOPixMap.h.

Referenced by OOGenerateMipMaps().

Typedef Documentation

◆ OOPixMap

typedef struct OOPixMap OOPixMap

◆ OOPixMapDimension

typedef uint_fast32_t OOPixMapDimension

Definition at line 33 of file OOPixMap.h.

Enumeration Type Documentation

◆ OOPixMapFormat

Enumerator
kOOPixMapInvalidFormat 
kOOPixMapGrayscale 
kOOPixMapGrayscaleAlpha 
kOOPixMapRGBA 

Definition at line 38 of file OOPixMap.h.

39{
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

Function Documentation

◆ OOAllocatePixMap()

OOPixMap OOAllocatePixMap ( OOPixMapDimension width,
OOPixMapDimension height,
OOPixMapFormat format,
size_t rowBytes,
size_t bufferSize )

Definition at line 73 of file OOPixMap.m.

74{
75 // Create pixmap struct with dummy pixel pointer to test validity.
76 OOPixMap pixMap = OOMakePixMap((void *)-1, width, height, format, rowBytes, bufferSize);
77 if (EXPECT_NOT(!OOIsValidPixMap(pixMap))) return kOONullPixMap;
78
79 pixMap.pixels = malloc(pixMap.bufferSize);
80 if (EXPECT_NOT(pixMap.pixels == NULL)) return kOONullPixMap;
81
82 return pixMap;
83}
#define EXPECT_NOT(x)
const OOPixMap kOONullPixMap
Definition OOPixMap.m:31
OOPixMap OOMakePixMap(void *pixels, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
Definition OOPixMap.m:53
BOOL OOIsValidPixMap(OOPixMap pixMap)
Definition OOPixMap.m:42
size_t bufferSize
Definition OOPixMap.h:53
void * pixels
Definition OOPixMap.h:49

References OOPixMap::bufferSize, EXPECT_NOT, kOONullPixMap, OOIsValidPixMap(), OOMakePixMap(), and OOPixMap::pixels.

Referenced by OOConvertCubeMapToLatLong(), OODuplicatePixMap(), OOPixMapToRGBA(), and OOScalePixMap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOCompactPixMap()

OOINLINE void OOCompactPixMap ( OOPixMap * ioPixMap)

Definition at line 103 of file OOPixMap.h.

103{ OOResizePixMap(ioPixMap, OOMinimumPixMapBufferSize(*ioPixMap)); }
OOINLINE size_t OOMinimumPixMapBufferSize(OOPixMap pixMap)
Definition OOPixMap.h:62
BOOL OOResizePixMap(OOPixMap *ioPixMap, size_t desiredSize)
Definition OOPixMap.m:110

References OOMinimumPixMapBufferSize(), and OOResizePixMap().

Referenced by OOExtractPixMapChannel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OODumpPixMap()

void OODumpPixMap ( OOPixMap pixMap,
NSString * name )

Definition at line 145 of file OOPixMap.m.

146{
147 if (!OOIsValidPixMap(pixMap)) return;
148
149 MyOpenGLView *gameView = [UNIVERSE gameView];
150
151 switch (pixMap.format)
152 {
153
155 break;
156
158 [gameView dumpGrayToFileNamed:name
159 bytes:pixMap.pixels
160 width:pixMap.width
161 height:pixMap.height
162 rowBytes:pixMap.rowBytes];
163 break;
164
166 [gameView dumpGrayAlphaToFileNamed:name
167 bytes:pixMap.pixels
168 width:pixMap.width
169 height:pixMap.height
170 rowBytes:pixMap.rowBytes];
171 break;
172
173 case kOOPixMapRGBA:
174 [gameView dumpRGBAToRGBFileNamed:[name stringByAppendingString:@" rgb"]
175 andGrayFileNamed:[name stringByAppendingString:@" alpha"]
176 bytes:pixMap.pixels
177 width:pixMap.width
178 height:pixMap.height
179 rowBytes:pixMap.rowBytes];
180 break;
181 }
182}
#define UNIVERSE
Definition Universe.h:833
OOPixMapDimension height
Definition OOPixMap.h:50
size_t rowBytes
Definition OOPixMap.h:52
OOPixMapDimension width
Definition OOPixMap.h:50
OOPixMapFormat format
Definition OOPixMap.h:51

References MyOpenGLView::dumpGrayAlphaToFileNamed:bytes:width:height:rowBytes:, MyOpenGLView::dumpGrayToFileNamed:bytes:width:height:rowBytes:, MyOpenGLView::dumpRGBAToRGBFileNamed:andGrayFileNamed:bytes:width:height:rowBytes:, OOPixMap::format, kOOPixMapGrayscale, kOOPixMapGrayscaleAlpha, kOOPixMapInvalidFormat, kOOPixMapRGBA, and OOIsValidPixMap().

+ Here is the call graph for this function:

◆ OODuplicatePixMap()

OOPixMap OODuplicatePixMap ( OOPixMap srcPixMap,
size_t desiredSize )

Definition at line 95 of file OOPixMap.m.

96{
97 if (EXPECT_NOT(!OOIsValidPixMap(srcPixMap))) return kOONullPixMap;
98
99 size_t minSize = OOMinimumPixMapBufferSize(srcPixMap);
100 if (desiredSize < minSize) desiredSize = minSize;
101
102 OOPixMap result = OOAllocatePixMap(srcPixMap.width, srcPixMap.width, srcPixMap.format, srcPixMap.rowBytes, desiredSize);
103 if (EXPECT_NOT(!OOIsValidPixMap(result))) return kOONullPixMap;
104
105 memcpy(result.pixels, srcPixMap.pixels, minSize);
106 return result;
107}
OOPixMap OOAllocatePixMap(OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
Definition OOPixMap.m:73

References EXPECT_NOT, OOPixMap::format, kOONullPixMap, OOAllocatePixMap(), OOIsValidPixMap(), OOMinimumPixMapBufferSize(), OOPixMap::pixels, OOPixMap::rowBytes, and OOPixMap::width.

Referenced by OOPixMapTextureLoader::dealloc.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOExpandPixMap()

BOOL OOExpandPixMap ( OOPixMap * ioPixMap,
size_t desiredSize )

Definition at line 130 of file OOPixMap.m.

131{
132 if (EXPECT_NOT(ioPixMap == NULL || !OOIsValidPixMap(*ioPixMap))) return NO;
133 if (desiredSize <= ioPixMap->bufferSize) return YES;
134
135 return OOResizePixMap(ioPixMap, desiredSize);
136}
BOOL OOResizePixMap(OOPixMap *ioPixMap, size_t desiredSize)
Definition OOPixMap.m:110

References EXPECT_NOT, OOIsValidPixMap(), and OOResizePixMap().

+ Here is the call graph for this function:

◆ OOFreePixMap()

void OOFreePixMap ( OOPixMap * ioPixMap)

Definition at line 86 of file OOPixMap.m.

87{
88 if (EXPECT_NOT(ioPixMap == NULL)) return;
89
90 free(ioPixMap->pixels);
91 *ioPixMap = kOONullPixMap;
92}

References EXPECT_NOT, kOONullPixMap, and OOPixMap::pixels.

◆ OOIsNullPixMap()

OOINLINE BOOL OOIsNullPixMap ( OOPixMap pixMap)

Definition at line 60 of file OOPixMap.h.

60{ return pixMap.pixels == NULL; }

References OOPixMap::pixels.

Referenced by OOPixMapToRGBA().

+ Here is the caller graph for this function:

◆ OOIsValidPixMap()

BOOL OOIsValidPixMap ( OOPixMap pixMap)

Definition at line 42 of file OOPixMap.m.

43{
44 return pixMap.pixels != NULL &&
45 pixMap.width > 0 &&
46 pixMap.height > 0 &&
48 pixMap.rowBytes >= pixMap.width * OOPixMapBytesPerPixelForFormat(pixMap.format) &&
49 pixMap.bufferSize >= pixMap.rowBytes * pixMap.height;
50}
BOOL OOIsValidPixMapFormat(OOPixMapFormat format)
Definition OOPixMap.m:186
unsigned short OOPixMapBytesPerPixelForFormat(OOPixMapFormat format)
Definition OOPixMap.m:202

References OOPixMap::bufferSize, OOPixMap::format, OOPixMap::height, OOIsValidPixMapFormat(), OOPixMapBytesPerPixelForFormat(), OOPixMap::pixels, OOPixMap::rowBytes, and OOPixMap::width.

Referenced by OOCombinedEmissionMapGenerator::anisotropy, OOPixMapTextureLoader::dealloc, EnsureCorrectDataSize(), OOAllocatePixMap(), OOConvertCubeMapToLatLong(), OODumpPixMap(), OODuplicatePixMap(), OOExpandPixMap(), OOExtractPixMapChannel(), OOMakePixMap(), OOPixMapAddPixMap(), OOPixMapModulatePixMap(), OOPixMapModulateUniform(), OOPixMapToRGBA(), OOResizePixMap(), OOScalePixMap(), SqueezeHorizontally1(), SqueezeHorizontally2(), SqueezeHorizontally4(), SqueezeVertically1(), SqueezeVertically2(), SqueezeVertically4(), StretchHorizontally1(), StretchHorizontally2(), and StretchHorizontally4().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOIsValidPixMapFormat()

BOOL OOIsValidPixMapFormat ( OOPixMapFormat format)

Definition at line 186 of file OOPixMap.m.

187{
188 switch (format)
189 {
190 case kOOPixMapInvalidFormat: return NO;
193 case kOOPixMapRGBA:
194 return YES;
195 }
196
197 return NO;
198}

References kOOPixMapGrayscale, kOOPixMapGrayscaleAlpha, kOOPixMapInvalidFormat, and kOOPixMapRGBA.

Referenced by OOIsValidPixMap().

+ Here is the caller graph for this function:

◆ OOMakePixMap()

OOPixMap OOMakePixMap ( void * pixels,
OOPixMapDimension width,
OOPixMapDimension height,
OOPixMapFormat format,
size_t rowBytes,
size_t bufferSize )

Definition at line 53 of file OOPixMap.m.

54{
55 if (rowBytes == 0) rowBytes = width * OOPixMapBytesPerPixelForFormat(format);
56 if (bufferSize == 0) bufferSize = rowBytes * height;
57
58 OOPixMap result =
59 {
60 .pixels = pixels,
61 .width = width,
62 .height = height,
63 .format = format,
64 .rowBytes = rowBytes,
65 .bufferSize = bufferSize
66 };
67
68 if (OOIsValidPixMap(result)) return result;
69 else return kOONullPixMap;
70}

References kOONullPixMap, OOIsValidPixMap(), and OOPixMapBytesPerPixelForFormat().

Referenced by OOAllocatePixMap(), and OOScalePixMap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOMinimumPixMapBufferSize()

OOINLINE size_t OOMinimumPixMapBufferSize ( OOPixMap pixMap)

Definition at line 62 of file OOPixMap.h.

62{ return pixMap.rowBytes * pixMap.height; }

References OOPixMap::height, and OOPixMap::rowBytes.

Referenced by OOCompactPixMap(), OODuplicatePixMap(), and OOResizePixMap().

+ Here is the caller graph for this function:

◆ OOPixMapBytesPerPixel()

OOINLINE unsigned short OOPixMapBytesPerPixel ( OOPixMap pixMap)

Definition at line 132 of file OOPixMap.h.

133{
135}
unsigned short OOPixMapBytesPerPixelForFormat(OOPixMapFormat format) PURE_FUNC
Definition OOPixMap.m:202

References OOPixMap::format, and OOPixMapBytesPerPixelForFormat().

Referenced by ModulateUniform_4(), OOScalePixMap(), SqueezeHorizontally1(), SqueezeHorizontally2(), SqueezeHorizontally4(), SqueezeVertically1(), SqueezeVertically2(), SqueezeVertically4(), StretchHorizontally1(), StretchHorizontally2(), StretchHorizontally4(), StretchVerticallyN_x1(), StretchVerticallyN_x4(), ToRGBA_1(), and ToRGBA_2().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOPixMapBytesPerPixelForFormat()

unsigned short OOPixMapBytesPerPixelForFormat ( OOPixMapFormat format)

Definition at line 202 of file OOPixMap.m.

203{
204 switch (format)
205 {
206 case kOOPixMapInvalidFormat: return 0;
207 case kOOPixMapGrayscale: return 1;
208 case kOOPixMapGrayscaleAlpha: return 2;
209 case kOOPixMapRGBA: return 4;
210 }
211
212 return -1;
213}

References kOOPixMapGrayscale, kOOPixMapGrayscaleAlpha, kOOPixMapInvalidFormat, and kOOPixMapRGBA.

Referenced by OOIsValidPixMap(), OOMakePixMap(), and OOPixMapBytesPerPixel().

+ Here is the caller graph for this function:

◆ OOPixMapFormatHasAlpha()

BOOL OOPixMapFormatHasAlpha ( OOPixMapFormat format)

Definition at line 232 of file OOPixMap.m.

233{
234 switch (format)
235 {
236 case kOOPixMapInvalidFormat: return NO;
237 case kOOPixMapGrayscale: return NO;
238 case kOOPixMapGrayscaleAlpha: return YES;
239 case kOOPixMapRGBA: return YES;
240 }
241
242 return NO;
243}

References kOOPixMapGrayscale, kOOPixMapGrayscaleAlpha, kOOPixMapInvalidFormat, and kOOPixMapRGBA.

◆ OOPixMapFormatName()

NSString * OOPixMapFormatName ( OOPixMapFormat format)

Definition at line 217 of file OOPixMap.m.

218{
219 switch (format)
220 {
221 case kOOPixMapInvalidFormat: return @"invalid";
222 case kOOPixMapGrayscale: return @"grayscale";
223 case kOOPixMapGrayscaleAlpha: return @"grayscale+alpha";
224 case kOOPixMapRGBA: return @"RGBA";
225 }
226
227 return [NSString stringWithFormat:@"invalid<%i>", (int)format];
228}
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

References kOOPixMapGrayscale, kOOPixMapGrayscaleAlpha, kOOPixMapInvalidFormat, and kOOPixMapRGBA.

Referenced by OOGenerateMipMaps().

+ Here is the caller graph for this function:

◆ OOResizePixMap()

BOOL OOResizePixMap ( OOPixMap * ioPixMap,
size_t desiredSize )

Definition at line 110 of file OOPixMap.m.

111{
112 if (EXPECT_NOT(ioPixMap == NULL || !OOIsValidPixMap(*ioPixMap))) return NO;
113 if (desiredSize == ioPixMap->bufferSize) return YES;
114 if (desiredSize < OOMinimumPixMapBufferSize(*ioPixMap)) return NO;
115
116 void *newPixels = realloc(ioPixMap->pixels, desiredSize);
117 if (newPixels != NULL)
118 {
119 ioPixMap->pixels = newPixels;
120 ioPixMap->bufferSize = desiredSize;
121 return YES;
122 }
123 else
124 {
125 return NO;
126 }
127}

References OOPixMap::bufferSize, EXPECT_NOT, OOIsValidPixMap(), OOMinimumPixMapBufferSize(), and OOPixMap::pixels.

Referenced by OOCompactPixMap(), and OOExpandPixMap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ kOONullPixMap

const OOPixMap kOONullPixMap
extern

Definition at line 31 of file OOPixMap.m.

32{
33 .pixels = NULL,
34 .width = 0,
35 .height = 0,
36 .format = kOOPixMapInvalidFormat,
37 .rowBytes = 0,
38 .bufferSize = 0
39};

Referenced by OOAllocatePixMap(), OOConvertCubeMapToLatLong(), OODuplicatePixMap(), OOFreePixMap(), OOMakePixMap(), and OOScalePixMap().