📄 ddibinfo.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 __DDIBINFO_H__#define __DDIBINFO_H__#include "dibinfo.h"#include "diagndescr.h"#include "ddibwarning.h"#include "ddibexception.h"class DDIBInfo : public DIBInfo{public: DDIBInfo() {} void AttachDiagnOutput(BDiagnOutput &diagnOutput) { m_diagnOutputPtr = diagnOutput; } template<class ByteInput> void Read(ByteInput &stream) { unsigned int nOfPaletteEntries; // // Please, note the functions that called below // are defined after the place of call specification. // It's possible because they definition placed // before actual instantiation of template. // ReadInfoHeader(stream, m_style, m_size, m_depth, m_origin, m_pelsPerMeter, m_rawExtension, nOfPaletteEntries, m_diagnOutputPtr); m_palette.ReAlloc(nOfPaletteEntries); ReadPalette(stream, m_style, m_palette, nOfPaletteEntries); }protected: BDiagnOutputPtr m_diagnOutputPtr;// change domain to protected for 'Set' functions. using DIBInfo::SetStyle; using DIBInfo::SetSize; using DIBInfo::SetDepth; using DIBInfo::SetOrigin; using DIBInfo::SetPelsPerMeter; using DIBInfo::SetPalette; using DIBInfo::SetRawExtension;};//// see previous comment// +// the best place for it is DPNMInfo,// but some compilers do not correctly compile static template members////template<class ByteInput>void ReadCoreInfoHeader( ByteInput &stream, RectSize &size, DIBDepth &depth, unsigned int &nOfPaletteEntries, BDiagnOutputPtr &diagnOutputPtr){ // we do not read size of structure here size.SetWidth (stream.Read16u()); size.SetHeight(stream.Read16u()); unsigned int nOfPlanes = stream.Read16u(); if(nOfPlanes != 1) diagnOutputPtr->Warning(DiagnDescrCT<DDIBWarning, DIBInfoWrongNOfPlanes>()); unsigned int bitCount = stream.Read16u(); switch(bitCount) { case 8: depth = Depth_8; nOfPaletteEntries = 1 << 8; break; case 24: depth = Depth_24; nOfPaletteEntries = 0; break; default: throw DiagnDescrCT<DDIBException,NotSupportedBitCount>(); }}template<class ByteInput>void ReadCommonInfoHeader( ByteInput &stream, RectSize &size, DIBDepth &depth, DIBOrigin &origin, RectSize &pelsPerMeter, unsigned int &nOfPaletteEntries, BDiagnOutputPtr &diagnOutputPtr){ // we do not read size of structure size.SetWidth(stream.Read32u()); int height = stream.Read32s(); if(height >= 0) { origin = BottomLeft; size.SetHeight((unsigned int)height); } else { origin = TopLeft; size.SetHeight((unsigned int)(-height)); } unsigned int nOfPlanes = stream.Read16u(); if(nOfPlanes != 1) diagnOutputPtr->Warning(DiagnDescrCT<DDIBWarning, DIBInfoWrongNOfPlanes>()); unsigned int bitCount = stream.Read16u(); switch(bitCount) { case 8: depth = Depth_8; nOfPaletteEntries = 1 << 8; break; case 24: depth = Depth_24; nOfPaletteEntries = 0; break; default: throw DiagnDescrCT<DDIBException,NotSupportedBitCount>(); } unsigned int compression = stream.Read32u(); if(compression != DIB_UNCOMPRESSED) throw DiagnDescrCT<DDIBException,NotSupportedCompression>(); stream.Read32u(); // this field (size of image data) is ignored, it can be zero for BI_RGB pelsPerMeter.SetWidth (stream.Read32u()); pelsPerMeter.SetHeight(stream.Read32u()); unsigned int clrUsed = stream.Read32u(); if(clrUsed && nOfPaletteEntries) nOfPaletteEntries = Min(clrUsed, nOfPaletteEntries); stream.Read32u(); // this field (the number of color indexes that are required for displaying the bitmap) is ignored, it can be zero if all colors are required}template<class ByteInput>void ReadInfoHeader( ByteInput &stream, DIBInfoStyle &style, RectSize &size, DIBDepth &depth, DIBOrigin &origin, RectSize &pelsPerMeter, FixedArray<Ipp8u> &rawExtension, unsigned int &nOfPaletteEntries, BDiagnOutputPtr &diagnOutputPtr){ unsigned int headerSize = stream.Read32u();/* if(headerSize < stream.TailSize() + sizeof(Ipp32u)) throw DiagnDescrCT<DDIBException,DataDamage>();*/ if(headerSize == InfoHeaderNOfBytes(Core)) { style = Core; origin = BottomLeft; ReadCoreInfoHeader(stream, size, depth, nOfPaletteEntries, diagnOutputPtr); } else { if(headerSize < InfoHeaderNOfBytes(Common)) throw DiagnDescrCT<DDIBException,DataDamage>(); style = Common; ReadCommonInfoHeader(stream, size, depth, origin, pelsPerMeter, nOfPaletteEntries, diagnOutputPtr); } rawExtension.ReAlloc(headerSize - InfoHeaderNOfBytes(Common)); stream.Read(rawExtension, rawExtension.Size());}template<class ByteInput>void ReadPalette( ByteInput &stream, DIBInfoStyle style, DIBRGBValue *palette, unsigned int nOfEntries){ unsigned int entry; switch(style) { case Common: for(entry = 0; entry < nOfEntries; entry++) { Ipp8u b = stream.Read8u(); Ipp8u g = stream.Read8u(); Ipp8u r = stream.Read8u(); stream.Read8u(); // reserved palette[entry] = DIBRGBValue(r, g, b); } break; default: for(entry = 0; entry < nOfEntries; entry++) { Ipp8u b = stream.Read8u(); Ipp8u g = stream.Read8u(); Ipp8u r = stream.Read8u(); palette[entry] = DIBRGBValue(r, g, b); } }}#endif // __DDIBINFO_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -