Main Page | Modules | Class Hierarchy | Data Structures | File List | Data Fields | Globals | Related Pages | Examples

jp2_decodeMT.cpp

Simple multi-threaded image decoder using CMJ2DecMT.

//
// jp2_decodeMT.cpp
//
// Simple multi-threaded image decoder using CMJ2DecMT.
//
// Copyright Morgan-Multimedia 1990-2005.
//

#include "iMJ2Dec.h"
#include "OEM_LIC.h"

int Decode2Fields(int nWidth, int nHeight, PBYTE pIn1, int nIn1, PBYTE pIn2, int nIn2,
                                  PBYTE pOut, int nOut, DWORD fccOut, int nOutBits)
{
        // Count CPUs
        SYSTEM_INFO SysInfo;
        GetSystemInfo(&SysInfo);

        // Create an decoder, bInterlaced=TRUE, bMT=TRUE
        CMJ2DecMT *pDec = new CMJ2DecMT(TRUE, TRUE, SysInfo.dwNumberOfProcessors/2, &OEM_LIC);

        if (!pDec) {return 0;}

        // Is license valid ?
        if (!pDec->IsLicenseValid())
        {
                // No
                delete pDec;
                return 0;
        }

        // Note: In this sample nHeight is the height of the output frame.

        // Prepare
        pDec->prepare(
                                NULL, 0, NULL, // jp2 = NULL, no codestream info returned
                                pIn1, nIn1,
                                nWidth, nHeight/2, // Field height is 1/2 of the frame height
                                0, 0, // in_fcc, in_bits passed as unknown
                                pOut, nOut,
                                0, 0, // out_of = 0, start filling first line
                                nWidth, nHeight,
                                fccOut, nOutBits);

        // Skip first line
        int ofs = WIDTHBYTES(nWidth * nOutBits); // Macro defined in JPEG2000.h

        // Decode
        int nSize = pDec->decode(
                                NULL, 0, NULL, // jp2 = NULL, no codestream info returned
                                pIn2, nIn2,
                                nWidth, nHeight/2, // Field height is 1/2 of the frame height
                                0, 0, // in_fcc, in_bits passed as unknown
                                pOut, nOut,
                                ofs, 0, // out_of = ofs, start filling second line
                                nWidth, nHeight,
                                fccOut, nOutBits);
        // Sync
        nSize += pDec->sync();

        // Delete decoder
        if (pDec) {delete pDec;}

        // Return the total number of bytes red in input codestreams
        return nSize;

        // Note : On a common implementation jp2 would be used and allocated
        // outside of this function, in this case you can use jp2.SizeField1 
        // and jp2.SizeField2 to store the number of bytes red in each input codestream
}

int Decode2Frames(int nWidth, int nHeight, PBYTE pIn1, int nIn1, PBYTE pIn2, int nIn2,
                                  PBYTE pOut1, int nOut1, PBYTE pOut2, int nOut2, DWORD fccOut, int nOutBits)
{
        // Count CPUs
        SYSTEM_INFO SysInfo;
        GetSystemInfo(&SysInfo);

        // Create an decoder, bInterlaced=FALSE, bMT=TRUE
        CMJ2DecMT *pDec = new CMJ2DecMT(FALSE, TRUE, SysInfo.dwNumberOfProcessors/2, &OEM_LIC);

        if (!pDec) {return 0;}

        // Is license valid ?
        if (!pDec->IsLicenseValid())
        {
                // No
                delete pDec;
                return 0;
        }

        // Prepare
        pDec->prepare(
                                NULL, 0, NULL, // jp2 = NULL, no codestream info returned
                                pIn1, nIn1,
                                nWidth, nHeight,
                                0, 0, // in_fcc, in_bits passed as unknown
                                pOut1, nOut1,
                                0, 0,
                                nWidth, nHeight,
                                fccOut, nOutBits);

        // Decode
        int nSize = pDec->decode(
                                NULL, 0, NULL, // jp2 = NULL, no codestream info returned
                                pIn2, nIn2,
                                nWidth, nHeight,
                                0, 0, // in_fcc, in_bits passed as unknown
                                pOut2, nOut2,
                                0, 0,
                                nWidth, nHeight,
                                fccOut, nOutBits);
        // Sync
        nSize += pDec->sync();

        // Delete decoder
        if (pDec) {delete pDec;}

        // Return the total number of bytes red in input codestreams
        return nSize;

        // Note : On a common implementation jp2 would be used and allocated
        // outside of this function, in this case you can use jp2.SizeField1 
        // and jp2.SizeField2 to store the number of bytes red in each input codestream
}

// CMJ2DecMT can be used single threaded as well
int DecodeST(int nWidth, int nHeight, PBYTE pIn, int nIn,
                                 PBYTE pOut, int nOut, DWORD fccOut, int nOutBits)
{
        // Create an decoder, bInterlaced=FALSE, bMT=FALSE
        CMJ2DecMT *pDec = new CMJ2DecMT(FALSE, FALSE, 0, &OEM_LIC);

        if (!pDec) {return 0;}

        // Is license valid ?
        if (!pDec->IsLicenseValid())
        {
                // No
                delete pDec;
                return 0;
        }

        // Decode
        int nSize = pDec->decode(
                                NULL, 0, NULL, // jp2 = NULL, no codestream info returned
                                pIn, nIn,
                                nWidth, nHeight,
                                0, 0, // in_fcc, in_bits passed as unknown
                                pOut, nOut,
                                0, 0,
                                nWidth, nHeight,
                                fccOut, nOutBits);

        // Delete decoder
        if (pDec) {delete pDec;}

        // Return the number of bytes red in input codestreams
        return nSize;
}

   

© Morgan Multimedia 1990-2005