⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 l_image.cpp

📁 网页游戏赤壁
💻 CPP
字号:
/*
                                   漏空函数

                                             骆文超 于1997年2月制
	v0020	Mar.22.1997, by Liu Gang
*/
//#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <sys\stat.h>
#include <sys\types.h>
#include <fcntl.h>

#include "Assert.h"
#include "L_image.h"

     //打开压缩文件;
void CPicture_image::image_open_compress (char compress_file_name[20])
{
    int   handle,compress_bytes;
    handle=open (compress_file_name,O_RDONLY|O_BINARY);

    if (handle!=-1)
       compress_bytes=filelength (handle);

    if ((compress_file=fopen (compress_file_name,"rb"))==NULL)
    {
	printf ("This file no find !!!");
	exit (1);
    }

    close ( handle );
    if ((compress_buf=new char [compress_bytes])==NULL)
    {
	printf("Memory out !!!");
	exit (2);
    }
    fread (compress_buf,1,compress_bytes,compress_file);
}

     //关闭压缩文件;
void CPicture_image::image_close_compress (void)
{
    fclose ( compress_file );
    delete (compress_buf);
}

     //打开索引文件;
void CPicture_image::image_open_index (char index_file_name[20])
{
    int   handle,index_bytes;
    handle=open (index_file_name,O_RDONLY);

    if (handle!=-1)
       index_bytes=filelength (handle);
    index_bytes=index_bytes>>1;
    if ((index_file=fopen (index_file_name,"rb"))==NULL)
    {
	printf ("This file no find !!!");
	exit (1);
    }

    close ( handle );
    if ((index_buf=new int [index_bytes])==NULL)
    {
	printf("Memory out !!!");
	exit (2);
    }
    fread (index_buf,4,index_bytes,index_file);
}
     //关闭索引文件;
void CPicture_image::image_close_index (void)
{
    fclose ( index_file );
    delete (index_buf);
}


//#define	_L_INVIDEO_
/*
   漏空贴函数:
	   int x:图片的左上角坐标;
       int y:图片的右上角坐标;
	   int   screen_width:屏幕的宽度;
	   char * screen_point:屏幕的指针;
	   int   color_variable:颜色的偏移量;
*/
// general functions, to change colors
void CPicture_image::P_image (int x,int y,
			      int   screen_width,
			      char  * screen_point,
			      int   color_variable,
			      int   picture_number
			      )
{
	char    * compress_backup;       //备份压缩数据指针;
	char    * screen_backup;         //备份screen_point;
	int       compress_data_length;  //换行;
	short     count,count0;   //记录0号色和非0号色的个数;
//	int       compress_picture_width;    //压缩图片包中图片的宽度;
//	short     compress_tag;   //图片宽度结束标志;
	short     i;
	short     screen_endl;

	compress_backup=compress_buf+*(index_buf+picture_number);

	//*屏幕指针操作(计算屏幕坐标)*/
	screen_point+=(x+y*screen_width);
	screen_backup=screen_point;

	//*压缩文件头操作*/
	screen_endl=screen_width-*((int *) compress_backup);
	compress_backup+=10;
	compress_data_length=*((int *) compress_backup)-4;      //压缩数据长度;
	compress_backup+=4;
	//*漏空贴操作*/
	while ( compress_data_length>=0 )
	{
		count0=*((short *) compress_backup);   //读0号色的个数;
		compress_backup+=2;
		count=*((short *) compress_backup);    //读非0号色的个数;
		compress_backup+=2;
		compress_data_length-=4;
		screen_backup+=count0;		 //跳过0号色(处理0号色);
		if (!count)		    //count==0;
		{  //将指针移动一行
			screen_backup+=screen_endl;
		}
		else
		{  //非0号色的处理;
			// standard C code
			//写缓冲区
#ifdef	_L_INVIDEO_
			memcpy (screen_buffers,compress_backup,count);
			for (i=0;i<count;i++)
			{
				if (( screen_buffers[i] >= START_COLOR_NUMBER )
				&& (screen_buffers[i] <= END_COLOR_NUMBER))
				{
					screen_buffers[i]+=color_variable;
				}
			}
			memcpy (screen_backup,screen_buffers,count);

			// counters and pointers
			compress_data_length-=count;
			compress_backup+=count;
			screen_backup+=count;
#else
		   for (i=0;i<count;i++)
		   {
			   if (( *compress_backup >= START_COLOR_NUMBER )
			  && (*compress_backup <= END_COLOR_NUMBER))
			   {
					  *screen_backup=*compress_backup+color_variable;
			   }
  		   
			   else
			   {
			  *screen_backup=*compress_backup;
			   }
			   screen_backup++;
			   compress_backup++;
		   }
			compress_data_length-=count;
#endif
		}
	}
}

