Oolite
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 uint32_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

Typedef Documentation

◆ OOPixMap

typedef struct OOPixMap OOPixMap

◆ OOPixMapDimension

typedef uint32_t OOPixMapDimension

Definition at line 32 of file OOPixMap.h.

Enumeration Type Documentation

◆ OOPixMapFormat

Enumerator
kOOPixMapInvalidFormat 
kOOPixMapGrayscale 
kOOPixMapGrayscaleAlpha 
kOOPixMapRGBA 

Definition at line 36 of file OOPixMap.h.

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

Function Documentation

◆ OOAllocatePixMap()

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

Definition at line 66 of file OOPixMap.m.

67{
68 // Create pixmap struct with dummy pixel pointer to test validity.
69 OOPixMap pixMap = OOMakePixMap((void*)-1, width, height, format, rowBytes, bufferSize);
70 if (EXPECT_NOT(!OOIsValidPixMap(pixMap)))
71 return kOONullPixMap;
72
73 pixMap.pixels = malloc(pixMap.bufferSize);
74 if (EXPECT_NOT(pixMap.pixels == NULL))
75 return kOONullPixMap;
76
77 return pixMap;
78}
#define EXPECT_NOT(x)
const OOPixMap kOONullPixMap
Definition OOPixMap.m:30
OOPixMap OOMakePixMap(void *pixels, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
Definition OOPixMap.m:44
BOOL OOIsValidPixMap(OOPixMap pixMap)
Definition OOPixMap.m:39
size_t bufferSize
Definition OOPixMap.h:48
void * pixels
Definition OOPixMap.h:44

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

Referenced by OOConcreteTexture::copyPixMapRepresentation, 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 91 of file OOPixMap.h.

91{ OOResizePixMap(ioPixMap, OOMinimumPixMapBufferSize(*ioPixMap)); }
OOINLINE size_t OOMinimumPixMapBufferSize(OOPixMap pixMap)
Definition OOPixMap.h:55
BOOL OOResizePixMap(OOPixMap *ioPixMap, size_t desiredSize)
Definition OOPixMap.m:106

References OOINLINE, OOMinimumPixMapBufferSize(), and OOResizePixMap().

Referenced by OOCombinedEmissionMapGenerator::loadTexture, and 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 140 of file OOPixMap.m.

141{
142 if (!OOIsValidPixMap(pixMap))
143 return;
144
145 MyOpenGLView* gameView = [UNIVERSE gameView];
146
147 switch (pixMap.format) {
148
150 break;
151
153 [gameView dumpGrayToFileNamed:name
154 bytes:pixMap.pixels
155 width:pixMap.width
156 height:pixMap.height
157 rowBytes:pixMap.rowBytes];
158 break;
159
161 [gameView dumpGrayAlphaToFileNamed:name
162 bytes:pixMap.pixels
163 width:pixMap.width
164 height:pixMap.height
165 rowBytes:pixMap.rowBytes];
166 break;
167
168 case kOOPixMapRGBA:
169 [gameView dumpRGBAToRGBFileNamed:[name stringByAppendingString:@" rgb"]
170 andGrayFileNamed:[name stringByAppendingString:@" alpha"]
171 bytes:pixMap.pixels
172 width:pixMap.width
173 height:pixMap.height
174 rowBytes:pixMap.rowBytes];
175 break;
176 }
177}
#define UNIVERSE
Definition Universe.h:827
OOPixMapDimension height
Definition OOPixMap.h:45
size_t rowBytes
Definition OOPixMap.h:47
OOPixMapDimension width
Definition OOPixMap.h:45
OOPixMapFormat format
Definition OOPixMap.h:46

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().

Referenced by OOTextureLoader(OOPrivate)::applySettings, and OOConcreteTexture(Private)::setUpTexture.

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

◆ OODuplicatePixMap()

OOPixMap OODuplicatePixMap ( OOPixMap srcPixMap,
size_t desiredSize )

Definition at line 89 of file OOPixMap.m.

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

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

Referenced by OOConcreteTexture::copyPixMapRepresentation, OOPixMapTextureLoader::initWithPixMap:textureOptions:freeWhenDone:, and OOCombinedEmissionMapGenerator::loadTexture.

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 125 of file OOPixMap.m.

126{
127 if (EXPECT_NOT(ioPixMap == NULL || !OOIsValidPixMap(*ioPixMap)))
128 return NO;
129 if (desiredSize <= ioPixMap->bufferSize)
130 return YES;
131
132 return OOResizePixMap(ioPixMap, desiredSize);
133}
BOOL OOResizePixMap(OOPixMap *ioPixMap, size_t desiredSize)
Definition OOPixMap.m:106

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

Referenced by OOTextureLoader(OOPrivate)::applySettings, and OOPixMapTextureLoader::loadTexture.

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

◆ OOFreePixMap()

void OOFreePixMap ( OOPixMap * ioPixMap)

Definition at line 80 of file OOPixMap.m.

81{
82 if (EXPECT_NOT(ioPixMap == NULL))
83 return;
84
85 free(ioPixMap->pixels);
86 *ioPixMap = kOONullPixMap;
87}

References EXPECT_NOT, kOONullPixMap, and OOPixMap::pixels.

Referenced by OOTextureLoader(OOPrivate)::applySettings, OOTextureVerifierStage(OOPrivate)::checkTextureNamed:inFolder:, OOCombinedEmissionMapGenerator::dealloc, OOPixMapTextureLoader::dealloc, and OOCombinedEmissionMapGenerator::loadTexture.

Here is the caller graph for this function:

◆ OOIsNullPixMap()

OOINLINE BOOL OOIsNullPixMap ( OOPixMap pixMap)

Definition at line 53 of file OOPixMap.h.

53{ return pixMap.pixels == NULL; }

References OOINLINE, and OOPixMap::pixels.

Referenced by OOCombinedEmissionMapGenerator::loadTexture, and OOPixMapToRGBA().

Here is the caller graph for this function:

◆ OOIsValidPixMap()

BOOL OOIsValidPixMap ( OOPixMap pixMap)

Definition at line 39 of file OOPixMap.m.

40{
41 return pixMap.pixels != NULL && pixMap.width > 0 && pixMap.height > 0 && OOIsValidPixMapFormat(pixMap.format) && pixMap.rowBytes >= pixMap.width * OOPixMapBytesPerPixelForFormat(pixMap.format) && pixMap.bufferSize >= pixMap.rowBytes * pixMap.height;
42}
BOOL OOIsValidPixMapFormat(OOPixMapFormat format)
Definition OOPixMap.m:180
unsigned short OOPixMapBytesPerPixelForFormat(OOPixMapFormat format)
Definition OOPixMap.m:195

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

Referenced by OOTextureLoader(OOPrivate)::applySettings, OOConcreteTexture::copyPixMapRepresentation, EnsureCorrectDataSize(), OOTextureLoader::getResult:format:originalWidth:originalHeight:, OOPixMapTextureLoader::initWithPixMap:textureOptions:freeWhenDone:, OOCombinedEmissionMapGenerator::loadTexture, OOAllocatePixMap(), OOConvertCubeMapToLatLong(), OODumpPixMap(), OODuplicatePixMap(), OOExpandPixMap(), OOExtractPixMapChannel(), OOMakePixMap(), OOPixMapAddPixMap(), OOPixMapModulatePixMap(), OOPixMapModulateUniform(), OOPixMapToRGBA(), OOResizePixMap(), OOScalePixMap(), ScaleToMatch(), 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 180 of file OOPixMap.m.

181{
182 switch (format) {
184 return NO;
187 case kOOPixMapRGBA:
188 return YES;
189 }
190
191 return NO;
192}

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 44 of file OOPixMap.m.

45{
46 if (rowBytes == 0)
47 rowBytes = width * OOPixMapBytesPerPixelForFormat(format);
48 if (bufferSize == 0)
49 bufferSize = rowBytes * height;
50
51 OOPixMap result = {
52 .pixels = pixels,
53 .width = width,
54 .height = height,
55 .format = format,
56 .rowBytes = rowBytes,
57 .bufferSize = bufferSize
58 };
59
60 if (OOIsValidPixMap(result))
61 return result;
62 else
63 return kOONullPixMap;
64}

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

Referenced by OOTextureLoader(OOPrivate)::applySettings, PlanetEntity(OOPrivate)::cloudTextureWithCloudColor:cloudImpress:cloudBias:, OOConcreteTexture::copyPixMapRepresentation, OOTextureLoader::getResult:format:originalWidth:originalHeight:, OOAllocatePixMap(), OOScalePixMap(), and PlanetEntity(OOPrivate)::planetTextureWithInfo:.

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 55 of file OOPixMap.h.

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

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

Referenced by OOPixMapTextureLoader::loadTexture, OOCompactPixMap(), OODuplicatePixMap(), and OOResizePixMap().

Here is the caller graph for this function:

◆ OOPixMapBytesPerPixel()

OOINLINE unsigned short OOPixMapBytesPerPixel ( OOPixMap pixMap)

Definition at line 118 of file OOPixMap.h.

119{
121}
unsigned short OOPixMapBytesPerPixelForFormat(OOPixMapFormat format) PURE_FUNC
Definition OOPixMap.m:195

References OOPixMap::format, OOINLINE, 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 195 of file OOPixMap.m.

196{
197 switch (format) {
199 return 0;
201 return 1;
203 return 2;
204 case kOOPixMapRGBA:
205 return 4;
206 }
207
208 return -1;
209}

References kOOPixMapGrayscale, kOOPixMapGrayscaleAlpha, kOOPixMapInvalidFormat, and kOOPixMapRGBA.

Referenced by OOConcreteTexture::copyPixMapRepresentation, OOIsValidPixMap(), OOMakePixMap(), and OOPixMapBytesPerPixel().

Here is the caller graph for this function:

◆ OOPixMapFormatHasAlpha()

BOOL OOPixMapFormatHasAlpha ( OOPixMapFormat format)

Definition at line 228 of file OOPixMap.m.

229{
230 switch (format) {
232 return NO;
234 return NO;
236 return YES;
237 case kOOPixMapRGBA:
238 return YES;
239 }
240
241 return NO;
242}

References kOOPixMapGrayscale, kOOPixMapGrayscaleAlpha, kOOPixMapInvalidFormat, and kOOPixMapRGBA.

Referenced by OOCombinedEmissionMapGenerator::loadTexture.

Here is the caller graph for this function:

◆ OOPixMapFormatName()

NSString * OOPixMapFormatName ( OOPixMapFormat format)

Definition at line 212 of file OOPixMap.m.

213{
214 switch (format) {
216 return @"invalid";
218 return @"grayscale";
220 return @"grayscale+alpha";
221 case kOOPixMapRGBA:
222 return @"RGBA";
223 }
224
225 return [NSString stringWithFormat:@"invalid<%i>", (int)format];
226}
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 106 of file OOPixMap.m.

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

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