home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
REND.LZH
/
REND
/
BACK.C
next >
Wrap
C/C++ Source or Header
|
1996-06-12
|
5KB
|
254 lines
/*
* 背景の読み込み
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "reader.h"
#include "glib.h"
#include "assert.h"
#ifndef NO_PICLIB
#include "piclib.h"
#endif
#define MAXSTRING 10
#ifdef NO_PICLIB
static int backfullcolorflag = FALSE;
#endif
#ifdef NO_PICLIB
static ColorCode Code ;
static int Length ;
static int FileXPixel, FileYPixel ;
#else
static PicData *pd;
static Pixel *ReadBuf = NULL;
static int lastX = 0;
#endif
static int BackXPixel, BackYPixel ;
static int Ycount;
static int Line ;
static FILE *fp ;
static ColorCode *FrameBuf ;
/*
proto -s back.c > temp
*/
static void BackCopyLine1( ColorCode* );
static void BackError( char*, char* );
static int getword( char* );
/* 画像ファイルのオープン */
void BackOpen( filename )
char *filename ;
{
int i ;
char str[MAXSTRING+1] ;
#ifdef NO_PICLIB
fp = fopen( filename, "rb" );
if ( fp == NULL )
BackError( "画像ファイル %s がオープンできません。", filename );
if ( getword( str ) && strcmp( str, "image" ) != 0 )
BackError( "%s は画像ファイルではありません。", filename );
backfullcolorflag = FALSE;
/* ヘッダ部分 */
for(;;)
{
if ( getword( str ) == EOF )
break ;
if ( strcmp( str, "pxn" ) == 0 )
{
getword( str );
FileXPixel = atoi( str );
getword( str );
FileYPixel = atoi( str );
}
else if ( strcmp( str, "col" ) == 0 )
{
getword( str );
if (atoi(str) == 16) {
backfullcolorflag = FALSE;
} else if (atoi(str) == 25) {
backfullcolorflag = TRUE;
}
}
else if ( strcmp( str, "mod" ) == 0 )
{
getword( str );
if ( strcmp( str, "rln" ) != 0 )
BackError( "画像ファイル %s は読み込めません。", filename );
}
}
for( i = 0 ; i < 4 ; ++i )
getc( fp );
{
extern int antiareas;
BackXPixel = XPixel;
BackYPixel = YPixel;
if ( XPixel / antiareas == 320 && YPixel / antiareas == 240) {
BackXPixel = 512 * antiareas;
BackYPixel = 512 * antiareas;
}
}
if (backfullcolorflag) {
extern unsigned long getlong(FILE *);
unsigned long c;
c = getlong(fp);
Code = (c & 0xffffff00L) | ((c & 0x00000080L) ? 1 : 0);
Length = (int)(c & 0x7fL);
} else {
Code = X68kcolorToColorCode( getshort(fp) );
Length = getshort( fp );
}
#else
pd = PicReadOpen(filename);
if ( pd == NULL )
BackError( "画像ファイル %s がオープンできません。", filename );
{
extern int antiareas;
BackXPixel = XPixel;
BackYPixel = YPixel;
if (pd->pixelX == 512 && pd->pixelY == 512
&& XPixel / antiareas == 320 && YPixel / antiareas == 240) {
BackXPixel = 512 * antiareas;
BackYPixel = 512 * antiareas;
}
}
/* フレームバッファ確保 */
if (lastX < pd->pixelX) {
if (ReadBuf != NULL) {
tempfree(ReadBuf);
}
ReadBuf = (Pixel*)tempalloc( sizeof( Pixel ) * pd->pixelX );
}
#endif
Ycount = 0;
Line = 0 ;
/* フレームバッファ確保 */
if ( FrameBuf == NULL )
FrameBuf = (ColorCode*)tempalloc( sizeof( ColorCode ) * BackXPixel );
}
/* 読み込み */
void BackCopy( framebuf )
ColorCode *framebuf ;
{
#ifdef NO_PICLIB
Ycount -= FileYPixel;
#else
Ycount -= pd->pixelY;
#endif
while (Ycount < 0) {
BackCopyLine1(FrameBuf);
Ycount += BackYPixel;
}
memcpy( (char*)framebuf, (char*)FrameBuf, sizeof( ColorCode )*XPixel );
Line ++ ;
}
/* 1ライン読み込み */
static void BackCopyLine1( framebuf )
ColorCode *framebuf ;
{
#ifdef NO_PICLIB
int x;
int count = 0;
for( x = FileXPixel ; x > 0 ; --x )
{
count -= BackXPixel;
while (count < 0) {
*framebuf++ = Code;
count += FileXPixel;
}
Length -- ;
if ( Length == 0 )
{
if (backfullcolorflag) {
extern unsigned long getlong(FILE *);
unsigned long c;
c = getlong(fp);
Code = (c & 0xffffff00L) | ((c & 0x00000080L) ? 1 : 0);
Length = (int)(c & 0x7fL);
} else {
Code = X68kcolorToColorCode( getshort(fp) );
Length = getshort( fp );
}
}
}
#else
int x;
int count = 0;
ColorCode code;
Pixel *p;
if (PicInputLine(pd, ReadBuf) == FALSE) {
BackError( "背景の読み込みに失敗しました。", "" );
}
p = ReadBuf;
for( x = pd->pixelX ; x > 0 ; --x )
{
code = (*p & 0xffffff00L) | ((*p & 0x00000080L) ? 1 : 0);
count -= BackXPixel;
while (count < 0) {
*framebuf++ = code;
count += pd->pixelX;
}
p++;
}
#endif
}
void BackClose()
{
#ifdef NO_PICLIB
fclose( fp );
#else
PicClose(pd);
#endif
}
static void BackError( msg, arg )
char *msg ;
char *arg ;
{
#ifdef MESSAGE
extern int printwarning(const char *format, ...);
printwarning( msg, arg );
#endif
fprintf( stderr, msg, arg );
fprintf( stderr, "\nエラーが発生しました。\n\n" );
exit( 1 );
}
#ifdef NO_PICLIB
static int getword( str )
char *str ;
{
int i, c ;
while( ! isalnum( c = getc( fp ) ) && c != 0x1A );
if ( c == 0x1A )
return( EOF );
for( i = 0 ; i < MAXSTRING && isalnum( c ) ; ++i )
{
*str++ = (char)c ;
c = getc( fp );
}
*str = '\0' ;
return TRUE;
}
#endif