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

📄 graphics.cxx

📁 windows mobile phone source code
💻 CXX
📖 第 1 页 / 共 4 页
字号:
/*
 * graphics.cxx
 *
 * Graphics, Canvas and drawing classes.
 *
 * 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: graphics.cxx,v $
 * Revision 1.38  1999/09/05 14:39:22  robertj
 * GNU 2.95 compatibility
 *
 * Revision 1.37  1998/10/16 11:08:15  robertj
 * GNU compatibility.
 *
 * Revision 1.36  1998/09/23 06:29:38  robertj
 * Added open source copyright license.
 *
 * Revision 1.35  1998/09/22 15:06:38  robertj
 * Added delayed HDC creation in PDrawCanvas.
 *
 * Revision 1.34  1998/03/20 03:14:11  robertj
 * Added function to get physical bounds of canvas. Allows to scale drawing.
 *
 * Revision 1.33  1997/04/27 05:50:21  robertj
 * DLL support.
 *
 * Revision 1.32  1996/11/04 03:39:34  robertj
 * Fixed warning about uninitialised variable.
 *
 * Revision 1.31  1996/07/15 10:34:21  robertj
 * Fixed uninitialised variable.
 * Changed endian classes to be memory mapped.
 *
 * Revision 1.30  1996/06/28 13:17:37  robertj
 * Removed integer size mismatch warnings
 *
 * Revision 1.29  1996/06/17 11:42:16  robertj
 * Creation of a default palette for 24 bit images.
 *
 * Revision 1.28  1996/01/28 02:52:02  robertj
 * Added assert into all Compare functions to assure comparison between compatible objects.
 *
 * Revision 1.27  1995/12/10 11:38:21  robertj
 * Removed eatwhite() as not in GNU library.
 * Fixed automatic operator translation incompatibility amongst compilers.
 *
 * Revision 1.26  1995/11/21 11:52:35  robertj
 * Improved streams compatibility.
 * Added 16 bit windows support for bitmap reading.
 *
 * Revision 1.24  1995/10/14 15:09:57  robertj
 * Changed return values to references for efficency.
 *
 * Revision 1.23  1995/08/12 22:33:42  robertj
 * Changed DrawBevelledRect() so does not change background colour.
 *
 * Revision 1.22  1995/04/25 11:29:20  robertj
 * Fixed Borland compiler warnings.
 *
 * Revision 1.21  1995/02/22 10:50:36  robertj
 * Changes required for compiling release (optimised) version.
 *
 * Revision 1.20  1995/01/27  11:13:43  robertj
 * Added pattern origin.
 *
 * Revision 1.19  1995/01/21  05:14:31  robertj
 * Added origin changing function, simpler than setting rectangles.
 * Fixed rounding error for negative numbers in coordinate system conversions.
 *
 * Revision 1.18  1995/01/06  10:43:59  robertj
 * Changed PRealFont usage from pointer to reference.
 *
 * Revision 1.17  1994/12/14  11:17:17  robertj
 * Changed PDIMENSION to be unsigned causing untold number of changes.
 *
 * Revision 1.16  1994/12/12  10:07:15  robertj
 * Made depth member of PPixels and removed virtual function.
 *
 * Revision 1.15  1994/12/05  11:34:25  robertj
 * Major rewrite of images, pictures and pixmaps.
 * Renamed PPict, PPixels and PImage to make sure all uses are found.
 *
 * Revision 1.14  1994/11/01  11:57:47  robertj
 * Removed lots of signed/unsigned mismatch warnings.
 *
 * Revision 1.13  1994/10/30  11:51:29  robertj
 * Added ability to change interactor foreground colour on a per interactor basis.
 *
 * Revision 1.12  1994/10/23  03:45:22  robertj
 * Added multiply and divide operators for points and dims.
 * Changed PPixels to have subclasses for each pixel size and be fully polymorhic.
 *
 * Revision 1.11  1994/08/21  23:43:02  robertj
 * Optimisation of DrawString() for transparent background.
 *
 * Revision 1.10  1994/08/01  03:41:24  robertj
 * Use of PNEW instead of new for heap debugging. Need undef for Unix end.
 *
 * Revision 1.9  1994/07/27  05:58:07  robertj
 * Synchronisation.
 *
 * Revision 1.8  1994/06/25  11:55:15  robertj
 * Unix version synchronisation.
 *
 * Revision 1.7  1994/04/20  12:17:44  robertj
 * assert changes
 *
 * Revision 1.6  1994/03/07  07:47:00  robertj
 * Major upgrade
 *
 * 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:53:02  robertj
 * Made inlines optional for debugging purposes.
 *
 * Revision 1.3  1993/12/15  23:41:27  robertj
 * Removed triadic conditional expressions as GCC can't do it.
 *
 * Revision 1.2  1993/12/04  05:23:25  robertj
 * More implementation
 *
 * Revision 1.1  1993/11/20  17:26:28  robertj
 * Initial revision
 */

