PGF Console 6.21.2
Loading...
Searching...
No Matches
Utilities.h File Reference
#include <math.h>
#include <stdlib.h>
#include <memory.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <assert.h>
#include <string>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <sstream>
#include <algorithm>

Go to the source code of this file.

Classes

struct  tagFILE_RGBA
 
struct  tagFILE_BGRA
 
struct  tagFILE_RGB
 
struct  tagFILE_BGR
 

Macros

#define FIBITMAP_ALIGNMENT   16
 
#define GREY(r, g, b)
 

Typedefs

typedef struct tagFILE_RGBA FILE_RGBA
 
typedef struct tagFILE_BGRA FILE_BGRA
 
typedef struct tagFILE_RGB FILE_RGB
 
typedef struct tagFILE_BGR FILE_BGR
 

Functions

void * FreeImage_Aligned_Malloc (size_t amount, size_t alignment)
 
void FreeImage_Aligned_Free (void *mem)
 
char * i2a (unsigned i, char *a, unsigned r)
 
char * _itoa (int i, char *a, int r)
 
unsigned char HINIBBLE (unsigned char byte)
 
unsigned char LOWNIBBLE (unsigned char byte)
 
int CalculateUsedBits (int bits)
 
int CalculateLine (int width, int bitdepth)
 
int CalculatePitch (int line)
 
int CalculateUsedPaletteEntries (int bit_count)
 
unsigned char * CalculateScanLine (unsigned char *bits, unsigned pitch, int scanline)
 
void ReplaceExtension (char *result, const char *filename, const char *extension)
 
void SwapShort (WORD *sp)
 
void SwapLong (DWORD *lp)
 
template<class T>
MAX (T a, T b)
 Max function.
 
template<class T>
MIN (T a, T b)
 Min function.
 
template<class T>
void INPLACESWAP (T &a, T &b)
 INPLACESWAP adopted from codeguru.com.
 
template<class T>
void MAXMIN (const T *L, long n, T &max, T &min)
 

Variables

static const char * FI_MSG_ERROR_MEMORY = "Not enough memory"
 

Macro Definition Documentation

◆ FIBITMAP_ALIGNMENT

#define FIBITMAP_ALIGNMENT   16

Definition at line 57 of file Utilities.h.

◆ GREY

#define GREY ( r,
g,
b )
Value:
(BYTE)(((WORD)r * 77 + (WORD)g * 150 + (WORD)b * 29) >> 8)

Definition at line 217 of file Utilities.h.

Typedef Documentation

◆ FILE_BGR

typedef struct tagFILE_BGR FILE_BGR

◆ FILE_BGRA

typedef struct tagFILE_BGRA FILE_BGRA

◆ FILE_RGB

typedef struct tagFILE_RGB FILE_RGB

◆ FILE_RGBA

typedef struct tagFILE_RGBA FILE_RGBA

Function Documentation

◆ _itoa()

char * _itoa ( int i,
char * a,
int r )
inline

Transforms integer i into an ascii string and stores the result in a; string is encoded in the base indicated by r.

Parameters
iNumber to be converted
aString result
rBase of value; must be in the range 2 - 36
Returns
Returns a

Definition at line 121 of file Utilities.h.

121 {
122 r = ((r < 2) || (r > 36)) ? 10 : r;
123 if(i < 0) {
124 *a = '-';
125 *i2a(-i, a+1, r) = 0;
126 }
127 else *i2a(i, a, r) = 0;
128 return a;
129}
char * i2a(unsigned i, char *a, unsigned r)
Definition Utilities.h:106

◆ CalculateLine()

int CalculateLine ( int width,
int bitdepth )
inline

Definition at line 160 of file Utilities.h.

160 {
161 return ((width * bitdepth) + 7) / 8;
162}

◆ CalculatePitch()

int CalculatePitch ( int line)
inline

Definition at line 165 of file Utilities.h.

165 {
166 return line + 3 & ~3;
167}

◆ CalculateScanLine()

unsigned char * CalculateScanLine ( unsigned char * bits,
unsigned pitch,
int scanline )
inline

Definition at line 178 of file Utilities.h.

178 {
179 return (bits + (pitch * scanline));
180}

◆ CalculateUsedBits()

int CalculateUsedBits ( int bits)
inline

Definition at line 144 of file Utilities.h.

144 {
145 int bit_count = 0;
146 unsigned bit = 1;
147
148 for (unsigned i = 0; i < 32; i++) {
149 if ((bits & bit) == bit) {
150 bit_count++;
151 }
152
153 bit <<= 1;
154 }
155
156 return bit_count;
157}

