WPBDC 2013.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/WPBDC/WPBDC.c +237 -0
- data/ext/WPBDC/analysis.c +672 -0
- data/ext/WPBDC/bridge.c +288 -0
- data/ext/WPBDC/bridge_cost.c +60 -0
- data/ext/WPBDC/bridge_hash.c +126 -0
- data/ext/WPBDC/bridge_parser.c +1119 -0
- data/ext/WPBDC/bridge_random.c +292 -0
- data/ext/WPBDC/bridge_sketch.c +125 -0
- data/ext/WPBDC/extconf.rb +5 -0
- data/ext/WPBDC/geometry.c +46 -0
- data/ext/WPBDC/internal.h +518 -0
- data/ext/WPBDC/judge.c +563 -0
- data/ext/WPBDC/judge.h +142 -0
- data/ext/WPBDC/loading.c +128 -0
- data/ext/WPBDC/params.c +166 -0
- data/ext/WPBDC/proto.h +98 -0
- data/ext/WPBDC/rc4.c +62 -0
- data/ext/WPBDC/rc4.h +19 -0
- data/ext/WPBDC/rc4_key.c +2 -0
- data/ext/WPBDC/rubydefs.h +75 -0
- data/ext/WPBDC/scenario.c +671 -0
- data/ext/WPBDC/sketch.c +496 -0
- data/ext/WPBDC/sketch.h +51 -0
- data/ext/WPBDC/stdafx.h +11 -0
- data/lib/WPBDC.rb +9 -0
- metadata +71 -0
data/ext/WPBDC/loading.c
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
#include "stdafx.h"
|
2
|
+
#include "internal.h"
|
3
|
+
|
4
|
+
// Loading ---------------------------------------------------------------------
|
5
|
+
|
6
|
+
// Initialize a loading.
|
7
|
+
void init_loading(TLoading *loading)
|
8
|
+
{
|
9
|
+
memset(loading, 0, sizeof(*loading));
|
10
|
+
}
|
11
|
+
|
12
|
+
// Free storage for a loading and re-initialize it.
|
13
|
+
void clear_loading(TLoading *loading)
|
14
|
+
{
|
15
|
+
unsigned i;
|
16
|
+
|
17
|
+
for (i = 1; i <= loading->n_load_instances; i++)
|
18
|
+
Safefree(loading->load_instances[i].point_load);
|
19
|
+
Safefree(loading->load_instances);
|
20
|
+
init_loading(loading);
|
21
|
+
}
|
22
|
+
|
23
|
+
// Fill in a loading with information from a bridge, its geometry, and
|
24
|
+
// analysis parameters.
|
25
|
+
void setup_loading(TLoading *loading,
|
26
|
+
TBridge *bridge,
|
27
|
+
TGeometry *geometry,
|
28
|
+
TParams *params)
|
29
|
+
{
|
30
|
+
unsigned joint_index, member_index, load_instance_index;
|
31
|
+
TGeometry local_geometry[1];
|
32
|
+
TParams local_params[1];
|
33
|
+
TLoadCase *lc;
|
34
|
+
unsigned n_equations = 2 * bridge->n_joints;
|
35
|
+
|
36
|
+
clear_loading(loading);
|
37
|
+
|
38
|
+
// If caller didn't provide these things, we'll do it ourselves.
|
39
|
+
if (!geometry) {
|
40
|
+
geometry = local_geometry;
|
41
|
+
init_geometry(geometry);
|
42
|
+
setup_geometry(geometry, bridge);
|
43
|
+
}
|
44
|
+
|
45
|
+
if (!params) {
|
46
|
+
params = local_params;
|
47
|
+
init_params(params);
|
48
|
+
setup_params(params);
|
49
|
+
}
|
50
|
+
|
51
|
+
loading->n_load_instances = bridge->load_scenario.n_loaded_joints + 1;
|
52
|
+
Newz(240, loading->load_instances, loading->n_load_instances + 1, TLoadInstance);
|
53
|
+
for (load_instance_index = 1; load_instance_index <= loading->n_load_instances; load_instance_index++) {
|
54
|
+
Newz(250, loading->load_instances[load_instance_index].point_load, n_equations + 1, TFloat);
|
55
|
+
}
|
56
|
+
|
57
|
+
// Apply self-weight.
|
58
|
+
|
59
|
+
for (member_index = 1; member_index <= bridge->n_members; member_index++) {
|
60
|
+
|
61
|
+
TMember *member = &bridge->members[member_index];
|
62
|
+
|
63
|
+
TFloat dead_load = params->dead_load_factor *
|
64
|
+
// half weight of member
|
65
|
+
params->shapes[member->x_section.section][member->x_section.size].area *
|
66
|
+
geometry->length[member_index] *
|
67
|
+
params->materials[member->x_section.material].density * 9.8066 / 2.0 / 1000.0;
|
68
|
+
|
69
|
+
unsigned dof1 = 2 * member->start_joint;
|
70
|
+
unsigned dof2 = 2 * member->end_joint;
|
71
|
+
|
72
|
+
for (load_instance_index = 1; load_instance_index <= loading->n_load_instances; load_instance_index++) {
|
73
|
+
TLoadInstance *load_instance = &loading->load_instances[load_instance_index];
|
74
|
+
load_instance->point_load[dof1] -= dead_load;
|
75
|
+
load_instance->point_load[dof2] -= dead_load;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
// Get access to the right load case.
|
80
|
+
|
81
|
+
lc = ¶ms->load_cases[bridge->load_scenario.load_case];
|
82
|
+
|
83
|
+
// Apply dead load.
|
84
|
+
|
85
|
+
for (joint_index = 1; joint_index <= bridge->load_scenario.n_loaded_joints; joint_index++) {
|
86
|
+
unsigned dof= 2 * joint_index;
|
87
|
+
for (load_instance_index = 1; load_instance_index <= loading->n_load_instances; load_instance_index++) {
|
88
|
+
|
89
|
+
TFloat load = lc->point_dead_load;
|
90
|
+
|
91
|
+
// Account for ends of deck.
|
92
|
+
if (joint_index == 1 || joint_index == bridge->load_scenario.n_loaded_joints)
|
93
|
+
load /= 2;
|
94
|
+
loading->load_instances[load_instance_index].point_load[dof] -= load;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
// Apply live load.
|
99
|
+
|
100
|
+
for (load_instance_index = 2; load_instance_index <= loading->n_load_instances - 1; load_instance_index++) {
|
101
|
+
TLoadInstance *load_instance = &loading->load_instances[load_instance_index];
|
102
|
+
unsigned dof_front = 2 * load_instance_index;
|
103
|
+
unsigned dof_rear = dof_front - 2;
|
104
|
+
load_instance->point_load[dof_front] -= params->live_load_factor * lc->front_axle_load;
|
105
|
+
load_instance->point_load[dof_rear] -= params->live_load_factor * lc->rear_axle_load;
|
106
|
+
}
|
107
|
+
|
108
|
+
#ifdef TEST_PRINT
|
109
|
+
for (load_instance_index = 1; load_instance_index <= loading->n_load_instances; load_instance_index++) {
|
110
|
+
TLoadInstance *load_instance = &loading->load_instances[load_instance_index];
|
111
|
+
printf("\nPoint Loads Load Case %d\n", load_instance_index);
|
112
|
+
printf("Jnt # X Y\n");
|
113
|
+
printf("----- ----------- -----------\n");
|
114
|
+
for (joint_index = 1; joint_index <= bridge->n_joints; joint_index++) {
|
115
|
+
printf("%5d %11.5lf %11.5lf\n",
|
116
|
+
joint_index,
|
117
|
+
load_instance->point_load[2 * joint_index - 1],
|
118
|
+
load_instance->point_load[2 * joint_index]);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
#endif;
|
122
|
+
|
123
|
+
if (geometry == local_geometry)
|
124
|
+
clear_geometry(geometry);
|
125
|
+
if (params == local_params)
|
126
|
+
clear_params(params);
|
127
|
+
}
|
128
|
+
|
data/ext/WPBDC/params.c
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
#include "stdafx.h"
|
2
|
+
#include "internal.h"
|
3
|
+
|
4
|
+
/*
|
5
|
+
|
6
|
+
Copied from internal.h...
|
7
|
+
|
8
|
+
#define NLoadCases 4
|
9
|
+
|
10
|
+
typedef load_case_t {
|
11
|
+
TFloat point_dead_load; // Dead load due to roadway.
|
12
|
+
TFloat front_axle_load; // Live load due to front axle.
|
13
|
+
TFloat rear_axle_load; // Live load due to rear axle.
|
14
|
+
} TLoadCase;
|
15
|
+
|
16
|
+
// Parameters of analysis.
|
17
|
+
typedef struct params_t {
|
18
|
+
TFloat dead_load_factor; // Dead load safety factor.
|
19
|
+
TFloat live_load_factor; // Live load safety factor.
|
20
|
+
TFloat compression_resistance_factor; // Compression loading safety factor.
|
21
|
+
TFloat tension_resistance_factor; // Tension loading safety factor.
|
22
|
+
TLoadCase load_cases[NLoadCases]; // Load cases.
|
23
|
+
TFloat connection_cost; // Cost of connecting members at a joint.
|
24
|
+
TFloat ordering_fee; // Fee per cross-section used.
|
25
|
+
TMaterial materials[NMaterials]; // Descriptions of available materials.
|
26
|
+
unsigned n_sizes[NSections]; // Number of sizes available by section.
|
27
|
+
TShape *shapes[NSections]; // Shape descriptions by section and size.
|
28
|
+
} TParams;
|
29
|
+
|
30
|
+
*/
|
31
|
+
|
32
|
+
#define DEAD_LOAD_FACTOR 1.25
|
33
|
+
|
34
|
+
// Constant part of the analysis parameters block. Rest has to be calculated.
|
35
|
+
// This is similar to the BD_VERSION==0x400, but the cost factors have changed.
|
36
|
+
static TParams constant_params = INIT_CONSTANT_PARAMS;
|
37
|
+
|
38
|
+
// Table mapping section to the number of available sizes of that section.
|
39
|
+
static unsigned constant_n_sizes[NSections] = {
|
40
|
+
NBarSizes,
|
41
|
+
NTubeSizes,
|
42
|
+
};
|
43
|
+
|
44
|
+
unsigned n_sizes(TSection section)
|
45
|
+
{
|
46
|
+
return (unsigned)section < NSections ? constant_n_sizes[section] : 0;
|
47
|
+
}
|
48
|
+
|
49
|
+
// Initialize a parameter block.
|
50
|
+
void init_params(TParams *params)
|
51
|
+
{
|
52
|
+
memset(params, 0, sizeof(*params));
|
53
|
+
}
|
54
|
+
|
55
|
+
// Free storage allocated to a parameter block and re-initialize it.
|
56
|
+
void clear_params(TParams *params)
|
57
|
+
{
|
58
|
+
unsigned section_index, size_index;
|
59
|
+
|
60
|
+
for (section_index = 0; section_index < NSections; section_index++) {
|
61
|
+
for (size_index = 0; size_index < params->n_sizes[section_index]; size_index++)
|
62
|
+
Safefree(params->shapes[section_index][size_index].name);
|
63
|
+
Safefree(params->shapes[section_index]);
|
64
|
+
}
|
65
|
+
init_params(params);
|
66
|
+
}
|
67
|
+
|
68
|
+
// Square a float.
|
69
|
+
static __inline TFloat sqr(TFloat x)
|
70
|
+
{
|
71
|
+
return x * x;
|
72
|
+
}
|
73
|
+
|
74
|
+
// Compute fourth power of a float.
|
75
|
+
static __inline TFloat p4(TFloat x)
|
76
|
+
{
|
77
|
+
return sqr(sqr(x));
|
78
|
+
}
|
79
|
+
|
80
|
+
// Fill in a parameter block.
|
81
|
+
void setup_params (TParams *params)
|
82
|
+
{
|
83
|
+
unsigned section_index, size_index;
|
84
|
+
char buf[256];
|
85
|
+
int width, tube_thickness;
|
86
|
+
|
87
|
+
/* From Steve, 15 Nov 2004. Last year these were computed. */
|
88
|
+
static int width_tbl[33] = {
|
89
|
+
30,35,40,45,50,55,60,65,70,75,80, /* 0 to 10 */
|
90
|
+
90,100,110,120,130,140,150,160,170,180,190,200, /* 11 to 22 */
|
91
|
+
220,240,260,280,300, /* 23 to 27 */
|
92
|
+
320,340,360,400,500 /* 28 to 32 */
|
93
|
+
};
|
94
|
+
|
95
|
+
assert(STATIC_ARRAY_SIZE(width_tbl) == NBarSizes && NBarSizes == NTubeSizes);
|
96
|
+
|
97
|
+
*params = constant_params;
|
98
|
+
memcpy(params->n_sizes, constant_n_sizes, sizeof(constant_n_sizes));
|
99
|
+
for (section_index = 0; section_index < NSections; section_index++) {
|
100
|
+
|
101
|
+
Newz(200, params->shapes[section_index], params->n_sizes[section_index], TShape);
|
102
|
+
|
103
|
+
for (size_index = 0; size_index < params->n_sizes[section_index]; size_index++) {
|
104
|
+
|
105
|
+
switch (section_index) {
|
106
|
+
|
107
|
+
case Bar:
|
108
|
+
width = width_tbl[size_index];
|
109
|
+
params->shapes[section_index][size_index].width = width;
|
110
|
+
params->shapes[section_index][size_index].area = sqr(width) * 1e-6;
|
111
|
+
params->shapes[section_index][size_index].moment = p4(width) / 12 * 1e-12;
|
112
|
+
sprintf(buf, "%dx%d", width, width);
|
113
|
+
NewStr(203, params->shapes[section_index][size_index].name, buf);
|
114
|
+
break;
|
115
|
+
|
116
|
+
case Tube:
|
117
|
+
width = width_tbl[size_index];
|
118
|
+
tube_thickness = width / 20;
|
119
|
+
if (tube_thickness < 2)
|
120
|
+
tube_thickness = 2;
|
121
|
+
params->shapes[section_index][size_index].width = width;
|
122
|
+
params->shapes[section_index][size_index].area = ( sqr(width) - sqr(width - 2 * tube_thickness) ) * 1e-6;
|
123
|
+
params->shapes[section_index][size_index].moment = ( p4(width) - p4(width - 2 * tube_thickness) ) / 12 * 1e-12;
|
124
|
+
sprintf(buf, "%dx%dx%d", width, width, tube_thickness);
|
125
|
+
NewStr(206, params->shapes[section_index][size_index].name, buf);
|
126
|
+
break;
|
127
|
+
|
128
|
+
default:
|
129
|
+
fprintf(stderr, "init_params: unhandled section\n");
|
130
|
+
exit(1);
|
131
|
+
break;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
void print_load_case(FILE *f, unsigned index, TLoadCase *load_case)
|
138
|
+
{
|
139
|
+
fprintf(f, "[%u] load case '%s':\n", index, load_case->name);
|
140
|
+
fprintf(f, " point_dead_load = %.4f\n", load_case->point_dead_load);
|
141
|
+
fprintf(f, " front_axle_load = %.4f\n", load_case->front_axle_load);
|
142
|
+
fprintf(f, " rear_axle_load = %.4f\n", load_case->rear_axle_load);
|
143
|
+
}
|
144
|
+
|
145
|
+
void print_params(FILE *f, TParams *params)
|
146
|
+
{
|
147
|
+
unsigned material_index,
|
148
|
+
section_index,
|
149
|
+
size_index,
|
150
|
+
load_case_index;
|
151
|
+
|
152
|
+
fprintf(f, "parameters:\n");
|
153
|
+
fprintf(f, " dead_load_factor = %.4f\n", params->dead_load_factor);
|
154
|
+
fprintf(f, " live_load_factor = %.4f\n", params->live_load_factor);
|
155
|
+
fprintf(f, " compression_resistance_factor = %.4f\n", params->compression_resistance_factor);
|
156
|
+
fprintf(f, " tension_resistance_factor = %.4f\n", params->tension_resistance_factor);
|
157
|
+
for (load_case_index = 0; load_case_index < NLoadCases; load_case_index++)
|
158
|
+
print_load_case(f, load_case_index, ¶ms->load_cases[load_case_index]);
|
159
|
+
fprintf(f, " connection_cost = %.4f\n", params->connection_cost);
|
160
|
+
fprintf(f, " ordering_fee = %.4f\n", params->ordering_fee);
|
161
|
+
for (material_index = 0; material_index < NMaterials; material_index++)
|
162
|
+
print_material(f, material_index, ¶ms->materials[material_index]);
|
163
|
+
for (section_index = 0; section_index < NSections; section_index++)
|
164
|
+
for (size_index = 0; size_index < params->n_sizes[section_index]; size_index++)
|
165
|
+
print_shape(f, section_index, size_index, ¶ms->shapes[section_index][size_index]);
|
166
|
+
}
|
data/ext/WPBDC/proto.h
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
/* analysis.c */
|
2
|
+
void init_analysis(TAnalysis *anal);
|
3
|
+
void clear_analysis(TAnalysis *anal);
|
4
|
+
void setup_analysis(TAnalysis *anal, TBridge *bridge, TGeometry *geometry, TLoading *loading, TParams *params);
|
5
|
+
void do_analyze(STRING *bridge_as_string, TAnalysis *analysis, TBridge *bridge, TGeometry *geometry, TLoading *loading, TParams *params, struct analysis_result_t *result);
|
6
|
+
char *analysis_to_html(TAnalysis *analysis, TBridge *bridge, TGeometry *geometry, TLoading *loading, TParams *params, struct analysis_result_t *result);
|
7
|
+
void print_analysis(FILE *f, TAnalysis *anal, TBridge *bridge, TGeometry *geometry, TLoading *loading, TParams *params);
|
8
|
+
/* bridge.c */
|
9
|
+
void init_bridge(TBridge *bridge);
|
10
|
+
void clear_bridge(TBridge *bridge);
|
11
|
+
TBool joint_lists_eq(TJoint *a, TJoint *b, unsigned n);
|
12
|
+
TBool x_section_lists_eq(TXSection *a, TXSection *b, unsigned n);
|
13
|
+
char *section_str(TSection section);
|
14
|
+
TBool member_lists_eq(TMember *a, TMember *b, unsigned n);
|
15
|
+
void copy_bridge(TBridge *dst, TBridge *src);
|
16
|
+
TBool bridges_indentical(TBridge *a, TBridge *b);
|
17
|
+
void canonicalize(TBridge *dst, TBridge *src);
|
18
|
+
void print_material(FILE *f, unsigned index, TMaterial *material);
|
19
|
+
void print_shape(FILE *f, unsigned section_index, unsigned size_index, TShape *shape);
|
20
|
+
/* bridge_cost.c */
|
21
|
+
int lookup_scenario_descriptor(TScenarioDescriptor *desc, char *id);
|
22
|
+
TFloat bridge_cost(TBridge *bridge, TGeometry *geometry, TParams *params);
|
23
|
+
int test_scenario_table(void);
|
24
|
+
/* bridge_hash.c */
|
25
|
+
void hashify_vec(unsigned *v, unsigned v_len, unsigned *hash, unsigned h_len);
|
26
|
+
char *hex_nibble(int n, char *p);
|
27
|
+
char *hex_byte(int b, char *p);
|
28
|
+
char *hex_str(char *s, unsigned n, char *p);
|
29
|
+
int hash_bridge(TBridge *bridge, char *hash);
|
30
|
+
/* bridge_parser.c */
|
31
|
+
char *get_line(char *buf, char **next);
|
32
|
+
char *parse_string(char *buf, char *str);
|
33
|
+
void basic_string(char *dst, char *src);
|
34
|
+
char *parse_comma(char *buf);
|
35
|
+
unsigned scan_unsigned(char *str, unsigned width, char **next);
|
36
|
+
int scan_int(char *str, unsigned width, char **next);
|
37
|
+
TTestStatus lookup_test_status_tag(const char *str);
|
38
|
+
char *get_to_delim(char *str, char **next);
|
39
|
+
void endecrypt_in_place(char *buf, int size);
|
40
|
+
void parse_bridge(TBridge *bridge, STRING *str);
|
41
|
+
void parse_unpacked_bridge_destructive(TBridge *bridge, char *str);
|
42
|
+
void parse_packed_bridge_destructive(TBridge *bridge, char *str);
|
43
|
+
char *unparse_bridge(TBridge *bridge);
|
44
|
+
char *unparse_packed_bridge(TBridge *bridge);
|
45
|
+
char *unparse_unpacked_bridge(TBridge *bridge);
|
46
|
+
void pack_bridge(STRING *in_str, STRING *out_str, TBool decrypt_p, TBool encrypt_p);
|
47
|
+
void unpack_bridge(STRING *in_str, STRING *out_str, TBool decrypt_p, TBool encrypt_p);
|
48
|
+
/* bridge_random.c */
|
49
|
+
void randomly_permute_unsigned(unsigned *v, unsigned n);
|
50
|
+
void randomly_permute_members(TMember *v, unsigned n);
|
51
|
+
void sample(unsigned *s, unsigned sn, unsigned m, unsigned n);
|
52
|
+
void perturb(TBridge *dst, TBridge *src, unsigned seed, unsigned n_joints, unsigned n_members);
|
53
|
+
int fix_failure(TBridge *dst, TBridge *src, TParams *params);
|
54
|
+
int induce_failure(TBridge *dst, TBridge *src, unsigned seed);
|
55
|
+
void vary(TBridge *dst, TBridge *src, unsigned seed);
|
56
|
+
/* bridge_sketch.c */
|
57
|
+
void do_sketch(TBridge *bridge, TAnalysis *analysis, int width, int height, COMPRESSED_IMAGE *compressed_image);
|
58
|
+
/* geometry.c */
|
59
|
+
void init_geometry(TGeometry *geometry);
|
60
|
+
void clear_geometry(TGeometry *geometry);
|
61
|
+
void setup_geometry(TGeometry *geometry, TBridge *bridge);
|
62
|
+
/* judge.c */
|
63
|
+
void endecrypt(STRING *bridge_as_string);
|
64
|
+
void analyze(STRING *bridge_as_string, struct analysis_result_t *result);
|
65
|
+
int compare(STRING *bridge_as_string_a, STRING *bridge_as_string_b);
|
66
|
+
char *variant(STRING *bridge_as_string, int seed);
|
67
|
+
char *failed_variant(STRING *bridge_as_string, int seed);
|
68
|
+
char *perturbation(STRING *bridge_as_string, int seed, int n_joints, int n_members);
|
69
|
+
void sketch(STRING *bridge_as_string, int width, int height, COMPRESSED_IMAGE *compressed_image, struct analysis_result_t *result);
|
70
|
+
char *analysis_table(STRING *bridge_as_string);
|
71
|
+
/* loading.c */
|
72
|
+
void init_loading(TLoading *loading);
|
73
|
+
void clear_loading(TLoading *loading);
|
74
|
+
void setup_loading(TLoading *loading, TBridge *bridge, TGeometry *geometry, TParams *params);
|
75
|
+
/* params.c */
|
76
|
+
unsigned n_sizes(TSection section);
|
77
|
+
void init_params(TParams *params);
|
78
|
+
void clear_params(TParams *params);
|
79
|
+
void setup_params(TParams *params);
|
80
|
+
void print_load_case(FILE *f, unsigned index, TLoadCase *load_case);
|
81
|
+
void print_params(FILE *f, TParams *params);
|
82
|
+
/* scenario.c */
|
83
|
+
void init_load_scenario(TLoadScenario *load_scenario);
|
84
|
+
void clear_load_scenario(TLoadScenario *load_scenario);
|
85
|
+
void setup_load_scenario(TLoadScenario *load_scenario, unsigned scenario_index);
|
86
|
+
void copy_load_scenario(TLoadScenario *dst, TLoadScenario *src);
|
87
|
+
/* sketch.c */
|
88
|
+
void init_image(IMAGE *image);
|
89
|
+
void clear_image(IMAGE *image);
|
90
|
+
void setup_image(IMAGE *image, UNSIGNED width, UNSIGNED height, RGB_TRIPLE *color);
|
91
|
+
void set_viewport(IMAGE *image, UNSIGNED x_left, UNSIGNED x_right, UNSIGNED y_bottom, UNSIGNED y_top);
|
92
|
+
void draw_line_raw(IMAGE *image, UNSIGNED x1, UNSIGNED y1, UNSIGNED x2, UNSIGNED y2, RGB_TRIPLE *color);
|
93
|
+
void draw_rect_raw(IMAGE *image, UNSIGNED x1, UNSIGNED y1, UNSIGNED x2, UNSIGNED y2, RGB_TRIPLE *color);
|
94
|
+
void clip_segment(FLOAT *x1p, FLOAT *y1p, FLOAT *x2p, FLOAT *y2p, FLOAT x_left, FLOAT x_right, FLOAT y_bottom, FLOAT y_top, int *segment_survives_p);
|
95
|
+
void draw_line(IMAGE *image, FLOAT x1, FLOAT y1, FLOAT x2, FLOAT y2, RGB_TRIPLE *color);
|
96
|
+
void init_compressed_image(COMPRESSED_IMAGE *compressed_image);
|
97
|
+
void clear_compressed_image(COMPRESSED_IMAGE *compressed_image);
|
98
|
+
int compress_image(IMAGE *image, COMPRESSED_IMAGE *compressed_image);
|
data/ext/WPBDC/rc4.c
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#include "rc4.h"
|
2
|
+
|
3
|
+
void init_rc4(TRC4State *state)
|
4
|
+
{
|
5
|
+
int x;
|
6
|
+
|
7
|
+
state->x = state->y = 0;
|
8
|
+
|
9
|
+
// Set up permutation.
|
10
|
+
for (x = 0; x < 256; x++)
|
11
|
+
state->buf[x] = x;
|
12
|
+
}
|
13
|
+
|
14
|
+
void clear_rc4(TRC4State *state)
|
15
|
+
{
|
16
|
+
init_rc4(state);
|
17
|
+
}
|
18
|
+
|
19
|
+
void setup_rc4(TRC4State *state, char *key, int keylen)
|
20
|
+
{
|
21
|
+
unsigned tmp;
|
22
|
+
int x, y;
|
23
|
+
|
24
|
+
// use only first 256 characters of key
|
25
|
+
if (keylen > 256)
|
26
|
+
keylen = 256;
|
27
|
+
|
28
|
+
for (x = y = 0; x < 256; x++) {
|
29
|
+
y = (y + state->buf[x] + key[x % keylen]) & 255;
|
30
|
+
tmp = state->buf[x];
|
31
|
+
state->buf[x] = state->buf[y];
|
32
|
+
state->buf[y] = tmp;
|
33
|
+
}
|
34
|
+
state->x = x;
|
35
|
+
state->y = y;
|
36
|
+
|
37
|
+
// DEBUG: Temporary while Steve fixes bug.
|
38
|
+
// Removed 1 December 2003
|
39
|
+
// state->y = 0;
|
40
|
+
}
|
41
|
+
|
42
|
+
unsigned endecrypt_rc4(unsigned char *buf, unsigned len, TRC4State *state)
|
43
|
+
{
|
44
|
+
int x, y;
|
45
|
+
unsigned char *s, tmp;
|
46
|
+
unsigned n;
|
47
|
+
|
48
|
+
x = state->x;
|
49
|
+
y = state->y;
|
50
|
+
s = state->buf;
|
51
|
+
n = len;
|
52
|
+
while (n--) {
|
53
|
+
x = (x + 1) & 255;
|
54
|
+
y = (y + s[x]) & 255;
|
55
|
+
tmp = s[x]; s[x] = s[y]; s[y] = tmp;
|
56
|
+
tmp = (s[x] + s[y]) & 255;
|
57
|
+
*buf++ ^= s[tmp];
|
58
|
+
}
|
59
|
+
state->x = x;
|
60
|
+
state->y = y;
|
61
|
+
return len;
|
62
|
+
}
|
data/ext/WPBDC/rc4.h
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#ifndef _RC4_H
|
2
|
+
#define _RC4_H
|
3
|
+
|
4
|
+
/*
|
5
|
+
* rc4.h -- Declarations for a simple rc4 encryption/decryption implementation.
|
6
|
+
* The code was inspired by libtomcrypt. See www.libtomcrypt.org.
|
7
|
+
*/
|
8
|
+
typedef struct TRC4State_t {
|
9
|
+
int x, y;
|
10
|
+
unsigned char buf[256];
|
11
|
+
} TRC4State;
|
12
|
+
|
13
|
+
/* rc4.c */
|
14
|
+
void init_rc4(TRC4State *state);
|
15
|
+
void clear_rc4(TRC4State *state);
|
16
|
+
void setup_rc4(TRC4State *state, char *key, int keylen);
|
17
|
+
unsigned endecrypt_rc4(unsigned char *buf, unsigned len, TRC4State *state);
|
18
|
+
|
19
|
+
#endif
|
data/ext/WPBDC/rc4_key.c
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#ifndef _RUBYDEFS_H
|
2
|
+
#define _RUBYDEFS_H
|
3
|
+
|
4
|
+
#if !defined(STAND_ALONE)
|
5
|
+
|
6
|
+
#include <ruby.h>
|
7
|
+
|
8
|
+
// For safety, generate a compile error if we try to call
|
9
|
+
// one of the underlying C allocators.
|
10
|
+
#undef malloc
|
11
|
+
#define malloc @oops@
|
12
|
+
#undef calloc
|
13
|
+
#define calloc @oops@
|
14
|
+
#undef realloc
|
15
|
+
#define realloc @oops@
|
16
|
+
#undef strdup
|
17
|
+
#define strdup @oops@
|
18
|
+
#undef free
|
19
|
+
#define free @oops@
|
20
|
+
|
21
|
+
#define New(x,v,n,t) \
|
22
|
+
do { \
|
23
|
+
v = ALLOC_N(t, n); \
|
24
|
+
} while (0)
|
25
|
+
|
26
|
+
#define Newz(x,v,n,t) \
|
27
|
+
do { \
|
28
|
+
v = ALLOC_N(t, n); \
|
29
|
+
MEMZERO(v, t, n); \
|
30
|
+
} while (0)
|
31
|
+
|
32
|
+
#define Renew(v,n,t) \
|
33
|
+
do { \
|
34
|
+
v = REALLOC_N(v, t, n); \
|
35
|
+
} while (0)
|
36
|
+
|
37
|
+
#define Safefree(p) \
|
38
|
+
do { \
|
39
|
+
xfree(p); \
|
40
|
+
} while (0)
|
41
|
+
|
42
|
+
#else
|
43
|
+
|
44
|
+
#define New(x,v,n,t) \
|
45
|
+
do { \
|
46
|
+
if ( !(v = (t*)malloc((n)*sizeof(t))) ) { \
|
47
|
+
fprintf(stderr, "out of memory (%d)\n", x); \
|
48
|
+
exit(1); \
|
49
|
+
} \
|
50
|
+
} while (0)
|
51
|
+
|
52
|
+
#define Newz(x,v,n,t) \
|
53
|
+
do { \
|
54
|
+
if ( !(v = (t*)calloc(n, sizeof(t))) ) { \
|
55
|
+
fprintf(stderr, "out of memory (%d)\n", x); \
|
56
|
+
exit(1); \
|
57
|
+
} \
|
58
|
+
} while (0)
|
59
|
+
|
60
|
+
#define Renew(v,n,t) \
|
61
|
+
do { \
|
62
|
+
if ( !(v = (t*)realloc(v, (n)*sizeof(t))) ) { \
|
63
|
+
fprintf(stderr, "out of memory in Renew\n");\
|
64
|
+
exit(1); \
|
65
|
+
} \
|
66
|
+
} while (0)
|
67
|
+
|
68
|
+
#define Safefree(p) \
|
69
|
+
do { \
|
70
|
+
free(p); \
|
71
|
+
} while (0)
|
72
|
+
|
73
|
+
#endif
|
74
|
+
|
75
|
+
#endif
|