File: graphic.c

package info (click to toggle)
ale-clone 1.15pre16.3-1
  • links: PTS
  • area: contrib
  • in suites: potato
  • size: 2,432 kB
  • ctags: 3,217
  • sloc: ansic: 37,483; sh: 1,105; makefile: 343
file content (188 lines) | stat: -rw-r--r-- 4,244 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
**	A clone of a famous game.
*/
/**@name graphic.c	-	The general graphic functions. */
/*
**
**	(c) Copyright 1999 by Lutz Sammer
**
**	$Id: graphic.c,v 1.3 1999/12/09 16:27:19 root Exp $
*/

//@{

/*----------------------------------------------------------------------------
--	Includes
----------------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "clone.h"
#include "video.h"

/*----------------------------------------------------------------------------
--	Declarations
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
--	Externals
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
--	Variables
----------------------------------------------------------------------------*/

local GraphicType GraphicImage8Type;	/// image type 8bit palette
local GraphicType GraphicImage16Type;	/// image type 16bit palette

/*----------------------------------------------------------------------------
--	Local functions
----------------------------------------------------------------------------*/

/**
**	Video draw 8bit graphic into 16 bit framebuffer.
**
**	@param graphic	Pointer to object
**	@param gx	X offset into object
**	@param gy	Y offset into object
**	@param w	width to display
**	@param h	height to display
**	@param x	X screen position
**	@param y	Y screen position
*/
local void VideoDrawGraphic8to16(
	OldGraphic* graphic,unsigned gx,unsigned gy,unsigned w,unsigned h,
	unsigned x,unsigned y)
{
    unsigned char* sp;
    unsigned char* lp;
    unsigned char* gp;
    int sa;
    VMemType16* dp;
    int da;

    sp=graphic->Data+gx+gy*graphic->Width;
    gp=sp+graphic->Width*h;
    sa=graphic->Width-w;
    dp=VideoMemory+x+y*VideoWidth;
    da=VideoWidth-w;
    --w;
    while( sp<gp ) {
	lp=sp+w;
	while( sp<lp ) {
	    *dp++=Pixels16[*sp++];	// unroll
	    *dp++=Pixels16[*sp++];
	}
	if( sp<=lp ) {
	    *dp++=Pixels16[*sp++];
	}
	sp+=sa;
	dp+=da;
    }
}

/*----------------------------------------------------------------------------
--	Global functions
----------------------------------------------------------------------------*/

/**
**	Make a graphic object.
**
**	@param depth	Pixel depth of the object (8,16,32)
**	@param width	Pixel width.
**	@param height	Pixel height.
**	@param data	Object data.
*/
global Graphic* MakeGraphic(
	unsigned depth,unsigned width,unsigned height,void* data)
{
    return NULL;
}

/**
**	Generate a filename into library.
**
**	Try current directory, user home directory, global directory.
**
**	FIXME: I want also support files stored into tar/zip archives.
**
**	@param file	Filename to open.
**	@param buffer	Allocated buffer for generated filename.
**
**	@return		Pointer to buffer.
*/
global char* LibraryFileName(const char* file,char* buffer)
{
    //
    //	Absolute path or in current directory.
    //
    strcpy(buffer,file);
    if( *buffer=='/' || !access(buffer,R_OK) ) {
	return buffer;
    }

    //
    //	In user home directory
    //
    sprintf(buffer,"%s/%s/%s",getenv("HOME"),CLONE_HOME_PATH,file);
    if( !access(buffer,R_OK) ) {
	return buffer;
    }

    //
    //	In global shared directory
    //
    sprintf(buffer,"%s/%s",CloneLibPath,file);
    if( !access(buffer,R_OK) ) {
	return buffer;
    }
    DebugLevel0(__FUNCTION__": File `%s' couldn't found\n",file);

    strcpy(buffer,file);
    return buffer;
}

/**
**	Load graphic from file.
**
**	@param name	File name.
**
**	@return		Graphic object.
*/
global Graphic* LoadGraphic(const char* name)
{
    Graphic* graphic;
    char buf[1024];

    // FIXME: I want also support JPG file format!

    if( (graphic=LoadGraphicPNG(LibraryFileName(name,buf))) ) {
	printf("Can't load the graphic `%s'\n",name);
	exit(-1);
    }
    return graphic;
}

/**
**	Init graphic
*/
global void InitGraphic(void)
{
    switch( VideoDepth ) {
	case 15:
	case 16:
	    break;

	case 8:
	case 24:
	case 32:

	default:
	    DebugLevel0(__FUNCTION__": unsupported %d bpp\n",VideoDepth);
	    abort();
    }
}

//@}