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

📄 encode.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void writeQCDMarker(ByteBuffer& stream, Ipp8u nOfWTLevels, const CmdOptions &options, int dynRange){    ByteBuffer qcdStream;    if(options.IsWT53Used())        WriteQuantWT53(dynRange, GUARD_BITS, nOfWTLevels, qcdStream);    else    {        if(options.IsDerivedQuant())            WriteQuantDerived(options.DerivedQuantBaseValue(), GUARD_BITS, qcdStream);        else            WriteQuantUnitStep(dynRange, GUARD_BITS, nOfWTLevels, qcdStream);    }    WriteMarker(QCD, (Ipp16u)qcdStream.Size(), stream);    TransferAllSrc(qcdStream, stream);}void writeSOTMarker(ByteBuffer& stream, Ipp16u index, Ipp32u length, Ipp8u tpIndex, Ipp8u nOfTileParts){    ByteBuffer sotStream;    sotStream.Write16u(index);    sotStream.Write32u(length);    sotStream.Write8u (tpIndex);    sotStream.Write8u (nOfTileParts);    WriteMarker(SOT, (Ipp16u)sotStream.Size(), stream);    TransferAllSrc(sotStream, stream);}void writeSODMarker(ByteBuffer& stream){    WriteMarker(SOD, stream);}void writeEOCMarker(ByteBuffer& stream){    WriteMarker(EOC, stream);}void writeCodeStreamMarkers(ByteBuffer& stream, Ipp16u nc, const Ipp8u* bpc, Ipp8u nOfWTLevels, const ImagePn<Ipp32s>& image, int dynRange, unsigned int normDataSize, const CmdOptions &options){    writeSOCMarker(stream);    writeSIZMarker(stream, image.Height(), image.Width(), nc, bpc);    if(nc==3)        writeCODMarker(stream, 0, 1, options.IsUseMCT(), options.IsWT53Used(), nOfWTLevels, 0, 0);    else        writeCODMarker(stream, 0, 1, false, options.IsWT53Used(), nOfWTLevels, 0, 0);    writeQCDMarker(stream, nOfWTLevels, options, dynRange);    writeSOTMarker(stream, 0, 0, 0, 1);    writeSODMarker(stream);    writeCodeStream(stream, nOfWTLevels, image, bpc[0], normDataSize, options);    writeEOCMarker(stream);}// ============================= Boxes ============================void writeSignatureBox(ByteBuffer& stream){    ByteBuffer body;    body.Write32u(jp2id);    WriteBoxHeader(jp__, body.Size(), stream);    TransferAllSrc(body, stream);}void writeFileTypeBox(ByteBuffer& stream){    ByteBuffer body;    body.Write32u(jp2_);    body.Write32u(0);    body.Write32u(jp2_);    WriteBoxHeader(ftyp, body.Size(), stream);    TransferAllSrc(body, stream);}void writeImageHeaderBox(ByteBuffer& stream, Ipp32u height, Ipp32u width, Ipp16u nc, const Ipp8u bpc, Ipp8u ipr){    ByteBuffer body;    body.Write32u(height);    body.Write32u(width);    body.Write16u(nc);    body.Write8u(bpc); // Bits per component. // HARD CODE //7    body.Write8u(7); // Compression type.    body.Write8u(0);    body.Write8u(ipr);    WriteBoxHeader(ihdr, body.Size(), stream);    TransferAllSrc(body, stream);}void writeBitPerCompBox(ByteBuffer& stream, Ipp16u nc, const Ipp8u* bpc){    ByteBuffer body;    for (Ipp16u i = 0; i < nc; i++)        body.Write8u(bpc[i]);    WriteBoxHeader(bpcc, body.Size(), stream);    TransferAllSrc(body, stream);}void writeColorSpecBox(ByteBuffer& stream, JP2Colorspace enumCS){    ByteBuffer body;    body.Write8u (1);    body.Write8u (0);    body.Write8u (0);    body.Write32u(enumCS);    WriteBoxHeader(colr, body.Size(), stream);    TransferAllSrc(body, stream);}void writePaletteBox(ByteBuffer& stream, const DIBRGBValue *entry, unsigned int nOfEntries){    static const unsigned int nOfChannels = 3;    ByteBuffer body;    body.Write16u((Ipp16u)nOfEntries);    body.Write8u ((Ipp8u)nOfChannels);    for(unsigned int i = 0; i < nOfChannels; i++)        body.Write8u(7);    for(unsigned int  j = 0; j < nOfEntries; j++)    {        DIBRGBValue element = entry[j];        body.Write8u(element.R());        body.Write8u(element.G());        body.Write8u(element.B());    }    WriteBoxHeader(pclr, body.Size(), stream);    TransferAllSrc(body, stream);}void writeCompMappingBox(ByteBuffer& stream){    Ipp8u nOfChannels = 3;    ByteBuffer body;    for(Ipp8u i = 0; i < nOfChannels; i++)    {        body.Write16u(0);        body.Write8u (0x01);        body.Write8u (i);    }    WriteBoxHeader(cmap, body.Size(), stream);    TransferAllSrc(body, stream);}void writeHeaderSuperBox(ByteBuffer& stream,    Ipp32u height, Ipp32u width,    Ipp16u nc, const Ipp8u bpc, Ipp8u ipr,    JP2Colorspace enumCS,    const DIBRGBValue *paletteEntry,    unsigned int nOfPaletteEntries,    bool isWritePalette){    ByteBuffer body;    writeImageHeaderBox(body, height, width, nc, bpc, ipr);    //writeBitPerCompBox(body, nc, bpc);    writeColorSpecBox(body, enumCS);    if(isWritePalette)    {        writePaletteBox(body, paletteEntry, nOfPaletteEntries);        writeCompMappingBox(body);    }    WriteBoxHeader(jp2h, body.Size(), stream);    TransferAllSrc(body, stream);}void writeCodestreamBox(ByteBuffer& stream, Ipp16u nc, const Ipp8u* bpc, Ipp8u nOfWTLevels, const ImagePn<Ipp32s> &image, int dynRange, unsigned int normDataSize, const CmdOptions &options){    ByteBuffer body;    writeCodeStreamMarkers(body, nc, bpc, nOfWTLevels, image, dynRange, normDataSize, options);    WriteUknLenBoxHeader(jp2c, stream);    TransferAllSrc(body, stream);}// ============================== =================================void encode(const CmdOptions &options, BDiagnOutput &diagnOutput){    unsigned int depth;    unsigned int srcNOfBytes;    unsigned int nOfComponents;    JP2Colorspace  enumCS;    bool           isWritePalette;    ImagePn<Ipp32s> image;    const DIBRGBValue  *paletteEntry;    unsigned int        nOfPaletteEntries;    if(options.SrcFileType() == CmdOptions::bmp)    {        MapFileBoundedInputLE dibStream;        dibStream.Open(options.SrcFileName());        DIBDecoder<MapFileBoundedInputLE> dib;        dib.AttachDiagnOutput(diagnOutput);        dib.Attach(dibStream);        dib.ReadFileHeader();        dib.ReadInfo();        image.ReAlloc(dib.Info().Size(), NOfChannels(dib.Info().Depth()));        dib.ReadImageData((ImageCoreC<Ipp32s, 1> *)image.Channels());        depth         = BitDepthPerChan(dib.Info().Depth());        nOfComponents = NOfChannels    (dib.Info().Depth());        if(nOfComponents==1)        {            switch(options.GrayscaleMode())            {            case CmdOptions::neverUseGrayscale:                enumCS = sRGB;                isWritePalette = true;                break;            case CmdOptions::forceGrayscale:                enumCS = Grayscale;                isWritePalette = false;                break;            default: //CmdOptions::autoDetectGrayscale                if(dib.Info().IsPaletteDeFactoStdGray())                {                    enumCS = Grayscale;                    isWritePalette = false;                }                else                {                    enumCS = sRGB;                    isWritePalette = true;                }                break;            }        }        else        {            enumCS = sRGB;            isWritePalette = false;        }        paletteEntry      = dib.Info().Palette();        nOfPaletteEntries = dib.Info().Palette().Size();        srcNOfBytes       = dib.Info().EstimateImageDataNOfBytes();    }    else // PNM    {        MapFileBoundedInputBE pnmStream;        pnmStream.Open(options.SrcFileName());        PNMDecoder<MapFileBoundedInputBE> pnm;        pnm.AttachDiagnOutput(diagnOutput);        pnm.Attach(pnmStream);        pnm.ReadFileHeader();        pnm.CheckMagicNumberConformance(options.SrcFileNameExt());        image.ReAlloc(pnm.Info().Size(), NOfChannels(pnm.Info().MagicNumber()));        pnm.ReadImageData((const ImageCoreC<Ipp32s,1> *)image.Channels());        depth             = BitDepth(pnm.Info().MaxValue());        nOfComponents     = NOfChannels(pnm.Info().MagicNumber());        enumCS            = (nOfComponents==1) ? Grayscale : sRGB;        paletteEntry      = 0;        nOfPaletteEntries = 0;        isWritePalette    = false;        srcNOfBytes = pnm.Info().EstimateImageDataNOfBytes((const ImageCoreC<Ipp32s,1> *)image.Channels());    }    ByteBuffer stream;    writeSignatureBox(stream);    writeFileTypeBox (stream);    FixedBuffer<Ipp8u> bpc(nOfComponents);    for(unsigned int i = 0; i < nOfComponents; i++)        bpc[i] = depth;    writeHeaderSuperBox(stream, image.Height(), image.Width(), (Ipp16u)nOfComponents, bpc[0], 0, enumCS, paletteEntry, nOfPaletteEntries, isWritePalette);    unsigned int nOfWTLevels = MaxNOfWTLevels(Min(image.Width(), image.Height()));    if((int)nOfWTLevels > options.MaxAllowedWTLevel()) nOfWTLevels = options.MaxAllowedWTLevel();    writeCodestreamBox(stream, (Ipp16u)nOfComponents, bpc, (Ipp8u)nOfWTLevels, image, depth + 1, srcNOfBytes, options);    MapFile jp2file(options.DstFileName(), stream.Size());    MemoryOutput jp2fileStream;    jp2fileStream.Attach((Ipp8u*)jp2file.Data());    TransferAllSrc(stream, jp2fileStream);}

⌨️ 快捷键说明

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