1 |
#include <stdio.h>
|
2 |
#include <stdlib.h>
|
3 |
#include <math.h>
|
4 |
#include <string.h>
|
5 |
#include <sys/resource.h>
|
6 |
#include <wand/MagickWand.h>
|
7 |
|
8 |
|
9 |
#include "uthash.h"
|
10 |
|
11 |
|
12 |
/*
|
13 |
#define MAX_WIDTH 6600
|
14 |
#define MAX_HEIGHT 8800
|
15 |
*/
|
16 |
/*
|
17 |
#define MAX_WIDTH 31200
|
18 |
#define MAX_HEIGHT 41600
|
19 |
*/
|
20 |
/*
|
21 |
#define MAX_WIDTH 7095
|
22 |
#define MAX_HEIGHT 11273
|
23 |
#define BORDER 75
|
24 |
*/
|
25 |
/*
|
26 |
#define MAX_WIDTH 20880
|
27 |
#define MAX_HEIGHT 27840
|
28 |
#define BORDER 25
|
29 |
*/
|
30 |
/*
|
31 |
als
|
32 |
#define MAX_WIDTH 24016
|
33 |
#define MAX_HEIGHT 17920
|
34 |
#define BORDER 120
|
35 |
#define SCALE_FACTOR 1
|
36 |
#define DIVIDE_SCALE_FACTOR
|
37 |
#define RI_SIZE 8192
|
38 |
*/
|
39 |
//#define SCALE_FACTOR 4
|
40 |
//#define DIVIDE_SCALE_FACTOR /4
|
41 |
|
42 |
|
43 |
|
44 |
#define MAX_WIDTH 20800
|
45 |
#define MAX_HEIGHT 33048
|
46 |
#define BORDER 300
|
47 |
#define SCALE_FACTOR 1
|
48 |
#define DIVIDE_SCALE_FACTOR
|
49 |
#define RI_SIZE 8192
|
50 |
|
51 |
/*
|
52 |
This is derived from cyclone_pick, but instead of picking various pictures,
|
53 |
we build them
|
54 |
|
55 |
Also, we make the filenames xxx_yyy_pic.png for the picture and
|
56 |
xxx_yyy_alpha.png for the alpha content.
|
57 |
|
58 |
|
59 |
final_frames.txt has the following format:
|
60 |
|
61 |
(0-24 from tilify.c rest from picking with cyclone_pick.c )
|
62 |
|
63 |
0 1 X (or column)
|
64 |
1 2 Y (or row)
|
65 |
2 3 top left x - in real coordinates
|
66 |
3 4 top left y - in real coordinates
|
67 |
4 5 Top right x - in real coordinates
|
68 |
5 6 top right y - in real coodrindates
|
69 |
6 7 bottom left x - in real coordinates
|
70 |
7 8 bottom left y - in real coordinates
|
71 |
8 9 bottom right x - in real coordinates
|
72 |
9 10 bottom right y - in real coordinates
|
73 |
10 11 R color - 0-255
|
74 |
11 12 g color - 0-255
|
75 |
12 13 b color - 0-255
|
76 |
13 14 top left x - in local coordinates
|
77 |
14 15 top left y - in local coordinates
|
78 |
15 16 top right x - in local coordiantes
|
79 |
16 17 top right y - in local coordinates
|
80 |
17 18 bottom left x - in local coordinates
|
81 |
18 19 bottom left y - in local coordinates
|
82 |
19 20 bottom right x - in local coordinates
|
83 |
20 21 bottom right y - in local coodinates
|
84 |
21 22 x offset to place the local to global
|
85 |
22 23 y offset ...
|
86 |
23 24 width
|
87 |
24 25 height
|
88 |
25 26 filename.ext
|
89 |
26 27 shift xoffset
|
90 |
27 28 shift yoffset
|
91 |
28 29 shift scale
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
*/
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
int bits[] = {0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1};
|
103 |
|
104 |
|
105 |
|
106 |
int read_image(char *name,ssize_t *pwidth,ssize_t *pheight,
|
107 |
unsigned short **prgbbuf)
|
108 |
{
|
109 |
|
110 |
|
111 |
MagickPixelPacket input_pixel;
|
112 |
MagickWand *input_wand = NULL;
|
113 |
PixelWand *c_wand = NULL;
|
114 |
PixelWand *c2_wand = NULL;
|
115 |
MagickBooleanType status;
|
116 |
PixelIterator *input_iterator;
|
117 |
PixelWand **input_pixels;
|
118 |
register ssize_t x;
|
119 |
ssize_t y;
|
120 |
|
121 |
|
122 |
/* read the input color */
|
123 |
input_wand =NewMagickWand();
|
124 |
fprintf(stderr,"%s:\n",name);
|
125 |
MagickReadImage(input_wand,name);
|
126 |
ssize_t width,height;
|
127 |
width = MagickGetImageWidth(input_wand);
|
128 |
height = MagickGetImageHeight(input_wand);
|
129 |
int number_of_points;
|
130 |
number_of_points=0;
|
131 |
unsigned short *rgbbuf;
|
132 |
|
133 |
rgbbuf= (unsigned short *)malloc(width*height*sizeof(unsigned short)*3);
|
134 |
if (!rgbbuf) {fprintf(stderr,"memory\n"); exit(-1);}
|
135 |
|
136 |
#define ThrowWandException(wand) \
|
137 |
{ \
|
138 |
char \
|
139 |
*description; \
|
140 |
\
|
141 |
ExceptionType \
|
142 |
severity; \
|
143 |
\
|
144 |
description=MagickGetException(wand,&severity); \
|
145 |
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
|
146 |
description=(char *) MagickRelinquishMemory(description); \
|
147 |
exit(-1); \
|
148 |
}
|
149 |
|
150 |
|
151 |
input_iterator=NewPixelIterator(input_wand);
|
152 |
if ((input_iterator == (PixelIterator *) NULL) )
|
153 |
ThrowWandException(input_wand);
|
154 |
|
155 |
for (y=0; y < (ssize_t) height; y++)
|
156 |
{
|
157 |
input_pixels=PixelGetNextIteratorRow(input_iterator,&width);
|
158 |
if ((input_pixels == (PixelWand **) NULL))
|
159 |
break;
|
160 |
for (x=0; x < (ssize_t) width; x++)
|
161 |
{
|
162 |
unsigned short *rl;
|
163 |
PixelGetMagickColor(input_pixels[x],&input_pixel);
|
164 |
rl=rgbbuf + ((y*width)+x)*3;
|
165 |
*(rl++) = input_pixel.red;
|
166 |
*(rl++) = input_pixel.green;
|
167 |
*(rl++) = input_pixel.blue;
|
168 |
}
|
169 |
}
|
170 |
if (y < (ssize_t) MagickGetImageHeight(input_wand))
|
171 |
ThrowWandException(input_wand);
|
172 |
input_iterator=DestroyPixelIterator(input_iterator);
|
173 |
input_wand=DestroyMagickWand(input_wand);
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
*prgbbuf = rgbbuf;
|
181 |
*pwidth = width;
|
182 |
*pheight=height;
|
183 |
|
184 |
|
185 |
|
186 |
return (0);
|
187 |
}
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
int convert_rgb(MagickWand *input_wand,ssize_t width,ssize_t height, unsigned short *rgbbuf)
|
195 |
{
|
196 |
|
197 |
|
198 |
MagickPixelPacket input_pixel;
|
199 |
PixelWand *c_wand = NULL;
|
200 |
PixelWand *c2_wand = NULL;
|
201 |
MagickBooleanType status;
|
202 |
PixelIterator *input_iterator;
|
203 |
PixelWand **input_pixels;
|
204 |
register ssize_t x;
|
205 |
ssize_t y;
|
206 |
|
207 |
int number_of_points;
|
208 |
number_of_points=0;
|
209 |
|
210 |
#define ThrowWandException(wand) \
|
211 |
{ \
|
212 |
char \
|
213 |
*description; \
|
214 |
\
|
215 |
ExceptionType \
|
216 |
severity; \
|
217 |
\
|
218 |
description=MagickGetException(wand,&severity); \
|
219 |
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
|
220 |
description=(char *) MagickRelinquishMemory(description); \
|
221 |
exit(-1); \
|
222 |
}
|
223 |
|
224 |
|
225 |
input_iterator=NewPixelIterator(input_wand);
|
226 |
if ((input_iterator == (PixelIterator *) NULL) )
|
227 |
ThrowWandException(input_wand);
|
228 |
|
229 |
for (y=0; y < (ssize_t) height; y++)
|
230 |
{
|
231 |
input_pixels=PixelGetNextIteratorRow(input_iterator,&width);
|
232 |
if ((input_pixels == (PixelWand **) NULL))
|
233 |
break;
|
234 |
for (x=0; x < (ssize_t) width; x++)
|
235 |
{
|
236 |
unsigned short *rl;
|
237 |
PixelGetMagickColor(input_pixels[x],&input_pixel);
|
238 |
rl=rgbbuf + ((y*width)+x)*3;
|
239 |
*(rl++) = input_pixel.red;
|
240 |
*(rl++) = input_pixel.green;
|
241 |
*(rl++) = input_pixel.blue;
|
242 |
}
|
243 |
}
|
244 |
if (y < (ssize_t) MagickGetImageHeight(input_wand))
|
245 |
ThrowWandException(input_wand);
|
246 |
input_iterator=DestroyPixelIterator(input_iterator);
|
247 |
|
248 |
return (0);
|
249 |
}
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
void make_stack_really_big() {
|
256 |
const rlim_t stacksize = 2000*1024*1024; // 2 gigabytes
|
257 |
struct rlimit rl;
|
258 |
int result;
|
259 |
result = getrlimit(RLIMIT_STACK, &rl);
|
260 |
if (result == 0)
|
261 |
{
|
262 |
if (rl.rlim_cur < stacksize)
|
263 |
{
|
264 |
rl.rlim_cur = stacksize;
|
265 |
result = setrlimit(RLIMIT_STACK, &rl);
|
266 |
if (result != 0)
|
267 |
{
|
268 |
fprintf(stderr, "setrlimit returned result = %d\n", result);
|
269 |
exit(-1);
|
270 |
}
|
271 |
}
|
272 |
}
|
273 |
else {
|
274 |
fprintf(stderr, "getrlimit returned result = %d\n", result);
|
275 |
exit(-1);
|
276 |
}
|
277 |
}
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
inline unsigned int get_full_alpha(unsigned int alpha,int unsigned quad_source_alpha) {
|
283 |
unsigned int alpha_full;
|
284 |
unsigned int alpha_dark;
|
285 |
unsigned int alpha_final;
|
286 |
/* find the alpha */
|
287 |
|
288 |
/*
|
289 |
if (alpha>=32768) {
|
290 |
alpha_full = 30000 + (alpha-32768)*(65530-30000)/(32768);
|
291 |
alpha_dark = (10000 + (alpha-32768)*(21845-10000)/(32768))/10;
|
292 |
}
|
293 |
else {
|
294 |
alpha_full = 7500 + (alpha*(16384-7500))/32768;
|
295 |
alpha_dark = (2500 + (alpha*(5460-2500))/(32768))/10;
|
296 |
}
|
297 |
alpha_final = alpha_dark + ((quad_source_alpha/256)* (alpha_full - alpha_dark))/256;
|
298 |
*/
|
299 |
|
300 |
alpha_final=quad_source_alpha;
|
301 |
/* also turn off if the sourse alpha is zero there */
|
302 |
if (!alpha) alpha_final=0;
|
303 |
/* OK - now we go between alpha_full and alpha */
|
304 |
|
305 |
|
306 |
if (alpha_final>65535) alpha_final=65535;
|
307 |
if (alpha_final<0) alpha_final=0;
|
308 |
return alpha_final;
|
309 |
}
|
310 |
|
311 |
|
312 |
void make_final_image(
|
313 |
unsigned short *quad_buf,
|
314 |
ssize_t quad_width,
|
315 |
ssize_t quad_height,
|
316 |
ssize_t local_width,
|
317 |
ssize_t local_height,
|
318 |
unsigned short *source_buf,
|
319 |
unsigned short *alpha_buf,
|
320 |
char *file_name,
|
321 |
double xoffset,
|
322 |
double yoffset,
|
323 |
double scale,
|
324 |
int xxx,
|
325 |
int yyy
|
326 |
) {
|
327 |
ssize_t width,height;
|
328 |
int quad_xoffset;
|
329 |
int quad_yoffset;
|
330 |
width = quad_width;
|
331 |
height = quad_height;
|
332 |
double one_over_scale = 1.0 / scale;
|
333 |
|
334 |
quad_xoffset = 0;
|
335 |
quad_yoffset = 0;
|
336 |
|
337 |
/* see if we need to make the height bigger to get all of the images together */
|
338 |
int testx,testy;
|
339 |
testx = (0.0 + xoffset)*scale;
|
340 |
if (testx < quad_xoffset) {
|
341 |
quad_xoffset = testx;
|
342 |
}
|
343 |
if (testx > width) {
|
344 |
width = testx;
|
345 |
}
|
346 |
testx = ((double)(local_width-1) +xoffset)*scale;
|
347 |
if (testx < quad_xoffset) {
|
348 |
quad_xoffset = testx;
|
349 |
}
|
350 |
if (testx > width) {
|
351 |
width = testx;
|
352 |
}
|
353 |
|
354 |
testy = (0.0 +yoffset)*scale;
|
355 |
if (testy < quad_yoffset) {
|
356 |
quad_yoffset = testy;
|
357 |
}
|
358 |
if (testy > height) {
|
359 |
height = testy;
|
360 |
}
|
361 |
testy = ((double)(local_height-1) +yoffset)*scale;
|
362 |
if (testy < quad_yoffset) {
|
363 |
quad_yoffset = testx;
|
364 |
}
|
365 |
if (testy > height) {
|
366 |
height = testy;
|
367 |
}
|
368 |
/* Expand the width and height appropriately so we can fit all images in */
|
369 |
width -= quad_xoffset;
|
370 |
height -= quad_yoffset;
|
371 |
fprintf(stderr,"original w,h: %d,%d offset %d,%d wh %d,%d\n",(int)quad_width,(int)quad_height,quad_xoffset,quad_yoffset,(int)width,(int)height);
|
372 |
|
373 |
#define ThrowWandException(wand) \
|
374 |
{ \
|
375 |
char \
|
376 |
*description; \
|
377 |
\
|
378 |
ExceptionType \
|
379 |
severity; \
|
380 |
\
|
381 |
description=MagickGetException(wand,&severity); \
|
382 |
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
|
383 |
description=(char *) MagickRelinquishMemory(description); \
|
384 |
exit(-1); \
|
385 |
}
|
386 |
|
387 |
MagickWand *m_wand;
|
388 |
PixelIterator *iterator;
|
389 |
PixelWand *c_wand;
|
390 |
PixelWand **pixels;
|
391 |
MagickPixelPacket pixel;
|
392 |
|
393 |
m_wand = NewMagickWand();
|
394 |
c_wand = NewPixelWand();
|
395 |
PixelSetColor(c_wand,"black"); /* for now */
|
396 |
MagickNewImage(m_wand,width,height,c_wand);
|
397 |
MagickSetImageChannelDepth(m_wand, AllChannels, 16);
|
398 |
MagickSetImageDepth(m_wand, 16);
|
399 |
iterator=NewPixelIterator(m_wand);
|
400 |
if ((iterator == (PixelIterator *) NULL) )
|
401 |
ThrowWandException(m_wand);
|
402 |
register ssize_t x;
|
403 |
ssize_t y;
|
404 |
for (y=0; y < (ssize_t) height; y++)
|
405 |
{
|
406 |
pixels=PixelGetNextIteratorRow(iterator,&width);
|
407 |
if ((pixels == (PixelWand **) NULL))
|
408 |
break;
|
409 |
for (x=0; x < (ssize_t) width; x++)
|
410 |
{
|
411 |
PixelGetMagickColor(pixels[x],&pixel);
|
412 |
int r,g,b;
|
413 |
int quad_source_alpha;
|
414 |
r=0;g=0;b=0;
|
415 |
|
416 |
/* add the quad in */
|
417 |
int quad_x,quad_y;
|
418 |
quad_x = x + quad_xoffset;
|
419 |
quad_y = y + quad_yoffset;
|
420 |
|
421 |
|
422 |
if ((quad_x >= 0)&&(quad_x < quad_width)&&(quad_y >= 0)&&(quad_y < quad_height)) {
|
423 |
unsigned short *rl;
|
424 |
rl = quad_buf+((quad_y*quad_width)+quad_x)*3;
|
425 |
quad_source_alpha = *rl;
|
426 |
}
|
427 |
else {
|
428 |
quad_source_alpha=0;
|
429 |
}
|
430 |
|
431 |
int source_x,source_y;
|
432 |
source_x = ((double)(quad_x-BORDER)) * one_over_scale - xoffset;
|
433 |
source_y = ((double)(quad_y-BORDER)) * one_over_scale - yoffset;
|
434 |
if ((source_x<0)||(source_y<0)||(source_x>=local_width)||(source_y>=local_height)) { /* out of bounds */
|
435 |
continue;
|
436 |
}
|
437 |
|
438 |
unsigned int alpha;
|
439 |
unsigned int alpha_final;
|
440 |
/* find the alpha */
|
441 |
alpha = alpha_buf[((source_y*local_width)+source_x)*3];
|
442 |
|
443 |
alpha_final = get_full_alpha(alpha,quad_source_alpha);
|
444 |
|
445 |
/* find the source r,g,b */
|
446 |
unsigned int source_r,source_g,source_b;
|
447 |
unsigned short *source_rgbp = source_buf+((source_y*local_width)+source_x)*3;
|
448 |
source_r = *(source_rgbp++);
|
449 |
source_g = *(source_rgbp++);
|
450 |
source_b = *(source_rgbp++);
|
451 |
|
452 |
r = source_r;
|
453 |
g = source_g;
|
454 |
b = source_b;
|
455 |
if (alpha_final) {
|
456 |
pixel.red=r;
|
457 |
pixel.green=g;
|
458 |
pixel.blue=b;
|
459 |
|
460 |
PixelSetMagickColor(pixels[x],&pixel);
|
461 |
}
|
462 |
}
|
463 |
(void) PixelSyncIterator(iterator);
|
464 |
}
|
465 |
if (y < (ssize_t) MagickGetImageHeight(m_wand))
|
466 |
ThrowWandException(m_wand);
|
467 |
iterator=DestroyPixelIterator(iterator);
|
468 |
|
469 |
|
470 |
/*
|
471 |
Write the image then destroy it.
|
472 |
*/
|
473 |
|
474 |
char oname[20000];
|
475 |
sprintf(oname,"%3.3d_%3.3d_b.png",xxx,yyy);
|
476 |
|
477 |
MagickBooleanType status;
|
478 |
status=MagickWriteImages(m_wand,oname,MagickTrue);
|
479 |
if (status == MagickFalse)
|
480 |
ThrowWandException(m_wand);
|
481 |
m_wand=DestroyMagickWand(m_wand);
|
482 |
}
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
void make_text_output(
|
500 |
unsigned short *quad_buf,
|
501 |
ssize_t quad_width,
|
502 |
ssize_t quad_height,
|
503 |
ssize_t local_width,
|
504 |
ssize_t local_height,
|
505 |
unsigned short *source_buf,
|
506 |
unsigned short *alpha_buf,
|
507 |
char *file_name,
|
508 |
double xoffset,
|
509 |
double yoffset,
|
510 |
double scale,
|
511 |
int xxx,
|
512 |
int yyy,
|
513 |
int bigpic_xoffset,
|
514 |
int bigpic_yoffset
|
515 |
) {
|
516 |
ssize_t width,height;
|
517 |
int quad_xoffset;
|
518 |
int quad_yoffset;
|
519 |
width = quad_width;
|
520 |
height = quad_height;
|
521 |
double one_over_scale = 1.0 / scale;
|
522 |
|
523 |
quad_xoffset = 0;
|
524 |
quad_yoffset = 0;
|
525 |
|
526 |
/* see if we need to make the height bigger to get all of the images together */
|
527 |
int testx,testy;
|
528 |
testx = (0.0 + xoffset)*scale;
|
529 |
if (testx < quad_xoffset) {
|
530 |
quad_xoffset = testx;
|
531 |
}
|
532 |
if (testx > width) {
|
533 |
width = testx;
|
534 |
}
|
535 |
testx = ((double)(local_width-1) +xoffset)*scale;
|
536 |
if (testx < quad_xoffset) {
|
537 |
quad_xoffset = testx;
|
538 |
}
|
539 |
if (testx > width) {
|
540 |
width = testx;
|
541 |
}
|
542 |
|
543 |
testy = (0.0 +yoffset)*scale;
|
544 |
if (testy < quad_yoffset) {
|
545 |
quad_yoffset = testy;
|
546 |
}
|
547 |
if (testy > height) {
|
548 |
height = testy;
|
549 |
}
|
550 |
testy = ((double)(local_height-1) +yoffset)*scale;
|
551 |
if (testy < quad_yoffset) {
|
552 |
quad_yoffset = testx;
|
553 |
}
|
554 |
if (testy > height) {
|
555 |
height = testy;
|
556 |
}
|
557 |
/* Expand the width and height appropriately so we can fit all images in */
|
558 |
width -= quad_xoffset;
|
559 |
height -= quad_yoffset;
|
560 |
fprintf(stderr,"original %d,%d w,h: %d,%d offset %d,%d wh %d,%d\n",xxx,yyy,(int)quad_width,(int)quad_height,quad_xoffset,quad_yoffset,(int)width,(int)height);
|
561 |
|
562 |
register ssize_t x;
|
563 |
ssize_t y;
|
564 |
for (y=0; y < (ssize_t) height; y+=SCALE_FACTOR)
|
565 |
{
|
566 |
for (x=0; x < (ssize_t) width; x+=SCALE_FACTOR)
|
567 |
{
|
568 |
int r,g,b;
|
569 |
int quad_source_alpha;
|
570 |
r=0;g=0;b=0;
|
571 |
|
572 |
/* add the quad in */
|
573 |
int quad_x,quad_y;
|
574 |
quad_x = x + quad_xoffset;
|
575 |
quad_y = y + quad_yoffset;
|
576 |
|
577 |
|
578 |
if ((quad_x >= 0)&&(quad_x < quad_width)&&(quad_y >= 0)&&(quad_y < quad_height)) {
|
579 |
unsigned short *rl;
|
580 |
rl = quad_buf+((quad_y*quad_width)+quad_x)*3;
|
581 |
quad_source_alpha = *rl;
|
582 |
}
|
583 |
else {
|
584 |
quad_source_alpha=0;
|
585 |
}
|
586 |
|
587 |
int source_x,source_y;
|
588 |
source_x = ((double)(quad_x-BORDER)) * one_over_scale - xoffset;
|
589 |
source_y = ((double)(quad_y-BORDER)) * one_over_scale - yoffset;
|
590 |
if ((source_x<0)||(source_y<0)||(source_x>=local_width)||(source_y>=local_height)) { /* out of bounds */
|
591 |
continue;
|
592 |
}
|
593 |
unsigned int alpha;
|
594 |
unsigned int alpha_final;
|
595 |
/* find the alpha */
|
596 |
alpha = alpha_buf[((source_y*local_width)+source_x)*3];
|
597 |
alpha_final = get_full_alpha(alpha,quad_source_alpha);
|
598 |
|
599 |
/* find the source r,g,b */
|
600 |
unsigned int source_r,source_g,source_b;
|
601 |
unsigned short *source_rgbp = source_buf+((source_y*local_width)+source_x)*3;
|
602 |
source_r = *(source_rgbp++);
|
603 |
source_g = *(source_rgbp++);
|
604 |
source_b = *(source_rgbp++);
|
605 |
|
606 |
r = source_r;
|
607 |
g = source_g;
|
608 |
b = source_b;
|
609 |
int xx = x+bigpic_xoffset+quad_xoffset;
|
610 |
int yy = y+bigpic_yoffset+quad_yoffset;
|
611 |
|
612 |
if (alpha_final&&(yy>=0)&&(xx>=0)&&(yy<MAX_HEIGHT)&&(xx<MAX_WIDTH)) /* hard coded hack???? */
|
613 |
printf("%6.6d|%6.6d|%3.3d|%3.3d|%d|%d|%d|%d\n",yy DIVIDE_SCALE_FACTOR,xx DIVIDE_SCALE_FACTOR,xxx DIVIDE_SCALE_FACTOR,yyy DIVIDE_SCALE_FACTOR,r,g,b,alpha_final);
|
614 |
}
|
615 |
}
|
616 |
}
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
void make_final_alpha_image(
|
628 |
unsigned short *quad_buf,
|
629 |
ssize_t quad_width,
|
630 |
ssize_t quad_height,
|
631 |
ssize_t local_width,
|
632 |
ssize_t local_height,
|
633 |
unsigned short *source_buf,
|
634 |
unsigned short *alpha_buf,
|
635 |
char *file_name,
|
636 |
double xoffset,
|
637 |
double yoffset,
|
638 |
double scale,
|
639 |
int xxx,
|
640 |
int yyy
|
641 |
) {
|
642 |
ssize_t width,height;
|
643 |
int quad_xoffset;
|
644 |
int quad_yoffset;
|
645 |
width = quad_width;
|
646 |
height = quad_height;
|
647 |
double one_over_scale = 1.0 / scale;
|
648 |
|
649 |
quad_xoffset = 0;
|
650 |
quad_yoffset = 0;
|
651 |
|
652 |
/* see if we need to make the height bigger to get all of the images together */
|
653 |
int testx,testy;
|
654 |
testx = (0.0 + xoffset)*scale;
|
655 |
if (testx < quad_xoffset) {
|
656 |
quad_xoffset = testx;
|
657 |
}
|
658 |
if (testx > width) {
|
659 |
width = testx;
|
660 |
}
|
661 |
testx = ((double)(local_width-1) +xoffset)*scale;
|
662 |
if (testx < quad_xoffset) {
|
663 |
quad_xoffset = testx;
|
664 |
}
|
665 |
if (testx > width) {
|
666 |
width = testx;
|
667 |
}
|
668 |
|
669 |
testy = (0.0 +yoffset)*scale;
|
670 |
if (testy < quad_yoffset) {
|
671 |
quad_yoffset = testy;
|
672 |
}
|
673 |
if (testy > height) {
|
674 |
height = testy;
|
675 |
}
|
676 |
testy = ((double)(local_height-1) +yoffset)*scale;
|
677 |
if (testy < quad_yoffset) {
|
678 |
quad_yoffset = testx;
|
679 |
}
|
680 |
if (testy > height) {
|
681 |
height = testy;
|
682 |
}
|
683 |
/* Expand the width and height appropriately so we can fit all images in */
|
684 |
width -= quad_xoffset;
|
685 |
height -= quad_yoffset;
|
686 |
//fprintf(stderr,"original w,h: %d,%d offset %d,%d wh %d,%d\n",(int)quad_width,(int)quad_height,quad_xoffset,quad_yoffset,(int)width,(int)height);
|
687 |
|
688 |
#define ThrowWandException(wand) \
|
689 |
{ \
|
690 |
char \
|
691 |
*description; \
|
692 |
\
|
693 |
ExceptionType \
|
694 |
severity; \
|
695 |
\
|
696 |
description=MagickGetException(wand,&severity); \
|
697 |
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
|
698 |
description=(char *) MagickRelinquishMemory(description); \
|
699 |
exit(-1); \
|
700 |
}
|
701 |
|
702 |
MagickWand *m_wand;
|
703 |
PixelIterator *iterator;
|
704 |
PixelWand *c_wand;
|
705 |
PixelWand **pixels;
|
706 |
MagickPixelPacket pixel;
|
707 |
|
708 |
m_wand = NewMagickWand();
|
709 |
c_wand = NewPixelWand();
|
710 |
PixelSetColor(c_wand,"black"); /* for now */
|
711 |
MagickNewImage(m_wand,width,height,c_wand);
|
712 |
MagickSetImageChannelDepth(m_wand, AllChannels, 16);
|
713 |
MagickSetImageDepth(m_wand, 16);
|
714 |
iterator=NewPixelIterator(m_wand);
|
715 |
if ((iterator == (PixelIterator *) NULL) )
|
716 |
ThrowWandException(m_wand);
|
717 |
register ssize_t x;
|
718 |
ssize_t y;
|
719 |
for (y=0; y < (ssize_t) height; y++)
|
720 |
{
|
721 |
pixels=PixelGetNextIteratorRow(iterator,&width);
|
722 |
if ((pixels == (PixelWand **) NULL))
|
723 |
break;
|
724 |
for (x=0; x < (ssize_t) width; x++)
|
725 |
{
|
726 |
PixelGetMagickColor(pixels[x],&pixel);
|
727 |
int r,g,b;
|
728 |
int quad_source_alpha;
|
729 |
r=0;g=0;b=0;
|
730 |
|
731 |
/* add the quad in */
|
732 |
int quad_x,quad_y;
|
733 |
quad_x = x + quad_xoffset;
|
734 |
quad_y = y + quad_yoffset;
|
735 |
|
736 |
|
737 |
if ((quad_x >= 0)&&(quad_x < quad_width)&&(quad_y >= 0)&&(quad_y < quad_height)) {
|
738 |
unsigned short *rl;
|
739 |
rl = quad_buf+((quad_y*quad_width)+quad_x)*3;
|
740 |
quad_source_alpha = *rl;
|
741 |
}
|
742 |
else {
|
743 |
quad_source_alpha=0;
|
744 |
}
|
745 |
|
746 |
int source_x,source_y;
|
747 |
source_x = ((double)(quad_x-BORDER)) * one_over_scale - xoffset;
|
748 |
source_y = ((double)(quad_y-BORDER)) * one_over_scale - yoffset;
|
749 |
if ((source_x<0)||(source_y<0)||(source_x>=local_width)||(source_y>=local_height)) { /* out of bounds */
|
750 |
continue;
|
751 |
}
|
752 |
|
753 |
unsigned int alpha_full;
|
754 |
unsigned int alpha_dark;
|
755 |
unsigned int alpha;
|
756 |
unsigned int alpha_final;
|
757 |
/* find the alpha */
|
758 |
alpha = alpha_buf[((source_y*local_width)+source_x)*3];
|
759 |
alpha_final = get_full_alpha(alpha,quad_source_alpha);
|
760 |
|
761 |
/* find the source r,g,b */
|
762 |
unsigned int source_r,source_g,source_b;
|
763 |
unsigned short *source_rgbp = source_buf+((source_y*local_width)+source_x)*3;
|
764 |
source_r = *(source_rgbp++);
|
765 |
source_g = *(source_rgbp++);
|
766 |
source_b = *(source_rgbp++);
|
767 |
|
768 |
r = source_r;
|
769 |
g = source_g;
|
770 |
b = source_b;
|
771 |
|
772 |
pixel.red=alpha_final;
|
773 |
pixel.green=alpha_final;
|
774 |
pixel.blue=alpha_final;
|
775 |
|
776 |
PixelSetMagickColor(pixels[x],&pixel);
|
777 |
}
|
778 |
(void) PixelSyncIterator(iterator);
|
779 |
}
|
780 |
if (y < (ssize_t) MagickGetImageHeight(m_wand))
|
781 |
ThrowWandException(m_wand);
|
782 |
iterator=DestroyPixelIterator(iterator);
|
783 |
|
784 |
|
785 |
/*
|
786 |
Write the image then destroy it.
|
787 |
*/
|
788 |
|
789 |
char oname[20000];
|
790 |
sprintf(oname,"%3.3d_%3.3d_c.png",xxx,yyy);
|
791 |
|
792 |
MagickBooleanType status;
|
793 |
status=MagickWriteImages(m_wand,oname,MagickTrue);
|
794 |
if (status == MagickFalse)
|
795 |
ThrowWandException(m_wand);
|
796 |
m_wand=DestroyMagickWand(m_wand);
|
797 |
}
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
/* usage - input file r g b iterations
|
806 |
With standard input being a list of filenames or
|
807 |
a list of the output of cycleone. For the output of cyclone, it makes
|
808 |
demonstration images so that you can see how the alogrithm picked the spot.
|
809 |
|
810 |
*/
|
811 |
int main(int argc,char **argv)
|
812 |
{
|
813 |
int text_flag=0;
|
814 |
/* set the stack limit to 500 megabytes */
|
815 |
make_stack_really_big();
|
816 |
if (argc >1) { // if we are outputting text
|
817 |
text_flag = 1;
|
818 |
}
|
819 |
|
820 |
/* seed1 ip_Address fname */
|
821 |
|
822 |
unsigned char *otherrand;
|
823 |
int other;
|
824 |
unsigned short *rgbbuf;
|
825 |
int number_of_points;
|
826 |
int number_second_points;
|
827 |
struct point *points_to_look_at;
|
828 |
struct point *second_points_to_look_at;
|
829 |
struct point *end_points_to_look_at;
|
830 |
struct point *temp_points;
|
831 |
int number_end_points;
|
832 |
MagickWand *m_wand = NULL;
|
833 |
PixelWand *c_wand = NULL;
|
834 |
PixelWand *c2_wand = NULL;
|
835 |
MagickPixelPacket pixel;
|
836 |
|
837 |
MagickWandGenesis();
|
838 |
ssize_t width,height;
|
839 |
|
840 |
unsigned short *source_buffer;
|
841 |
unsigned short *alpha_buffer;
|
842 |
source_buffer = (unsigned short *)malloc(sizeof(short)*3*RI_SIZE*RI_SIZE);
|
843 |
alpha_buffer = (unsigned short *)malloc(sizeof(short)*3*RI_SIZE*RI_SIZE);
|
844 |
if (!source_buffer) {
|
845 |
fprintf(stderr, "Could not allocate for source_buffer\n");
|
846 |
exit(-1);
|
847 |
}
|
848 |
if (!alpha_buffer) {
|
849 |
fprintf(stderr, "Could not allocate for alpha_buffer\n");
|
850 |
exit(-1);
|
851 |
}
|
852 |
|
853 |
char buf[20000];
|
854 |
while (gets(buf)) {
|
855 |
char file_name[10000];
|
856 |
double xoffset;
|
857 |
double yoffset;
|
858 |
double scale;
|
859 |
int bigpic_xoffset;
|
860 |
int bigpic_yoffset;
|
861 |
int xxx;
|
862 |
int yyy;
|
863 |
|
864 |
char source_name[10000],alpha_name[10000];
|
865 |
{
|
866 |
char buf2[10000];
|
867 |
field(buf,buf2,0); xxx = atoi(buf2);
|
868 |
field(buf,buf2,1); yyy = atoi(buf2);
|
869 |
field(buf,file_name,25);
|
870 |
field(buf,buf2,21); bigpic_xoffset = atoi(buf2);
|
871 |
field(buf,buf2,22); bigpic_yoffset = atoi(buf2);
|
872 |
field(buf,buf2,26); xoffset = atof(buf2);
|
873 |
field(buf,buf2,27); yoffset = atof(buf2);
|
874 |
field(buf,buf2,28); scale = atof(buf2);
|
875 |
}
|
876 |
|
877 |
char iname[2000];
|
878 |
sprintf(iname,"%3.3d_%3.3d_a.png",xxx,yyy);
|
879 |
read_image(iname,&width,&height,&rgbbuf);
|
880 |
|
881 |
|
882 |
/* build the filenames for the tile images to use */
|
883 |
sprintf(source_name,"../ri/%s",file_name);
|
884 |
sprintf(alpha_name,"../rk/%s",file_name);
|
885 |
|
886 |
int local_width;
|
887 |
int local_height;
|
888 |
MagickWand *source_wand = NULL;
|
889 |
MagickWand *alpha_wand = NULL;
|
890 |
source_wand =NewMagickWand();
|
891 |
alpha_wand =NewMagickWand();
|
892 |
MagickReadImage(source_wand,source_name);
|
893 |
MagickReadImage(alpha_wand,alpha_name);
|
894 |
local_width = MagickGetImageWidth(source_wand);
|
895 |
local_height = MagickGetImageHeight(source_wand);
|
896 |
if ((local_width != RI_SIZE)||(local_height != RI_SIZE)) {
|
897 |
fprintf(stderr,"%s is not %dx%d. exiting\n",source_name,RI_SIZE,RI_SIZE);
|
898 |
exit(-1);
|
899 |
}
|
900 |
local_width = MagickGetImageWidth(alpha_wand);
|
901 |
local_height = MagickGetImageHeight(alpha_wand);
|
902 |
if ((local_width != RI_SIZE)||(local_height != RI_SIZE)) {
|
903 |
fprintf(stderr,"%s is not %dx%d. exiting\n",alpha_name,RI_SIZE,RI_SIZE);
|
904 |
exit(-1);
|
905 |
}
|
906 |
|
907 |
/* convert the wand into rgb pixels so it is easier to do random io on them */
|
908 |
convert_rgb(source_wand,local_width,local_height,source_buffer);
|
909 |
convert_rgb(alpha_wand,local_width,local_height,alpha_buffer);
|
910 |
|
911 |
if (!text_flag)
|
912 |
{
|
913 |
make_final_image(rgbbuf,width,height,local_width,local_height,source_buffer,alpha_buffer,file_name,xoffset,yoffset,scale,
|
914 |
xxx,yyy);
|
915 |
make_final_alpha_image(rgbbuf,width,height,local_width,local_height,source_buffer,alpha_buffer,file_name,xoffset,yoffset,scale,
|
916 |
xxx,yyy);
|
917 |
}
|
918 |
else {
|
919 |
make_text_output(rgbbuf,width,height,local_width,local_height,source_buffer,alpha_buffer,file_name,xoffset,yoffset,scale,
|
920 |
xxx,yyy,bigpic_xoffset,bigpic_yoffset);
|
921 |
/* make_text_output(rgbbuf,width/4,height/4,local_width,local_height,source_buffer,alpha_buffer,file_name,xoffset,yoffset,scale*0.25,
|
922 |
xxx,yyy,bigpic_xoffset/4,bigpic_yoffset/4);*/
|
923 |
|
924 |
}
|
925 |
|
926 |
|
927 |
source_wand = DestroyMagickWand(source_wand);
|
928 |
alpha_wand = DestroyMagickWand(alpha_wand);
|
929 |
|
930 |
|
931 |
free(rgbbuf);
|
932 |
rgbbuf=NULL;
|
933 |
} /* for each file */
|
934 |
|
935 |
|
936 |
MagickWandTerminus();
|
937 |
return(0);
|
938 |
}
|
939 |
|