📄 dpnminfo.h
字号:
/* //////////////////////////////////////////////////////////////////////////// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright(c) 2004-2005 Intel Corporation. All Rights Reserved.//////*/#ifndef __DPNMINFO_H__#define __DPNMINFO_H__#include "pnminfo.h"#include "stricmp.h"#include "diagndescr.h"#include "dpnmwarning.h"class DPNMInfo : public PNMInfo{public: DPNMInfo() {} void AttachDiagnOutput(BDiagnOutput &diagnOutput) { m_diagnOutputPtr = diagnOutput; } template<class ByteInput> void Read(ByteInput &stream) { SetMagicNumber(ReadPNMMagicNumber(stream)); unsigned int width = GetIntegerFromPNMHeader(stream); unsigned int height = GetIntegerFromPNMHeader(stream); SetSize(RectSize(width, height)); if(ColorFormat(MagicNumber()) != PNM_BLACKNWHITE) SetMaxValue(GetIntegerFromPNMHeader(stream)); else SetMaxValue(1); } void CheckMagicNumberConformance(const char *fileExt) { if(0 == Stricmp(fileExt, "pnm")) return; if(!( 0 == Stricmp(fileExt, SpecFileNameExt(ColorFormat(MagicNumber()))) )) m_diagnOutputPtr->Warning(DiagnDescrCT<DPNMWarning, WrongPNMMagicNumber>()); }protected: BDiagnOutputPtr m_diagnOutputPtr; using PNMInfo::SetMagicNumber; using PNMInfo::SetMaxValue; using PNMInfo::SetSize;};//// the best place for it is DPNMInfo,// but some compilers do not correctly compile static template members////template<class ByteInput>PNMMagicNumber ReadPNMMagicNumber(ByteInput &stream){ unsigned int magic = stream.Read16u(); switch(magic) { case PNM_PBM_TXT: case PNM_PGM_TXT: case PNM_PPM_TXT: case PNM_PBM_BIN: case PNM_PGM_BIN: case PNM_PPM_BIN: break; default: throw DiagnDescrCT<DPNMException,WrongPNMMagicNumberException>(); } return (PNMMagicNumber)magic;}template<class ByteInput>unsigned int GetIntegerFromPNMHeader(ByteInput &stream){ unsigned char symbol; unsigned char number[INT_TO_STR_MAX_SIZE]; unsigned int i = 1; symbol = stream.Read8u(); while(symbol < '0' || symbol > '9') { if(symbol == '#') while(stream.Read8u() != '\n'); symbol = stream.Read8u(); } number[0] = symbol; while(symbol >= '0' && symbol <= '9' && i < INT_TO_STR_MAX_SIZE) { number[i] = symbol = stream.Read8u(); i++; } number[i - 1] = 0; if(symbol == '#') while(stream.Read8u() != '\n'); return atoi((const char *)number);}#endif // __DPNMINFO_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -