📄 dpnmimagedata.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 __DPNMIMAGEDATA_H__#define __DPNMIMAGEDATA_H__#include "pnminfo.h"#include "dpnmexception.h"#include "image.h"#include "fixedbuffer.h"#include "stralg.h"#include "stricmp.h"#include "auxmath.h"template<class ByteInput, class T>void ReadPNMImageData( ByteInput &stream, const PNMInfo &pnmInfo, const ImageCoreC<T,1> *channel){ switch(pnmInfo.MagicNumber()) { case PNM_PBM_TXT: ReadImageDataPBMTxt(stream, channel[0], pnmInfo.Size()); break; case PNM_PGM_TXT: ReadImageDataPGMTxt(stream, channel[0], pnmInfo.Size()); break; case PNM_PPM_TXT: ReadImageDataPPMTxt(stream, channel[0], channel[1], channel[2], pnmInfo.Size()); break; case PNM_PBM_BIN: ReadImageDataPBMBin(stream, channel[0], pnmInfo.Size()); break; case PNM_PGM_BIN: ReadImageDataPGMBin(stream, channel[0], pnmInfo.Size(), pnmInfo.MaxValue()); break; case PNM_PPM_BIN: ReadImageDataPPMBin(stream, channel[0], channel[1], channel[2], pnmInfo.Size(), pnmInfo.MaxValue()); break; default: break; }}template<class ByteInput, class T>void ReadImageDataPGMBin( ByteInput &stream, const ImageCoreC<T,1> &img, const RectSize &size, unsigned int maxValue){ unsigned int bitDepth = BitDepth(maxValue); if (bitDepth < 8) ReadImageDataPGMBin_8s (stream, img, size); else if(bitDepth < 16) ReadImageDataPGMBin_16s(stream, img, size); else ReadImageDataPGMBin_32s(stream, img, size);}template<class ByteInput, class T>void ReadImageDataPPMBin( ByteInput &stream, const ImageCoreC<T,1> &r, const ImageCoreC<T,1> &g, const ImageCoreC<T,1> &b, const RectSize &size, unsigned int maxValue){ unsigned int bitDepth = BitDepth(maxValue); if (bitDepth < 8) ReadImageDataPPMBin_8s (stream, r, g, b, size); else if(bitDepth < 16) ReadImageDataPPMBin_16s(stream, r, g, b, size); else ReadImageDataPPMBin_32s(stream, r, g, b, size);}template<class ByteInput>unsigned int ReadIntInASCII(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') 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; return atoi((const char *)number);}template<class ByteInput, class T>void ReadImageDataPBMTxt( ByteInput &stream, const ImageCoreC<T,1> &img, const RectSize &size){ unsigned int width = size.Width(); unsigned int height = size.Height(); T *imgDst; int imgLineStep; imgDst = img.Data(); imgLineStep = (int)img.LineStep(); for(unsigned int y = 0; y < height; y++) { for(unsigned int x = 0; x < width; x++) { imgDst[x] = !(ReadIntInASCII(stream)); } addrInc(imgDst, imgLineStep); }}template<class ByteInput, class T>void ReadImageDataPGMTxt( ByteInput &stream, const ImageCoreC<T,1> &img, const RectSize &size){ unsigned int width = size.Width(); unsigned int height = size.Height(); T *imgDst; int imgLineStep; imgDst = img.Data(); imgLineStep = (int)img.LineStep(); for(unsigned int y = 0; y < height; y++) { for(unsigned int x = 0; x < width; x++) { imgDst[x] = ReadIntInASCII(stream); } addrInc(imgDst, imgLineStep); }}template<class ByteInput, class T>void ReadImageDataPPMTxt( ByteInput &stream, const ImageCoreC<T,1> &r, const ImageCoreC<T,1> &g, const ImageCoreC<T,1> &b, const RectSize &size){ unsigned int width = size.Width(); unsigned int height = size.Height(); T *rDst; T *gDst; T *bDst; int rLineStep; int gLineStep; int bLineStep; rDst = r.Data(); gDst = g.Data(); bDst = b.Data(); rLineStep = (int)r.LineStep(); gLineStep = (int)g.LineStep(); bLineStep = (int)b.LineStep(); for(unsigned int y = 0; y < height; y++) { for(unsigned int x = 0; x < width; x++) { rDst[x] = (ReadIntInASCII(stream)); gDst[x] = (ReadIntInASCII(stream)); bDst[x] = (ReadIntInASCII(stream)); } addrInc(rDst, rLineStep); addrInc(gDst, gLineStep); addrInc(bDst, bLineStep); }}template<class ByteInput, class T>void ReadImageDataPBMBin( ByteInput &stream, const ImageCoreC<T,1> &img, const RectSize &size){ unsigned int width = size.Width(); unsigned int height = size.Height(); unsigned int nOfBytes = (width + 7) >> 3; FixedBuffer<unsigned char> PBMLine(nOfBytes); T *imgDst; int imgLineStep; imgDst = img.Data(); imgLineStep = (int)img.LineStep(); for(unsigned int y = 0; y < height; y++) { stream.Read(PBMLine, nOfBytes); unsigned int x = 0; for(; x < (width >> 3); x++) { for(unsigned int i = 0; i < 8; i++) imgDst[8 * x + i] = (~(PBMLine[x]) >> (7 - i)) & 1; } if(width & 7) { for(unsigned int i = 0; i < (width & 7); i++) imgDst[8 * x + i] = (~(PBMLine[x]) >> (7 - i)) & 1; } addrInc(imgDst, imgLineStep); }}template<class ByteInput, class T>void ReadImageDataPGMBin_8s( ByteInput &stream, const ImageCoreC<T,1> &img, const RectSize &size){ unsigned int width = size.Width(); unsigned int height = size.Height(); FixedBuffer<unsigned char> PGMLine(width); T *imgDst; int imgLineStep; imgDst = img.Data(); imgLineStep = (int)img.LineStep(); for(unsigned int y = 0; y < height; y++) { stream.Read(PGMLine, width); for(unsigned int x = 0; x < width; x++) imgDst[x] = (T)PGMLine[x]; addrInc(imgDst, imgLineStep); }}template<class ByteInput, class T>void ReadImageDataPGMBin_16s( ByteInput &stream, const ImageCoreC<T,1> &img, const RectSize &size){ unsigned int width = size.Width(); unsigned int height = size.Height(); T *imgDst; int imgLineStep; imgDst = img.Data(); imgLineStep = (int)img.LineStep(); for(unsigned int y = 0; y < height; y++) { for(unsigned int x = 0; x < width; x++) imgDst[x] = (T)stream.Read16s(); addrInc(imgDst, imgLineStep); }}template<class ByteInput, class T>void ReadImageDataPGMBin_32s( ByteInput &stream, const ImageCoreC<T,1> &img, const RectSize &size){ unsigned int width = size.Width(); unsigned int height = size.Height(); T *imgDst; int imgLineStep; imgDst = img.Data(); imgLineStep = (int)img.LineStep(); for(unsigned int y = 0; y < height; y++) { for(unsigned int x = 0; x < width; x++) { imgDst[x] = (T)stream.Read32s(); } addrInc(imgDst, imgLineStep); }}template<class ByteInput, class T>void ReadImageDataPPMBin_8s( ByteInput &stream, const ImageCoreC<T,1> &r, const ImageCoreC<T,1> &g, const ImageCoreC<T,1> &b, const RectSize &size){ unsigned int width = size.Width(); unsigned int height = size.Height(); FixedBuffer<unsigned char> PNMLine(3 * width); T *rDst; T *gDst; T *bDst; int rLineStep; int gLineStep; int bLineStep; rDst = r.Data(); gDst = g.Data(); bDst = b.Data(); rLineStep = (int)r.LineStep(); gLineStep = (int)g.LineStep(); bLineStep = (int)b.LineStep(); for(unsigned int y = 0; y < height; y++) { stream.Read(PNMLine, 3 * width); for(unsigned int x = 0; x < width; x++) { rDst[x] = (T)PNMLine[3 * x + 0]; gDst[x] = (T)PNMLine[3 * x + 1]; bDst[x] = (T)PNMLine[3 * x + 2]; } addrInc(rDst, rLineStep); addrInc(gDst, gLineStep); addrInc(bDst, bLineStep); }}template<class ByteInput, class T>void ReadImageDataPPMBin_16s( ByteInput &stream, const ImageCoreC<T,1> &r, const ImageCoreC<T,1> &g, const ImageCoreC<T,1> &b, const RectSize &size){ unsigned int width = size.Width(); unsigned int height = size.Height(); T *rDst; T *gDst; T *bDst; int rLineStep; int gLineStep; int bLineStep; rDst = r.Data(); gDst = g.Data(); bDst = b.Data(); rLineStep = (int)r.LineStep(); gLineStep = (int)g.LineStep(); bLineStep = (int)b.LineStep(); for(unsigned int y = 0; y < height; y++) { for(unsigned int x = 0; x < width; x++) { rDst[x] = (T)stream.Read16s(); gDst[x] = (T)stream.Read16s(); bDst[x] = (T)stream.Read16s(); } addrInc(rDst, rLineStep); addrInc(gDst, gLineStep); addrInc(bDst, bLineStep); }}template<class ByteInput, class T>void ReadImageDataPPMBin_32s( ByteInput &stream, const ImageCoreC<T,1> &r, const ImageCoreC<T,1> &g, const ImageCoreC<T,1> &b, const RectSize &size){ unsigned int width = size.Width(); unsigned int height = size.Height(); T *rDst; T *gDst; T *bDst; int rLineStep; int gLineStep; int bLineStep; rDst = r.Data(); gDst = g.Data(); bDst = b.Data(); rLineStep = (int)r.LineStep(); gLineStep = (int)g.LineStep(); bLineStep = (int)b.LineStep(); for(unsigned int y = 0; y < height; y++) { for(unsigned int x = 0; x < width; x++) { rDst[x] = (T)stream.Read32u(); gDst[x] = (T)stream.Read32u(); bDst[x] = (T)stream.Read32u(); } addrInc(rDst, rLineStep); addrInc(gDst, gLineStep); addrInc(bDst, bLineStep); }}#endif // __DPNMIMAGEDATA_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -