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/sketch.c
ADDED
@@ -0,0 +1,496 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* sketch.c -- Routines to draw in a memory buffer and compress
|
4
|
+
* the image in PNG format.
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include "stdafx.h"
|
8
|
+
#include "internal.h"
|
9
|
+
#include "sketch.h"
|
10
|
+
#include "png.h"
|
11
|
+
|
12
|
+
|
13
|
+
/* ----- Drawing in bitmap ------------------------------------------ */
|
14
|
+
|
15
|
+
// initialize an image to null
|
16
|
+
void init_image(IMAGE *image)
|
17
|
+
{
|
18
|
+
ZERO_PTR(image);
|
19
|
+
}
|
20
|
+
|
21
|
+
// free any storage allocated for image
|
22
|
+
void clear_image(IMAGE *image)
|
23
|
+
{
|
24
|
+
Safefree(image->data);
|
25
|
+
init_image(image);
|
26
|
+
}
|
27
|
+
|
28
|
+
// Allocate storage to give an image the given width and height.
|
29
|
+
// Initialize it with the given background color.
|
30
|
+
void setup_image(IMAGE *image, UNSIGNED width, UNSIGNED height, RGB_TRIPLE *color)
|
31
|
+
{
|
32
|
+
UNSIGNED i;
|
33
|
+
|
34
|
+
clear_image(image);
|
35
|
+
New(2001, image->data, width * height, RGB_TRIPLE);
|
36
|
+
if (!image->data)
|
37
|
+
image->width = image->height = 0;
|
38
|
+
else {
|
39
|
+
image->width = width;
|
40
|
+
image->height = height;
|
41
|
+
}
|
42
|
+
image->x_left = 0;
|
43
|
+
image->x_right = width - 1;
|
44
|
+
image->y_bottom = 0;
|
45
|
+
image->y_top = height - 1;
|
46
|
+
|
47
|
+
if (color->r == color->g && color->g == color->b)
|
48
|
+
SET_MULTIPLE_PTR(image->data, color->r, width * height);
|
49
|
+
else
|
50
|
+
for (i = 0; i < width * height; i++)
|
51
|
+
image->data[i] = *color;
|
52
|
+
}
|
53
|
+
|
54
|
+
// Set the clipping viewport within the image.
|
55
|
+
void set_viewport(IMAGE *image,
|
56
|
+
UNSIGNED x_left, UNSIGNED x_right,
|
57
|
+
UNSIGNED y_bottom, UNSIGNED y_top)
|
58
|
+
{
|
59
|
+
// Turn off clipping for bad viewport coords.
|
60
|
+
if (x_left > x_right) {
|
61
|
+
x_left = 0;
|
62
|
+
x_right = image->width - 1;
|
63
|
+
}
|
64
|
+
|
65
|
+
if (y_bottom > y_top) {
|
66
|
+
y_bottom = 0;
|
67
|
+
y_top = image->height - 1;
|
68
|
+
}
|
69
|
+
|
70
|
+
// Chop viewport to image boundary.
|
71
|
+
if (x_left >= image->width)
|
72
|
+
x_left = image->width - 1;
|
73
|
+
|
74
|
+
if (x_right >= image->width)
|
75
|
+
x_right = image->width - 1;
|
76
|
+
|
77
|
+
if (y_bottom >= image->height)
|
78
|
+
y_bottom = image->height - 1;
|
79
|
+
|
80
|
+
if (y_top >= image->height)
|
81
|
+
y_top = image->height - 1;
|
82
|
+
|
83
|
+
image->x_left = x_left;
|
84
|
+
image->x_right = x_right;
|
85
|
+
image->y_bottom = y_bottom;
|
86
|
+
image->y_top = y_top;
|
87
|
+
}
|
88
|
+
|
89
|
+
// Return a pointer to the RGB triple at the given row and column
|
90
|
+
// within the given image. Row zero is at top of image.
|
91
|
+
INLINE RGB_TRIPLE *rgb_triple_rc(IMAGE *image, UNSIGNED row, UNSIGNED col)
|
92
|
+
{
|
93
|
+
assert(row < image->height);
|
94
|
+
assert(col < image->width);
|
95
|
+
return &image->data[row * image->width + col];
|
96
|
+
}
|
97
|
+
|
98
|
+
// Same as above, but use x and y rather than row and column.
|
99
|
+
INLINE RGB_TRIPLE *rgb_triple_xy(IMAGE *image, UNSIGNED x, UNSIGNED y)
|
100
|
+
{
|
101
|
+
return rgb_triple_rc(image, image->height - 1 - y, x);
|
102
|
+
}
|
103
|
+
|
104
|
+
// Draw a line of width 1 pixel in the image. If end points are outside
|
105
|
+
// the window, just truncate them to get them in the window. Note the
|
106
|
+
// full implementation of eight bresenham cases makes a starburst fully
|
107
|
+
// symmetrical. Algorithms that swap end points won't do this correctly.
|
108
|
+
void draw_line_raw(IMAGE *image,
|
109
|
+
UNSIGNED x1, UNSIGNED y1,
|
110
|
+
UNSIGNED x2, UNSIGNED y2,
|
111
|
+
RGB_TRIPLE *color)
|
112
|
+
{
|
113
|
+
UNSIGNED w = image->width;
|
114
|
+
UNSIGNED h = image->height;
|
115
|
+
UNSIGNED i, i2;
|
116
|
+
int dx, dy, e;
|
117
|
+
|
118
|
+
// Chop!
|
119
|
+
if (x1 >= w) x1 = w - 1;
|
120
|
+
if (y1 >= h) y1 = h - 1;
|
121
|
+
if (x2 >= w) x2 = w - 1;
|
122
|
+
if (y2 >= h) y2 = h - 1;
|
123
|
+
|
124
|
+
i = (h - 1 - y1) * w + x1;
|
125
|
+
i2 = (h - 1 - y2) * w + x2;
|
126
|
+
dx = (int)x2 - (int)x1;
|
127
|
+
dy = (int)y2 - (int)y1;
|
128
|
+
e = 0;
|
129
|
+
|
130
|
+
#define bres_loop(Ind_Step, Ind_Update, Step_Comp, Dep_Step, Dep_Update) \
|
131
|
+
for (;;) { \
|
132
|
+
assert(i < w * h); \
|
133
|
+
image->data[i] = *color; \
|
134
|
+
if (i == i2) break; \
|
135
|
+
Ind_Update; \
|
136
|
+
if (Step_Comp) { Dep_Step; Dep_Update; } \
|
137
|
+
Ind_Step; \
|
138
|
+
}
|
139
|
+
#define incx i++
|
140
|
+
#define decx i--
|
141
|
+
#define incy i -= w
|
142
|
+
#define decy i += w
|
143
|
+
|
144
|
+
if (dx > 0)
|
145
|
+
if (dy > 0)
|
146
|
+
if (dx > dy)
|
147
|
+
bres_loop(incx, e += dy, e + e >= dx, incy, e -= dx)
|
148
|
+
else
|
149
|
+
bres_loop(incy, e += dx, e + e >= dy, incx, e -= dy)
|
150
|
+
else
|
151
|
+
if (dx + dy > 0)
|
152
|
+
bres_loop(incx, e -= dy, e + e >= dx, decy, e -= dx)
|
153
|
+
else
|
154
|
+
bres_loop(decy, e -= dx, e + e <= dy, incx, e -= dy)
|
155
|
+
else
|
156
|
+
if (dy > 0)
|
157
|
+
if (dx + dy < 0)
|
158
|
+
bres_loop(decx, e -= dy, e + e <= dx, incy, e -= dx)
|
159
|
+
else
|
160
|
+
bres_loop(incy, e -= dx, e + e >= dy, decx, e -= dy)
|
161
|
+
else
|
162
|
+
if (dx < dy)
|
163
|
+
bres_loop(decx, e += dy, e + e <= dx, decy, e -= dx)
|
164
|
+
else
|
165
|
+
bres_loop(decy, e += dx, e + e <= dy, decx, e -= dy)
|
166
|
+
}
|
167
|
+
|
168
|
+
// Draw a rectangle with given corner points.
|
169
|
+
void draw_rect_raw(IMAGE *image,
|
170
|
+
UNSIGNED x1, UNSIGNED y1,
|
171
|
+
UNSIGNED x2, UNSIGNED y2,
|
172
|
+
RGB_TRIPLE *color)
|
173
|
+
{
|
174
|
+
draw_line_raw(image, x1, y1, x2, y1, color);
|
175
|
+
draw_line_raw(image, x2, y1, x2, y2, color);
|
176
|
+
draw_line_raw(image, x2, y2, x1, y2, color);
|
177
|
+
draw_line_raw(image, x1, y2, x1, y1, color);
|
178
|
+
}
|
179
|
+
|
180
|
+
|
181
|
+
// Implementation of Cohen-Sutherland line clipping.
|
182
|
+
#define LEFT 8
|
183
|
+
#define TOP 4
|
184
|
+
#define RIGHT 2
|
185
|
+
#define BOTTOM 1
|
186
|
+
|
187
|
+
INLINE unsigned clip_code(FLOAT x, FLOAT y,
|
188
|
+
FLOAT x_left, FLOAT y_top, FLOAT x_right, FLOAT y_bottom)
|
189
|
+
{
|
190
|
+
unsigned code;
|
191
|
+
|
192
|
+
code = (x < x_left);
|
193
|
+
code <<= 1;
|
194
|
+
code |= (y > y_top);
|
195
|
+
code <<= 1;
|
196
|
+
code |= (x > x_right);
|
197
|
+
code <<= 1;
|
198
|
+
code |= (y < y_bottom);
|
199
|
+
|
200
|
+
return code;
|
201
|
+
}
|
202
|
+
|
203
|
+
void clip_segment(FLOAT *x1p, FLOAT *y1p,
|
204
|
+
FLOAT *x2p, FLOAT *y2p,
|
205
|
+
FLOAT x_left, FLOAT x_right,
|
206
|
+
FLOAT y_bottom, FLOAT y_top,
|
207
|
+
int *segment_survives_p)
|
208
|
+
{
|
209
|
+
FLOAT x1 = *x1p, y1 = *y1p;
|
210
|
+
FLOAT x2 = *x2p, y2 = *y2p;
|
211
|
+
FLOAT dx = x2 - x1;
|
212
|
+
FLOAT dy = y2 - y1;
|
213
|
+
|
214
|
+
UNSIGNED p1_code = clip_code(x1, y1, x_left, y_top, x_right, y_bottom);
|
215
|
+
UNSIGNED p2_code = clip_code(x2, y2, x_left, y_top, x_right, y_bottom);
|
216
|
+
|
217
|
+
#define chop(Code, X, Y) do { \
|
218
|
+
if (Code & LEFT) { \
|
219
|
+
Y += (x_left - X) * dy / dx; \
|
220
|
+
X = x_left; \
|
221
|
+
} \
|
222
|
+
else if (Code & RIGHT) { \
|
223
|
+
Y += (x_right - X) * dy / dx; \
|
224
|
+
X = x_right; \
|
225
|
+
} \
|
226
|
+
else if (Code & BOTTOM) { \
|
227
|
+
X += (y_bottom - Y) * dx / dy; \
|
228
|
+
Y = y_bottom; \
|
229
|
+
} \
|
230
|
+
else { /* TOP */ \
|
231
|
+
X += (y_top - Y) * dx / dy; \
|
232
|
+
Y = y_top; \
|
233
|
+
} \
|
234
|
+
Code = clip_code(X, Y, x_left, y_top, x_right, y_bottom); } while(0)
|
235
|
+
|
236
|
+
for (;;) {
|
237
|
+
if ( (p1_code | p2_code) == 0 ) {
|
238
|
+
// Trivial accept.
|
239
|
+
*segment_survives_p = 1;
|
240
|
+
break;
|
241
|
+
}
|
242
|
+
|
243
|
+
if ( (p1_code & p2_code) != 0 ) {
|
244
|
+
// Trivial reject.
|
245
|
+
*segment_survives_p = 0;
|
246
|
+
break;
|
247
|
+
}
|
248
|
+
|
249
|
+
// Chop against a boundary and try again.
|
250
|
+
if (p1_code != 0)
|
251
|
+
chop(p1_code, x1, y1);
|
252
|
+
else
|
253
|
+
chop(p2_code, x2, y2);
|
254
|
+
}
|
255
|
+
*x1p = x1; *y1p = y1;
|
256
|
+
*x2p = x2; *y2p = y2;
|
257
|
+
}
|
258
|
+
|
259
|
+
// Draw a line properly clipped to the viewport.
|
260
|
+
void draw_line(IMAGE *image,
|
261
|
+
|
262
|
+
FLOAT x1, FLOAT y1,
|
263
|
+
FLOAT x2, FLOAT y2,
|
264
|
+
|
265
|
+
RGB_TRIPLE *color)
|
266
|
+
{
|
267
|
+
int segment_survives_p;
|
268
|
+
|
269
|
+
clip_segment(&x1, &y1, &x2, &y2,
|
270
|
+
(FLOAT)image->x_left, (FLOAT)image->x_right, (FLOAT)image->y_bottom, (FLOAT)image->y_top,
|
271
|
+
&segment_survives_p);
|
272
|
+
if (segment_survives_p)
|
273
|
+
draw_line_raw(image, (UNSIGNED)x1, (UNSIGNED)y1, (UNSIGNED)x2, (UNSIGNED)y2, color);
|
274
|
+
}
|
275
|
+
|
276
|
+
/* ----- PNG image compression -------------------------------------- */
|
277
|
+
|
278
|
+
// Initialize a compressed image to null.
|
279
|
+
void init_compressed_image(COMPRESSED_IMAGE *compressed_image)
|
280
|
+
{
|
281
|
+
ZERO_PTR(compressed_image);
|
282
|
+
}
|
283
|
+
|
284
|
+
// Release any storage allocated for a compressed image.
|
285
|
+
void clear_compressed_image(COMPRESSED_IMAGE *compressed_image)
|
286
|
+
{
|
287
|
+
Safefree(compressed_image->data);
|
288
|
+
init_compressed_image(compressed_image);
|
289
|
+
}
|
290
|
+
|
291
|
+
// Callback for memory allocation. We call the perl allocator.
|
292
|
+
static png_voidp png_malloc_callback(png_structp png_reader_or_writer, png_size_t size)
|
293
|
+
{
|
294
|
+
BYTE *ptr;
|
295
|
+
|
296
|
+
New(1010, ptr, size, BYTE);
|
297
|
+
return (png_voidp)ptr;
|
298
|
+
}
|
299
|
+
|
300
|
+
// Callback to free memory. We call the perl deallocator.
|
301
|
+
static void png_free_callback(png_structp png_reader_or_writer, png_voidp ptr)
|
302
|
+
{
|
303
|
+
Safefree(ptr);
|
304
|
+
}
|
305
|
+
|
306
|
+
// Callback to write a block of compressed data. We copy to a memory buffer
|
307
|
+
// in the compressed image.
|
308
|
+
static void png_write_callback(png_structp png_writer, png_bytep data, png_size_t length)
|
309
|
+
{
|
310
|
+
// We put the compressed_image output buffer on the io_ptr below when
|
311
|
+
// we called png_set_write_fn. Retrieve it now!
|
312
|
+
COMPRESSED_IMAGE *compressed_image = png_get_io_ptr(png_writer);
|
313
|
+
UNSIGNED new_size;
|
314
|
+
|
315
|
+
if (compressed_image->size - compressed_image->filled < length) {
|
316
|
+
if (compressed_image->size == 0) {
|
317
|
+
new_size = INIT_COMPRESSED_IMAGE_SIZE;
|
318
|
+
New(1020, compressed_image->data, new_size, BYTE);
|
319
|
+
}
|
320
|
+
else
|
321
|
+
new_size = compressed_image->size;
|
322
|
+
while (new_size - compressed_image->filled < length)
|
323
|
+
new_size *= 2;
|
324
|
+
if (new_size > compressed_image->size) {
|
325
|
+
Renew(compressed_image->data, new_size, BYTE);
|
326
|
+
compressed_image->size = new_size;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
memcpy(&compressed_image->data[compressed_image->filled], data, length);
|
330
|
+
compressed_image->filled += length;
|
331
|
+
}
|
332
|
+
|
333
|
+
// Callback to flush data previously written. A no-op here.
|
334
|
+
static void png_flush_callback(png_structp png_ptr)
|
335
|
+
{
|
336
|
+
// No need to do anything!
|
337
|
+
}
|
338
|
+
|
339
|
+
// Callback to handle serious errors. We quietly longjmp to the error exit point.
|
340
|
+
static void png_error_callback(png_structp png_reader_or_writer, png_const_charp error_msg)
|
341
|
+
{
|
342
|
+
longjmp(png_jmpbuf(png_reader_or_writer), 1);
|
343
|
+
}
|
344
|
+
|
345
|
+
// Callback to handle warnings. We quietly do nothing.
|
346
|
+
static void png_warning_callback(png_structp png_reader_or_writer, png_const_charp warning_msg)
|
347
|
+
{
|
348
|
+
}
|
349
|
+
|
350
|
+
// Compress an image into PNG format in compressed_image. This follows the example
|
351
|
+
// provided with libpng fairly closely.
|
352
|
+
int compress_image(IMAGE *image,
|
353
|
+
COMPRESSED_IMAGE *compressed_image)
|
354
|
+
{
|
355
|
+
png_structp png_writer;
|
356
|
+
png_infop png_info;
|
357
|
+
png_bytepp row_pointers;
|
358
|
+
UNSIGNED row;
|
359
|
+
|
360
|
+
png_writer = png_create_write_struct_2(
|
361
|
+
PNG_LIBPNG_VER_STRING,
|
362
|
+
NULL, /* (png_voidp)user_error_ptr, */
|
363
|
+
png_error_callback,
|
364
|
+
png_warning_callback,
|
365
|
+
NULL, /* (png_voidp)user_mem_ptr */
|
366
|
+
png_malloc_callback,
|
367
|
+
png_free_callback);
|
368
|
+
|
369
|
+
png_info = png_create_info_struct(png_writer);
|
370
|
+
if (!png_info) {
|
371
|
+
png_destroy_write_struct(&png_writer, NULL);
|
372
|
+
return 1;
|
373
|
+
}
|
374
|
+
|
375
|
+
if ( setjmp(png_jmpbuf(png_writer)) ) {
|
376
|
+
png_destroy_write_struct(&png_writer, &png_info);
|
377
|
+
return 2;
|
378
|
+
}
|
379
|
+
|
380
|
+
clear_compressed_image(compressed_image);
|
381
|
+
png_set_write_fn(png_writer,
|
382
|
+
compressed_image, // Pass memory buffer on the helpful pointer.
|
383
|
+
png_write_callback,
|
384
|
+
png_flush_callback);
|
385
|
+
|
386
|
+
png_set_IHDR(png_writer, png_info,
|
387
|
+
image->width, image->height,
|
388
|
+
N_BITS(image->data[0].r),
|
389
|
+
PNG_COLOR_TYPE_RGB,
|
390
|
+
PNG_INTERLACE_NONE,
|
391
|
+
PNG_COMPRESSION_TYPE_DEFAULT,
|
392
|
+
PNG_FILTER_TYPE_DEFAULT);
|
393
|
+
|
394
|
+
row_pointers = png_malloc(png_writer, image->height * sizeof(png_bytep));
|
395
|
+
if (!row_pointers) {
|
396
|
+
png_destroy_write_struct(&png_writer, &png_info);
|
397
|
+
return 3;
|
398
|
+
}
|
399
|
+
for (row = 0; row < image->height; row++)
|
400
|
+
row_pointers[row] = (png_bytep)rgb_triple_rc(image, row, 0);
|
401
|
+
|
402
|
+
png_set_rows(png_writer, png_info, row_pointers);
|
403
|
+
|
404
|
+
png_write_png(png_writer, png_info, PNG_TRANSFORM_IDENTITY, NULL);
|
405
|
+
|
406
|
+
// Successful completion.
|
407
|
+
png_free(png_writer, row_pointers);
|
408
|
+
png_destroy_write_struct(&png_writer, &png_info);
|
409
|
+
return 0;
|
410
|
+
}
|
411
|
+
|
412
|
+
#ifdef SKETCH_TEST
|
413
|
+
|
414
|
+
void draw_starburst(IMAGE *image)
|
415
|
+
{
|
416
|
+
int x, y, c;
|
417
|
+
static RGB_TRIPLE colors[] = {
|
418
|
+
{ 0, 0, 0 },
|
419
|
+
{ 255, 0, 0 },
|
420
|
+
{ 0, 255, 0 },
|
421
|
+
{ 0, 0, 255 },
|
422
|
+
{ 255, 255, 0 },
|
423
|
+
{ 255, 0, 255 },
|
424
|
+
{ 0, 255, 255 },
|
425
|
+
};
|
426
|
+
|
427
|
+
#define L 0
|
428
|
+
#define R 383
|
429
|
+
#define B 0
|
430
|
+
#define T 511
|
431
|
+
#define I 8
|
432
|
+
|
433
|
+
for (x = y = c = 0 ; x <= R; x += I)
|
434
|
+
draw_line(image, (FLOAT)R/2, (FLOAT)T/2, (FLOAT)x, (FLOAT)y, &colors[++c % 7]);
|
435
|
+
for (x = R ; y < T; y += I)
|
436
|
+
draw_line(image, (FLOAT)R/2, (FLOAT)T/2, (FLOAT)x, (FLOAT)y, &colors[++c % 7]);
|
437
|
+
for (y = T ; x > 0; x -= I)
|
438
|
+
draw_line(image, (FLOAT)R/2, (FLOAT)T/2, (FLOAT)x, (FLOAT)y, &colors[++c % 7]);
|
439
|
+
for (x = 0 ; y > 0; y -= I)
|
440
|
+
draw_line(image, (FLOAT)R/2, (FLOAT)T/2, (FLOAT)x, (FLOAT)y, &colors[++c % 7]);
|
441
|
+
}
|
442
|
+
|
443
|
+
int main(void)
|
444
|
+
{
|
445
|
+
IMAGE image[1];
|
446
|
+
COMPRESSED_IMAGE compressed_image[1];
|
447
|
+
FILE *f;
|
448
|
+
UNSIGNED n;
|
449
|
+
RGB_TRIPLE white[1] = {{255, 255, 255}};
|
450
|
+
init_image(image);
|
451
|
+
init_compressed_image(compressed_image);
|
452
|
+
|
453
|
+
for (n = 0; n < 1; n++) {
|
454
|
+
|
455
|
+
fprintf(stderr, ".");
|
456
|
+
|
457
|
+
setup_image(image, R+1, T+1, white);
|
458
|
+
|
459
|
+
#define X1 50
|
460
|
+
#define X2 R/2-50
|
461
|
+
#define X3 R/2+50
|
462
|
+
#define X4 R-50
|
463
|
+
#define Y1 50
|
464
|
+
#define Y2 T/2-50
|
465
|
+
#define Y3 T/2+50
|
466
|
+
#define Y4 T-50
|
467
|
+
|
468
|
+
set_viewport(image, X1, X2, Y1, Y2);
|
469
|
+
draw_starburst(image);
|
470
|
+
set_viewport(image, X3, X4, Y1, Y2);
|
471
|
+
draw_starburst(image);
|
472
|
+
set_viewport(image, X1, X2, Y3, Y4);
|
473
|
+
draw_starburst(image);
|
474
|
+
set_viewport(image, X3, X4, Y3, Y4);
|
475
|
+
draw_starburst(image);
|
476
|
+
set_viewport(image, X2, X3, Y2, Y3);
|
477
|
+
draw_starburst(image);
|
478
|
+
|
479
|
+
compress_image(image, compressed_image);
|
480
|
+
clear_image(image);
|
481
|
+
}
|
482
|
+
fprintf(stderr, "\n");
|
483
|
+
|
484
|
+
f = fopen("sketch.png", "wb");
|
485
|
+
if (!f) {
|
486
|
+
fprintf(stderr, "can't open sketch.png for output\n");
|
487
|
+
return 1;
|
488
|
+
}
|
489
|
+
fwrite(compressed_image->data, 1, compressed_image->filled, f);
|
490
|
+
clear_compressed_image(compressed_image);
|
491
|
+
fclose(f);
|
492
|
+
|
493
|
+
return 0;
|
494
|
+
}
|
495
|
+
|
496
|
+
#endif
|
data/ext/WPBDC/sketch.h
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#ifndef _SKETCH_H
|
2
|
+
#define _SKETCH_H
|
3
|
+
|
4
|
+
/* sketch.h -- Header for sketches that end up as compressed bitmaps. */
|
5
|
+
|
6
|
+
#define SET_MULTIPLE_PTR(Ptr,Val,N) memset(Ptr, Val, N * sizeof *Ptr)
|
7
|
+
#define SET_PTR(Ptr,Val) SET_MULTIPLE_PTR(Ptr, Val, 1)
|
8
|
+
#define SET(X, Val) SET_PTR(&(X), Val)
|
9
|
+
#define ZERO_PTR(Ptr) SET_PTR(Ptr, 0)
|
10
|
+
#define ZERO(X) SET(X, 0)
|
11
|
+
#define N_BITS(X) (8 * sizeof X)
|
12
|
+
|
13
|
+
typedef unsigned char BYTE;
|
14
|
+
typedef float FLOAT;
|
15
|
+
typedef unsigned UNSIGNED;
|
16
|
+
|
17
|
+
#ifndef INLINE
|
18
|
+
#define INLINE __inline
|
19
|
+
#endif
|
20
|
+
|
21
|
+
typedef struct rgb_triple_t {
|
22
|
+
BYTE r, g, b;
|
23
|
+
} RGB_TRIPLE;
|
24
|
+
|
25
|
+
typedef struct image_t {
|
26
|
+
UNSIGNED width, height;
|
27
|
+
UNSIGNED x_left, x_right, y_bottom, y_top;
|
28
|
+
RGB_TRIPLE *data;
|
29
|
+
} IMAGE;
|
30
|
+
|
31
|
+
#define INIT_COMPRESSED_IMAGE_SIZE 1024
|
32
|
+
typedef struct compressed_image_t {
|
33
|
+
UNSIGNED size;
|
34
|
+
UNSIGNED filled;
|
35
|
+
BYTE *data;
|
36
|
+
} COMPRESSED_IMAGE;
|
37
|
+
|
38
|
+
/* sketch.c */
|
39
|
+
void init_image(IMAGE *image);
|
40
|
+
void clear_image(IMAGE *image);
|
41
|
+
void setup_image(IMAGE *image, UNSIGNED width, UNSIGNED height, RGB_TRIPLE *color);
|
42
|
+
void set_viewport(IMAGE *image, UNSIGNED x_left, UNSIGNED x_right, UNSIGNED y_bottom, UNSIGNED y_top);
|
43
|
+
void draw_line_raw(IMAGE *image, UNSIGNED x1, UNSIGNED y1, UNSIGNED x2, UNSIGNED y2, RGB_TRIPLE *color);
|
44
|
+
void draw_rect_raw(IMAGE *image, UNSIGNED x1, UNSIGNED y1, UNSIGNED x2, UNSIGNED y2, RGB_TRIPLE *color);
|
45
|
+
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);
|
46
|
+
void draw_line(IMAGE *image, FLOAT x1, FLOAT y1, FLOAT x2, FLOAT y2, RGB_TRIPLE *color);
|
47
|
+
void init_compressed_image(COMPRESSED_IMAGE *compressed_image);
|
48
|
+
void clear_compressed_image(COMPRESSED_IMAGE *compressed_image);
|
49
|
+
int compress_image(IMAGE *image, COMPRESSED_IMAGE *compressed_image);
|
50
|
+
|
51
|
+
#endif
|
data/ext/WPBDC/stdafx.h
ADDED
data/lib/WPBDC.rb
ADDED
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: WPBDC
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2013.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gene Ressler
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Container for C code extension that implements the West Point Bridge
|
15
|
+
Contest Judge.
|
16
|
+
email: gene.ressler@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions:
|
19
|
+
- ext/WPBDC/extconf.rb
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/WPBDC.rb
|
23
|
+
- ext/WPBDC/analysis.c
|
24
|
+
- ext/WPBDC/bridge.c
|
25
|
+
- ext/WPBDC/bridge_cost.c
|
26
|
+
- ext/WPBDC/bridge_hash.c
|
27
|
+
- ext/WPBDC/bridge_parser.c
|
28
|
+
- ext/WPBDC/bridge_random.c
|
29
|
+
- ext/WPBDC/bridge_sketch.c
|
30
|
+
- ext/WPBDC/geometry.c
|
31
|
+
- ext/WPBDC/judge.c
|
32
|
+
- ext/WPBDC/loading.c
|
33
|
+
- ext/WPBDC/params.c
|
34
|
+
- ext/WPBDC/rc4.c
|
35
|
+
- ext/WPBDC/rc4_key.c
|
36
|
+
- ext/WPBDC/scenario.c
|
37
|
+
- ext/WPBDC/sketch.c
|
38
|
+
- ext/WPBDC/WPBDC.c
|
39
|
+
- ext/WPBDC/internal.h
|
40
|
+
- ext/WPBDC/judge.h
|
41
|
+
- ext/WPBDC/proto.h
|
42
|
+
- ext/WPBDC/rc4.h
|
43
|
+
- ext/WPBDC/rubydefs.h
|
44
|
+
- ext/WPBDC/sketch.h
|
45
|
+
- ext/WPBDC/stdafx.h
|
46
|
+
- ext/WPBDC/extconf.rb
|
47
|
+
homepage: http://rubygems.org/gems/wpbdc_judge
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.24
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Judge functions of the West Point Bridge Design Contest
|
71
|
+
test_files: []
|