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

📄 pcx_provider_generic.h

📁 这是一款2d游戏引擎
💻 H
字号:
/*  $Id: pcx_provider_generic.h,v 1.9 2003/10/14 15:52:12 mbn Exp $
**
**  ClanLib Game SDK
**  Copyright (C) 2003  The ClanLib Team
**  For a total list of contributers see the file CREDITS.
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**
**  This library is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**  Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser General Public
**  License along with this library; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

#ifndef header_pcx_provider_generic
#define header_pcx_provider_generic

#if _MSC_VER > 1000
#pragma once
#endif

#include "API/Display/Providers/pcx_provider.h"
#include "Display/pixel_buffer_generic.h"
#include "API/Core/IOData/inputsource.h"
#include "API/Core/IOData/inputsource_provider.h"

//: Surface provider that can load PCX files.
//- <p>The PCX decoder has been modified to load most PCX files
//- (instead of just the ones created by Deluxe Paint IIe).
//- It now support 1,2,4,8, or 24 bit files... and has been tested
//- in all but a few situations.</p>
//-
//- <p>Technically, the implementation cheats in that it doesnt
//- store images with less than 8 bits per pixel in their 
//- native format.  It simply converts them to PAL8
//- pixelformat instead of creating other pixelformats.</p>
//-
//- <p>Also note that the PCX decoder creates more bytes per 
//- line than the image is supposed to contain.  We rely on the clipping
//- capabilities of ClanLib to take care of that.  Also note that some
//- default palettes were defined in the read_header() method.  These 
//- definitions might be better placed in palette.h.  Since the scope of 
//- the PCX_Provider rewrite was limited to the provider itself, no files
//- outside of pcx_provider.h and pcx_provider.cpp were modified.</p>
//-
//- <p>The PCX decoding code was moved to read_data() and read_header()
//- to make it easier to follow the code (called from perform_unlock()).</p>
class CL_PCXProvider_Generic : public CL_PixelBuffer_Generic
{
//! Construction:
public:
	//: Constructs a surface provider that can read pcx files.
	//param name: Name of the pcx file to load.
	//param provider: Input source provider that delivers the pcx file.
	//param transparent: True if a color in image should be transparent.
	//param trans_col: Transparency color used if 'transparent' is true. Defaults to color 0.
	CL_PCXProvider_Generic(
		std::string name,
		CL_InputSourceProvider *provider,
		bool transparent=false,
		unsigned char trans_col=0);

	//: PCX Provider destructor
	virtual ~CL_PCXProvider_Generic();

//! Attributes:
public:
	//: Returns the pitch of the image (bytes per line).
	unsigned int get_pitch() const { return pitch; }

	//: Returns the width of the image.
	unsigned int get_width() const { return bounding_right-bounding_left; }

	//: Returns the height of the image.
	unsigned int get_height() const { return bounding_bottom-bounding_top; }

	//: Returns the number of subsprites in the image.
	unsigned int get_num_frames() const { return 1; }

	//: Get red mask
	unsigned int get_red_mask() const;

	//: Get green mask
	unsigned int get_green_mask() const;

	//: Get blue mask
	unsigned int get_blue_mask() const;

	//: Get alpha mask
	unsigned int get_alpha_mask() const;

	//: Get depth
	unsigned int get_depth() const;

	//: Is indexed
	bool is_indexed() const { return true; }

	//: Uses src colour key	
	bool uses_src_colorkey() const { return trans_col != -1; }

	//: Returns the transparency color used, -1 if none.
	unsigned int get_src_colorkey() const { return trans_col; }

//! Operations:
public:
	//: Returns the image data. Provider must be locked before pointer is valid.
	virtual void *get_data() { return image+bounding_left+bounding_top*pitch; }

	//: Locks the surface provider.
	virtual void perform_lock();

	//: Unlocks the surface provider.
	virtual void perform_unlock();

//! Implementation:
private:
	//: Loads header data into class variables.  Called by read_data().
	void read_header(CL_InputSource *_datafile);

	//: Decodes image data
	void read_data();

	////////////////////////////////
	// PCX data variables:

	//: Number of color planes in file data.
	int num_planes;

	//: Number of color planes in final image format.
	int dest_num_planes;

	//: Size of data in file.
	int size_data;

	//: PCX Version.
	unsigned char pcx_version;

	//: Bit per pixel per plane.
	unsigned char bits_per_pixel_per_plane;
	
	//: Bytes to decode per scanline (different than pitch).
	int decode_pitch;
	
	//: Bytes to allocate for decoding process.
	//: This is not necessarily the same as the image size.
	int bytes_to_allocate;

	////////////////////////////////
	// Surface Provider variables:

	//: Inputsource provider from which pcx file is loaded.
	CL_InputSourceProvider *provider;

	//: Bytes per scanline in decoded image.
	int pitch;

	//: Height of image.
	int height;

	//: Bounding rectangle.
	int bounding_left, bounding_top, bounding_right, bounding_bottom;

	//: True if colorkey is used.
	bool transparent;

	//: Colorkey color.
	int trans_col;

	//: Name of pcx file.
	std::string name;

	//: Pixel format.
	int pixelformat;

	//: Image data.
	unsigned char *image;
};

#endif

⌨️ 快捷键说明

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