◆ CalculateUsedPaletteEntries()

int CalculateUsedPaletteEntries ( int bit_count)
inline

Definition at line 170 of file Utilities.h.

170 {
171 if ((bit_count >= 1) && (bit_count <= 8))
172 return 1 << bit_count;
173
174 return 0;
175}

◆ FreeImage_Aligned_Free()

void FreeImage_Aligned_Free ( void * mem)

◆ FreeImage_Aligned_Malloc()

void * FreeImage_Aligned_Malloc ( size_t amount,
size_t alignment )

◆ HINIBBLE()

unsigned char HINIBBLE ( unsigned char byte)
inline

Definition at line 134 of file Utilities.h.

134 {
135 return byte & 0xF0;
136}

◆ i2a()

char * i2a ( unsigned i,
char * a,
unsigned r )
inline

Definition at line 106 of file Utilities.h.

106 {
107 if (i/r > 0) a = i2a(i/r,a,r);
108 *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
109 return a+1;
110}

◆ INPLACESWAP()

template<class T>
void INPLACESWAP ( T & a,
T & b )

INPLACESWAP adopted from codeguru.com.

Definition at line 237 of file Utilities.h.

237 {
238 a ^= b; b ^= a; a ^= b;
239}

◆ LOWNIBBLE()

unsigned char LOWNIBBLE ( unsigned char byte)
inline

Definition at line 139 of file Utilities.h.

139 {
140 return byte & 0x0F;
141}

◆ MAX()

template<class T>
T MAX ( T a,
T b )

Max function.

Definition at line 227 of file Utilities.h.

227 {
228 return (a > b) ? a: b;
229}

◆ MAXMIN()

template<class T>
void MAXMIN ( const T * L,
long n,
T & max,
T & min )

This procedure computes minimum min and maximum max of n numbers using only (3n/2) - 2 comparisons. min = L[i1] and max = L[i2]. ref: Aho A.V., Hopcroft J.E., Ullman J.D., The design and analysis of computer algorithms, Addison-Wesley, Reading, 1974.

Definition at line 249 of file Utilities.h.

249 {
250 long i1, i2, i, j;
251 T x1, x2;
252 long k1, k2;
253
254 i1 = 0; i2 = 0; min = L[0]; max = L[0]; j = 0;
255 if((n % 2) != 0) j = 1;
256 for(i = j; i < n; i+= 2) {
257 k1 = i; k2 = i+1;
258 x1 = L[k1]; x2 = L[k2];
259 if(x1 > x2) {
260 k1 = k2; k2 = i;
261 x1 = x2; x2 = L[k2];
262 }
263 if(x1 < min) {
264 min = x1; i1 = k1;
265 }
266 if(x2 > max) {
267 max = x2; i2 = k2;
268 }
269 }
270}

◆ MIN()

template<class T>
T MIN ( T a,
T b )

Min function.

Definition at line 232 of file Utilities.h.

232 {
233 return (a < b) ? a: b;
234}

◆ ReplaceExtension()

void ReplaceExtension ( char * result,
const char * filename,
const char * extension )
inline

Definition at line 183 of file Utilities.h.

183 {
184 for (size_t i = strlen(filename) - 1; i > 0; --i) {
185 if (filename[i] == '.') {
186 memcpy(result, filename, i);
187 result[i] = '.';
188 memcpy(result + i + 1, extension, strlen(extension) + 1);
189 return;
190 }
191 }
192
193 memcpy(result, filename, strlen(filename));
194 result[strlen(filename)] = '.';
195 memcpy(result + strlen(filename) + 1, extension, strlen(extension) + 1);
196}

◆ SwapLong()

void SwapLong ( DWORD * lp)
inline

Definition at line 208 of file Utilities.h.

208 {
209 BYTE *cp = (BYTE *)lp, t = cp[0]; cp[0] = cp[3]; cp[3] = t;
210 t = cp[1]; cp[1] = cp[2]; cp[2] = t;
211}

◆ SwapShort()

void SwapShort ( WORD * sp)
inline

Definition at line 203 of file Utilities.h.

203 {
204 BYTE *cp = (BYTE *)sp, t = cp[0]; cp[0] = cp[1]; cp[1] = t;
205}

Variable Documentation

◆ FI_MSG_ERROR_MEMORY

const char* FI_MSG_ERROR_MEMORY = "Not enough memory"
static

Definition at line 276 of file Utilities.h.