Newer
Older
#include "stdint.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "strings.h"
#include "sys/mman.h"
#include "sys/select.h"
#include "sys/time.h"
#include "sys/types.h"
#include "unistd.h"
struct cgc_aes_state {
uint8_t vec[16] __attribute__((__aligned__(1)));
uint8_t key[16] __attribute__((__aligned__(1)));
uint8_t datetime[16] __attribute__((__aligned__(1)));
} __attribute__((__packed__, __aligned__(1)));
typedef struct cgc_aes_state cgc_aes_state;
struct cgc_prng {
cgc_aes_state state ;
uint8_t intermediate[16] ;
uint8_t random_data[16] ;
uint8_t random_idx ;
};
typedef struct cgc_prng cgc_prng_0;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
struct __anonstruct_t3DCPixel_1 {
int16_t x __attribute__((__aligned__(1)));
int16_t y __attribute__((__aligned__(1)));
int16_t z __attribute__((__aligned__(1)));
uint8_t r __attribute__((__aligned__(1)));
uint8_t g __attribute__((__aligned__(1)));
uint8_t b __attribute__((__aligned__(1)));
uint8_t a __attribute__((__aligned__(1)));
} __attribute__((__packed__, __aligned__(1)));
typedef struct __anonstruct_t3DCPixel_1 t3DCPixel;
enum __anonenum_2 {
R = 0,
G = 1,
B = 2
};
enum __anonenum_menuSelections_2 {
NO_FUNC = 0,
NEW_FILE = 1,
CHECK_FILE = 2,
SKEW_IMAGE = 3,
ROTATE_IMAGE = 4,
BRIGHTNESS = 5,
OPACITY = 6,
COMPRESS = 7,
DECOMPRESS = 8,
SHOW_PIXEL = 9,
SCALE_IMAGE = 10,
EXIT = 11
};
enum __anonenum_coords_3 {
X = 0,
Y = 1,
Z = 2
};
__attribute__((__noreturn__)) void cgc__terminate(unsigned int status);
int cgc_transmit(int fd, void const *buf, size_t count, size_t *tx_bytes);
int cgc_receive(int fd, void *buf, size_t count, size_t *rx_bytes);
int cgc_fdwait(int nfds, fd_set *readfds, fd_set *writefds,
struct timeval const *timeout, int *readyfds);
int cgc_allocate(size_t length, int is_executable, void **addr);
int cgc_deallocate(void *addr, size_t length);
int cgc_random(void *buf, size_t count, size_t *rnd_bytes);
int receive_bytes_iPcz(char *buffer, size_t count);
int __prng_state;
/*@ assigns __prng_state;
assigns __prng_state \from seedValue; */
void seed_prng(uint32_t seedValue);
/*@ assigns \result, __prng_state;
assigns \result \from __prng_state;
assigns __prng_state \from __prng_state;
*/
uint32_t cgc_prng(void);
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
int receive_bytes_iPcz(char *buffer, size_t count)
{
int __retres;
size_t total;
size_t rxbytes;
total = (unsigned int)0;
while (total < count) {
int tmp;
rxbytes = (unsigned int)0;
tmp = cgc_receive(0,(void *)(buffer + total),count - total,& rxbytes);
if (tmp == 0)
if (rxbytes == (size_t)0) {
__retres = 0;
goto return_label;
}
else total += rxbytes;
else {
__retres = -1;
goto return_label;
}
}
__retres = 0;
return_label: return __retres;
}
int cgc_check_timeout(struct timeval const *timeout)
{
int __retres;
if (! timeout) {
__retres = 0;
goto return_label;
}
else
if ((time_t)0 > timeout->tv_sec) goto _LOR;
else
if (0 > timeout->tv_usec) {
_LOR: {
__retres = 22;
goto return_label;
}
}
else {
__retres = 0;
goto return_label;
}
return_label: return __retres;
}
void cgc_init_prng(cgc_prng_0 *, cgc_aes_state const *);
void cgc_aes_get_bytes(cgc_prng_0 *, uint32_t, uint8_t *);
__attribute__((__noreturn__)) void cgc__terminate(unsigned int status);
void cgc__terminate(unsigned int status)
{
exit((int)status);
return;
}
int cgc_transmit(int fd, void const *buf, size_t count, size_t *tx_bytes)
{
int __retres;
ssize_t const ret = write(fd,buf,count);
if (ret < 0) {
__retres = __fc_errno;
goto return_label;
}
else
if (tx_bytes != (size_t *)0) *tx_bytes = (unsigned int)ret;
__retres = 0;
return_label: return __retres;
}
int cgc_receive(int fd, void *buf, size_t count, size_t *rx_bytes)
{
int __retres;
ssize_t const ret = read(fd,buf,count);
if (ret < 0) {
__retres = __fc_errno;
goto return_label;
}
else
if (rx_bytes != (size_t *)0) *rx_bytes = (unsigned int)ret;
__retres = 0;
return_label: return __retres;
}
static int cgc_copy_cgc_fd_set(fd_set const *cgc_fds, fd_set *os_fds,
int *num_fds)
{
int __retres;
{
unsigned int fd = (unsigned int)0;
while (fd < (unsigned int)8 * sizeof(long)) {
{
int tmp;
tmp = FD_ISSET((int)fd,cgc_fds);
if (tmp) {
if (fd >= (unsigned int)(3 + 2 * 10)) {
__retres = 9;
goto return_label;
}
if (fd > (unsigned int)8 * sizeof(long)) goto __Cont;
FD_SET((int)fd,os_fds);
(*num_fds) ++;
}
}
__Cont: fd ++;
}
}
__retres = 0;
return_label: return __retres;
}
static void cgc_copy_os_fd_set(fd_set const *os_fds, fd_set *cgc_fds)
{
unsigned int fd = (unsigned int)0;
while (1) {
unsigned int tmp_0;
if ((unsigned int)8 * sizeof(long) < (unsigned int)8 * sizeof(long))
tmp_0 = (unsigned int)8 * sizeof(long);
else tmp_0 = (unsigned int)8 * sizeof(long);
;
if (! (fd < tmp_0)) break;
{
int tmp;
tmp = FD_ISSET((int)fd,os_fds);
if (tmp) FD_SET((int)fd,cgc_fds);
}
fd ++;
}
return;
}
int cgc_fdwait(int nfds, fd_set *readfds, fd_set *writefds,
struct timeval const *timeout, int *readyfds)
{
int __retres;
fd_set read_fds;
fd_set write_fds;
int tmp_3;
struct timeval *tmp_0;
fd_set *tmp_1;
fd_set *tmp_2;
int ret = cgc_check_timeout(timeout);
int actual_num_fds = 0;
struct timeval max_wait_time = {.tv_sec = (long)0, .tv_usec = 0};
if (ret) {
__retres = ret;
goto return_label;
}
else
if (0 > nfds) goto _LOR;
else
if ((unsigned int)8 * sizeof(long) < (unsigned int)nfds) {
_LOR: {
__retres = 22;
goto return_label;
}
}
FD_ZERO(& read_fds);
FD_ZERO(& write_fds);
if (readfds) {
ret = cgc_copy_cgc_fd_set((fd_set const *)readfds,& read_fds,
& actual_num_fds);
if (0 != ret) {
__retres = ret;
goto return_label;
}
}
if (writefds) {
ret = cgc_copy_cgc_fd_set((fd_set const *)writefds,& write_fds,
& actual_num_fds);
if (0 != ret) {
__retres = ret;
goto return_label;
}
}
if (actual_num_fds != nfds) {
__retres = 22;
goto return_label;
}
if (readfds) FD_ZERO(readfds);
if (writefds) FD_ZERO(writefds);
if (timeout) {
max_wait_time.tv_sec = timeout->tv_sec;
max_wait_time.tv_usec = timeout->tv_usec;
}
if (timeout) tmp_0 = & max_wait_time; else tmp_0 = (struct timeval *)0;
if (writefds) tmp_1 = & write_fds; else tmp_1 = (fd_set *)0;
if (readfds) tmp_2 = & read_fds; else tmp_2 = (fd_set *)0;
;
tmp_3 = select(nfds,tmp_2,tmp_1,(fd_set *)0,tmp_0);
int num_selected_fds = tmp_3;
if (num_selected_fds < 0) {
__retres = __fc_errno;
goto return_label;
}
if (readfds) cgc_copy_os_fd_set((fd_set const *)(& read_fds),readfds);
if (writefds) cgc_copy_os_fd_set((fd_set const *)(& write_fds),writefds);
if (readyfds) *readyfds = num_selected_fds;
__retres = 0;
return_label: return __retres;
}
int cgc_allocate(size_t length, int is_executable, void **addr)
{
int __retres;
int page_perms = 0x1 | 0x2;
if (is_executable) page_perms |= 0x4;
void *return_address =
mmap((void *)0,length,page_perms,0x20 | 0x02,-1,(long)0);
if (return_address == (void *)(-1)) {
__retres = __fc_errno;
goto return_label;
}
if (addr) *addr = return_address;
memset(return_address,0,length);
__retres = 0;
return_label: return __retres;
}
int cgc_deallocate(void *addr, size_t length)
{
int __retres;
int const ret = munmap(addr,length);
if (ret < 0) {
__retres = __fc_errno;
goto return_label;
}
__retres = 0;
return_label: return __retres;
}
static cgc_prng_0 *cgc_internal_prng = (cgc_prng_0 *)0;
/*@ requires valid_read_string(s);
requires valid_read_string(format);
requires \valid(param0);
ensures \initialized(param0);
assigns \result, *param0;
assigns \result
\from (indirect: *(s + (0 ..))), (indirect: *(format + (0 ..)));
assigns *param0
\from (indirect: *(s + (0 ..))), (indirect: *(format + (0 ..)));
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
int sscanf_va_1(char const * __restrict s, char const * __restrict format,
unsigned char *param0);
static void cgc_try_init_prng(void)
{
if (cgc_internal_prng != (cgc_prng_0 *)0) goto return_label;
uint8_t prng_seed[16 * 3] =
{(unsigned char)0x73,
(unsigned char)0x65,
(unsigned char)0x65,
(unsigned char)0x64,
(unsigned char)0x73,
(unsigned char)0x65,
(unsigned char)0x65,
(unsigned char)0x64,
(unsigned char)0x73,
(unsigned char)0x65,
(unsigned char)0x65,
(unsigned char)0x64,
(unsigned char)0x73,
(unsigned char)0x65,
(unsigned char)0x65,
(unsigned char)0x64,
(unsigned char)0x30,
(unsigned char)0x31,
(unsigned char)0x32,
(unsigned char)0x33,
(unsigned char)0x34,
(unsigned char)0x35,
(unsigned char)0x36,
(unsigned char)0x37,
(unsigned char)0x38,
(unsigned char)0x39,
(unsigned char)0x61,
(unsigned char)0x62,
(unsigned char)0x63,
(unsigned char)0x64,
(unsigned char)0x65,
(unsigned char)0x66,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00,
(unsigned char)0x00};
char const *prng_seed_hex = getenv("seed");
if (prng_seed_hex != (char const *)0) {
size_t tmp_0;
tmp_0 = strlen(prng_seed_hex);
if (tmp_0 == (size_t)((16 * 3) * 2)) {
char const *pos = prng_seed_hex;
{
int i = 0;
while (i < 16 * 3) {
sscanf_va_1(pos,"%2hhx",(unsigned char *)(& prng_seed[i]));
pos += 2;
i ++;
}
}
}
}
cgc_internal_prng = (cgc_prng_0 *)malloc(sizeof(cgc_prng_0));
cgc_aes_state *seed = (cgc_aes_state *)(prng_seed);
cgc_init_prng(cgc_internal_prng,(cgc_aes_state const *)seed);
return_label: return;
}
int cgc_random(void *buf, size_t count, size_t *rnd_bytes)
{
int __retres;
cgc_try_init_prng();
cgc_aes_get_bytes(cgc_internal_prng,count,(uint8_t *)buf);
if (rnd_bytes) *rnd_bytes = count;
__retres = 0;
return __retres;
}
/*@ assigns \nothing; */
static void cgc_initialize_flag_page(void) __attribute__((__constructor__));
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
void cgc_Push(t3DCPixel **px_list_0, t3DCPixel *px);
void cgc_RunTask(t3DCPixel **px_list_0,
void (*exec_task)(t3DCPixel *, int16_t ), int16_t fptr_arg);
void cgc_ReadFile(t3DCPixel **px_list_0);
void cgc_NewFile(t3DCPixel **px_list_0, char *buf);
void cgc_ShowPixel(t3DCPixel *px);
void cgc_CheckFile(t3DCPixel **px, int16_t num);
void cgc_RotateX(t3DCPixel *px, int16_t degree);
void cgc_RotateY(t3DCPixel *px, int16_t degree);
void cgc_RotateZ(t3DCPixel *px, int16_t degree);
void cgc_SkewX(t3DCPixel *px, int16_t skew_val);
void cgc_SkewY(t3DCPixel *px, int16_t skew_val);
void cgc_SkewZ(t3DCPixel *px, int16_t skew_val);
void cgc_Scale(t3DCPixel *px, int16_t scale_val);
void cgc_Brightness(t3DCPixel *px, int16_t bright_val);
void cgc_Opacity(t3DCPixel *px, int16_t opacity_val);
int32_t cgc_multiply(double a, double b);
int16_t cgc_divide(double a, double b);
int16_t cgc_degree_to_radian(int16_t degree);
void cgc_Push(t3DCPixel **px_list_0, t3DCPixel *px)
{
int i;
if (px == (t3DCPixel *)0) goto return_label;
if (px_list_0 == (t3DCPixel **)0) goto return_label;
t3DCPixel *new = malloc(sizeof(t3DCPixel));
memcpy((void *)new,(void const *)px,sizeof(t3DCPixel));
i = 0;
while ((unsigned int)i <= (unsigned int)4096 / sizeof(t3DCPixel)) {
if (*(px_list_0 + i) == (t3DCPixel *)0) {
*(px_list_0 + i) = new;
break;
}
i ++;
}
return_label: return;
}
void cgc_RunTask(t3DCPixel **px_list_0,
void (*exec_task)(t3DCPixel *, int16_t ), int16_t fptr_arg)
{
int16_t count = (short)((unsigned int)4096 / sizeof(t3DCPixel));
int16_t i = (short)0;
while (1) {
int16_t tmp_0;
tmp_0 = count;
count = (int16_t)((int)count - 1);
;
if (! tmp_0) break;
{
int16_t tmp;
;
tmp = i;
i = (int16_t)((int)i + 1);
;
(*exec_task)(*(px_list_0 + tmp),fptr_arg);
}
}
return;
}
void cgc_ReadFile(t3DCPixel **px_list_0)
{
t3DCPixel *px;
int32_t dataSize = 4096;
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
uint32_t offset = (unsigned int)0;
while (dataSize > 0) {
uint32_t tmp;
uint32_t tmp_0;
uint32_t tmp_1;
uint32_t tmp_2;
uint32_t tmp_3;
uint32_t tmp_4;
uint32_t tmp_5;
px = (t3DCPixel *)malloc(sizeof(t3DCPixel));
tmp = cgc_prng();
px->x = (short)tmp;
tmp_0 = cgc_prng();
px->y = (short)tmp_0;
tmp_1 = cgc_prng();
px->z = (short)tmp_1;
tmp_2 = cgc_prng();
px->r = (unsigned char)tmp_2;
tmp_3 = cgc_prng();
px->g = (unsigned char)tmp_3;
tmp_4 = cgc_prng();
px->b = (unsigned char)tmp_4;
tmp_5 = cgc_prng();
px->a = (unsigned char)tmp_5;
cgc_Push(px_list_0,px);
dataSize = (int)((unsigned int)dataSize - sizeof(t3DCPixel));
free((void *)px);
}
return;
}
/*@ requires valid_read_string(format);
assigns \result, __fc_stdout->__fc_FILE_data;
assigns \result
\from (indirect: __fc_stdout->__fc_FILE_id),
(indirect: __fc_stdout->__fc_FILE_data),
(indirect: *(format + (0 ..))), (indirect: param0);
assigns __fc_stdout->__fc_FILE_data
\from (indirect: __fc_stdout->__fc_FILE_id),
__fc_stdout->__fc_FILE_data, (indirect: *(format + (0 ..))),
param0;
*/
int printf_va_1(char const * __restrict format, int param0);
/*@ requires valid_read_string(format);
assigns \result, __fc_stdout->__fc_FILE_data;
assigns \result
\from (indirect: __fc_stdout->__fc_FILE_id),
(indirect: __fc_stdout->__fc_FILE_data),
(indirect: *(format + (0 ..)));
assigns __fc_stdout->__fc_FILE_data
\from (indirect: __fc_stdout->__fc_FILE_id),
__fc_stdout->__fc_FILE_data, (indirect: *(format + (0 ..)));
*/
int printf_va_2(char const * __restrict format);
void cgc_NewFile(t3DCPixel **px_list_0, char *buf)
{
t3DCPixel *tmp;
uint16_t maxSize =
(unsigned short)(((unsigned int)4096 / sizeof(t3DCPixel)) * sizeof(t3DCPixel));
printf_va_1("Please submit your new file data (%hd bytes):\n",(int)maxSize);
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
uint16_t offset = (unsigned short)0;
uint16_t i = (unsigned short)0;
while ((int)offset < (int)maxSize) {
uint16_t tmp_0;
tmp_0 = i;
i = (uint16_t)((int)i + 1);
tmp = *(px_list_0 + tmp_0);
memcpy((void *)(& tmp->x),(void const *)(buf + (int)offset),
sizeof(int16_t));
offset = (unsigned short)((unsigned int)offset + sizeof(int16_t));
memcpy((void *)(& tmp->y),(void const *)(buf + (int)offset),
sizeof(int16_t));
offset = (unsigned short)((unsigned int)offset + sizeof(int16_t));
memcpy((void *)(& tmp->z),(void const *)(buf + (int)offset),
sizeof(int16_t));
offset = (unsigned short)((unsigned int)offset + sizeof(int16_t));
memcpy((void *)(& tmp->r),(void const *)(buf + (int)offset),
sizeof(uint8_t));
offset = (unsigned short)((unsigned int)offset + sizeof(uint8_t));
memcpy((void *)(& tmp->g),(void const *)(buf + (int)offset),
sizeof(uint8_t));
offset = (unsigned short)((unsigned int)offset + sizeof(uint8_t));
memcpy((void *)(& tmp->b),(void const *)(buf + (int)offset),
sizeof(uint8_t));
offset = (unsigned short)((unsigned int)offset + sizeof(uint8_t));
memcpy((void *)(& tmp->a),(void const *)(buf + (int)offset),
sizeof(uint8_t));
offset = (unsigned short)((unsigned int)offset + sizeof(uint8_t));
}
printf_va_2("New file loaded\n");
return;
}
/*@ requires valid_read_string(format);
assigns \result, __fc_stdout->__fc_FILE_data;
assigns \result
\from (indirect: __fc_stdout->__fc_FILE_id),
(indirect: __fc_stdout->__fc_FILE_data),
(indirect: *(format + (0 ..))), (indirect: param2),
(indirect: param1), (indirect: param0);
assigns __fc_stdout->__fc_FILE_data
\from (indirect: __fc_stdout->__fc_FILE_id),
__fc_stdout->__fc_FILE_data, (indirect: *(format + (0 ..))),
param2, param1, param0;
*/
int printf_va_3(char const * __restrict format, int param0, int param1,
int param2);
/*@ requires valid_read_string(format);
assigns \result, __fc_stdout->__fc_FILE_data;
assigns \result
\from (indirect: __fc_stdout->__fc_FILE_id),
(indirect: __fc_stdout->__fc_FILE_data),
(indirect: *(format + (0 ..))), (indirect: param3),
(indirect: param2), (indirect: param1), (indirect: param0);
assigns __fc_stdout->__fc_FILE_data
\from (indirect: __fc_stdout->__fc_FILE_id),
__fc_stdout->__fc_FILE_data, (indirect: *(format + (0 ..))),
param3, param2, param1, param0;
*/
int printf_va_4(char const * __restrict format, int param0, int param1,
int param2, int param3);
/*@ requires valid_read_string(format);
assigns \result, __fc_stdout->__fc_FILE_data;
assigns \result
\from (indirect: __fc_stdout->__fc_FILE_id),
(indirect: __fc_stdout->__fc_FILE_data),
(indirect: *(format + (0 ..)));
assigns __fc_stdout->__fc_FILE_data
\from (indirect: __fc_stdout->__fc_FILE_id),
__fc_stdout->__fc_FILE_data, (indirect: *(format + (0 ..)));
*/
int printf_va_5(char const * __restrict format);
void cgc_ShowPixel(t3DCPixel *px)
{
printf_va_3("XYZ: (%d, %d, %d)\n",(int)px->x,(int)px->y,(int)px->z);
printf_va_4("RGBA: (#%02hx%02hx%02hx%02hx)\n",(int)px->r,(int)px->g,
(int)px->b,(int)px->a);
printf_va_5("\n");
return;
}
/*@ requires valid_read_string(format);
assigns \result, __fc_stdout->__fc_FILE_data;
assigns \result
\from (indirect: __fc_stdout->__fc_FILE_id),
(indirect: __fc_stdout->__fc_FILE_data),
(indirect: *(format + (0 ..))), (indirect: param2),
(indirect: param1), (indirect: param0);
assigns __fc_stdout->__fc_FILE_data
\from (indirect: __fc_stdout->__fc_FILE_id),
__fc_stdout->__fc_FILE_data, (indirect: *(format + (0 ..))),
param2, param1, param0;
*/
int printf_va_6(char const * __restrict format, int param0, int param1,
int param2);
/*@ requires valid_read_string(format);
assigns \result, __fc_stdout->__fc_FILE_data;
assigns \result
\from (indirect: __fc_stdout->__fc_FILE_id),
(indirect: __fc_stdout->__fc_FILE_data),
(indirect: *(format + (0 ..))), (indirect: param3),
(indirect: param2), (indirect: param1), (indirect: param0);
assigns __fc_stdout->__fc_FILE_data
\from (indirect: __fc_stdout->__fc_FILE_id),
__fc_stdout->__fc_FILE_data, (indirect: *(format + (0 ..))),
param3, param2, param1, param0;
*/
int printf_va_7(char const * __restrict format, int param0, int param1,
int param2, int param3);
/*@ requires valid_read_string(format);
assigns \result, __fc_stdout->__fc_FILE_data;
assigns \result
\from (indirect: __fc_stdout->__fc_FILE_id),
(indirect: __fc_stdout->__fc_FILE_data),
(indirect: *(format + (0 ..)));
assigns __fc_stdout->__fc_FILE_data
\from (indirect: __fc_stdout->__fc_FILE_id),
__fc_stdout->__fc_FILE_data, (indirect: *(format + (0 ..)));
*/
int printf_va_8(char const * __restrict format);
void cgc_CheckFile(t3DCPixel **px, int16_t num)
{
if (px == (t3DCPixel **)0) goto return_label;
{
int i = 0;
while (i < (int)num) {
printf_va_6("XYZ: (%d, %d, %d)\n",(int)(*(px + i))->x,
(int)(*(px + i))->y,(int)(*(px + i))->z);
printf_va_7("RGBA: (#%02hx%02hx%02hx%02hx)\n",(int)(*(px + i))->r,
(int)(*(px + i))->g,(int)(*(px + i))->b,
(int)(*(px + i))->a);
printf_va_8("\n");
i ++;
}
}
return_label: return;
}
void cgc_RotateX(t3DCPixel *px, int16_t degree)
{
int16_t tmp;
int32_t tmp_1;
double tmp_0;
int32_t tmp_3;
double tmp_2;
int32_t tmp_5;
double tmp_4;
int32_t tmp_7;
double tmp_6;
tmp = cgc_degree_to_radian(degree);
double a = (double)tmp;
tmp_0 = cos(a);
;
tmp_1 = cgc_multiply((double)px->y,tmp_0);
tmp_2 = sin(a);
;
tmp_3 = cgc_multiply((double)px->z,tmp_2);
px->y = (short)((int)((short)tmp_1) - tmp_3);
tmp_4 = sin(a);
;
tmp_5 = cgc_multiply((double)px->y,tmp_4);
tmp_6 = cos(a);
;
tmp_7 = cgc_multiply((double)px->z,tmp_6);
px->z = (short)((int)((short)tmp_5) + tmp_7);
return;
}
void cgc_RotateY(t3DCPixel *px, int16_t degree)
{
int16_t tmp;
int32_t tmp_1;
double tmp_0;
int32_t tmp_3;
double tmp_2;
int32_t tmp_5;
double tmp_4;
int32_t tmp_7;
double tmp_6;
tmp = cgc_degree_to_radian(degree);
double a = (double)tmp;
tmp_0 = sin(a);
;
tmp_1 = cgc_multiply((double)px->z,tmp_0);
tmp_2 = cos(a);
;
tmp_3 = cgc_multiply((double)px->x,tmp_2);
px->x = (short)((int)((short)tmp_1) + tmp_3);
tmp_4 = cos(a);
;
tmp_5 = cgc_multiply((double)px->z,tmp_4);
tmp_6 = sin(a);
;
tmp_7 = cgc_multiply((double)px->x,tmp_6);
px->z = (short)((int)((short)tmp_5) - tmp_7);
return;
}
void cgc_RotateZ(t3DCPixel *px, int16_t degree)
{
int16_t tmp;
int32_t tmp_1;
double tmp_0;
int32_t tmp_3;
double tmp_2;
int32_t tmp_5;
double tmp_4;
int32_t tmp_7;
double tmp_6;
tmp = cgc_degree_to_radian(degree);
double a = (double)tmp;
tmp_0 = cos(a);
;
tmp_1 = cgc_multiply((double)px->x,tmp_0);
tmp_2 = sin(a);
;
tmp_3 = cgc_multiply((double)px->y,tmp_2);
px->x = (short)((int)((short)tmp_1) - tmp_3);
tmp_4 = sin(a);
;
tmp_5 = cgc_multiply((double)px->x,tmp_4);
tmp_6 = cos(a);
;
tmp_7 = cgc_multiply((double)px->y,tmp_6);
px->y = (short)((int)((short)tmp_5) + tmp_7);
return;
}
void cgc_SkewX(t3DCPixel *px, int16_t skew_val)
{
px->x = (short)((int)skew_val + (int)px->x);
return;
}
void cgc_SkewY(t3DCPixel *px, int16_t skew_val)
{
px->y = (short)((int)px->y + (int)skew_val);
return;
}
void cgc_SkewZ(t3DCPixel *px, int16_t skew_val)
{
px->z = (short)((int)px->z + (int)skew_val);
return;
}
void cgc_Scale(t3DCPixel *px, int16_t scale_val)
{
int16_t tmp;
int32_t tmp_x;
int32_t tmp_y;
int32_t tmp_z;
if ((int)scale_val < 1) goto _LOR;
else
if ((int)scale_val > 200) _LOR: goto return_label;
tmp = cgc_divide((double)scale_val,(double)100);
double percent = (double)tmp;
tmp_x = cgc_multiply((double)px->x,percent);
tmp_y = cgc_multiply((double)px->y,percent);
tmp_z = cgc_multiply((double)px->z,percent);
if (tmp_x > 0xffff)
if ((int)px->x < 0) px->x = (short)(-32768); else px->x = (short)32767;
else px->x = (short)tmp_x;
if (tmp_y > 0xffff)
if ((int)px->y < 0) px->y = (short)(-32768); else px->y = (short)32767;
else px->y = (short)tmp_y;
if (tmp_z > 0xffff)
if ((int)px->z < 0) px->z = (short)(-32768); else px->z = (short)32767;
else px->z = (short)tmp_z;
return_label: return;
}
void cgc_Brightness(t3DCPixel *px, int16_t bright_val)
{
int16_t new_r;
int16_t new_g;
int16_t new_b;
if ((int)bright_val < -255) goto _LOR;
else
if ((int)bright_val > 255) _LOR: goto return_label;
new_r = (short)((int)px->r + (int)bright_val);
new_g = (short)((int)px->g + (int)bright_val);
new_b = (short)((int)px->b + (int)bright_val);
if ((int)new_r > 255) px->r = (unsigned char)255;
else
if ((int)new_r < 0) px->r = (unsigned char)0;
else px->r = (unsigned char)new_r;
if ((int)new_g > 255) px->g = (unsigned char)255;
else
if ((int)new_g < 0) px->g = (unsigned char)0;
else px->g = (unsigned char)new_g;
if ((int)new_b > 255) px->b = (unsigned char)255;
else
if ((int)new_b < 0) px->b = (unsigned char)0;
else px->b = (unsigned char)new_b;
return_label: return;
}
void cgc_Opacity(t3DCPixel *px, int16_t opacity_val)
{
px->a = (unsigned char)opacity_val;
return;
}
int32_t cgc_multiply(double a, double b)
{
int32_t __retres;
__retres = (int)(a * b);
return __retres;
}
int16_t cgc_divide(double a, double b)
{
int16_t __retres;
__retres = (short)(a / b);
return __retres;
}
int16_t cgc_degree_to_radian(int16_t degree)
{
int16_t __retres;
int32_t tmp_0;
int16_t tmp;
tmp = cgc_divide(0x1.921fb54442d18p1,(double)180);
;
tmp_0 = cgc_multiply((double)degree,(double)tmp);
__retres = (short)tmp_0;
return __retres;
}
uint8_t cgc_ClosestMatch(uint8_t type, int16_t val);
void cgc_Compress(t3DCPixel **px_list_0, uint8_t *compressed_data,
uint16_t *data_len);
void cgc_Decompress(uint8_t *in_data, uint8_t *out_data, uint16_t *data_len);
void cgc_WriteOut(t3DCPixel **px_list_0, uint8_t *data, uint16_t data_len);
int red_blue[8] = {0x00, 0x20, 0x40, 0x60, 0xA0, 0xC0, 0xE0, 0xFF};
int green[4] = {0x00, 0x60, 0xB0, 0xFF};
uint8_t cgc_ClosestMatch(uint8_t type, int16_t val)
{
int tmp;
int i;
uint8_t close_diff = (unsigned char)0xff;
uint8_t temp_diff = (unsigned char)0;
if ((int)type == R) tmp = 8;
else
if ((int)type == B) tmp = 8; else tmp = 4;
uint8_t max_idx = (unsigned char)tmp;
uint8_t close_idx = max_idx;
i = 0;
while (i < (int)max_idx) {
if ((int)type == R) goto _LOR;
else
if ((int)type == B)
_LOR:
if ((int)val - red_blue[i] < 0) temp_diff = (unsigned char)(- (
(int)val - red_blue[i]));
else temp_diff = (unsigned char)((int)val - red_blue[i]);
else
if ((int)val - green[i] < 0) temp_diff = (unsigned char)(- ((int)val - green[i]));
else temp_diff = (unsigned char)((int)val - green[i]);
if ((int)temp_diff < (int)close_diff) {
close_diff = temp_diff;
close_idx = (unsigned char)i;
}
i ++;
}
return close_idx;
}
void cgc_Compress(t3DCPixel **px_list_0, uint8_t *compressed_data,
uint16_t *data_len)
{
if (px_list_0 == (t3DCPixel **)0) goto return_label;
uint8_t color = (unsigned char)0;
uint8_t coord = (unsigned char)0;
t3DCPixel *px = (t3DCPixel *)0;
uint16_t count =
(unsigned short)(((unsigned int)4096 / sizeof(t3DCPixel)) * (unsigned int)7);
uint16_t i = (unsigned short)0;
int p_idx = 0;
while ((int)i < (int)count) {
int tmp;
uint8_t tmp_0;
uint8_t tmp_1;
uint8_t tmp_2;
color = (unsigned char)0;
tmp = p_idx;
p_idx ++;
px = *(px_list_0 + tmp);
tmp_0 = cgc_ClosestMatch((unsigned char)R,(short)px->r);
color = (unsigned char)((int)color + ((int)tmp_0 << 5));
tmp_1 = cgc_ClosestMatch((unsigned char)G,(short)px->g);
color = (unsigned char)((int)color + ((int)tmp_1 << 3));
tmp_2 = cgc_ClosestMatch((unsigned char)B,(short)px->b);
color = (unsigned char)((int)color + ((int)tmp_2 << 0));
memcpy((void *)(compressed_data + (int)i),(void const *)(& px->x),
sizeof(int16_t));
i = (unsigned short)((unsigned int)i + sizeof(int16_t));
memcpy((void *)(compressed_data + (int)i),(void const *)(& px->y),
sizeof(int16_t));
i = (unsigned short)((unsigned int)i + sizeof(int16_t));
memcpy((void *)(compressed_data + (int)i),(void const *)(& px->z),
sizeof(int16_t));
i = (unsigned short)((unsigned int)i + sizeof(int16_t));
memcpy((void *)(compressed_data + (int)i),(void const *)(& color),
(unsigned int)1);
i = (uint16_t)((int)i + 1);
}
memcpy((void *)data_len,(void const *)(& i),(unsigned int)2);
return_label: return;
}
void cgc_Decompress(uint8_t *in_data, uint8_t *out_data, uint16_t *data_len)
{
uint8_t color;
uint8_t r;