pixels.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:21k
- /*
- * pixels.h
- *
- * Pixel image.
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: pixels.h,v $
- * Revision 1.24 1999/08/24 06:54:36 robertj
- * Cleaned up the smart pointer code (macros).
- *
- * Revision 1.23 1999/03/10 03:49:52 robertj
- * More documentation adjustments.
- *
- * Revision 1.22 1999/03/09 08:01:49 robertj
- * Changed comments for doc++ support (more to come).
- *
- * Revision 1.21 1999/02/16 08:08:46 robertj
- * MSVC 6.0 compatibility changes.
- *
- * Revision 1.20 1998/12/01 12:55:56 robertj
- * new directory structure.
- *
- * Revision 1.19 1998/10/16 11:08:11 robertj
- * GNU compatibility.
- *
- * Revision 1.18 1998/09/23 06:28:00 robertj
- * Added open source copyright license.
- *
- * Revision 1.17 1995/11/09 12:18:30 robertj
- * Changed read image function to accept any stream.
- *
- * Revision 1.16 1995/06/17 11:12:55 robertj
- * Documentation update.
- *
- * Revision 1.15 1995/03/14 12:42:03 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.14 1995/01/09 12:39:03 robertj
- * Documentation.
- *
- * Revision 1.13 1994/12/12 10:06:21 robertj
- * Renamed PWrapper to PSmartPointer.
- * Made depth member of PPixels and removed virtual function.
- *
- * Revision 1.12 1994/12/05 11:34:12 robertj
- * Major rewrite of images, pictures and pixmaps.
- * Renamed PPict, PPixels and PImage to make sure all uses are found.
- *
- * Revision 1.11 1994/10/23 04:51:26 robertj
- * Split PPixels into a number of subclasses for each pixel size.
- *
- * Revision 1.10 1994/08/23 11:32:52 robertj
- * Oops
- *
- * Revision 1.9 1994/08/22 00:46:48 robertj
- * Added pragma fro GNU C++ compiler.
- *
- * Revision 1.8 1994/06/25 11:55:15 robertj
- * Unix version synchronisation.
- *
- * Revision 1.7 1994/04/03 08:34:18 robertj
- * Added help and focus functionality.
- *
- * Revision 1.6 1994/03/07 07:38:19 robertj
- * Major enhancementsacross the board.
- *
- * Revision 1.5 1994/01/03 04:42:23 robertj
- * Mass changes to common container classes and interactors etc etc etc.
- *
- * Revision 1.4 1993/12/31 06:45:38 robertj
- * Made inlines optional for debugging purposes.
- *
- * Revision 1.3 1993/12/29 04:40:47 robertj
- * Mac port.
- *
- * Revision 1.2 1993/12/01 16:09:05 robertj
- * Windows NT port.
- *
- * Revision 1.1 1993/10/16 20:33:20 robertj
- * Initial revision
- *
- */
- #define _PPIXELS
- #ifdef __GNUC__
- #pragma interface
- #endif
- #ifndef _PIMAGE
- #include <pwlib/image.h>
- #endif
- #ifndef _PPALETTE
- #include <pwlib/palette.h>
- #endif
- PARRAY(PColourArray, PColour);
- class PPixelBase;
- /*
- PDECLARE_CLASS(PPixelImage, PImage)
- This class is used to represent a pixel image. It works in conjuction with
- the Ref{PPixelBase} class using the "smart" pointer system.
-
- A pixel image is one for which each indiviual pixel is stored and rendered.
- This give maximum flexibility in what the image may display at the expense
- of large memory usage.
-
- A common use for images is by the Ref{PMemoryCanvas} class for drawing to
- off screen memory.
- */
- class PPixelImage : public PImage
- {
- PSMART_POINTER_INFO(PPixelImage, PImage, PPixelBase);
- public:
- /**Create a pixel image container.
- Access to this image will assert.
- */
- PPixelImage(PPixelBase * obj = NULL);
- /**Create a new, blank pixmap or the specified dimensions. The pixel image
- may then be drawn into via a Ref{PMemoryCanvas} instance.
- */
- PPixelImage(
- PDIMENSION dx, /// Width of image in pixels.
- PDIMENSION dy, /// Height of image in pixels.
- BYTE depth /// Depth of image in bits per pixel.
- );
- /**Create a pixel image, reading it from the applications resources. This
- would typically be created by the PWRC program IMAGE keyword.
- */
- PPixelImage(
- PRESOURCE_ID resID /// Unique identifier for pixel image resource.
- );
- /**Create a pixel image, reading the picture from the file in standard
- platform specific format. For example under MS-Windows this would read
- a ".BMP" file.
- */
- PPixelImage(
- istream & stream /// Stream to read pixel image from.
- );
- };
- class PPixelBase : public PImageBase
- {
- PCLASSINFO(PPixelBase, PImageBase)
- /* A class representing a graphic drawing shape that is a pixel bitmap image.
- This is used in conjuction with the Ref{PPixelImage} class using the
- "smart" pointer system.
- A pixel image is one for which each indiviual pixel is stored and rendered.
- This gives maximum flexibility in what the image may display at the expense
- of large memory usage and lack of scalability. The alternative is to use
- the Ref{PPictImage} which stores the image as a set of drawing commands.
-
- This is an abstract class as a sub-class based on a particular depth is
- really created and placed into the smart pointer.
- */
- protected:
- /**Create a bit image with the dimensions specified. This will allocate
- storage for the internal representation o fthe pixmap. As this can be
- a significant amount, the Ref{GetPixelDataPtr()} function should be
- checked to see if the memory allocation succeeded.
- */
- PPixelBase(
- PDIMENSION dx, /// Width of image in pixels.
- PDIMENSION dy, /// Height of image in pixels.
- BYTE depth /// Depth of image in bits per pixel.
- );
- /** Delete the pixel bitmap and its internal memory storage. */
- ~PPixelBase();
- public:
- /**@name Overrides from class PObject */
- /**Determine if the two pixel images are the same. Note that this is
- different from having two pixel images that merely {bf look} the
- same. They must be references to the same pixel image file or if
- loaded from resources, the same resource ID.
- @return
- #EqualTo# if reference the same pixel image,
- #GreaterThan# if different.
- */
- virtual Comparison Compare(
- const PObject & obj /// Another pixel image to compare against.
- ) const;
- /**@name Overrides from class PImage */
- /**Write the picture drawing into the specified file in platform specific
- format. For example under MS-Windows this would read a ".BMP" file.
- */
- virtual BOOL Write(
- PFile & dwg /// File to write the pixel image to.
- );
- /**@name New functions for class */
- /**Get the memory storage pointer for the raw pixel data. This is not
- generally useful to a platform independent application as the exact
- format of the pixels in the memory block is platform specific.
-
- The normal use of this function is to check that a memory block was
- successfully allocated on systems for which memory is a limited
- resource.
- @return
- pointer to a memory block.
- */
- PPixelDataPtr GetPixelDataPtr() const;
- /**Get a pointer to the raw pixel data for the raster line. This is not
- generally useful to a platform independent application as the exact
- format of the pixels in the memory block is platform specific.
-
- An application that requires special processing of the data and takes
- responsibility for all of the pixel depth detection etc could use this
- function. For example if only 8 bit images are used the pixel packing
- into the raster is very uniform across platforms and high levels of
- optimisation could be made.
-
- It is recommended that the Ref{GetRaster()} and Ref{SetRaster()}
- function be used instead of this function.
-
- Note that this function should be used instead of the
- Ref{GetPixelDataPtr()} function as the order of the raster lines is
- platform dependent. That is:
-
- # GetRaster(0) != GetPixelDataPtr()#
-
- may be TRUE.
-
- @return
- pointer to memory block at start of raster line.
- */
- PPixelDataPtr GetRasterDataPtr(PORDINATE y) const;
- /**Determine if the pixel image can display full RGB colours. Essentially
- this means the image has a depth greater than 24 bits per pixel.
- Returns TRUE if true colour pixel image.
- */
- BOOL IsFullColour() const;
- /**Determine the depth (number of bits per pixel) of the bitmap image. The
- descendent class determines this value even tough it is stored as a
- member variable. That variable should {bf not} be changed.
- @return
- bits per pixel for image.
- */
- BYTE GetDepth() const;
- /**Get the palette associated with the pixel image.
-
- For non true colour pixel images, this determines the correspondence
- between the pixel values and the RGB colours they represent. For true
- colour images this is only used as a hint to the destination device
- about the best colours to use, assuming the destination device is not
- a true colour display itself.
- @return
- palette used for image.
- */
- PPalette GetPalette() const;
- /**Set the palette associated with the pixel map.
-
- For non true colour pixel images, this determines the correspondence
- between the pixel values and the RGB colours they represent. For true
- colour images this is only used as a hint to the destination device
- about the best colours to use, assuming the destination device is not
- a true colour display itself.
-
- Note changing the palette for an existing image can have very strange
- effects as the pixel values themselves do not change.
- */
- void SetPalette(
- const PPalette & pal /// New palette for pixel image.
- );
- /**Set the pixel at the location specified to the particular colour. For
- true colour images the pixel is set to that colour. For non true colour
- images the pixel is set to the nearest colour contained in the palette.
- */
- virtual void SetPixelColour(
- PORDINATE x, /// Horizontal position of pixel in raster.
- PORDINATE y, /// Vertical raster line.
- const PColour& colour /// Colour to set pixel to.
- );
- /**Get the colour of the pixel at the specified location. For non true
- colour images this is the colour in the palette at the index determined
- by the pixel value.
- @return
- colour for the pixel.
- */
- virtual PColour GetPixelColour(
- PORDINATE x, /// Horizontal position of pixel in raster.
- PORDINATE y /// Vertical raster line.
- ) const;
- /**Set the pixel at the location to the specified value. If the image is
- true colour then the it will set a grey scale value for the pixel. For
- non true colour images this sets the colour of the pixel to that in the
- palette at the index position.
- */
- virtual void SetPixel(
- PORDINATE x, /// Horizontal position of pixel in raster.
- PORDINATE y, /// Vertical raster line.
- BYTE value /// New value for pixel.
- ) = 0;
- /**Get the pixel at the location. If the image is true colour then it
- returns the luminance for the pixel colour. If a non true colour image
- then this returns the index into the palette that the pixel value
- represents.
-
- @return
- current value of pixel.
- */
- virtual BYTE GetPixel(
- PORDINATE x, /// Horizontal position of pixel in raster.
- PORDINATE y /// Vertical raster line.
- ) const = 0;
- /**Set the pixels for the whole or part of the raster line. Note this
- expects the data to be unpacked (one pixel per byte) and packages it
- into the correct internal representation used by the platform.
-
- This is functionally equivalent to repeated calls to the
- Ref{SetPixelColour()} or Ref{SetPixel()} functions but is optimised
- for each image depth and platform.
- */
- void SetRaster(
- PORDINATE y, /// Vertical raster line.
- const PColourArray & rasterColours, /// Array of colours for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to set
- );
- void SetRaster(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- const PColourArray & rasterColours, /// Array of colours for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to set
- );
- void SetRaster(
- PORDINATE y, /// Vertical raster line.
- const PBYTEArray & rasterBytes, /// Array of values for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to set
- );
- void SetRaster(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- const PBYTEArray & rasterBytes, /// Array of values for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to set
- );
- void SetRaster(
- PORDINATE y, /// Vertical raster line.
- const BYTE * raster, /// Pointer to array of values for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to set
- );
- void SetRaster(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- const BYTE * raster, /// Pointer to array of values for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to set
- );
- /**Get the pixels for the whole or part of the raster line. Note this
- provides the data unpacked (one pixel per byte) from the correct
- internal representation used by the platform.
- This is functionally equivalent to repeated calls to the
- Ref{SetPixelColour()} or Ref{SetPixel()} functions but is optimised
- for each image depth and platform.
- */
- void GetRaster(
- PORDINATE y, /// Vertical raster line.
- PColourArray & rasterColours, /// Array of colours for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to get.
- ) const;
- void GetRaster(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- PColourArray & rasterColours, /// Array of colours for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to get.
- ) const;
- void GetRaster(
- PORDINATE y, /// Vertical raster line.
- PBYTEArray & rasterBytes, /// Array of values for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to get.
- ) const;
- void GetRaster(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- PBYTEArray & rasterBytes, /// Array of values for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to get.
- ) const;
- void GetRaster(
- PORDINATE y, /// Vertical raster line.
- BYTE * raster, /// Pointer to array of values for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to get.
- ) const;
- void GetRaster(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- BYTE * raster, /// Pointer to array of values for pixels.
- PDIMENSION width = P_MAX_INDEX /// Number of pixels in raster to get.
- ) const;
- /**Extract a section of pixels out of the image. The new image is of the
- same depth as the current image but has dimensions the size of the
- section extracted.
- @return
- new pixel image of section of current image.
- */
- PPixelImage ExtractPixels(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- PDIMENSION width, /// Horizontal width of the section of image to extract.
- PDIMENSION height /// Vertical height of the section of image to extract.
- ) const;
- PPixelImage ExtractPixels(
- const PRect & rect
- /// Position and dimensions of the section of image to extract.
- ) const;
- /**Get the dirty area for the pixel image.
-
- The dirty area is set by calls to the Ref{SetPixelColour()},
- Ref{SetPixel()} and Ref{SetRaster()} functions. This can be used to
- optimise processing by easily determining how much of image has been
- changed. The dirty area continues to increase in size until the
- Ref{ClearDirtyArea()} function is called.
- */
- const PRect & GetDirtyArea() const;
- void ClearDirtyArea();
- /**Clear the dirty area for the pixel image.
-
- The dirty area is set by calls to the Ref{SetPixelColour()},
- Ref{SetPixel()} and Ref{SetRaster()} functions. This can be used to
- optimise processing by easily determining how much of image has been
- changed. The dirty area continues to increase in size until the
- ClearDirtyArea() function is called.
- */
- protected:
- /** Expand the dirty area to include the specified pixels. */
- void SetDirtyArea(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- PDIMENSION width = 1 /// Number of pixels to set as "dirty".
- );
- /**Calculate the address of the byte that contains the specified pixel
- in the raster line in the pixel image.
-
- @return
- pointer to the position in the raster line.
- */
- PPixelDataPtr CalculateRaster(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- PDIMENSION & widthToLastX
- /**Width value to convert to a last X value. This is a number of pixels
- provided by the calling function that is altered to a horizontal
- pixel number. This is assured to be within the bounds of raster line.
- */
- ) const;
- /**Set the colours of a raster line in the pixel image. This is the
- polymorphic form of the Ref{SetRaster()} functions.
- */
- virtual void SetRasterColours(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- const PColourArray & rasterColours, /// Array of colours for pixels.
- PDIMENSION width /// Number of pixels in raster to set
- );
- /**Get the colours of a raster line in the pixel image. This is the
- polymorphic form of the Ref{GetRaster()} functions.
- */
- virtual void GetRasterColours(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- PColourArray & rasterColours, /// Array of colours for pixels.
- PDIMENSION width /// Number of pixels in raster to get.
- ) const;
- /**Set the colours of a raster line in the pixel image. This is the
- polymorphic form of the Ref{SetRaster()} functions.
- */
- virtual void SetRasterValues(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- const BYTE * raster, /// Pointer to array of values for pixels.
- PDIMENSION width /// Number of pixels in raster to set.
- ) = 0;
- /**Get the colours of a raster line in the pixel image. This is the
- polymorphic form of the Ref{GetRaster()} functions.
- */
- virtual void GetRasterValues(
- PORDINATE x, /// Horizontal position of start pixel in raster.
- PORDINATE y, /// Vertical raster line.
- BYTE * raster, /// Pointer to array of values for pixels.
- PDIMENSION width /// Number of pixels in raster to get.
- ) const = 0;
- /** Colour look up table */
- PPalette palette;
- /** Memory block for pixel data */
- PPixelDataPtr pixels;
- /** Width of a scan line in pixel data in bytes */
- PINDEX pixelLineBytes;
- /** Area of pix map that was changed */
- PRect dirtyArea;
- friend class PPixelImage;
-
- #ifdef DOC_PLUS_PLUS
- };
- #endif
- // Class declaration continued in platform specific header file ///////////////