/[opencvs]/eyes/fp_to_txt.c
ViewVC logotype

Contents of /eyes/fp_to_txt.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations)
Tue Feb 2 04:02:35 2016 UTC (2 years, 2 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +122 -1 lines
File MIME type: text/plain
added is_image_grey
1 /* fp_to_image is part of the next generation set of generators for
2 hologram material.
3 */
4
5 #include <stdio.h>
6 #include <math.h>
7 #include <stdlib.h>
8 #include "holo_complex.h"
9
10
11 static real buf[1048576];
12 static real buf2[1048576];
13 static real buf3[1048576];
14
15 void usage() {
16 fprintf(stderr,"Usages:\n"
17 "fp_to_txt real <xsize> <ysize> <grey_file_name> <fp_file_name>\n"
18 "fp_to_txt imaginary <xsize> <ysize> <grey_file_name> <fp_file_name>\n"
19 "fp_to_txt rgb <xsize> <ysize> <grey_file_name> <fp_file_name>\n"
20 "fp_to_txt color <xsize> <ysize> <grey_file_name> <im_grey_file_name> <fp_file_name>\n"
21 "fp_to_txt binary <xsize> <ysize> <grey_file_name> <fp_file_name> [threshold]\n"
22 "fp_to_txt trinary <xsize> <ysize> <grey_file_name> <fp_file_name>\n"
23 "fp_to_txt binary_spartain <xsize> <ysize> <grey_file_name> <fp_file_name> [threshold] (leave white space on odd pixels)\n"
24 "fp_to_txt timeless <xsize> <ysize> <grey_file_name> <fp_file_name1> <fp_file_name2 (color some of the pixels for japan_timeless)\n"
25 );
26 }
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 int output_real_grey_scale(int argc,char *argv[]) {
45 int xsize;
46 int ysize;
47 char *grey_file_name;
48 char *fp_file_name;
49
50
51 /* mode is first argument - ignored for now */
52 xsize = atoi(argv[2]);
53 ysize = atoi(argv[3]);
54 /* grey file */
55 grey_file_name = argv[4];
56 fp_file_name = argv[5];
57
58
59
60
61 real greys[256];
62 FILE *xf;
63 xf = fopen(grey_file_name,"r");
64 if (!xf) {
65 fprintf(stderr,"Could not open the grey file\n");
66 exit(-1);
67 }
68 int r;
69 r=fread(greys,sizeof(real),256,xf);
70 fclose(xf);
71
72
73 xf = fopen(fp_file_name,"r");
74 if (!xf) {
75 fprintf(stderr,"Could not open the fp file\n");
76 exit(-1);
77 }
78
79
80 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
81
82 int x,y;
83 x=0;y=0;
84 size_t read;
85 while (read=fread(buf,sizeof(real)*2,1048576/2,xf)) {
86 int i;
87 for (i=0;i<read;i++) {
88 real val = buf[i+i];
89
90 /* binary search val with greys */
91 int gh = 256;
92 int gl=0;
93 int g=(gh+gl)/2;
94 while ((gh-gl)>1) {
95 if (val >= greys[g]) {
96 gl=g;
97 g=(gh+gl)/2;
98 }
99 else {
100 gh=g;
101 g=(gh+gl)/2;
102 }
103 } /* while binary searching to find the right appropriate color for the dot */
104 printf("%d,%d: (%d,%d,%d) #%06x rgb(%d,%d,%d)\n",x,y,g,g,g,g*65536+g*256+g,g,g,g);
105
106 x = x + 1;
107 if (x>=xsize) {
108 x=0;
109 y=y+1;
110 }
111 } /* for each read item */
112 } /* while each read */
113 fclose(xf);
114 return(0);
115 }
116
117
118
119
120
121
122 int output_timeless(int argc,char *argv[]) {
123 int xsize;
124 int ysize;
125 char *grey_file_name;
126 char *fp_file_name1;
127 char *fp_file_name2;
128
129 /* mode is first argument - ignored for now */
130 xsize = atoi(argv[2]);
131 ysize = atoi(argv[3]);
132 /* grey file */
133 grey_file_name = argv[4];
134 fp_file_name1 = argv[5];
135 fp_file_name2 = argv[6];
136
137
138 real greys[256];
139 FILE *xf;
140 FILE *xf2;
141 xf = fopen(grey_file_name,"r");
142 if (!xf) {
143 fprintf(stderr,"Could not open the grey file\n");
144 exit(-1);
145 }
146 int r;
147 r=fread(greys,sizeof(real),256,xf);
148 fclose(xf);
149
150
151 xf = fopen(fp_file_name1,"r");
152 if (!xf) {
153 fprintf(stderr,"Could not open the fp file\n");
154 exit(-1);
155 }
156
157 xf2 = fopen(fp_file_name2,"r");
158 if (!xf2) {
159 fprintf(stderr,"Could not open the second fp file\n");
160 exit(-1);
161 }
162
163
164 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
165
166 int x,y;
167 x=0;y=0;
168 size_t read;
169 while (read=fread(buf2,sizeof(real)*2,xsize/2,xf)) {
170 int i;
171 fread(buf3,sizeof(real)*2,xsize/2,xf2);
172
173 int xx=x;
174 int j=0;
175 for (i=0;i<read;i++) {
176 buf[j+j] = buf2[i+i];
177 j++;
178 }
179 for (i=0;i<read;i++) {
180 buf[j+j] = buf3[i+i];
181 j++;
182 }
183 read = read*2;
184
185 for (i=0;i<read;i++) {
186 real val = buf[i+i];
187
188 /* binary search val with greys */
189 int gh = 256;
190 int gl=0;
191 int g=(gh+gl)/2;
192 while ((gh-gl)>1) {
193 if (val >= greys[g]) {
194 gl=g;
195 g=(gh+gl)/2;
196 }
197 else {
198 gh=g;
199 g=(gh+gl)/2;
200 }
201 } /* while binary searching to find the right appropriate color for the dot */
202 int r;
203 int b;
204 r=g;b=g;
205 if (g>248) {
206 g=248;
207 r=r-g+r;
208 if (r>255) r=255;
209 b = r;
210 }
211 else if (g==128) { b=255;g=46;r=0;}
212 else if (g<16) {
213 r=r+16;
214 b=0;
215 g=0;
216 }
217 printf("%d,%d: (%d,%d,%d)\n",x,y,r,g,b);
218
219 x = x + 1;
220 if (x>=xsize) {
221 x=0;
222 y=y+1;
223 }
224 } /* for each read item */
225 } /* while each read */
226 fclose(xf);
227 return(0);
228 }
229
230
231
232
233
234
235 int output_real_rgb_scale(int argc,char *argv[]) {
236 int xsize;
237 int ysize;
238 char *grey_file_name;
239 char *fp_file_name;
240
241
242 /* mode is first argument - ignored for now */
243 xsize = atoi(argv[2]);
244 ysize = atoi(argv[3]);
245 /* grey file */
246 grey_file_name = argv[4];
247 fp_file_name = argv[5];
248
249
250
251
252 real greys[256];
253 FILE *xf;
254 xf = fopen(grey_file_name,"r");
255 if (!xf) {
256 fprintf(stderr,"Could not open the grey file\n");
257 exit(-1);
258 }
259 int r;
260 r=fread(greys,sizeof(real),256,xf);
261 fclose(xf);
262
263
264 xf = fopen(fp_file_name,"r");
265 if (!xf) {
266 fprintf(stderr,"Could not open the fp file\n");
267 exit(-1);
268 }
269
270
271 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
272
273 int x,y;
274 x=0;y=0;
275 size_t read;
276 while (read=fread(buf,sizeof(real)*2,174762,xf)) {
277 int i;
278 for (i=0;i<read;i+=3) {
279 int red,green,blue;
280 real val;
281 val = buf[i+i];
282
283 /* binary search val with greys */
284 int gh = 256;
285 int gl=0;
286 int g=(gh+gl)/2;
287 while ((gh-gl)>1) {
288 if (val >= greys[g]) {
289 gl=g;
290 g=(gh+gl)/2;
291 }
292 else {
293 gh=g;
294 g=(gh+gl)/2;
295 }
296 } /* while binary searching to find the right appropriate color for the dot */
297 red = g;
298
299 val = buf[i+i+2];
300
301 /* binary search val with greys */
302 gh = 256;
303 gl=0;
304 g=(gh+gl)/2;
305 while ((gh-gl)>1) {
306 if (val >= greys[g]) {
307 gl=g;
308 g=(gh+gl)/2;
309 }
310 else {
311 gh=g;
312 g=(gh+gl)/2;
313 }
314 } /* while binary searching to find the right appropriate color for the dot */
315 green = g;
316
317 val = buf[i+i+4];
318
319 /* binary search val with greys */
320 gh = 256;
321 gl=0;
322 g=(gh+gl)/2;
323 while ((gh-gl)>1) {
324 if (val >= greys[g]) {
325 gl=g;
326 g=(gh+gl)/2;
327 }
328 else {
329 gh=g;
330 g=(gh+gl)/2;
331 }
332 } /* while binary searching to find the right appropriate color for the dot */
333 blue = g;
334
335 /* int avg = (red+blue+green)/3;
336 red = (red+red+avg)/3;
337 green = (green+green+avg)/3;
338 blue = (blue+blue+avg)/3;
339 */
340 printf("%d,%d: (%d,%d,%d)\n",x,y,red,green,blue);
341
342 x = x + 1;
343 if (x>=xsize) {
344 x=0;
345 y=y+1;
346 }
347 } /* for each read item */
348 } /* while each read */
349 fclose(xf);
350 return(0);
351 }
352
353
354
355 int output_imaginary_grey_scale(int argc,char *argv[]) {
356 int xsize;
357 int ysize;
358 char *grey_file_name;
359 char *fp_file_name;
360
361
362
363 /* mode is first argument - ignored for now */
364 xsize = atoi(argv[2]);
365 ysize = atoi(argv[3]);
366 /* grey file */
367 grey_file_name = argv[4];
368 fp_file_name = argv[5];
369
370
371
372
373 real greys[256];
374 FILE *xf;
375 xf = fopen(grey_file_name,"r");
376 if (!xf) {
377 fprintf(stderr,"Could not open the grey file\n");
378 exit(-1);
379 }
380 int r;
381 r=fread(greys,sizeof(real),256,xf);
382 fclose(xf);
383
384
385 xf = fopen(fp_file_name,"r");
386 if (!xf) {
387 fprintf(stderr,"Could not open the fp file\n");
388 exit(-1);
389 }
390
391
392 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
393
394 int x,y;
395 x=0;y=0;
396 size_t read;
397 while (read=fread(buf,sizeof(real)*2,1048576/2,xf)) {
398 int i;
399 for (i=0;i<read;i++) {
400 real val = buf[i+i+1]; /* imaginary number */
401
402 /* binary search val with greys */
403 int gh = 256;
404 int gl=0;
405 int g=(gh+gl)/2;
406 while ((gh-gl)>1) {
407 if (val >= greys[g]) {
408 gl=g;
409 g=(gh+gl)/2;
410 }
411 else {
412 gh=g;
413 g=(gh+gl)/2;
414 }
415 } /* while binary searching to find the right appropriate color for the dot */
416 printf("%d,%d: (%d,%d,%d) #%06x rgb(%d,%d,%d)\n",x,y,g,g,g,g*65536+g*256+g,g,g,g);
417
418 x = x + 1;
419 if (x>=xsize) {
420 x=0;
421 y=y+1;
422 }
423 } /* for each read item */
424 } /* while each read */
425 fclose(xf);
426 return(0);
427 }
428
429
430
431
432
433
434
435 int output_binary_grey_scale(int argc,char *argv[]) {
436 int xsize;
437 int ysize;
438 char *grey_file_name;
439 char *fp_file_name;
440 double threshold;
441 int grey_index;
442
443
444 /* mode is first argument - ignored for now */
445 xsize = atoi(argv[2]);
446 ysize = atoi(argv[3]);
447 /* grey file */
448 grey_file_name = argv[4];
449 fp_file_name = argv[5];
450 if (argc>6) {
451 threshold = atof(argv[6]);
452 }
453 else {
454 threshold = 0.;
455 }
456 if (!threshold) {
457 grey_index=128;
458 }
459 else {
460 grey_index = (threshold*256);
461 if (grey_index>255) grey_index=255;
462 if (grey_index<0) grey_index=0;
463 }
464
465
466
467 real greys[256];
468 FILE *xf;
469 xf = fopen(grey_file_name,"r");
470 if (!xf) {
471 fprintf(stderr,"Could not open the binary grey file\n");
472 exit(-1);
473 }
474 int r;
475 r=fread(greys,sizeof(real),256,xf);
476 fclose(xf);
477
478
479 double transition;
480 if (!threshold) { transition=0;}
481 else {
482 transition = greys[grey_index];
483 fprintf(stderr,"grey_index %d transition %lf\n",grey_index,greys[grey_index]);
484 }
485
486
487 xf = fopen(fp_file_name,"r");
488 if (!xf) {
489 fprintf(stderr,"Could not open the fp file\n");
490 exit(-1);
491 }
492
493
494 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
495
496 int x,y;
497 x=0;y=0;
498 size_t read;
499 while (read=fread(buf,sizeof(real)*2,1048576/2,xf)) {
500 int i;
501 for (i=0;i<read;i++) {
502 real val = buf[i+i];
503
504
505 int g;
506 if (val > transition) g=255;
507 else g=0;
508
509 printf("%d,%d: (%d,%d,%d) #%06x rgb(%d,%d,%d)\n",x,y,g,g,g,g*65536+g*256+g,g,g,g);
510
511 x = x + 1;
512 if (x>=xsize) {
513 x=0;
514 y=y+1;
515 }
516 } /* for each read item */
517 } /* while each read */
518 fclose(xf);
519 return(0);
520 }
521
522
523
524
525
526
527
528 int output_binary_spartain_grey_scale(int argc,char *argv[]) {
529 int xsize;
530 int ysize;
531 char *grey_file_name;
532 char *fp_file_name;
533 double threshold;
534 int grey_index;
535
536
537 /* mode is first argument - ignored for now */
538 xsize = atoi(argv[2]);
539 ysize = atoi(argv[3]);
540 /* grey file */
541 grey_file_name = argv[4];
542 fp_file_name = argv[5];
543 if (argc>6) {
544 threshold = atof(argv[6]);
545 }
546 else {
547 threshold = 0.;
548 }
549 if (!threshold) {
550 grey_index=128;
551 }
552 else {
553 grey_index = (threshold*256);
554 if (grey_index>255) grey_index=255;
555 if (grey_index<0) grey_index=0;
556 }
557
558
559
560 real greys[256];
561 FILE *xf;
562 xf = fopen(grey_file_name,"r");
563 if (!xf) {
564 fprintf(stderr,"Could not open the binary grey file\n");
565 exit(-1);
566 }
567 int r;
568 r=fread(greys,sizeof(real),256,xf);
569 fclose(xf);
570
571
572 double transition;
573 if (!threshold) { transition=0;}
574 else {
575 transition = greys[grey_index];
576 fprintf(stderr,"spartain_grey_index %d transition %lf\n",grey_index,greys[grey_index]);
577 }
578
579
580 xf = fopen(fp_file_name,"r");
581 if (!xf) {
582 fprintf(stderr,"Could not open the fp file\n");
583 exit(-1);
584 }
585
586
587 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
588
589 int x,y;
590 x=0;y=0;
591 size_t read;
592 while (read=fread(buf,sizeof(real)*2,1048576/2,xf)) {
593 int i;
594 for (i=0;i<read;i++) {
595 real val = buf[i+i];
596
597
598 int g;
599 if ((x%2)||(y%2)||(val > transition)) g=255;
600 else g=0;
601
602 printf("%d,%d: (%d,%d,%d) #%06x rgb(%d,%d,%d)\n",x,y,g,g,g,g*65536+g*256+g,g,g,g);
603
604 x = x + 1;
605 if (x>=xsize) {
606 x=0;
607 y=y+1;
608 }
609 } /* for each read item */
610 } /* while each read */
611 fclose(xf);
612 return(0);
613 }
614
615
616
617 int output_trinary_grey_scale(int argc,char *argv[]) { /* 0 is 127,127,127 */
618 int xsize;
619 int ysize;
620 char *grey_file_name;
621 char *fp_file_name;
622
623
624
625 /* mode is first argument - ignored for now */
626 xsize = atoi(argv[2]);
627 ysize = atoi(argv[3]);
628 /* grey file */
629 grey_file_name = argv[4];
630 fp_file_name = argv[5];
631
632
633
634
635 real greys[256];
636 FILE *xf;
637 xf = fopen(grey_file_name,"r");
638 if (!xf) {
639 fprintf(stderr,"Could not open the binary grey file\n");
640 exit(-1);
641 }
642 int r;
643 r=fread(greys,sizeof(real),256,xf);
644 fclose(xf);
645
646
647 xf = fopen(fp_file_name,"r");
648 if (!xf) {
649 fprintf(stderr,"Could not open the fp file\n");
650 exit(-1);
651 }
652
653
654 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
655
656 int x,y;
657 x=0;y=0;
658 size_t read;
659 while (read=fread(buf,sizeof(real)*2,1048576/2,xf)) {
660 int i;
661 for (i=0;i<read;i++) {
662 real val = buf[i+i];
663 int g;
664 if (val > 0.) g=255;
665 else if (val < 0.) g=0;
666 else g=127;
667
668 printf("%d,%d: (%d,%d,%d) #%06x rgb(%d,%d,%d)\n",x,y,g,g,g,g*65536+g*256+g,g,g,g);
669
670 x = x + 1;
671 if (x>=xsize) {
672 x=0;
673 y=y+1;
674 }
675 } /* for each read item */
676 } /* while each read */
677 fclose(xf);
678 return(0);
679 }
680
681
682 /* color wheel from green to cyan,blue,purple, etc
683 But we want to start at blue - so we will add 180 */
684 static int chroma[] = {
685 0,255,0,
686 0,255,6,
687 0,255,12,
688 0,255,18,
689 0,255,24,
690 0,255,30,
691 0,255,36,
692 0,255,43,
693 0,255,49,
694 0,255,55,
695 0,255,61,
696 0,255,67,
697 0,255,73,
698 0,255,79,
699 0,255,85,
700 0,255,91,
701 0,255,97,
702 0,255,103,
703 0,255,109,
704 0,255,115,
705 0,255,121,
706 0,255,128,
707 0,255,134,
708 0,255,140,
709 0,255,146,
710 0,255,152,
711 0,255,158,
712 0,255,164,
713 0,255,170,
714 0,255,176,
715 0,255,182,
716 0,255,188,
717 0,255,194,
718 0,255,300,
719 0,255,206,
720 0,255,214,
721 0,255,219,
722 0,255,225,
723 0,255,231,
724 0,255,237,
725 0,255,243,
726 0,255,249,
727 0,255,255,
728 0,250,255,
729 0,244,255,
730 0,238,255,
731 0,232,255,
732 0,226,255,
733 0,220,255,
734 0,213,255,
735 0,208,255,
736 0,202,255,
737 0,196,255,
738 0,190,255,
739 0,184,255,
740 0,178,255,
741 0,172,255,
742 0,166,255,
743 0,160,255,
744 0,154,255,
745 0,148,255,
746 0,142,255,
747 0,136,255,
748 0,130,255,
749 0,125,255,
750 0,119,255,
751 0,113,255,
752 0,107,255,
753 0,101,255,
754 0,95,255,
755 0,89,255,
756 0,83,255,
757 0,77,255,
758 0,71,255,
759 0,65,255,
760 0,59,255,
761 0,53,255,
762 0,47,255,
763 0,42,255,
764 0,36,255,
765 0,30,255,
766 0,24,255,
767 0,18,255,
768 0,12,255,
769 0,6,255,
770 0,0,255,
771 6,0,255,
772 12,0,255,
773 18,0,255,
774 24,0,255,
775 30,0,255,
776 36,0,255,
777 43,0,255,
778 49,0,255,
779 55,0,255,
780 61,0,255,
781 67,0,255,
782 73,0,255,
783 79,0,255,
784 85,0,255,
785 91,0,255,
786 97,0,255,
787 103,0,255,
788 109,0,255,
789 115,0,255,
790 121,0,255,
791 128,0,255,
792 134,0,255,
793 140,0,255,
794 146,0,255,
795 152,0,255,
796 158,0,255,
797 164,0,255,
798 170,0,255,
799 176,0,255,
800 182,0,255,
801 188,0,255,
802 194,0,255,
803 300,0,255,
804 206,0,255,
805 214,0,255,
806 219,0,255,
807 225,0,255,
808 231,0,255,
809 237,0,255,
810 243,0,255,
811 249,0,255,
812 255,0,255,
813 255,0,250,
814 255,0,244,
815 255,0,238,
816 255,0,232,
817 255,0,226,
818 255,0,220,
819 255,0,213,
820 255,0,208,
821 255,0,202,
822 255,0,196,
823 255,0,190,
824 255,0,184,
825 255,0,178,
826 255,0,172,
827 255,0,166,
828 255,0,160,
829 255,0,154,
830 255,0,148,
831 255,0,142,
832 255,0,136,
833 255,0,130,
834 255,0,125,
835 255,0,119,
836 255,0,113,
837 255,0,107,
838 255,0,101,
839 255,0,95,
840 255,0,89,
841 255,0,83,
842 255,0,77,
843 255,0,71,
844 255,0,65,
845 255,0,59,
846 255,0,53,
847 255,0,47,
848 255,0,42,
849 255,0,36,
850 255,0,30,
851 255,0,24,
852 255,0,18,
853 255,0,12,
854 255,0,6,
855 255,0,0,
856 255,6,0,
857 255,12,0,
858 255,18,0,
859 255,24,0,
860 255,30,0,
861 255,36,0,
862 255,43,0,
863 255,49,0,
864 255,55,0,
865 255,61,0,
866 255,67,0,
867 255,73,0,
868 255,79,0,
869 255,85,0,
870 255,91,0,
871 255,97,0,
872 255,103,0,
873 255,109,0,
874 255,115,0,
875 255,121,0,
876 255,128,0,
877 255,134,0,
878 255,140,0,
879 255,146,0,
880 255,152,0,
881 255,158,0,
882 255,164,0,
883 255,170,0,
884 255,176,0,
885 255,182,0,
886 255,188,0,
887 255,194,0,
888 255,300,0,
889 255,206,0,
890 255,214,0,
891 255,219,0,
892 255,225,0,
893 255,231,0,
894 255,237,0,
895 255,243,0,
896 255,249,0,
897 255,255,0,
898 250,255,0,
899 244,255,0,
900 238,255,0,
901 232,255,0,
902 226,255,0,
903 220,255,0,
904 213,255,0,
905 208,255,0,
906 202,255,0,
907 196,255,0,
908 190,255,0,
909 184,255,0,
910 178,255,0,
911 172,255,0,
912 166,255,0,
913 160,255,0,
914 154,255,0,
915 148,255,0,
916 142,255,0,
917 136,255,0,
918 130,255,0,
919 125,255,0,
920 119,255,0,
921 113,255,0,
922 107,255,0,
923 101,255,0,
924 95,255,0,
925 89,255,0,
926 83,255,0,
927 77,255,0,
928 71,255,0,
929 65,255,0,
930 59,255,0,
931 53,255,0,
932 47,255,0,
933 42,255,0,
934 36,255,0,
935 30,255,0,
936 25,255,0,
937 20,255,0,
938 15,255,0,
939 10,255,0,
940 5,255,0,
941 };
942
943
944
945 int output_color_scale(int argc,char *argv[]) {
946 int xsize;
947 int ysize;
948 char *greyr_file_name;
949 char *greyi_file_name;
950 char *fp_file_name;
951
952
953
954 /* mode is first argument - ignored for now */
955 xsize = atoi(argv[2]);
956 ysize = atoi(argv[3]);
957 /* grey files */
958 greyr_file_name = argv[4];
959 greyi_file_name = argv[5];
960 fp_file_name = argv[6];
961
962
963
964
965 real real_greys[256];
966 real imaginary_greys[256];
967
968 FILE *xf;
969 xf = fopen(greyr_file_name,"r");
970 if (!xf) {
971 fprintf(stderr,"Could not open the real grey file\n");
972 exit(-1);
973 }
974 int r;
975 r=fread(real_greys,sizeof(real),256,xf);
976 fclose(xf);
977
978
979 xf = fopen(greyi_file_name,"r");
980 if (!xf) {
981 fprintf(stderr,"Could not open the imaginary grey file\n");
982 exit(-1);
983 }
984 r=fread(imaginary_greys,sizeof(real),256,xf);
985 fclose(xf);
986
987
988
989 xf = fopen(fp_file_name,"r");
990 if (!xf) {
991 fprintf(stderr,"Could not open the fp file\n");
992 exit(-1);
993 }
994
995
996 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
997
998 int x,y;
999 x=0;y=0;
1000 size_t read;
1001 while (read=fread(buf,sizeof(real)*2,1048576/2,xf)) {
1002 int i;
1003 for (i=0;i<read;i++) {
1004 real val = buf[i+i];
1005
1006 /* binary search val with greys */
1007 int gh = 256;
1008 int gl=0;
1009 int g=(gh+gl)/2;
1010 while ((gh-gl)>1) {
1011 if (val >= real_greys[g]) {
1012 gl=g;
1013 g=(gh+gl)/2;
1014 }
1015 else {
1016 gh=g;
1017 g=(gh+gl)/2;
1018 }
1019 } /* while binary searching to find the right appropriate color for the dot */
1020
1021 /* g now has the real value */
1022
1023 /* now find the imaginary value based on imaginay greys - again a bnary search */
1024 real ival = buf[i+i+1];
1025
1026 /* binary search val with greys */
1027 int igh = 256;
1028 int igl=0;
1029 int ig=(igh+igl)/2;
1030 while ((igh-igl)>1) {
1031 if (ival >= imaginary_greys[ig]) {
1032 igl=ig;
1033 ig=(igh+igl)/2;
1034 }
1035 else {
1036 igh=ig;
1037 ig=(igh+igl)/2;
1038 }
1039 } /* while binary searching to find the right appropriate color for the dot */
1040
1041 /* ig now has the imaginary value */
1042 /* now look up the chroma to use for the given imaginary value */
1043 real r1,g1,b1;
1044 real rvalue;
1045 rvalue = g; /* convert to floating point once */
1046 r1 = chroma[((ig+200)%256)*3];
1047 g1 = chroma[((ig+200)%256)*3+1];
1048 b1 = chroma[((ig+200)%256)*3+2];
1049
1050
1051
1052
1053 /* all right - now we need to binary search for a rate where the rate is as big as it can get.
1054 The rate can go from 0 to 1 inclusive.
1055 What we do -
1056 First add the color as much as we can by the rate.
1057 Then look at the effective black and white luma
1058 then offset the values so the luma is bigger
1059 Then see if any numbers are outside the boundary (0-255)
1060 And if so, it failed - try smaller.
1061 0 will always succeed
1062 We do this by using a delta
1063 */
1064 real lo,hi;
1065 real delta;
1066 int r4,b4,g4; /* same as spreadsheet */
1067 hi=1.0;
1068 lo=0.0;
1069 delta = 1.;
1070 r4 = g;
1071 g4 = g;
1072 b4 = g;
1073 while (delta > 0.000000001) {
1074 real rate;
1075 real r2,g2,b2; /* with rate applied */
1076 real effective_total;
1077 real offset;
1078 real diff;
1079 int r3,b3,g3; /* same as spreadsheet */
1080
1081 rate = (hi+lo)*0.5; /* try half way */
1082 r2 = rvalue + (r1-rvalue)* rate;
1083 g2 = rvalue + (g1-rvalue)* rate;
1084 b2 = rvalue + (b1-rvalue)* rate;
1085
1086 /* fprintf(stderr,"rate %lf p2 %lf,%lf,%lf\n",rate,r2,g2,b2);*/
1087
1088 effective_total = (r2*76.+g2*151.+b2*28)/255.;
1089 diff = rvalue - effective_total;
1090
1091 r3 = r2 + diff;
1092 g3 = g2 + diff;
1093 b3 = b2 + diff;
1094
1095 /* fprintf(stderr,"rate %lf p2 %d,%d,%d\n",rate,r3,g3,b3);*/
1096
1097 /* OK - if this works, then we will go higher and try to find a more vivid color
1098 If it cant( because of range issues ) we stay lower */
1099 if ((r3<0)||(g3<0)||(b3<0)||
1100 (r3>255)||(g3>255)||(b3>255)) {
1101 hi=rate; /* no fit, try a lower rate */
1102 }
1103 else {
1104 r4=r3;
1105 g4=g3;
1106 b4=b3;
1107 lo=rate; /* it fits - try something higher */
1108 }
1109 delta = hi-lo;
1110 }
1111
1112 printf("%d,%d: (%d,%d,%d) #%06x rgb(%d,%d,%d)\n",x,y,r4,g4,b4,r4*65536+g4*256+b4,r4,g4,b4);
1113
1114 x = x + 1;
1115 if (x>=xsize) {
1116 x=0;
1117 y=y+1;
1118 }
1119 } /* for each read item */
1120 } /* while each read */
1121 fclose(xf);
1122 return(0);
1123 }
1124
1125
1126
1127
1128
1129 int main (int argc, char *argv[]) {
1130 char *mode;
1131
1132 mode = argv[1];
1133 if (strcmp(mode,"binary")==0) {
1134 return output_binary_grey_scale(argc,argv);
1135 }
1136 if (strcmp(mode,"binary_spartain")==0) {
1137 return output_binary_spartain_grey_scale(argc,argv);
1138 }
1139 if (strcmp(mode,"trinary")==0) {
1140 return output_trinary_grey_scale(argc,argv);
1141 }
1142 if (strcmp(mode,"real")==0) {
1143 return output_real_grey_scale(argc,argv);
1144 }
1145 if (strcmp(mode,"imaginary")==0) {
1146 return output_imaginary_grey_scale(argc,argv);
1147 }
1148 if (strcmp(mode,"color")==0) {
1149 return output_color_scale(argc,argv);
1150 }
1151 if (strcmp(mode,"rgb")==0) {
1152 return output_real_rgb_scale(argc,argv);
1153 }
1154 if (strcmp(mode,"timeless")==0) {
1155 return output_timeless(argc,argv);
1156 }
1157 fprintf(stderr,"invalid mode\n");
1158 usage();
1159 exit(-1);
1160 }
1161

  ViewVC Help
Powered by ViewVC 1.1.5