Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * OpenTyrian: A modern cross-platform port of Tyrian
  3.  * Copyright (C) 2007-2009  The OpenTyrian Development Team
  4.  *
  5.  * This program is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU General Public License
  7.  * as published by the Free Software Foundation; either version 2
  8.  * of the License, or (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  18.  */
  19. #include "pcxload.h"
  20.  
  21. #include "file.h"
  22. #include "opentyr.h"
  23. #include "palette.h"
  24. #include "video.h"
  25.  
  26. void JE_loadPCX( const char *file ) // this is only meant to load tshp2.pcx
  27. {
  28.         Uint8 *s = VGAScreen->pixels; /* 8-bit specific */
  29.        
  30.         FILE *f = dir_fopen_die(data_dir(), file, "rb");
  31.        
  32.         fseek(f, -769, SEEK_END);
  33.        
  34.         if (fgetc(f) == 12)
  35.         {
  36.                 for (int i = 0; i < 256; i++)
  37.                 {
  38.                         efread(&colors[i].r, 1, 1, f);
  39.                         efread(&colors[i].g, 1, 1, f);
  40.                         efread(&colors[i].b, 1, 1, f);
  41.                 }
  42.         }
  43.        
  44.         fseek(f, 128, SEEK_SET);
  45.        
  46.         for (int i = 0; i < 320 * 200; )
  47.         {
  48.                 Uint8 p = fgetc(f);
  49.                 if ((p & 0xc0) == 0xc0)
  50.                 {
  51.                         i += (p & 0x3f);
  52.                         memset(s, fgetc(f), (p & 0x3f));
  53.                         s += (p & 0x3f);
  54.                 } else {
  55.                         i++;
  56.                         *s = p;
  57.                         s++;
  58.                 }
  59.                 if (i && (i % 320 == 0))
  60.                 {
  61.                         s += VGAScreen->pitch - 320;
  62.                 }
  63.         }
  64.        
  65.         fclose(f);
  66. }
  67.  
  68.