~ubuntu-branches/debian/stretch/opentyrian/stretch

« back to all changes in this revision

Viewing changes to src/picload.c

  • Committer: Package Import Robot
  • Author(s): Etienne Millon
  • Date: 2015-03-31 08:48:54 UTC
  • Revision ID: package-import@ubuntu.com-20150331084854-f5a4uoz7uv3vopk6
Tags: upstream-2.1.20130907+dfsg
ImportĀ upstreamĀ versionĀ 2.1.20130907+dfsg

Show diffs side-by-side

added added

removed removed

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