#include <pwlib.h>
#include <ctype.h>

#define new PNEW


///////////////////////////////////////////////////////////////////////////////
// PDim

#if defined(_PDIM)

PObject * PDim::Clone() const
{
  return new PDim(width, height);
}


PObject::Comparison PDim::Compare(const PObject & obj) const
{
  PAssert(obj.IsDescendant(PDim::Class()), PInvalidCast);
  const PDim & other = (const PDim &)obj;
  if (height == other.height && width == other.width)
    return EqualTo;
  else
    return width*height < other.width*other.height ? LessThan : GreaterThan;
}


PDim PDim::operator+(const PDim & dim) const
{
  return PDim(width+dim.width, height+dim.height);
}


PDim PDim::operator+(const PPoint & pt) const
{
  return PDim(width+pt.X(), height+pt.Y());
}


PDim & PDim::operator+=(const PDim & dim)
{
  width += dim.width;
  height += dim.height;
  return *this;
}


PDim & PDim::operator+=(const PPoint & pt)
{
  width += (PDIMENSION)pt.X();
  height += (PDIMENSION)pt.Y();
  return *this;
}


PDim PDim::operator-(const PDim & dim) const
{
  return PDim(width-dim.width, height-dim.height);
}


PDim & PDim::operator-=(const PDim & dim)
{
  width -= dim.width;
  height -= dim.height;
  return *this;
}


PDim & PDim::operator-=(const PPoint & pt)
{
  width -= (PDIMENSION)pt.X();
  height -= (PDIMENSION)pt.Y();
  return *this;
}


PDim PDim::operator*(PDIMENSION scale) const
{
  return PDim(width*scale, height*scale);
}


PDim & PDim::operator*=(PDIMENSION scale)
{
  width *= scale;
  height *= scale;
  return *this;
}

PDim PDim::operator/(PDIMENSION scale) const
{
  return PDim(width/scale, height/scale);
}


PDim & PDim::operator/=(PDIMENSION scale)
{
  width /= scale;
  height /= scale;
  return *this;
}


#endif


///////////////////////////////////////////////////////////////////////////////
// PPoint

#if defined(_PPOINT)

PObject * PPoint::Clone() const
{
  return new PPoint(*this);
}


PObject::Comparison PPoint::Compare(const PObject & obj) const
{
  PAssert(obj.IsDescendant(PPoint::Class()), PInvalidCast);
  const PPoint & other = (const PPoint &)obj;
  if (X() == other.X() && Y() == other.Y())
    return EqualTo;

  return X()+Y() < other.X()+other.Y() ? LessThan : GreaterThan;
}


PPoint PPoint::operator+(const PPoint & pt) const
{
  return PPoint(X()+pt.X(), Y()+pt.Y());
}


PPoint PPoint::operator+(const PDim & dim) const
{
  return PPoint(X()+dim.Width(), Y()+dim.Height());
}


PPoint PPoint::operator-(const PPoint & pt) const
{
  return PPoint(X()-pt.X(), Y()-pt.Y());
}


PPoint PPoint::operator-(const PDim & dim) const
{
  return PPoint(X()-dim.Width(), Y()-dim.Height());
}


PPoint PPoint::operator*(const PPoint & pt) const
{
  return PPoint(X()*pt.X(), Y()*pt.Y());
}


PPoint PPoint::operator*(const PDim & dim) const
{
  return PPoint(X()*dim.Width(), Y()*dim.Height());
}


PPoint PPoint::operator*(PORDINATE scale) const
{
  return PPoint(X()*scale, Y()*scale);
}


PPoint PPoint::operator/(const PPoint & pt) const
{
  return PPoint(X()/pt.X(), Y()/pt.Y());
}


PPoint PPoint::operator/(const PDim & dim) const
{
  return PPoint(X()/dim.Width(), Y()/dim.Height());
}


PPoint PPoint::operator/(PORDINATE scale) const
{
  return PPoint(X()/scale, Y()/scale);
}


#endif


///////////////////////////////////////////////////////////////////////////////
// PRect

#if defined(_PRECT)

