2
* The 3D Studio File Format Library
3
* Copyright (C) 1996-2001 by J.E. Hoffmann <je-h@gmx.net>
6
* This program is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; either version 2.1 of the License, or (at
9
* your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14
* License for more details.
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program; if not, write to the Free Software Foundation,
18
* Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
* $Id: background.cpp 1563 2003-01-24 15:12:54Z robert $
23
#include "background.h"
25
#include "readwrite.h"
31
* \defgroup background Background Settings
33
* \author J.E. Hoffmann <je-h@gmx.net>
38
solid_bgnd_read(Lib3dsBackground *background, FILE *f)
43
if (!lib3ds_chunk_read_start(&c, LIB3DS_SOLID_BGND, f)) {
47
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
49
case LIB3DS_LIN_COLOR_F:
50
lib3ds_rgb_read(background->solid.col, f);
53
lib3ds_rgb_read(background->solid.col, f);
56
lib3ds_chunk_unknown(chunk);
60
lib3ds_chunk_read_end(&c, f);
66
v_gradient_read(Lib3dsBackground *background, FILE *f)
75
if (!lib3ds_chunk_read_start(&c, LIB3DS_V_GRADIENT, f)) {
78
background->gradient.percent=lib3ds_float_read(f);
79
lib3ds_chunk_read_tell(&c, f);
82
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
85
lib3ds_rgb_read(col[0][index[0]],f);
88
case LIB3DS_LIN_COLOR_F:
89
lib3ds_rgb_read(col[1][index[1]],f);
94
lib3ds_chunk_unknown(chunk);
100
background->gradient.top[i]=col[have_lin][0][i];
101
background->gradient.middle[i]=col[have_lin][1][i];
102
background->gradient.bottom[i]=col[have_lin][2][i];
105
lib3ds_chunk_read_end(&c, f);
111
* \ingroup background
114
lib3ds_background_read(Lib3dsBackground *background, FILE *f)
118
if (!lib3ds_chunk_read(&c, f)) {
119
return(LIB3DS_FALSE);
125
if (!lib3ds_string_read(background->bitmap.name, 64, f)) {
126
return(LIB3DS_FALSE);
130
case LIB3DS_SOLID_BGND:
132
lib3ds_chunk_read_reset(&c, f);
133
if (!solid_bgnd_read(background, f)) {
134
return(LIB3DS_FALSE);
138
case LIB3DS_V_GRADIENT:
140
lib3ds_chunk_read_reset(&c, f);
141
if (!v_gradient_read(background, f)) {
142
return(LIB3DS_FALSE);
146
case LIB3DS_USE_BIT_MAP:
148
background->bitmap.use=LIB3DS_TRUE;
151
case LIB3DS_USE_SOLID_BGND:
153
background->solid.use=LIB3DS_TRUE;
156
case LIB3DS_USE_V_GRADIENT:
158
background->gradient.use=LIB3DS_TRUE;
168
colorf_write(Lib3dsRgba rgb, FILE *f)
172
c.chunk=LIB3DS_COLOR_F;
174
lib3ds_chunk_write(&c,f);
175
lib3ds_rgb_write(rgb,f);
177
c.chunk=LIB3DS_LIN_COLOR_F;
179
lib3ds_chunk_write(&c,f);
180
lib3ds_rgb_write(rgb,f);
186
colorf_defined(Lib3dsRgba rgb)
189
for (i=0; i<3; ++i) {
190
if (fabs(rgb[i])>LIB3DS_EPSILON) {
199
* \ingroup background
202
lib3ds_background_write(Lib3dsBackground *background, FILE *f)
204
if (strlen(background->bitmap.name)) { /*---- LIB3DS_BIT_MAP ----*/
206
c.chunk=LIB3DS_BIT_MAP;
207
c.size=6+1+strlen(background->bitmap.name);
208
lib3ds_chunk_write(&c,f);
209
lib3ds_string_write(background->bitmap.name, f);
212
if (colorf_defined(background->solid.col)) { /*---- LIB3DS_SOLID_BGND ----*/
214
c.chunk=LIB3DS_SOLID_BGND;
216
lib3ds_chunk_write(&c,f);
217
colorf_write(background->solid.col,f);
220
if (colorf_defined(background->gradient.top) ||
221
colorf_defined(background->gradient.middle) ||
222
colorf_defined(background->gradient.bottom)) { /*---- LIB3DS_V_GRADIENT ----*/
224
c.chunk=LIB3DS_V_GRADIENT;
226
lib3ds_chunk_write(&c,f);
227
lib3ds_float_write(background->gradient.percent,f);
228
colorf_write(background->gradient.top,f);
229
colorf_write(background->gradient.middle,f);
230
colorf_write(background->gradient.bottom,f);
233
if (background->bitmap.use) { /*---- LIB3DS_USE_BIT_MAP ----*/
235
c.chunk=LIB3DS_USE_BIT_MAP;
237
lib3ds_chunk_write(&c,f);
240
if (background->solid.use) { /*---- LIB3DS_USE_SOLID_BGND ----*/
242
c.chunk=LIB3DS_USE_SOLID_BGND;
244
lib3ds_chunk_write(&c,f);
247
if (background->gradient.use) { /*---- LIB3DS_USE_V_GRADIENT ----*/
249
c.chunk=LIB3DS_USE_V_GRADIENT;
251
lib3ds_chunk_write(&c,f);
260
\typedef Lib3dsBackground
262
\sa _Lib3dsBackground