12 #define random(x) (rand() % (x))
13 #define frandom(x) ((float)rand() * (float)(x) / (float)(RAND_MAX))
17 static __inline
double mestinvsqrt(double x
)
19 asm ("frsqrte %0,%1" : "=f" (x
) : "0" (x
));
23 static __inline
double mestinv(double x
)
25 asm ("fres %0,%1" : "=f" (x
) : "0" (x
));
29 #define estinvsqrt(x) mestinvsqrt(x)
30 #define estinv(x) mestinv(x)
34 double estinv(double);
35 double estinvsqrt(double);
40 #define max(a,b) ((a) > (b) ? (a) : (b))
44 #define min(a,b) ((a) <= (b) ? (a) : (b))
47 float frand(float max
);
48 double fsqrt(double x
);
49 char *strdup(const char*);
50 char *strcat(char *, const char *);
51 char *strncpy(char *, const char *, size_t);
52 int stricmp(const char *, const char *);
53 char *strstr(const char *, const char *);
55 #define GETR5(c) (((c)>>11)&0x1f)
56 #define GETG6(c) (((c)>>5)&0x3f)
57 #define GETB5(c) ((c) & 0x1f)
59 #define MASKR5(c) ((c) & 0xf800)
60 #define MASKG6(c) ((c) & 0x7e0)
61 #define MASKB5(c) ((c) & 0x1f)
63 #define ColorF2I(r,g,b) ( ( (int)( (r)*255.0f ) << 16 ) | ( (int)( (g)*255.0f ) << 8 ) | ( (int)( (b)*255.0f ) ) )
64 #define ColorI2I(r,g,b) (ULONG)( (r)<<16 | (g)<<8 | (b) )
66 #define ftoi(x) ((int)(x))
68 static inline int align(int a
, int b
)
70 return (a
+ b
- 1) & (~(b
- 1));
75 void chk_PutImageBrightnessPPC(struct chkimage
*image
,int x0
,int y0
,unsigned char *dest
,int destwidth
,int destheight
,int bri
);
76 void chk_AddImagePPC(struct chkimage
*image
,int x0
,int y0
,unsigned char *dest
,int destwidth
,int destheight
);
78 /* string functions */
80 char *strduplicate(char *str
);
81 #define strDuplicate(str) strduplicate(str)
83 void strFixPath(char *str
);
84 char *strReplaceExt(char *oldstring
, char *oldext
, char *newext
);
85 char *strSetExtension(char *str
, char *ext
);
86 char *strPathOnly(char *str
);
87 int strIsDir(char *path
);
88 int strMatch(char *name
, char *pattern
);
89 char *strReplace(char *oldname
, char *newname
);
91 /* params functions */
93 void ParamsInit(int argc
, char *argv
[]);
94 int FindParam(char *param
);
96 /* memory allocation functions */
98 #define MALLOC_STRUCT(s) malloc( sizeof(s) )
99 #define CALLOC_STRUCT(s) calloc(1,sizeof(s))
101 /* conversion functions */
103 void convertARGB1555_to_ARGB8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
104 void convertARGB1555_to_RGB888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
105 void convertARGB1555_to_RGB565( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
106 void convertARGB4444_to_ARGB8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
107 void convertARGB4444_to_RGB888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
108 void convertARGB4444_to_RGB565( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
109 void convertRGB565_to_ARGB8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
110 void convertRGB565_to_RGB888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
111 void convertRGB565_to_RGB565( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
112 void convertRGB888_to_RGB565( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
113 void convertRGB888_to_RGB888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
114 void convertARGB8888_to_ARGB8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
115 void convertL8_to_L8( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
116 void convertRGB888_to_ARGB8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
117 void convertRGB888_to_L8( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
118 void convertRGB888_to_A8( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
119 void convertRGBA8888_to_RGBA4444( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
120 void convertRGBA8888_to_ARGB4444( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
121 void convertARGB8888_to_ARGB4444( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
122 void convertRGBA8888_to_RGB888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
123 void convertARGB8888_to_RGB888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
124 void convertRGBA8888_to_RGB565( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
125 void convertRGBA8888_to_ARGB8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
126 void convertARGB0888_to_ARGB8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
127 void convertRGBA8888_to_A8( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
128 void convertRGBA8888_to_L8( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
129 void convertARGB8888_to_L8( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
130 void convertA8_to_RGBA8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
131 void convertA8_to_RGB888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
132 void convertL8_to_RGB888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
133 void convertL8_to_ARGB8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
134 void convertA8_to_ARGB8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
135 void convertA8_to_ARGB4444( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
136 void convertL8_to_RGB565( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
137 void convertRGB888_to_ARGB4444( unsigned char *src
, unsigned char *dst
, int xsize
, int ysize
);
138 void convertARGB8888_to_RGBA8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
139 void convertRGB888_to_RGBA8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
141 void expandRGB888_to_RGBA8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
142 void expandRGB888_to_ARGB8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
143 void expandL8_to_ARGB8888( unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
145 void convertRGB888_to_YUV422(unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
146 void convertRGB888_to_YUV422_custom(unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
147 void convertYUV422_to_RGB888(unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
148 void convertYUV422_to_RGB888_custom(unsigned char *src
, unsigned char *dst
,int xsize
, int ysize
);
149 void convertYUV422_to_ARGB8888_custom(unsigned char *src
, unsigned char *dst
, int xsize
, int ysize
);
151 void ConversionInit(void);
153 float fClamp(float a
);
154 #define clamp(_a, _amin, _amax) \
157 typeof(_a) amin = _amin; \
158 typeof(_a) amax = _amax; \
159 a < amin ? amin : a > amax ? amax : a; \
162 void scaleCoordsWithAspect(int width
, int height
, int destWidth
, int destHeight
, int *newWidth
, int *newHeight
);