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 "picload.h"
  20.  
  21. #include "file.h"
  22. #include "opentyr.h"
  23. #include "palette.h"
  24. #include "pcxmast.h"
  25. #include "video.h"
  26.  
  27. #include <string.h>
  28.  
  29. void JE_loadPic(SDL_Surface *screen, JE_byte PCXnumber, JE_boolean storepal )
  30. {
  31.         PCXnumber--;
  32.  
  33.         FILE *f = dir_fopen_die(data_dir(), "tyrian.pic", "rb");
  34.  
  35.         static bool first = true;
  36.         if (first)
  37.         {
  38.                 first = false;
  39.  
  40.                 Uint16 temp;
  41.                 efread(&temp, sizeof(Uint16), 1, f);
  42.                 for (int i = 0; i < PCX_NUM; i++)
  43.                 {
  44.                         efread(&pcxpos[i], sizeof(JE_longint), 1, f);
  45.                 }
  46.  
  47.                 pcxpos[PCX_NUM] = ftell_eof(f);
  48.         }
  49.  
  50.         unsigned int size = pcxpos[PCXnumber + 1] - pcxpos[PCXnumber];
  51.         Uint8 *buffer = malloc(size);
  52.  
  53.         fseek(f, pcxpos[PCXnumber], SEEK_SET);
  54.         efread(buffer, sizeof(Uint8), size, f);
  55.         fclose(f);
  56.  
  57.         Uint8 *p = buffer;
  58.         Uint8 *s; /* screen pointer, 8-bit specific */
  59.  
  60.         s = (Uint8 *)screen->pixels;
  61.  
  62.         for (int i = 0; i < 320 * 200; )
  63.         {
  64.                 if ((*p & 0xc0) == 0xc0)
  65.                 {
  66.                         i += (*p & 0x3f);
  67.                         memset(s, *(p + 1), (*p & 0x3f));
  68.                         s += (*p & 0x3f); p += 2;
  69.                 } else {
  70.                         i++;
  71.                         *s = *p;
  72.                         s++; p++;
  73.                 }
  74.                 if (i && (i % 320 == 0))
  75.                 {
  76.                         s += screen->pitch - 320;
  77.                 }
  78.         }
  79.  
  80.         free(buffer);
  81.  
  82.         memcpy(colors, palettes[pcxpal[PCXnumber]], sizeof(colors));
  83.  
  84.         if (storepal)
  85.                 set_palette(colors, 0, 255);
  86. }
  87.  
  88.