Waitrud Weber’s blog

things and reminders for memories

3d: windows-make: PPM start is better.

We are going to use buffer anyway for the sensitive work so that we could start to use simple format and start the PPM format.

 

.\vDisplayController_002.cpp Sat Mar 26 16:01:16 2022
...
40 ://
41 :int vDisplayController_002::write_ppm_002 (char* filename, float*** img, int width, int height, int flag) {
42 : int i, j;
43 : FILE *fp;
44 : FILE *start_fp;
45 : char w[1];
46 : char head[128];
47 : int count = 0, index = 0;
48 :
49 : printf("int write_ppm_002 starts.\n");
50 :
51 :
52 : for ( i = 0; i<128; i++ )
53 : head[i] = 0;
54 :
55 : fp = fopen ( (char*) filename, "wb" );
56 : start_fp = fp;
57 :
58 : sprintf( head, "P6\r%d %d\r%d\r", width, height, 255 );
59 :
60 : // count the buffer.
61 : for ( i = 0; i<128; i++ ) {
62 : if ( head[i] == '\r' )
63 : count++;
64 :
65 : if ( count == 3 ) {
66 : index = i;
67 : break;
68 : }
69 : }
70 :
71 : printf("index %d flag %d filename %s\n", index, flag, filename );
72 : printf("start|fp| to |fp| = |%p| to |%p|\n", start_fp, fp);
73 :
74 : fwrite( (char*)head, 128, index, fp );
75 :
76 : printf("start|fp| to |fp| = |%p| to |%p|\n", start_fp, fp);
77 :
78 : if ( flag == 1 ) {
79 : for ( j = 0; j< height; j++ ) {
80 : for ( i = 0; i< width; i++ ) {
81 : printf(" i, j = %d, %d\n", i, j );
82 : w[0] = 255.0f * img[j][i][0];
83 : fwrite( (char*) w, 1, 1, fp );
84 : w[0] = 255.0f * img[j][i][1];
85 : fwrite( (char*) w, 1, 1, fp );
86 : w[0] = 255.0f * img[j][i][2];
87 : fwrite( (char*) w, 1, 1, fp );
88 : }
89 : }
90 : } else if ( flag == 0 ) {
91 : printf("We are going to Print the message in the header.\n");
92 : fprintf(fp, "#Print Only Header flag %d.\n", flag);
93 : }
94 :
95 : printf("start|fp| to |fp| = |%p| to |%p|\n", start_fp, fp);
96 : fclose (fp);
97 :
98 : printf("int write_ppm_002 ends. fp=|%p|\n", fp);
99 :
00 : return 0;
01 :}
02 :

 

*

willinglytranslate.blogspot.com