[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/depth.hh"
|
---|
| 10 | #include "image/image8.hh"
|
---|
| 11 | #include "file/file.hh"
|
---|
| 12 | #include "arch.hh"
|
---|
| 13 | #include "error/error.hh"
|
---|
| 14 | #include "image/context.hh"
|
---|
| 15 |
|
---|
| 16 | i4_bool fli_read_rle(w8 *im, w32 w, w32 h, i4_file_class *fp)
|
---|
| 17 | //{{{
|
---|
| 18 | {
|
---|
| 19 | w8 *line,c;
|
---|
| 20 | sw8 size;
|
---|
| 21 |
|
---|
| 22 | for (w32 y=0; y<h; y++)
|
---|
| 23 | {
|
---|
| 24 | line=im;
|
---|
| 25 | im+=w;
|
---|
| 26 | w8 tpackets=fp->read_8();
|
---|
| 27 | for (w32 k=0; k<tpackets; k++)
|
---|
| 28 | {
|
---|
| 29 | size=fp->read_8();
|
---|
| 30 | if (size>0)
|
---|
| 31 | {
|
---|
| 32 | c=fp->read_8();
|
---|
| 33 | while (size)
|
---|
| 34 | {
|
---|
| 35 | *line=c;
|
---|
| 36 | ++line;
|
---|
| 37 | size--;
|
---|
| 38 | }
|
---|
| 39 | } else
|
---|
| 40 | {
|
---|
| 41 | if (fp->read(line,-size)!=-size)
|
---|
| 42 | return i4_F;
|
---|
| 43 | else line+=-size;
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | return i4_T;
|
---|
| 48 | }
|
---|
| 49 | //}}}
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | i4_bool fli_read_lc(w8 *prev, w8 *im, w32 w, w32 h, i4_file_class *fp)
|
---|
| 53 | //{{{
|
---|
| 54 | {
|
---|
| 55 | w32 x,y;
|
---|
| 56 | w16 skip_lines,change_lines;
|
---|
| 57 |
|
---|
| 58 | w8 *line,*prev_line,tpackets,c;
|
---|
| 59 | sw8 size;
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | skip_lines=fp->read_16();
|
---|
| 63 | memcpy(im,prev,skip_lines*w);
|
---|
| 64 | im+=skip_lines*w;
|
---|
| 65 | prev+=skip_lines*w;
|
---|
| 66 |
|
---|
| 67 | change_lines=fp->read_16();
|
---|
| 68 | for (y=0; y<change_lines; y++)
|
---|
| 69 | {
|
---|
| 70 | tpackets=fp->read_8();
|
---|
| 71 | line=im;
|
---|
| 72 | prev_line=prev;
|
---|
| 73 | im+=w;
|
---|
| 74 | prev+=w;
|
---|
| 75 |
|
---|
| 76 | if (tpackets==0)
|
---|
| 77 | memcpy(line,prev_line,w);
|
---|
| 78 | else
|
---|
| 79 | {
|
---|
| 80 | for (x=0; x<tpackets; x++)
|
---|
| 81 | {
|
---|
| 82 | w8 skip=fp->read_8();
|
---|
| 83 | memcpy(line,prev_line,skip);
|
---|
| 84 | line+=skip;
|
---|
| 85 | prev_line+=skip;
|
---|
| 86 |
|
---|
| 87 | size=fp->read_8();
|
---|
| 88 | if (size<0)
|
---|
| 89 | {
|
---|
| 90 | c=fp->read_8();
|
---|
| 91 | while (size)
|
---|
| 92 | {
|
---|
| 93 | *line=c;
|
---|
| 94 | ++line;
|
---|
| 95 | ++prev_line;
|
---|
| 96 | size++;
|
---|
| 97 | }
|
---|
| 98 | } else
|
---|
| 99 | {
|
---|
| 100 | if (fp->read(line,size)!=size)
|
---|
| 101 | return i4_F;
|
---|
| 102 | line+=size;
|
---|
| 103 | prev_line+=size;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | return i4_T;
|
---|
| 112 | }
|
---|
| 113 | //}}}
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | i4_bool fli_read_ss2(w8 *prev, w8 *im, w32 w, w32 h, i4_file_class *fp)
|
---|
| 117 | //{{{
|
---|
| 118 | {
|
---|
| 119 | w32 x,y;
|
---|
| 120 | w16 skip_lines,change_lines;
|
---|
| 121 |
|
---|
| 122 | w16 *line,*prev_line,code_word,c;
|
---|
| 123 | sw8 size;
|
---|
| 124 |
|
---|
| 125 | change_lines=fp->read_16();
|
---|
| 126 | for (y=0; y<change_lines; y++)
|
---|
| 127 | {
|
---|
| 128 | do
|
---|
| 129 | {
|
---|
| 130 | code_word=fp->read_16();
|
---|
| 131 | switch(code_word>>14)
|
---|
| 132 | {
|
---|
| 133 | case 0:
|
---|
| 134 | break;
|
---|
| 135 | case 1:
|
---|
| 136 | return i4_F;
|
---|
| 137 |
|
---|
| 138 | case 2:
|
---|
| 139 | {
|
---|
| 140 | *(im+w-1) = code_word & 0xff;
|
---|
| 141 | } break;
|
---|
| 142 |
|
---|
| 143 | case 3:
|
---|
| 144 | skip_lines = -code_word;
|
---|
| 145 | im += w*skip_lines;
|
---|
| 146 | prev += w*skip_lines;
|
---|
| 147 | break;
|
---|
| 148 | }
|
---|
| 149 | } while (code_word & 0x8000);
|
---|
| 150 |
|
---|
| 151 | line=(w16*)im;
|
---|
| 152 | prev_line=(w16*)prev;
|
---|
| 153 |
|
---|
| 154 | im+=w;
|
---|
| 155 | prev+=w;
|
---|
| 156 |
|
---|
| 157 | if (code_word==0)
|
---|
| 158 | memcpy(line,prev_line,w-1);
|
---|
| 159 | else
|
---|
| 160 | {
|
---|
| 161 | for (x=0; x<code_word; x++)
|
---|
| 162 | {
|
---|
| 163 | w8 skip=fp->read_8();
|
---|
| 164 | memcpy(line,prev_line,skip);
|
---|
| 165 | line+= (skip>>1);
|
---|
| 166 | prev_line+= (skip>>1);
|
---|
| 167 |
|
---|
| 168 | size=fp->read_8();
|
---|
| 169 | if (size<0)
|
---|
| 170 | {
|
---|
| 171 | c=fp->read_16();
|
---|
| 172 | while (size)
|
---|
| 173 | {
|
---|
| 174 | *line=c;
|
---|
| 175 | ++line;
|
---|
| 176 | ++prev_line;
|
---|
| 177 | size++;
|
---|
| 178 | }
|
---|
| 179 | } else
|
---|
| 180 | {
|
---|
| 181 | if (fp->read(line,size*2)!=size*2)
|
---|
| 182 | return i4_F;
|
---|
| 183 | line+=size;
|
---|
| 184 | prev_line+=size;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | return i4_T;
|
---|
| 193 | }
|
---|
| 194 | //}}}
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | //hacked on 5-23-97, loads a series of .pcx files
|
---|
| 198 | i4_image_class **i4_load_fli(i4_file_class *fp, w32 &frames)
|
---|
| 199 | {
|
---|
| 200 | return NULL;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /*
|
---|
| 204 | i4_image_class **i4_load_fli(i4_file_class *fp, w32 &frames)
|
---|
| 205 | //{{{
|
---|
| 206 | {
|
---|
| 207 | //{{{ FLI chunk signatures
|
---|
| 208 | enum
|
---|
| 209 | {
|
---|
| 210 | FLI_COLOR_MAP256=4,
|
---|
| 211 | FLI_SS2=7,
|
---|
| 212 | FLI_COLOR_MAP=11,
|
---|
| 213 | FLI_COMPRESSED_LINE=12,
|
---|
| 214 | FLI_BLACK=13,
|
---|
| 215 | FLI_RLE=15,
|
---|
| 216 | FLI_RAW=16,
|
---|
| 217 | FLI_PSTAMP=18
|
---|
| 218 | } ;
|
---|
| 219 | //}}}
|
---|
| 220 |
|
---|
| 221 | w32 offset,shift=0;
|
---|
| 222 | w32 size,frame_size,k;
|
---|
| 223 | w16 signature,
|
---|
| 224 | depth,
|
---|
| 225 | w, h,
|
---|
| 226 | chunk_type,
|
---|
| 227 | tchunks;
|
---|
| 228 |
|
---|
| 229 | w8 buffer[114];
|
---|
| 230 | w32 chunk_size,
|
---|
| 231 | frame_on;
|
---|
| 232 |
|
---|
| 233 | int error = 0;
|
---|
| 234 |
|
---|
| 235 | size=fp->read_32();
|
---|
| 236 | signature=fp->read_16();
|
---|
| 237 |
|
---|
| 238 | frames=fp->read_16();
|
---|
| 239 | w=fp->read_16();
|
---|
| 240 | h=fp->read_16();
|
---|
| 241 |
|
---|
| 242 | depth=fp->read_16();
|
---|
| 243 | if (depth!=8)
|
---|
| 244 | return 0;
|
---|
| 245 |
|
---|
| 246 | if (signature==0xaf11) // FLI signature
|
---|
| 247 | {
|
---|
| 248 | if (fp->read(buffer,114)!=114)
|
---|
| 249 | return 0;
|
---|
| 250 | }
|
---|
| 251 | else if (signature==0xaf12) // FLC signature
|
---|
| 252 | {
|
---|
| 253 | // read offset to first frame chunk to skip prefixes, etc.
|
---|
| 254 | fp->seek(80);
|
---|
| 255 | offset = fp->read_32();
|
---|
| 256 | // go to first frame
|
---|
| 257 | fp->seek(offset);
|
---|
| 258 | }
|
---|
| 259 | else
|
---|
| 260 | return 0;
|
---|
| 261 |
|
---|
| 262 | i4_pal_handle_class pal;
|
---|
| 263 | i4_unmatched_image8 **im;
|
---|
| 264 | im=(i4_unmatched_image8 **)i4_malloc(sizeof(i4_unmatched_image8 *)*frames,"fli frame pointers");
|
---|
| 265 |
|
---|
| 266 | for (frame_on=0; frame_on<frames && !error; frame_on++)
|
---|
| 267 | {
|
---|
| 268 | frame_size=fp->read_32();
|
---|
| 269 | if (fp->read_16()!=0xf1fa)
|
---|
| 270 | error = 1;
|
---|
| 271 | else
|
---|
| 272 | {
|
---|
| 273 | im[frame_on]=new i4_unmatched_image8(w,h,pal);
|
---|
| 274 | tchunks=fp->read_16();
|
---|
| 275 | fp->read(buffer,8);
|
---|
| 276 |
|
---|
| 277 | for (k=0; k<tchunks && !error; k++)
|
---|
| 278 | {
|
---|
| 279 | chunk_size=fp->read_32();
|
---|
| 280 | chunk_type=fp->read_16();
|
---|
| 281 | switch ((w8)(chunk_type&0xff))
|
---|
| 282 | {
|
---|
| 283 | case FLI_COMPRESSED_LINE :
|
---|
| 284 | //{{{
|
---|
| 285 | if (!fli_read_lc(im[frame_on-1]->local_sub_data(0,0),
|
---|
| 286 | im[frame_on]->local_sub_data(0,0),
|
---|
| 287 | w,h,
|
---|
| 288 | fp))
|
---|
| 289 | error = 1;
|
---|
| 290 | break;
|
---|
| 291 | //}}}
|
---|
| 292 | case FLI_RAW :
|
---|
| 293 | //{{{
|
---|
| 294 | if (fp->read(im[frame_on]->local_sub_data(0,0),64000)!=64000)
|
---|
| 295 | error = 1;
|
---|
| 296 | break;
|
---|
| 297 | //}}}
|
---|
| 298 | case FLI_RLE :
|
---|
| 299 | //{{{
|
---|
| 300 | if (!fli_read_rle(im[frame_on]->local_sub_data(0,0), w,h, fp))
|
---|
| 301 | error = 1;
|
---|
| 302 | break;
|
---|
| 303 | //}}}
|
---|
| 304 | case FLI_COLOR_MAP :
|
---|
| 305 | //{{{
|
---|
| 306 | shift = 2;
|
---|
| 307 | //}}}
|
---|
| 308 | case FLI_COLOR_MAP256 :
|
---|
| 309 | //{{{
|
---|
| 310 | {
|
---|
| 311 | w32 pald[256],*p;
|
---|
| 312 |
|
---|
| 313 | p=pald;
|
---|
| 314 | memset(pald,0,sizeof(pald));
|
---|
| 315 | w32 i,j;
|
---|
| 316 | w16 change;
|
---|
| 317 | w8 trip[3];
|
---|
| 318 | w16 count=fp->read_16();
|
---|
| 319 | for (i=0; i<count; i++)
|
---|
| 320 | {
|
---|
| 321 | p+=fp->read_8();
|
---|
| 322 | change=fp->read_8();
|
---|
| 323 | if (!change)
|
---|
| 324 | change=256;
|
---|
| 325 | for (j=0; j<change; j++)
|
---|
| 326 | {
|
---|
| 327 | fp->read(trip,3);
|
---|
| 328 | if (p>pald+256)
|
---|
| 329 | i4_error("fli gone crazy");
|
---|
| 330 |
|
---|
| 331 | *p=(trip[0] << (16+shift))|
|
---|
| 332 | (trip[1] << (8+shift))|
|
---|
| 333 | (trip[2] << shift);
|
---|
| 334 | p++;
|
---|
| 335 |
|
---|
| 336 | }
|
---|
| 337 | pal=i4_pal_man.register_pal(i4_pal_handle_class::ID_8BIT,pald);
|
---|
| 338 | }
|
---|
| 339 | shift = 0;
|
---|
| 340 | } break;
|
---|
| 341 | //}}}
|
---|
| 342 | case FLI_BLACK :
|
---|
| 343 | //{{{
|
---|
| 344 | {
|
---|
| 345 | i4_draw_context_class context(0,0,w-1,h-1);
|
---|
| 346 | im[frame_on]->clear(0,context);
|
---|
| 347 | } break;
|
---|
| 348 | //}}}
|
---|
| 349 | case FLI_SS2 :
|
---|
| 350 | //{{{
|
---|
| 351 | if (!fli_read_ss2(im[frame_on-1]->local_sub_data(0,0),
|
---|
| 352 | im[frame_on]->local_sub_data(0,0),
|
---|
| 353 | w,h,
|
---|
| 354 | fp))
|
---|
| 355 | error = 1;
|
---|
| 356 | break;
|
---|
| 357 | //}}}
|
---|
| 358 | default :
|
---|
| 359 | //{{{
|
---|
| 360 | fp->seek(fp->tell()+chunk_size - 6);
|
---|
| 361 | //}}}
|
---|
| 362 | }
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | if (error)
|
---|
| 368 | {
|
---|
| 369 | for (w32 j=0; j<frame_on; j++)
|
---|
| 370 | delete im[j];
|
---|
| 371 | i4_free(im);
|
---|
| 372 | return 0;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | for (k=0; k<frames; k++)
|
---|
| 376 | im[k]->set_pal(pal);
|
---|
| 377 |
|
---|
| 378 | return (i4_image_class **)im;
|
---|
| 379 | }
|
---|
| 380 | //}}}
|
---|
| 381 | */
|
---|
| 382 |
|
---|
| 383 |
|
---|
| 384 |
|
---|
| 385 | //{{{ Emacs Locals
|
---|
| 386 | // Local Variables:
|
---|
| 387 | // folded-file: t
|
---|
| 388 | // End:
|
---|
| 389 | //}}}
|
---|
| 390 |
|
---|