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

📄 encode.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) 2002-2005 Intel Corporation. All Rights Reserved.//////*/#include <math.h>#include "j2kit.h"#include "ejp2box.h"#include "ejp2marker.h"#include "ddib.h"#include "dpnm.h"#include "mapfile.h"#include "wtfwd.h"#include "etile.h"#include "genalg.h"#include "imageconvert.h"#include "equant.h"#include "epreprocess.h"#include "mapfileinput.h"#include "byteinput.h"#include "memoryoutput.h"typedef ByteInputSigned<ByteInputLE<MapFileInput> > MapFileInputLE;typedef ByteInputSigned<ByteInputBE<MapFileInput> > MapFileInputBE;class MapFileBoundedInputLE : public ByteInputBoundService<MapFileInputLE>{public:    MapFileBoundedInputLE() {}    void Open(const char *fileName)    {        MapFileInput::Open(fileName);        PushSize(MapFileInput::Size());    }    void Close()    {        MapFileInput::Close();        PopSize();    }};class MapFileBoundedInputBE : public ByteInputBoundService<MapFileInputBE>{public:    MapFileBoundedInputBE() {}    void Open(const char *fileName)    {        MapFileInput::Open(fileName);        PushSize(MapFileInput::Size());    }    void Close()    {        MapFileInput::Close();        PopSize();    }};static const int RI_BMP = 8; // bitmap dynamic rangestatic const Ipp8u GUARD_BITS = 2;static const int MAX_N_OF_RES_LEVELES = 33;typedef enum{    sRGB      = 16,    Grayscale = 17} JP2Colorspace;inline void PreProcess(const ImagePn<Ipp32s> &image, const CmdOptions &options, unsigned int bitDepth){    FixedBuffer<JP2BitsPerComp> bitsPerComp(image.NOfChannels());    for(unsigned int i = 0; i < image.NOfChannels(); i++)        bitsPerComp[i] = JP2BitsPerComp(bitDepth);#ifdef XSCALE    PreProcess#else    PreProcess32s32f#endif        (image.Channels(), image.Size(), bitsPerComp, image.NOfChannels(), options.IsUseMCT(), options.IsWT53Used());}#ifndef XSCALEinline void Convert32f32s(const SBTree<Ipp32f> &sbTree){    Convert32f32s(sbTree.LxLy(), sbTree.LxLy().Size());    for(unsigned int i = 0; i < sbTree.NOfWTLevels(); i++)    {        Convert32f32s(sbTree.LxHy(i), sbTree.LxHy(i).Size());        Convert32f32s(sbTree.HxLy(i), sbTree.HxLy(i).Size());        Convert32f32s(sbTree.HxHy(i), sbTree.HxHy(i).Size());    }}#endif //#ifndef XSCALE// ========================== CodeStream ============================void writeCodeStream(ByteBuffer& stream, int nOfWTLevels, const ImagePn<Ipp32s> &image, const Ipp8u depth, unsigned int normDataSize, const CmdOptions &options){    PreProcess(image, options, depth);    unsigned int nOfComponents = image.NOfChannels();    SBTree<Ipp32s>::Array       sbTrees(nOfComponents);    FixedBuffer<QuantComponent> qComponents(nOfComponents);    if(options.IsWT53Used())    {        for(unsigned int i = 0; i < nOfComponents; i++)        {            sbTrees[i].ReAlloc(Rect(Point(0, 0), image.Size()), nOfWTLevels);            WT53Fwd(image.Channel(i), Rect(Point(0, 0), image.Size()), sbTrees[i]);            qComponents[i].InitUnitStep(depth + 1, nOfWTLevels);        }    }    else    {#ifdef XSCALE        for(unsigned int i = 0; i < nOfComponents; i++)        {            sbTrees[i].ReAlloc(Rect(Point(0, 0), image.Size()), nOfWTLevels);            WT97Fwd(image.Channel(i), Rect(Point(0, 0), image.Size()), sbTrees[i]);            if(options.IsDerivedQuant())            {                qComponents[i].InitDerived(options.DerivedQuantBaseValue(), nOfWTLevels);                QuantFwd(sbTrees[i], qComponents[i], depth + 1);            }            else qComponents[i].InitUnitStep(depth + 1, nOfWTLevels);            RShift(sbTrees[i].LxLy(), sbTrees[i].LxLy().Size(), WT97_POST_PROC_SCALE_FACTOR);            for(int j = 0; j < (int)sbTrees[i].NOfWTLevels(); j++)            {                RShift(sbTrees[i].LxHy(j), sbTrees[i].LxHy(j).Size(), WT97_POST_PROC_SCALE_FACTOR);                RShift(sbTrees[i].HxLy(j), sbTrees[i].HxLy(j).Size(), WT97_POST_PROC_SCALE_FACTOR);                RShift(sbTrees[i].HxHy(j), sbTrees[i].HxHy(j).Size(), WT97_POST_PROC_SCALE_FACTOR);            }        }#else        const SBTree<Ipp32f> *sbTrees32f = (const SBTree<Ipp32f> *)((SBTree<Ipp32s> *)sbTrees);        for(unsigned int i = 0; i < nOfComponents; i++)        {            sbTrees[i].ReAlloc(Rect(Point(0, 0), image.Size()), nOfWTLevels);            WT97Fwd((const ImageCoreC<Ipp32f, 1> &)image.Channels()[i], Rect(Point(0, 0), image.Size()), sbTrees32f[i]);            if(options.IsDerivedQuant())            {                qComponents[i].InitDerived(options.DerivedQuantBaseValue(), nOfWTLevels);                QuantFwd(sbTrees32f[i], qComponents[i], depth + 1);            }            else qComponents[i].InitUnitStep(depth + 1, nOfWTLevels);            Convert32f32s(sbTrees32f[i]);        }#endif    }    //    // Fill precinct and codeblock parameters to initialize    //   tile encoding.    //    // Very simple case implemented that is single precinct (size 2 ^ 15),    // codeblock size 64x64 and all sizes are the same for every resolution    // level and every component.    //    //    Int2D prXStepOrder(nOfComponents, MAX_N_OF_RES_LEVELES);    Int2D prYStepOrder(nOfComponents, MAX_N_OF_RES_LEVELES);    Int2D cbXStepOrder(nOfComponents, MAX_N_OF_RES_LEVELES);    Int2D cbYStepOrder(nOfComponents, MAX_N_OF_RES_LEVELES);    FixedBuffer<int> nOfWTLevelsC(nOfComponents);    for(unsigned int j = 0; j < nOfComponents; j++)    {        nOfWTLevelsC[j] = nOfWTLevels;        for(unsigned int i = 0; i < (unsigned int)MAX_N_OF_RES_LEVELES; i++)        {            prXStepOrder[j][i] = 15;            prYStepOrder[j][i] = 15;            cbXStepOrder[j][i] =  6;            cbYStepOrder[j][i] =  6;        }    }    Rect imgRect(Point(0, 0), image.Size());    FixedBuffer<Rect> rects(nOfComponents);    {        for(unsigned int i = 0; i < nOfComponents; i++)            rects[i] = imgRect;    }    CBEncoder cbEncoder(GUARD_BITS);    ETile     tile;    FixedBuffer<int> cmpDynRange(nOfComponents);    for(unsigned int component = 0; component < nOfComponents; component++)        cmpDynRange[component] = depth + 1;    tile.Init(rects, prXStepOrder, prYStepOrder, cbXStepOrder, cbYStepOrder,        cmpDynRange, qComponents,        nOfWTLevelsC, nOfComponents);    tile.Encode(cbEncoder, sbTrees);    if(options.Ratio() > 0)    {        if(options.IsWT53Used())            tile.WeightDistAsWT53();        else            tile.WeightDistAsWT97();        if(options.IsUseMCT() && nOfComponents==3)        {            if(options.IsWT53Used())                tile.WeightDistAsRCT();            else                tile.WeightDistAsICT();        }        // only single layer implemented        int length = (int)(normDataSize / options.Ratio());        tile.SetCurPassToFirst();        tile.AssignLayers(&length, 1);    }    tile.SetCurPassToFirst();    // Layer-resolution level-component-position progression    int nOfResLevels = NOfResLevels(nOfWTLevels);    for(int resLevel = 0; resLevel < nOfResLevels; resLevel++)        for(unsigned int component = 0; component < nOfComponents; component++)            for(int precinct = 0; precinct < tile.NOfPrecincts(0, resLevel); precinct++)                tile.WriteToPacket(component, resLevel, precinct, 0,stream);}// ============================ Markers ============================void writeSOCMarker(ByteBuffer& stream){    WriteMarker(SOC, stream);}void writeSIZMarker(ByteBuffer& stream, Ipp32u height, Ipp32u width, Ipp16u nc, const Ipp8u* bpc){    ByteBuffer sizStream;    sizStream.Write16u(0);    sizStream.Write32u(width);    sizStream.Write32u(height);    sizStream.Write32u(0);    sizStream.Write32u(0);    sizStream.Write32u(width);    sizStream.Write32u(height);    sizStream.Write32u(0);    sizStream.Write32u(0);    sizStream.Write16u(nc);    for (Ipp16u i = 0; i < nc; i++)    {        sizStream.Write8u(bpc[i]);        sizStream.Write8u(1);        sizStream.Write8u(1);    }    WriteMarker(SIZ, (Ipp16u)sizStream.Size(), stream);    TransferAllSrc(sizStream, stream);}void writeCODMarker(ByteBuffer& stream, Ipp8u pOrder, Ipp16u nOfLayers, bool isMCTused, bool isWT53Used, Ipp8u nOfWTLevels, Ipp8u codingStyle, Ipp8u* pPrecintSize){    if ((codingStyle & 0x01) && (pPrecintSize == 0))        throw 0;    ByteBuffer codStream;    codStream.Write8u (codingStyle);    codStream.Write8u (pOrder);    codStream.Write16u(nOfLayers);    if (isMCTused)        codStream.Write8u(1);    else        codStream.Write8u(0);    codStream.Write8u(nOfWTLevels);    codStream.Write8u(4);    codStream.Write8u(4);    codStream.Write8u(0);    if (isWT53Used)        codStream.Write8u(1);    else        codStream.Write8u(0);    if (codingStyle & 0x01)        for (int i = 0; i < nOfWTLevels; i++)            codStream.Write8u(pPrecintSize[i]);    WriteMarker(COD, (Ipp16u)codStream.Size(), stream);    TransferAllSrc(codStream, stream);}

⌨️ 快捷键说明

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