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

📄 pixelformat.cpp

📁 vncviewer_source_1.0
💻 CPP
字号:
/* Copyright (C) 2006 Lucas Gomez  All Rights Reserved.
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

// INCLUDE FILES
#include "PixelFormat.h"

//LITERALS

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CPixelFormat::CPixelFormat()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CPixelFormat::CPixelFormat(TInt aBpp,TInt aDepth,TBool aBigEndian,TBool aTrueColor,
    					   TInt aRedMax,TInt aGreenMax,TInt aBlueMax,
    					   TInt aRedShift,TInt aGreenShift,TInt aBlueShift)
{
	iBpp=aBpp;
    iDepth=aDepth;
    iBigEndian=aBigEndian;
    iTrueColor=aTrueColor;
    
	iRedMax=aRedMax;
	iGreenMax=aGreenMax;
	iBlueMax=aBlueMax;
	iRedShift=aRedShift;
	iGreenShift=aGreenShift;
	iBlueShift=aBlueShift;
}

// ---------------------------------------------------------------------------
// CPixelFormat::~CPixelFormat()
// Destructor.
// ---------------------------------------------------------------------------
//
CPixelFormat::~CPixelFormat()
{
	
}

TBool CPixelFormat::Equal(CPixelFormat* aPF)
{
	return ((iBpp==aPF->iBpp) &&
			(iDepth==aPF->iDepth) &&
			iBigEndian==aPF->iBigEndian &&
			(!iTrueColor || ((iRedMax==aPF->iRedMax) &&
							(iGreenMax==aPF->iGreenMax) &&
							(iBlueMax==aPF->iBlueMax) &&
							(iRedShift==aPF->iRedShift) &&
							(iGreenShift==aPF->iGreenShift) &&
							(iBlueShift==aPF->iBlueShift))));
}

void CPixelFormat::Read(InStream* aIS)
{
	iBpp=aIS->ReadU8();
	iDepth=aIS->ReadU8();
	iBigEndian=aIS->ReadU8()!=0;
	iTrueColor=aIS->ReadU8()!=0;
	iRedMax=aIS->ReadU16();
	iGreenMax=aIS->ReadU16();
	iBlueMax=aIS->ReadU16();
	iRedShift=aIS->ReadU8();
	iGreenShift=aIS->ReadU8();
	iBlueShift=aIS->ReadU8();
	aIS->Skip(3);
}

void CPixelFormat::Write(OutStream* aOS)
{
	aOS->WriteU8(iBpp);
	aOS->WriteU8(iDepth);
	aOS->WriteU8(iBigEndian?1:0);
	aOS->WriteU8(iTrueColor?1:0);
	aOS->WriteU16(iRedMax);
	aOS->WriteU16(iGreenMax);
	aOS->WriteU16(iBlueMax);
	aOS->WriteU8(iRedShift);
	aOS->WriteU8(iGreenShift);
	aOS->WriteU8(iBlueShift);
	aOS->WriteU8(0);
	aOS->WriteU8(0);
	aOS->WriteU8(0);
}

void CPixelFormat::Print(TDes& aS)
{
    aS.Append(_L("depth "));
    aS.AppendNum(iDepth);
    aS.Append(_L(" ("));
    aS.AppendNum(iBpp);
    aS.Append(_L("bpp)"));
    if(iBpp!=8) 
    {
      	if(iBigEndian)
        	aS.Append(_L(" big-endian"));
      	else
        	aS.Append(_L(" little-endian"));
    }

    if(!iTrueColor) 
    {
      	aS.Append(_L(" colour-map"));
      	//return aS;
    }

    else if (iBlueShift == 0 && iGreenShift > iBlueShift && iRedShift > iGreenShift &&
        iBlueMax  == (1 << iGreenShift) - 1 &&
        iGreenMax == (1 << (iRedShift-iGreenShift)) - 1 &&
        iRedMax   == (1 << (iDepth-iRedShift)) - 1)
    {
      	aS.Append(_L(" rgb"));
      	aS.AppendNum((iDepth-iRedShift)+(iRedShift-iGreenShift)+iGreenShift);
      	//return aS;
    }

    else if (iRedShift == 0 && iGreenShift > iRedShift && iBlueShift > iGreenShift &&
        iRedMax   == (1 << iGreenShift) - 1 &&
        iGreenMax == (1 << (iBlueShift-iGreenShift)) - 1 &&
        iBlueMax  == (1 << (iDepth-iBlueShift)) - 1)
    {
      	aS.Append(_L(" bgr"));
      	aS.AppendNum((iDepth-iBlueShift)+(iBlueShift-iGreenShift)+iGreenShift);
      	//return aS;
    }
	else
	{
	    aS.Append(_L(" rgb max "));
	    aS.AppendNum(iRedMax);
	    aS.Append(',');
	    aS.AppendNum(iGreenMax);
	    aS.Append(',');
	    aS.AppendNum(iBlueMax);
	    aS.Append(_L(" shift "));
	    aS.AppendNum(iRedShift);
	    aS.Append(',');
	    aS.AppendNum(iGreenShift);
	    aS.Append(',');
	    aS.AppendNum(iBlueShift);
	    //return aS;
	}
}

⌨️ 快捷键说明

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