PObject * PRect::Clone() const
{
  return new PRect(*this);
}



PPoint PRect::Centre() const
{
  return PPoint(X()+Width()/2, Y()+Height()/2);
}


void PRect::SetOrigin(PORDINATE nx, PORDINATE ny)
{
  SetX(nx);
  SetY(ny);
}


void PRect::SetOrigin(const PPoint & org)
{
  SetX(org.X());
  SetY(org.Y());
}


void PRect::SetCorner(PORDINATE nx, PORDINATE ny)
{
  SetRight(nx);
  SetBottom(ny);
}


void PRect::SetCorner(const PPoint & cnr)
{
  SetRight(cnr.X());
  SetBottom(cnr.Y());
}


void PRect::SetDimensions(PDIMENSION dx, PDIMENSION dy)
{
  SetWidth(dx);
  SetHeight(dy);
}


void PRect::SetDimensions(const PDim & dim)
{
  SetWidth(dim.Width());
  SetHeight(dim.Height());
}


#endif


///////////////////////////////////////////////////////////////////////////////
// PPixels

PPixelImage::PPixelImage(PDIMENSION dx, PDIMENSION dy, BYTE depth)
{
  switch (depth) {
    case 32 :
      operator=(PPixelImage(new PPixels32(dx, dy)));
      break;

    case 24 :
      operator=(PPixelImage(new PPixels24(dx, dy)));
      break;

    case 8 :
      operator=(PPixelImage(new PPixels8(dx, dy)));
      break;

    case 4 :
      operator=(PPixelImage(new PPixels4(dx, dy)));
      break;

    case 2 :
      operator=(PPixelImage(new PPixels2(dx, dy)));
      break;

    case 1 :
      operator=(PPixelImage(new PPixels1(dx, dy)));
      break;

    default:
      PAssertAlways(PUnsupportedFeature);
  }
}


struct P_BITMAPINFOHEADER {
  P_BITMAPINFOHEADER(istream & s)
    { s >> biWidth >> biHeight >> biPlanes >> biBitCount
        >> biCompression >> biSizeImage >> biXPelsPerMeter
        >> biYPelsPerMeter >> biClrUsed >> biClrImportant;
    }

  PUInt32l biWidth;
  PUInt32l biHeight;
  PUInt16l biPlanes;
  PUInt16l biBitCount;
  PUInt32l biCompression;
  PUInt32l biSizeImage;
  PUInt32l biXPelsPerMeter;
  PUInt32l biYPelsPerMeter;
  PUInt32l biClrUsed;
  PUInt32l biClrImportant;
};

struct P_RGBQUAD {
  P_RGBQUAD(istream & s)
    { s >> rgbBlue >> rgbGreen >> rgbRed >> rgbReserved; }

  operator PColour() const { return PColour(rgbRed, rgbGreen, rgbBlue); }

  PUInt8 rgbBlue;
  PUInt8 rgbGreen;
  PUInt8 rgbRed;
  PUInt8 rgbReserved;
};

struct P_BITMAPCOREHEADER {
  P_BITMAPCOREHEADER(istream & s)
    { s >> bcWidth >> bcHeight >> bcPlanes >> bcBitCount; }

  PUInt16l bcWidth;
  PUInt16l bcHeight;
  PUInt16l bcPlanes;
  PUInt16l bcBitCount;
};


struct P_RGBTRIPLE {
  P_RGBTRIPLE(istream & s)
    { s >> rgbtBlue >> rgbtGreen >> rgbtRed; }

  operator PColour() const { return PColour(rgbtRed, rgbtGreen, rgbtBlue); }

  PUInt8 rgbtBlue;
  PUInt8 rgbtGreen;
  PUInt8 rgbtRed;
};


static void ReadBMP(istream & stream, PPixelImage & image)
{
  stream.ignore(12); // Skip rest of BITMAPFILEHEADER structure

  PUInt32l hdrsize;  // Read size of header for bitmap
  stream >> hdrsize;

  PPalette palette;
  DWORD width, height, imageSize;
  WORD bitCount;
  PINDEX colourCount;

  switch ((DWORD)hdrsize) {
    case 40 : {
      P_BITMAPINFOHEADER bmih(stream);
      if (!stream.good())
        return;

      width = bmih.biWidth;
      height = bmih.biHeight;
      bitCount = bmih.biBitCount;
      imageSize = bmih.biSizeImage;

      if (bitCount < 24 && (DWORD)bmih.biClrUsed == 0)
        colourCount = 1 << bitCount;
      else

⌨️ 快捷键说明

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