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

📄 epnmimagedata.h

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 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 __EPNMIMAGEDATA_H__#define __EPNMIMAGEDATA_H__#include "pnm.h"#include "pnminfo.h"#include "imagecore.h"#include "auxmath.h"template<class ByteOutput, class T>void WritePNMImageData(    ByteOutput            &stream,    const PNMInfo         &pnmInfo,    const ImageCoreC<T,1> *channel){    switch(pnmInfo.MagicNumber())    {    case PNM_PBM_TXT: WriteImageDataPBMTxt(stream, channel[0], pnmInfo.Size());                         break;    case PNM_PGM_TXT: WriteImageDataPGMTxt(stream, channel[0], pnmInfo.Size());                         break;    case PNM_PPM_TXT: WriteImageDataPPMTxt(stream, channel[0], channel[1], channel[2], pnmInfo.Size()); break;    case PNM_PBM_BIN: WriteImageDataPBMBin(stream, channel[0], pnmInfo.Size());                         break;    case PNM_PGM_BIN: WriteImageDataPGMBin(stream, channel[0], pnmInfo.Size(), pnmInfo.MaxValue());     break;    case PNM_PPM_BIN: WriteImageDataPPMBin(stream, channel[0], channel[1], channel[2], pnmInfo.Size(), pnmInfo.MaxValue());     break;    default: break;    }}template<class ByteOutput, class T>void WriteImageDataPGMBin(    ByteOutput            &stream,    const ImageCoreC<T,1> &img,    const RectSize        &size,    unsigned int           maxValue){    unsigned int bitDepth = BitDepth(maxValue);    if     (bitDepth <  8) WriteImageDataPGMBin_8s (stream, img, size);    else if(bitDepth < 16) WriteImageDataPGMBin_16s(stream, img, size);    else                   WriteImageDataPGMBin_32s(stream, img, size);}template<class ByteOutput, class T>void WriteImageDataPPMBin(    ByteOutput            &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) WriteImageDataPPMBin_8s (stream, r, g, b, size);    else if(bitDepth < 16) WriteImageDataPPMBin_16s(stream, r, g, b, size);    else                   WriteImageDataPPMBin_32s(stream, r, g, b, size);}template<class ByteOutput, class T>void WriteImageDataPBMTxt(    ByteOutput            &stream,    const ImageCoreC<T,1> &img,    const RectSize        &size){    unsigned int width  = size.Width();    unsigned int height = size.Height();    char buffer[INT_TO_STR_MAX_SIZE];    int length;    const T *imgSrc;    int imgLineStep;    imgSrc = img.Data();    imgLineStep = (int)img.LineStep();    for(unsigned int y = 0; y < height; y++)    {        for(unsigned int i = 0; i < width - 1; i++)        {            IntToStrR10((int)(!imgSrc[i]), buffer);            length = StrSize(buffer);            stream.Write((const unsigned char *)buffer, length);            stream.Write8u(' ');        }        IntToStrR10((int)(!imgSrc[width - 1]), buffer);        length = StrSize(buffer);        stream.Write((const unsigned char *)buffer, length);        stream.Write8u('\n');        addrInc(imgSrc, imgLineStep);    }}template<class ByteOutput, class T>void WriteImageDataPGMTxt(    ByteOutput            &stream,    const ImageCoreC<T,1> &img,    const RectSize        &size){    unsigned int width  = size.Width();    unsigned int height = size.Height();    char buffer[INT_TO_STR_MAX_SIZE];    int length;    const T *imgSrc;    int imgLineStep;    imgSrc = img.Data();    imgLineStep = (int)img.LineStep();    for(unsigned int y = 0; y < height; y++)    {        for(unsigned int i = 0; i < width - 1; i++)        {            IntToStrR10((unsigned int)imgSrc[i], buffer);            length = StrSize(buffer);            stream.Write((const unsigned char *)buffer, length);            stream.Write8u(' ');        }        IntToStrR10((unsigned int)imgSrc[width - 1], buffer);        length = StrSize(buffer);        stream.Write((const unsigned char *)buffer, length);        stream.Write8u('\n');        addrInc(imgSrc, imgLineStep);    }}template<class ByteOutput, class T>void WriteImageDataPPMTxt(    ByteOutput            &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();    char buffer[INT_TO_STR_MAX_SIZE];    int length;    const T *rSrc;    const T *gSrc;    const T *bSrc;    int rLineStep;    int gLineStep;    int bLineStep;    rSrc = r.Data();    gSrc = g.Data();    bSrc = 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 - 1; x++)        {            IntToStrR10((unsigned int)rSrc[x], buffer);            length = StrSize(buffer);            stream.Write((const unsigned char *)buffer, length);            stream.Write8u(' ');            IntToStrR10((unsigned int)gSrc[x], buffer);            length = StrSize(buffer);            stream.Write((const unsigned char *)buffer, length);            stream.Write8u(' ');            IntToStrR10((unsigned int)bSrc[x], buffer);            length = StrSize(buffer);            stream.Write((const unsigned char *)buffer, length);            stream.Write8u(' ');        }        IntToStrR10((unsigned int)rSrc[width - 1], buffer);        length = StrSize(buffer);        stream.Write((const unsigned char *)buffer, length);        stream.Write8u(' ');        IntToStrR10((unsigned int)gSrc[width - 1], buffer);        length = StrSize(buffer);        stream.Write((const unsigned char *)buffer, length);        stream.Write8u(' ');        IntToStrR10((unsigned int)bSrc[width - 1], buffer);        length = StrSize(buffer);        stream.Write((const unsigned char *)buffer, length);        stream.Write8u('\n');        addrInc(rSrc, rLineStep);        addrInc(gSrc, gLineStep);        addrInc(bSrc, bLineStep);    }}template<class ByteOutput, class T>void WriteImageDataPBMBin(    ByteOutput            &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<Ipp8u> PBMLine(nOfBytes);    const T *imgSrc;    int imgLineStep;    imgSrc = img.Data();    imgLineStep = (int)img.LineStep();    for(unsigned int y = 0; y < height; y++)    {        unsigned int x = 0;        for(; x < (width >> 3); x++)        {            PBMLine[x] = (Ipp8u)~(imgSrc[8 * x + 0] << 7 |                                  imgSrc[8 * x + 1] << 6 |                                  imgSrc[8 * x + 2] << 5 |                                  imgSrc[8 * x + 3] << 4 |                                  imgSrc[8 * x + 4] << 3 |                                  imgSrc[8 * x + 5] << 2 |                                  imgSrc[8 * x + 6] << 1 |                                  imgSrc[8 * x + 7] << 0);        }        if(width & 7)        {            PBMLine[x] = 0;            for(unsigned int i = 0; i < (width & 7); i++)                PBMLine[x] |= (Ipp8u)((!imgSrc[8 * x + i]) << (7 - i));        }        stream.Write(PBMLine, nOfBytes);        addrInc(imgSrc, imgLineStep);    }}template<class ByteOutput, class T>void WriteImageDataPGMBin_8s(    ByteOutput            &stream,    const ImageCoreC<T,1> &img,    const RectSize        &size){    unsigned int width  = size.Width();    unsigned int height = size.Height();    FixedBuffer<unsigned char> PGMLine(width);    const T *imgSrc;    int imgLineStep;    imgSrc = img.Data();    imgLineStep = (int)img.LineStep();    for(unsigned int y = 0; y < height; y++)    {        for(unsigned int x = 0; x < width; x++)        {            PGMLine[x] = (Ipp8u)imgSrc[x];        }        stream.Write(PGMLine, width);        addrInc(imgSrc, imgLineStep);    }}template<class ByteOutput, class T>void WriteImageDataPGMBin_16s(    ByteOutput            &stream,    const ImageCoreC<T,1> &img,    const RectSize        &size){    unsigned int width  = size.Width();    unsigned int height = size.Height();    const T *imgSrc;    int imgLineStep;    imgSrc = img.Data();    imgLineStep = (int)img.LineStep();    for(unsigned int y = 0; y < height; y++)    {        for(unsigned int x = 0; x < width; x++)        {            stream.Write16s((Ipp16s)imgSrc[x]);        }        addrInc(imgSrc, imgLineStep);    }}template<class ByteOutput, class T>void WriteImageDataPGMBin_32s(    ByteOutput            &stream,    const ImageCoreC<T,1> &img,    const RectSize        &size){    unsigned int width  = size.Width();    unsigned int height = size.Height();    const T *imgSrc;    int imgLineStep;    imgSrc = img.Data();    imgLineStep = (int)img.LineStep();    for(unsigned int y = 0; y < height; y++)    {        for(unsigned int x = 0; x < width; x++)        {            stream.Write32s((Ipp32s)imgSrc[x]);        }        addrInc(imgSrc, imgLineStep);    }}template<class ByteOutput, class T>void WriteImageDataPPMBin_8s(    ByteOutput            &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> PPMLine(3 * width);    const T *rSrc;    const T *gSrc;    const T *bSrc;    int rLineStep;    int gLineStep;    int bLineStep;    rSrc = r.Data();    gSrc = g.Data();    bSrc = 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++)        {            PPMLine[3 * x + 0] = (Ipp8u)rSrc[x];            PPMLine[3 * x + 1] = (Ipp8u)gSrc[x];            PPMLine[3 * x + 2] = (Ipp8u)bSrc[x];        }        stream.Write(PPMLine, 3 * width);        addrInc(rSrc, rLineStep);        addrInc(gSrc, gLineStep);        addrInc(bSrc, bLineStep);    }}template<class ByteOutput, class T>void WriteImageDataPPMBin_16s(    ByteOutput            &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();    const T *rSrc;    const T *gSrc;    const T *bSrc;    int rLineStep;    int gLineStep;    int bLineStep;    rSrc = r.Data();    gSrc = g.Data();    bSrc = 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++)        {            stream.Write16s((Ipp16s)rSrc[x]);            stream.Write16s((Ipp16s)gSrc[x]);            stream.Write16s((Ipp16s)bSrc[x]);        }        addrInc(rSrc, rLineStep);        addrInc(gSrc, gLineStep);        addrInc(bSrc, bLineStep);    }}template<class ByteOutput, class T>void WriteImageDataPPMBin_32s(    ByteOutput            &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();    const T *rSrc;    const T *gSrc;    const T *bSrc;    int rLineStep;    int gLineStep;    int bLineStep;    rSrc = r.Data();    gSrc = g.Data();    bSrc = 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++)        {            stream.Write32s((Ipp32s)rSrc[x]);            stream.Write32s((Ipp32s)gSrc[x]);            stream.Write32s((Ipp32s)bSrc[x]);        }        addrInc(rSrc, rLineStep);        addrInc(gSrc, gLineStep);        addrInc(bSrc, bLineStep);    }}#endif // __EPNMIMAGEDATA_H__

⌨️ 快捷键说明

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