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

📄 image.h

📁 这是VCF框架的代码
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef _VCF_IMAGE_H__#define _VCF_IMAGE_H__//Image.h/*Copyright 2000-2004 The VCF Project.Please see License.txt in the top level directorywhere you installed the VCF.*/#if _MSC_VER > 1000#   pragma once#endif/* Generated by Together */namespace VCF{class ImageBits;class GraphicsContext;/**\class Image Image.h "vcf/GraphicsKit/Image.h"The Image class is an abstract class that defines how you can work with and manipulate an image.An image provides access to information such as the pixel layout, the number of color channels in the image, the number of bits in each channel, and whether or not the channel data is floating point or integer based. You can get or set the height or width of an image. You can manipulate the bits of the image as well. Setting the size will destroy any existing data in the image.Image bits are manipulated through the ImageBits class. Each image has an ImageBits instance - the ImageBits holds a pointer to the buffer of data for the image. Depending on the system the buffer may be allocated by the VCF or it may be allocated by the platform. In other words, *don't* reallocate or delete this memory - it's not your's to play with! Feel to modify the pixel values to your heart's content though. \codeImage* img = //... get the image from somewhereSysPixelType* pixels = img->getImageBits()->pixels_;//assume a 4 color channel imageint sz = img->getHeight() * img->getWidth();for (int i=0;i<sz;i++ ) {	pixels[i].b = //...determine some cool blue value	pixels[i].g = //...determine some cool green value	pixels[i].r = //...determine some cool red value	pixels[i].a = //...determine some cool alpha value}\endcodeEach platform defines a specific type of SysPixelType. For example on Win32 it's defined as BGRAPixel<unsigned char>, which means that each pixel type is laid out in blue, green, red, alpha order, and each unit (of b,g,r,a) is an unsigned char (8 bits). By default, the ImageBits data uses this as it unit of storage in it's buffer.To support AGG integration, the ImageBits has a renderBuffer_ member. You can initialize this like so :\codeimg->getImageBits()->attachRenderBuffer( img->getWidth(), img->getHeight() );\endcodeOnce initialized, you can use the render buffer in AGG operations (see <a href="http://www.antigrain.com/doc/index.html">http://www.antigrain.com/doc/index.html</a> for more on AGG).Unlike many of the other classes in the VCF, the Image class does not use a peer. Instead a concrete platform implementation is provided for each platform the VCF is ported to. So what you have is (on Win32, for example):\verbatim Image  |  +--- AbstractImage               |               +--- Win32Image\endverbatimThus any instance of an Image that you deal with on the Win32 platform is ultimately a Win32Image instance. The AbstractImage is used to implement the basic housekeeping methods that are almost certainly guaranteed to be the same no matter the platform. The rest are then implemented in the concrete platform class.Part of the idea behind the ImageBits class is to support a number of different image types. The idea being that we would have 4 channel color images, or 1 channel grey scale images, with potentially different channel sizes and pixel layout order. This is currently accomplished through the use of templates.\noteCurrently while we have the potential to support grey scale images, we do not in practice actually do so yet. Nor do we fully support alpha blending - we do have the data there, we just don't make any use of it yet.We do support a *sort* of transparency. The image has ability to set a transparency color, and then toggle whether or not this should be used (see Image::setTransparencyColor() and Image::setIsTransparent() ) .Drawing images is done by creating an image and then calling the various image drawing methods on the GraphicsContext.Drawing an image (on Win32) means we take a couple of things into consideration:\li 1) do we have a current transform in the GraphicsContext that is not an identity set? An identity set means that nothing needs to be transformed.\li 2) is the image transparent (Image::isTransparent() returns true)?If the current transform is *not* "default" i.e. it's an identity set, then we do the more complex code that uses AGG to transform the image and then blend it with the underlying bits that belong to the graphics context HDC.If the transform is default then we create a sub image and transfer whatever pixels we need that are within our image bounds rect. Then if the image is transparent we execute some insane code that uses a 1 bit mask to clear out, or render invisible (using extra HBITMAP's and ROP code magic) and pixels in the image that correspond to the image's transparent color. So if an image has it's transparent color set to "green" then any green pixels in the image will become invisible and the underlying pixels of the graphics context will show through.*/class GRAPHICSKIT_API Image {public:	/**	This indicates the type of image. An image may be either	Color (this is the default) or Grayscale. Color images	have four channels, grayscale images have 1. The precise	value of the enum is the number of channels the image	has. Thus itGrayscale is 1 for one channel, and itColor	is 4 for 4 channels.	*/	enum ImageType{		/**		Indicates a Color image with four channels		*/		itColor = 0x4,		/**		Indicates a Grayscale image with one channel		*/		itGrayscale = 1	};	/**	This indicates the size of each channel	*/	enum ImageChannelSize {		ics8Bit = 0x08,		ics16Bit = 0x10,		ics32Bit = 0x20	};	enum ImageChannelType {		ictInteger = 0,		ictFloatingPoint = 1	};	enum PixelLayoutOrder {		ploRGBA,		ploBGRA,		ploARGB,		ploABGR	};	typedef unsigned long ImageDescriptor;	virtual ~Image(){};	/**	returns the type of image that this Image instance represents.	The integer value also indicates the number of color channels	the Image has. Currently there are only 2 types, full color	4 channel RGBA images, and 1 channel grayscale images.	@return ImageType the value that represent the images type. The	values have the follwing meanings:			\li Image::itColor - indicate a full color image with red, green, blue, and alpha		channels present. The integer value of this is 4 and can be used in operations		to determine the total data size of the image, for example.		\li Image::itGrayscale - indicates a grayscale image with a single channel. The		numerical value of this is 1.		*/	virtual ImageType getType() const = 0;	/**	returns the number of bits each channel value represents. For example, by default, on	Win32 systems, an Image is a full color RGBA image, with each value of a channel	taking 8 bits, thus a single of pixel of this type of image takes up 32 bits - 4 channels	with each channel component 8 bits in size.	@return the channel's component size. Can be one of the following values:			\li Image::ics8Bit - each channel component is 8 bits in sizem, thus the numerical		value of this enum is 8.		\li Image::ics16Bit - each channel component is 8 bits in sizem, thus the numerical		value of this enum is 16.		\li Image::ics32Bit - each channel component is 8 bits in sizem, thus the numerical		value of this enum is 32.		The last two types (Image::ics16Bit and Image::ics32Bit) are typically used for high end imaging.	*/	virtual ImageChannelSize getChannelSize() const = 0;	/**	returns whether the values for a channel are integer based or floating point based.	@return ImageChannelType the image channel's value type. Can be one of			\li  Image::ictInteger - the value of a channel is integer based. It's min and max values		can be expressed by ImageBits::Traits::minVal() and ImageBits::Traits::maxVal() respectively.		Typically this is a value between 0 and 2<sup>getChannelSize()</sup> (inclusive).		\li  Image::ictFloatingPoint - the value of a channel is integer based. It's min and max values		can be expressed by ImageBits::Traits::minVal() and ImageBits::Traits::maxVal() respectively.		Typically this is a value in the range of 0.0 and 1.0 inclusive.		*/	virtual ImageChannelType getChannelType() const = 0;	/**	returns the pixel layout order. This explains how the individual color components	of each of the color channels are laid out.	@return PixelLayoutOrder the binary layout order of a single pixel value. Can be one of			\li  Image::ploRGBA - indicates the Red value is in the MSB position, followed		by Green, Blue and finally Alpha values. In code it might		look like this for an Image with integer based 8 bit color channels		\code			ulong32 pixelColor = (redVal &lt;&lt; 24) | (greenVal &lt;&lt; 16) | (blueVal &lt;&lt; 8) | (alphaVal);		\endcode		Extracting the values from a single pixel color would be:		\code			redVal	= (pixelColor &amp; 0xFF000000) &gt;&gt; 24;

⌨️ 快捷键说明

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