/*
   漏空贴函数:
	   int x:图片的左上角坐标;
       int y:图片的右上角坐标;
	   int   screen_width:屏幕的宽度;
	   char * screen_point:屏幕的指针;
	   int   color_variable:颜色的偏移量;
*/
// 不变色
// do not change colors
void CPicture_image::P_imageDirect (int x,int y,
			      int   screen_width,
			      char  * screen_point,
			      int   color_variable,
			      int   picture_number
			      )
{
	char    * compress_backup;       //备份压缩数据指针;
	char    * screen_backup;         //备份screen_point;
	int       compress_data_length;  //换行;
	short     count,count0;   //记录0号色和非0号色的个数;
//	int       compress_picture_width;    //压缩图片包中图片的宽度;
//	short     compress_tag;   //图片宽度结束标志;
//	short     i;
	short     screen_endl;

	compress_backup=compress_buf+*(index_buf+picture_number);

	//*屏幕指针操作(计算屏幕坐标)*/
	screen_point+=(x+y*screen_width);
	screen_backup=screen_point;

	//*压缩文件头操作*/
	screen_endl=screen_width-*((int *) compress_backup);
	compress_backup+=10;
	compress_data_length=*((int *) compress_backup)-4;      //压缩数据长度;
	compress_backup+=4;
	//*漏空贴操作*/
	while ( compress_data_length>=0 )
	{
		count0=*((short *) compress_backup);   //读0号色的个数;
		compress_backup+=2;
		count=*((short *) compress_backup);    //读非0号色的个数;
		compress_backup+=2;
		compress_data_length-=4;
		screen_backup+=count0;		 //跳过0号色(处理0号色);
		if (!count)		    //count==0;
		{  //将指针移动一行
			screen_backup+=screen_endl;
		}
		else
		{  //非0号色的处理;
			memcpy (screen_backup,compress_backup,count);

			// counters and pointers
			compress_data_length-=count;
			compress_backup+=count;
			screen_backup+=count;
		}
	}
}


//-for MMX extension, Liu Gang
extern "C"
{
extern void MMX_PImage(
	char *lpDest,	// 目的地缓冲区指针
	char *lpSrc,	// 源缓冲区指针
	int nColor,		// 要被改变成的色系
	int nCount		// 缓冲区字节数
);
}
//-for MMX extension, Liu Gang

/*
   漏空贴函数:
	   int x:图片的左上角坐标;
       int y:图片的右上角坐标;
	   int   screen_width:屏幕的宽度;
	   char * screen_point:屏幕的指针;
	   int   color_variable:颜色的偏移量;
*/
// MMX extension
void CPicture_image::P_imageMMX (int x,int y,
			      int   screen_width,
			      char  * screen_point,
			      int   color_variable,
			      int   picture_number
			      )
{
	char    * compress_backup;       //备份压缩数据指针;
	char    * screen_backup;         //备份screen_point;
	int       compress_data_length;  //换行;
	short     count,count0;   //记录0号色和非0号色的个数;
//	int       compress_picture_width;    //压缩图片包中图片的宽度;
//	short     compress_tag;   //图片宽度结束标志;
//	short     i;
	short     screen_endl;

	compress_backup=compress_buf+*(index_buf+picture_number);

	/*屏幕指针操作(计算屏幕坐标)*/
	screen_point+=(x+y*screen_width);
	screen_backup=screen_point;

	//*压缩文件头操作*/
	screen_endl=screen_width-*((int *) compress_backup);
	compress_backup+=10;
	compress_data_length=*((int *) compress_backup)-4;      //压缩数据长度;
	compress_backup+=4;
	//*漏空贴操作*/
	while ( compress_data_length>=0 )
	{
		count0=*((short *) compress_backup);   //读0号色的个数;
		compress_backup+=2;
		count=*((short *) compress_backup);    //读非0号色的个数;
		compress_backup+=2;
		compress_data_length-=4;
		screen_backup+=count0;		 //跳过0号色(处理0号色);
		if (!count)		    //count==0;
		{  //将指针移动一行
			screen_backup+=screen_endl;
		}
		else
		{  //非0号色的处理;
			memcpy (screen_buffers,compress_backup,count);
//-for MMX extension, Liu Gang
			// MMX extension
			MMX_PImage( screen_buffers, screen_buffers, color_variable, count );
//-for MMX extension, Liu Gang
			memcpy (screen_backup,screen_buffers,count);

			// counters and pointers
			compress_data_length-=count;
			compress_backup+=count;
			screen_backup+=count;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -