[80] | 1 | /********************************************************************** <BR>
|
---|
| 2 | This file is part of Crack dot Com's free source code release of
|
---|
| 3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
| 4 | information about compiling & licensing issues visit this URL</a>
|
---|
| 5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
| 6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
| 7 | ***********************************************************************/
|
---|
| 8 |
|
---|
| 9 | #include "image/image.hh"
|
---|
| 10 | #include "tex_cache.hh"
|
---|
| 11 | #include "tex_id.hh"
|
---|
| 12 | #include "mip.hh"
|
---|
| 13 | #include "file/file.hh"
|
---|
| 14 | #include "r1_res.hh"
|
---|
| 15 | #include "memory/malloc.hh"
|
---|
| 16 |
|
---|
| 17 | int r1_load_gtext(w32 id, i4_image_class **images)
|
---|
| 18 | {
|
---|
| 19 | i4_file_class *fp;
|
---|
| 20 | tex_cache_header_t theader;
|
---|
| 21 | mipheader_t header;
|
---|
| 22 |
|
---|
| 23 | fp=i4_open(r1_get_cache_file());
|
---|
| 24 | if (!fp)
|
---|
| 25 | return 0;
|
---|
| 26 |
|
---|
| 27 | theader.read(fp);
|
---|
| 28 | delete fp;
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | i4_str *fn = r1_texture_id_to_filename(id, r1_get_decompressed_dir());
|
---|
| 32 | fp=i4_open(*fn);
|
---|
| 33 | delete fn;
|
---|
| 34 | if (!fp)
|
---|
| 35 | return 0;
|
---|
| 36 |
|
---|
| 37 | header.read(fp);
|
---|
| 38 |
|
---|
| 39 | int w=header.base_width, h=header.base_height, i;
|
---|
| 40 | const i4_pal *pal;
|
---|
| 41 |
|
---|
| 42 | if (header.flags & R1_MIP_IS_TRANSPARENT)
|
---|
| 43 | pal=i4_pal_man.register_pal(&theader.chroma_format);
|
---|
| 44 | else if (header.flags & R1_MIP_IS_ALPHATEXTURE)
|
---|
| 45 | pal=i4_pal_man.register_pal(&theader.alpha_format);
|
---|
| 46 | else
|
---|
| 47 | pal=i4_pal_man.register_pal(&theader.regular_format);
|
---|
| 48 |
|
---|
| 49 | for (i=0; i<header.num_mip_levels; i++)
|
---|
| 50 | {
|
---|
| 51 | fp->seek(header.offsets[i]+8);
|
---|
| 52 |
|
---|
| 53 | w16 *data=(w16 *)i4_malloc(w*h*2,"");
|
---|
| 54 | fp->read(data,w*h*2);
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | i4_image_class *im=i4_create_image(w,h, pal, (w8 *)data, w*2);
|
---|
| 58 | im->dont_free_data=i4_F;
|
---|
| 59 |
|
---|
| 60 | images[i]=im;
|
---|
| 61 | w/=2;
|
---|
| 62 | h/=2;
|
---|
| 63 | }
|
---|
| 64 | delete fp;
|
---|
| 65 |
|
---|
| 66 | return header.num_mip_levels;
|
---|
| 67 | }
|
---|