This repository has been archived by the owner on Jan 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
phpwb_bitmap.c
156 lines (111 loc) · 2.92 KB
/
phpwb_bitmap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*******************************************************************************
WINBINDER - The native Windows binding for PHP for PHP
Copyright © Hypervisual - see LICENSE.TXT for details
Author: Rubem Pechansky (http://winbinder.org/contact.php)
ZEND wrapper for bitmap functions
*******************************************************************************/
//----------------------------------------------------------------- DEPENDENCIES
#include <math.h>
#include "phpwb.h"
//----------------------------------------------------------- EXPORTED FUNCTIONS
/*
index is the index of the image on the file if filename is an icon library. Default is 0.
*/
ZEND_FUNCTION(wb_load_image)
{
char *s;
int s_len;
long index;
long param = 0;
HANDLE hImage;
TCHAR *wcs = 0;
// Default parameter values
index = 0;
param = FALSE;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s|ll", &s, &s_len, &index, ¶m) == FAILURE)
return;
wcs = Utf82WideChar(s, s_len);
hImage = wbLoadImage(wcs, index, param);
wbFree(wcs);
if(!hImage) {
RETURN_NULL();
} else
RETURN_LONG((long)hImage);
}
ZEND_FUNCTION(wb_save_image)
{
long hbm;
char *s;
int s_len;
TCHAR *wcs = 0;
BOOL ret;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"ls", &hbm, &s, &s_len) == FAILURE)
RETURN_BOOL(FALSE);
if(!hbm)
RETURN_NULL();
wcs = Utf82WideChar(s, s_len);
ret = wbSaveBitmap((HBITMAP)hbm, wcs);
wbFree(wcs);
RETURN_BOOL(ret);
}
ZEND_FUNCTION(wb_create_image)
{
long w, h, bmi = 0, bits = 0;
int nargs;
nargs = ZEND_NUM_ARGS();
if(zend_parse_parameters(nargs TSRMLS_CC,
"ll|ll", &w, &h, &bmi, &bits) == FAILURE)
return;
if(nargs == 3) {
zend_error(E_WARNING, "Invalid parameter type passed to function %s()",
get_active_function_name(TSRMLS_C));
RETURN_LONG(0);
}
RETURN_LONG((LONG)wbCreateBitmap(w, h, (BITMAPINFO *)bmi, (void *)bits))
}
ZEND_FUNCTION(wb_get_image_data)
{
long hbm;
BYTE *lpBits = NULL;
DWORD size;
BOOL compress4to3 = FALSE;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l|l", &hbm, &compress4to3) == FAILURE)
return;
size = wbGetBitmapBits((HBITMAP)hbm, &lpBits, compress4to3);
if(!size || !lpBits)
RETURN_NULL();
RETVAL_STRINGL(lpBits, size, TRUE);
efree(lpBits);
}
// TODO: perform a non-destructive masking
ZEND_FUNCTION(wb_create_mask)
{
long hbm, c;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"ll", &hbm, &c) == FAILURE)
return;
if(!hbm)
RETURN_NULL();
RETURN_LONG((LONG)wbCreateMask((HBITMAP)hbm, c))
}
ZEND_FUNCTION(wb_destroy_image)
{
long hbm;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l", &hbm) == FAILURE)
return;
if(!hbm)
RETURN_NULL();
RETURN_BOOL(wbDestroyBitmap((HBITMAP)hbm))
}
#ifdef __LCC__
// This is needed by PHP 5.1
int _finite(double x)
{
return (fpclassify(x) >= 0);
}
#endif
//------------------------------------------------------------------ END OF FILE