2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
19 #include <SDL_byteorder.h>
21 /*---------------------------------------------------------------------------*/
23 void put_float(FILE *fout, const float *f)
25 unsigned char *p = (unsigned char *) f;
27 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
28 fputc((int) p[3], fout);
29 fputc((int) p[2], fout);
30 fputc((int) p[1], fout);
31 fputc((int) p[0], fout);
33 fputc((int) p[0], fout);
34 fputc((int) p[1], fout);
35 fputc((int) p[2], fout);
36 fputc((int) p[3], fout);
40 void put_index(FILE *fout, const int *i)
42 unsigned char *p = (unsigned char *) i;
44 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
45 fputc((int) p[3], fout);
46 fputc((int) p[2], fout);
47 fputc((int) p[1], fout);
48 fputc((int) p[0], fout);
50 fputc((int) p[0], fout);
51 fputc((int) p[1], fout);
52 fputc((int) p[2], fout);
53 fputc((int) p[3], fout);
57 void put_array(FILE *fout, const float *v, size_t n)
61 for (i = 0; i < n; i++)
62 put_float(fout, v + i);
65 /*---------------------------------------------------------------------------*/
67 void get_float(FILE *fin, float *f)
69 unsigned char *p = (unsigned char *) f;
71 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
72 p[3] = (unsigned char) fgetc(fin);
73 p[2] = (unsigned char) fgetc(fin);
74 p[1] = (unsigned char) fgetc(fin);
75 p[0] = (unsigned char) fgetc(fin);
77 p[0] = (unsigned char) fgetc(fin);
78 p[1] = (unsigned char) fgetc(fin);
79 p[2] = (unsigned char) fgetc(fin);
80 p[3] = (unsigned char) fgetc(fin);
84 void get_index(FILE *fin, int *i)
86 unsigned char *p = (unsigned char *) i;
88 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
89 p[3] = (unsigned char) fgetc(fin);
90 p[2] = (unsigned char) fgetc(fin);
91 p[1] = (unsigned char) fgetc(fin);
92 p[0] = (unsigned char) fgetc(fin);
94 p[0] = (unsigned char) fgetc(fin);
95 p[1] = (unsigned char) fgetc(fin);
96 p[2] = (unsigned char) fgetc(fin);
97 p[3] = (unsigned char) fgetc(fin);
101 void get_array(FILE *fin, float *v, size_t n)
105 for (i = 0; i < n; i++)
106 get_float(fin, v + i);
109 /*---------------------------------------------------------------------------*/