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

📄 medib.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ////////////////////////////////////////////////////////////////////////////                  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.//////*/#include "medib.h"#include "calcvector.h"#include "medibwarning.h"#include "resize.h"#include "imageconvert.h"#include "pp.h"#ifdef XSCALE#include "medibexception.h"#endifstatic const unsigned int DIB_PALETTE_BIT_DEPTH =   7;static const unsigned int DIB_PALETTE_MAX_SIZE  = 256;/*void ConvertPalette(    const DIBRGBValue       *entry,    unsigned int             nOfEntries,    const MRstrImagePalette &palette);  void ConvertPalette(    const DIBRGBValue       *entry,    unsigned int             nOfEntries,    const MRstrImagePalette &palette){    palette.ReAlloc(3, 3, nOfEntries);    MRstrImageDepth depth(false, 7);    palette.SetEnumChannelDepth(0, depth);    palette.SetEnumChannelDepth(1, depth);    palette.SetEnumChannelDepth(2, depth);    palette.SetIsChannelMappedDirectly(0, false);    palette.SetIsChannelMappedDirectly(1, false);    palette.SetIsChannelMappedDirectly(2, false);    palette.SetEnumChannelIndex(0, 0);    palette.SetEnumChannelIndex(1, 1);    palette.SetEnumChannelIndex(2, 2);    palette.EnumChannelLUT(palette.EnumChannelIndex(0)}*/inline void ConvertDynRangeToDIB(    const Ipp64s  *src,    Ipp8u         *dst,    int            size,    unsigned int   srcBitDepth,  // NOTE: Actual bit depth is BitDepth + 1;    bool           srcIsSigned){    Ipp64s shift = (Ipp64s)srcBitDepth - (Ipp64s)8 + (Ipp64s)1;    Ipp64s add   = srcIsSigned ? (Ipp64s)1 << (Ipp64s)srcBitDepth : (Ipp64s)0;    ShiftAddConvert(src, dst, size, shift, add);}// return false if impossibleinline void CovertPaletteChannel(    const MRstrImagePalette &metaPalette,    Ipp16u                   channel,    Ipp8u                   *dibPaletteChannel,    unsigned int             dibNOfEntries,    BDiagnOutputPtr          &diagnOutputPtr){    if(metaPalette.IsChannelMappedDirectly(channel))    {        for(unsigned int i = 0; i < dibNOfEntries; i++)            dibPaletteChannel[i] = (Ipp8u)i;    }    else    {        unsigned int bitDepth = metaPalette.ChannelDepth(channel).BitDepth();        bool         isSigned = metaPalette.ChannelDepth(channel).IsSigned();        if     (isSigned)        {                        diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBPaletteBitDepthIsSigned>());        }        if     (bitDepth > DIB_PALETTE_BIT_DEPTH)        {                        diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBPaletteBitDepthExceedAllowable>());        }        else if(bitDepth < DIB_PALETTE_BIT_DEPTH)        {                        diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBPaletteBitDepthBelowAllowable>());        }        const Ipp64s *metaPaletteChannel = metaPalette.EnumChannelLUT(metaPalette.EnumChannelIndex(channel));        unsigned int metaNOfEntries    = metaPalette.NOfEntries();        unsigned int nOfPaddingEntries = (dibNOfEntries > metaNOfEntries) ? dibNOfEntries - metaNOfEntries : 0;        unsigned int nOfActualEntries  = Min(dibNOfEntries, metaNOfEntries);        ConvertDynRangeToDIB(            metaPaletteChannel,            dibPaletteChannel,            nOfActualEntries,            bitDepth,            isSigned);        SetValue((Ipp8u)0, &dibPaletteChannel[nOfActualEntries], nOfPaddingEntries);    }}inline bool IsDIBPaletteConvertionAvailable(const MRstrImage &rstrImage){    return     rstrImage.NOfComponents() == 1          &&   rstrImage.ComponentDepth()[0].BitDepth() <= 7          && (!rstrImage.ComponentDepth()[0].IsSigned());}inline void MakeDIBPalette(    const MRstrImagePalette &metaPalette,    FixedArray<DIBRGBValue> &dibPalette,    BDiagnOutputPtr          &diagnOutputPtr){    unsigned int dibNOfEntries = metaPalette.NOfEntries();    if(dibNOfEntries > DIB_PALETTE_MAX_SIZE)    {        diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBPaletteNOfEntriesExceedAllowable>());        dibNOfEntries = DIB_PALETTE_MAX_SIZE;    }    dibPalette.ReAlloc(dibNOfEntries);    switch(metaPalette.NOfChannels())    {    case 1:        {            FixedBuffer<unsigned char> dibPaletteChannel(dibNOfEntries);            CovertPaletteChannel(metaPalette, 0, dibPaletteChannel, dibNOfEntries, diagnOutputPtr);            for(unsigned int entry = 0; entry < dibNOfEntries; entry++)                dibPalette[entry] = DIBRGBValue(dibPaletteChannel[entry]);        }        break;    case 3:        {            FixedBuffer2D<unsigned char> dibPaletteChannel(3, dibNOfEntries);            Ipp16u channel;            for(channel = 0; channel < 3; channel++)            {                if(metaPalette.IsChannelMappedDirectly(channel))                {                    dibNOfEntries = DIB_PALETTE_MAX_SIZE;                    break;                }            }            for(channel = 0; channel < 3; channel++)                CovertPaletteChannel(metaPalette, channel, dibPaletteChannel[channel], dibNOfEntries, diagnOutputPtr);            for(unsigned int entry = 0; entry < dibNOfEntries; entry++)                dibPalette[entry] = DIBRGBValue(                    dibPaletteChannel[0][entry],                    dibPaletteChannel[1][entry],                    dibPaletteChannel[2][entry]);        }        break;    default:        diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBPaletteNOfComponentsIsNotAllowed>());    }}const RectSize DIBDefaultPelsPerMeter(3780, 3780);void SetBestDIBSizeAndResolution(    const MRstrImage &rstrImage,    DIBInfo          &dibInfo,    bool              isDisplayResolutionPrefferable,    BDiagnOutputPtr   &diagnOutputPtr){    dibInfo.SetSize(rstrImage.RefGridRect().Size());    RectSize capturePelsPerMeter(        RoundCenterU(rstrImage.CaptureResolution().X().PelsPerMeter()),        RoundCenterU(rstrImage.CaptureResolution().Y().PelsPerMeter()));    RectSize displayPelsPerMeter(        RoundCenterU(rstrImage.DisplayResolution().X().PelsPerMeter()),        RoundCenterU(rstrImage.DisplayResolution().Y().PelsPerMeter()));    if(isDisplayResolutionPrefferable)    {        if(rstrImage.DisplayResolution().IsActual())        {            dibInfo.SetPelsPerMeter(displayPelsPerMeter);            if(rstrImage.CaptureResolution().IsActual())                diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBCaptureResolutionLoss>());        }        else if(rstrImage.CaptureResolution().IsActual())        {            dibInfo.SetPelsPerMeter(capturePelsPerMeter);            if(rstrImage.DisplayResolution().IsActual())                diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBDisplayResolutionLoss>());        }        else        {            dibInfo.SetPelsPerMeter(DIBDefaultPelsPerMeter);            diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBDefaultResolutionIsUsed>());        }    }    else    {        if(rstrImage.CaptureResolution().IsActual())        {            dibInfo.SetPelsPerMeter(capturePelsPerMeter);            if(rstrImage.DisplayResolution().IsActual())                diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBDisplayResolutionLoss>());        }        else if(rstrImage.DisplayResolution().IsActual())        {            dibInfo.SetPelsPerMeter(displayPelsPerMeter);            if(rstrImage.CaptureResolution().IsActual())                diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBCaptureResolutionLoss>());        }        else        {            dibInfo.SetPelsPerMeter(DIBDefaultPelsPerMeter);            diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBDefaultResolutionIsUsed>());        }    }}void SetBestDIBDepthAndPalette(    const MRstrImage &rstrImage,    DIBInfo          &dibInfo,    BDiagnOutputPtr   &diagnOutputPtr){    if(!rstrImage.Palette().IsActual())    {        if(rstrImage.NOfComponents() == 3) dibInfo.SetDepth(Depth_24);        else        {            dibInfo.SetDepth(Depth_8);            dibInfo.SetPaletteDeFactoStdGray();        }    }    else    {        if(IsDIBPaletteConvertionAvailable(rstrImage))        {            dibInfo.SetDepth(Depth_8);            FixedArray<DIBRGBValue> dibPalette;            MakeDIBPalette(rstrImage.Palette(), dibPalette, diagnOutputPtr);            dibInfo.SetPalette(dibPalette, dibPalette.Size());        }        else        {            if(rstrImage.Palette().NOfChannels()==3) dibInfo.SetDepth(Depth_24);            else            {                dibInfo.SetDepth(Depth_8);                dibInfo.SetPaletteDeFactoStdGray();            }            diagnOutputPtr->Warning(DiagnDescrCT<MEDIBWarning, MEDIBPaletteCnvrtToNonPalette>());        }    }}/*// dst is point to rectangle itself, function does NOT any correction of pointers by dstRefRect parameter// BUT there is NO need to have any border data too.// dstRefRect origin is used only to correct sampling phase (center of source sample in destination).inline void ResizeUpAndConvertDynRangeForDIB(    const ImageCoreC<Ipp32s,1> &src,    const RectSize             &srcSize,    const RectSize             &srcSampleSize,    MRstrImageDepth             srcDepth,    const ImageCoreC<Ipp32s,1> &dst,    const Rect                 &dstRefRect){    ResizeUp(src, srcSize, srcSampleSize, dst, dstRefRect);    ConvertDynRange(dst, dstRefRect.Size(), srcDepth.BitDepth(), srcDepth.IsSigned(), 7, false);}*/inline void ConvertDynRangeForDIB(    const ImageCoreC<Ipp32s,1> &srcDst,    MRstrImageDepth             srcDepth,    const RectSize             &srcDstSize){    ConvertDynRange(srcDst, srcDstSize, srcDepth.BitDepth(), srcDepth.IsSigned(), 7, false);}inline void ConvertDynRangeAndAverage(    const ImageCoreC<Ipp32s,1> *src,    const MRstrImageDepth      *srcDepth,    unsigned int                nOfComponents,    const ImageCoreC<Ipp32s,1> &dst,    const MRstrImageDepth      &dstDepth,    const RectSize             &size){

⌨️ 快捷键说明

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