]>
iEval git - xfishtank.git/blob - ppmtofish/fishtoppm.c
8 unsigned int red
, green
, blue
;
12 WritePPM(char *outfile
, unsigned char *data
, int width
, int height
, struct rgb_color
*colrs
)
17 if ((fp
= fopen(outfile
, "w")) == NULL
)
19 fprintf(fp
, "P6\n%d %d\n255\n", width
, height
);
20 for (i
= 0; i
< width
* height
; i
++) {
21 fputc(colrs
[data
[i
]].red
, fp
);
22 fputc(colrs
[data
[i
]].green
, fp
);
23 fputc(colrs
[data
[i
]].blue
, fp
);
29 ReadFish(fp
, w
, h
, colrs
, filename
)
32 struct rgb_color
*colrs
;
43 for (i
= 0; i
< 4; i
++) {
44 fscanf(fp
, "%s %s %d\n", junk
, name
, &val
);
45 cptr
= strrchr(name
, '_');
52 if (strcmp(cptr
, "width") == 0) {
54 } else if (strcmp(cptr
, "height") == 0) {
56 } else if (strcmp(cptr
, "colors") == 0) {
61 cptr
= strrchr(name
, '_');
66 strcpy(filename
, name
);
73 for (i
= 0; i
< scale
; i
++) {
74 fscanf(fp
, " %d", &val
);
75 colrs
[i
].red
= val
/ 256;
83 for (i
= 0; i
< scale
; i
++) {
84 fscanf(fp
, " %d", &val
);
85 colrs
[i
].green
= val
/ 256;
93 for (i
= 0; i
< scale
; i
++) {
94 fscanf(fp
, " %d", &val
);
95 colrs
[i
].blue
= val
/ 256;
99 for (i
= scale
; i
< MAXCOLORS
; i
++) {
109 data
= (unsigned char *) malloc(2 * (*w
) * (*h
));
111 for (i
= 0; i
< ((*w
) * (*h
)); i
++) {
112 fscanf(fp
, " 0x%x", &val
);
113 *ptr
++ = (unsigned char) val
;
121 for (i
= 0; i
< ((*w
) * (*h
)); i
++) {
122 fscanf(fp
, " 0x%x", &val
);
123 *ptr
++ = (unsigned char) val
;
138 struct rgb_color colrs
[MAXCOLORS
];
140 unsigned char *data1
;
141 unsigned char *data2
;
149 fprintf(stderr
, "Usage: %s <fish.h> [<outprefix>]\n", argv
[0]);
153 ifd
= fopen(argv
[1], "r");
155 fprintf(stderr
, "Error: cannot open (%s) for read\n", argv
[1]);
159 data
= ReadFish(ifd
, &width
, &height
, colrs
, outname
);
163 data1
= (unsigned char *) malloc(width
* height
);
165 for (i
= 0; i
< (width
* height
); i
++) {
169 data2
= (unsigned char *) malloc(width
* height
);
171 for (i
= 0; i
< (width
* height
); i
++) {
176 strcpy(outname
, argv
[2]);
179 sprintf(outfile
, "%s_1.ppm", outname
);
181 WritePPM(outfile
, data1
, width
, height
, colrs
);
183 sprintf(outfile
, "%s_2.ppm", outname
);
185 WritePPM(outfile
, data2
, width
, height
, colrs
);
This page took 0.04395 seconds and 4 git commands to generate.