示例#1
0
文件: JXRTest.c 项目: Alexpux/ResIL
static ERR GetTestInfo(const char* szExt, const PKIIDInfo** ppInfo)
{
    ERR err = WMP_errSuccess;

    static PKIIDInfo iidInfo[] = {
        {".bmp", &IID_PKImageBmpEncode, &IID_PKImageBmpDecode},
        {".ppm", &IID_PKImagePnmEncode, &IID_PKImagePnmDecode},
        {".pgm", &IID_PKImagePnmEncode, &IID_PKImagePnmDecode},
        {".pnm", &IID_PKImagePnmEncode, &IID_PKImagePnmDecode},
        {".pfm", &IID_PKImagePnmEncode, &IID_PKImagePnmDecode},
        {".tif", &IID_PKImageTifEncode, &IID_PKImageTifDecode},
        {".hdr", &IID_PKImageHdrEncode, &IID_PKImageHdrDecode},
        {".iyuv", &IID_PKImageIyuvEncode, &IID_PKImageIyuvDecode},
        {".yuv422", &IID_PKImageYuv422Encode, &IID_PKImageYuv422Decode},
        {".yuv444", &IID_PKImageYuv444Encode, &IID_PKImageYuv444Decode},
    };
    size_t i = 0;

    *ppInfo = NULL;
    for (i = 0; i < sizeof2(iidInfo); ++i)
    {
        if (0 == PKStrnicmp(szExt, iidInfo[i].szExt, strlen(iidInfo[i].szExt)))
        {
            *ppInfo = &iidInfo[i];
            goto Cleanup;
        }
    }

    Call(WMP_errUnsupportedFormat);

Cleanup:
    return err;
}
示例#2
0
int GetArguments(int* pc, char** ppv[])
{
    size_t i = 0;
    static char line[132];
    static char* args[20] =
    {
        "WMPDecApp.exe",
        "-i",
        DEFDIR "test.wdp",
        "-o",
        DEFDIR "test.bmp",
        "-c",
        "0",
        "-v",
        "-t",
        NULL,
    };

    FILE* pfIn = fopen(DEFDIR "WMPIni.txt", "r");

    // default arguments to return
    *pc = 9;
    *ppv = args;

    while (fgets(line, sizeof2(line), pfIn))
    {
        // search for the matching line
        if (0 == strcmp(strtok(line, " \t"), args[0]))
        {
            // extract each argument from the matching line
            for (i = 1; i < sizeof2(args) - 1 && (args[i] = strtok(NULL, " \t\n\r")); ++i);
            *pc = i;

            printf("Args from WMPIni.txt" CRLF);
            break;
        }
    }

    fclose(pfIn);

    for (i = 0; i < (size_t)*pc; printf("%s ", args[i++]));
    puts("");
    return 0;
}
示例#3
0
ERR PKFormatConverter_Initialize(PKFormatConverter* pFC, PKImageDecode* pID, char *pExt, PKPixelFormatGUID enPF)
{
    ERR err = WMP_errSuccess;

    static PKPixelConverterInfo pcInfo[] = {
        {&GUID_PKPixelFormat24bppRGB, &GUID_PKPixelFormat24bppBGR, RGB24_BGR24},
        {&GUID_PKPixelFormat24bppBGR, &GUID_PKPixelFormat24bppRGB, BGR24_RGB24},
        {&GUID_PKPixelFormat24bppRGB, &GUID_PKPixelFormat8bppGray, RGB24_Gray8},
        {&GUID_PKPixelFormat24bppBGR, &GUID_PKPixelFormat8bppGray, BGR24_Gray8},
        {&GUID_PKPixelFormat8bppGray, &GUID_PKPixelFormat24bppRGB, Gray8_RGB24},
        {&GUID_PKPixelFormat8bppGray, &GUID_PKPixelFormat24bppBGR, Gray8_BGR24},
    };
    PKPixelFormatGUID enPFFrom = GUID_PKPixelFormatDontCare;

    //================================
    pFC->pDecoder = pID;
    pFC->enPixelFormat = enPF;

    if (pExt != NULL && IsEqualGUID(&enPF, &GUID_PKPixelFormat24bppRGB)) {
        const PKIID *pkIID = NULL;
        if (GetImageEncodeIID (pExt, &pkIID) == WMP_errSuccess && *pkIID == IID_PKImageBmpEncode) // do not use "Call" here - this may fault but it's ok
            enPF = GUID_PKPixelFormat24bppBGR;
    }
    //================================
    Call(pFC->pDecoder->GetPixelFormat(pFC->pDecoder, &enPFFrom));

    if (!IsEqualGUID(&enPFFrom, &enPF))
    {
        size_t i = 0;
        for (i = 0; i < sizeof2(pcInfo); ++i)
        {
            PKPixelConverterInfo* pPCI = pcInfo + i;

            if (IsEqualGUID(&enPFFrom, pPCI->pGUIDPixFmtFrom) && IsEqualGUID(&enPF, pPCI->pGUIDPixFmtTo))
            {
                pFC->Convert= pPCI->Convert;
                goto Cleanup;
            }
        }
        goto Cleanup;

        Call(WMP_errUnsupportedFormat);
    }

Cleanup:
    return err;
}
示例#4
0
ERR WmpDecAppParseArgs(int argc, char* argv[], WMPDECAPPARGS* args)
{
    ERR err = WMP_errSuccess;

    int c = 0, i = 1;
    // char* arg = NULL;

    static const PKPixelFormatGUID* pixelFormat[] =
    {
        &GUID_PKPixelFormat24bppRGB,

        &GUID_PKPixelFormatBlackWhite,

        &GUID_PKPixelFormat8bppGray,
        &GUID_PKPixelFormat16bppGray,
        &GUID_PKPixelFormat16bppGrayFixedPoint,
        &GUID_PKPixelFormat16bppGrayHalf,
        &GUID_PKPixelFormatDontCare, // &GUID_PKPixelFormat32bppGray,
        &GUID_PKPixelFormat32bppGrayFixedPoint,
        &GUID_PKPixelFormat32bppGrayFloat,

        &GUID_PKPixelFormat24bppRGB,
        &GUID_PKPixelFormat48bppRGB,
        &GUID_PKPixelFormat48bppRGBFixedPoint,
        &GUID_PKPixelFormat48bppRGBHalf,
        &GUID_PKPixelFormatDontCare, // &GUID_PKPixelFormat96bppRGB,
        &GUID_PKPixelFormat96bppRGBFixedPoint,
        &GUID_PKPixelFormat128bppRGBFloat,

        &GUID_PKPixelFormat32bppRGBE,
        &GUID_PKPixelFormat32bppCMYK,
        &GUID_PKPixelFormat64bppCMYK,

        &GUID_PKPixelFormat12bppYUV420, 
        &GUID_PKPixelFormat16bppYUV422,
        &GUID_PKPixelFormat24bppYUV444,

//        &GUID_PKPixelFormat32bppRGBA,
        &GUID_PKPixelFormat32bppBGRA,
        &GUID_PKPixelFormat64bppRGBA,
        &GUID_PKPixelFormat64bppRGBAFixedPoint,
        &GUID_PKPixelFormat64bppRGBAHalf,
        &GUID_PKPixelFormatDontCare, // &GUID_PKPixelFormat128bppRGBA,
        &GUID_PKPixelFormat128bppRGBAFixedPoint,
        &GUID_PKPixelFormat128bppRGBAFloat,
        &GUID_PKPixelFormat16bppRGB555,
        &GUID_PKPixelFormat16bppRGB565,
        &GUID_PKPixelFormat32bppRGB101010,
        &GUID_PKPixelFormat40bppCMYKAlpha,
        &GUID_PKPixelFormat80bppCMYKAlpha,
        &GUID_PKPixelFormat32bppBGR,
        &GUID_PKPixelFormat32bppPBGRA,
        &GUID_PKPixelFormat64bppPRGBA,
        &GUID_PKPixelFormat128bppPRGBAFloat,
    };

    size_t InvalidPF[9] = {6, 13, 19, 20, 21, 26, 35, 36, 37};
    int k;

    WmpDecAppInitDefaultArgs(args);

    while(i < argc && argv[i][0] == '-')
//    while (EOF != (c = argit(argc, argv, "i:o:c:ptv", &arg)))
    {
         /* separate out the no-argument switches */
        switch ((c = argv[i][1])) {
            case 't':
                // NOOP - now we always print timing info
                break;

            case 'v':
                args->bVerbose = !FALSE;
                break;

            case 'C':
                args->bIgnoreOverlap = TRUE;
                break;
            
            case 'f': 
                args->bfBitstreamFormat = FREQUENCY;
                break;

            default:
                i ++;
                if (i == argc || argv[i][0] == '-') // need more info
                    Call(WMP_errInvalidArgument);
                
                switch (c)
                {
                case 'i':
                    args->szInputFile= argv[i];
                    break;

                case 'o':
                    args->szOutputFile = argv[i];
                    break;
                
                case 'p':
                    args->cPostProcStrength = (U8)atoi(argv[i]);
                    break;

                case 'c':
                {
                    size_t idxPF = (size_t)atol(argv[i]);

                    FailIf(sizeof2(pixelFormat) <= idxPF, WMP_errUnsupportedFormat);

                    for (k = 0; k < 9; k++)
                    {
                        if (InvalidPF[k] == idxPF)
                        {
                            printf("*** ERROR: Unsupported format in JPEG XR ***\n");
                            Call(WMP_errInvalidArgument);
                        }
                    }

                    args->guidPixFormat = *pixelFormat[idxPF];

                    break;
                }

/*                case 'R': 
                    args->bFlagRGB_BGR = (Bool)atoi(argv[i]);
                    break;
*/
                case 'a': 
                    args->uAlphaMode = (U8)atoi(argv[i]);
                    break;

                case 's': 
                    args->sbSubband = (SUBBAND)atoi(argv[i]);
                    break;

                case 'r': // Region decode
                    if(i + 3 >= argc || argv[i + 1][0] == '-' || argv[i + 2][0] == '-' || argv[i + 3][0] == '-') // not a valid region
                        Call(WMP_errInvalidArgument);

                    args->rTopY = (size_t)atoi(argv[i]);
                    args->rLeftX = (size_t)atoi(argv[i + 1]);
                    args->rHeight = (size_t)atoi(argv[i + 2]);
                    args->rWidth = (size_t)atoi(argv[i + 3]);
                    i += 3;

                    break;

                case 'T': // thumnail decode
                    args->tThumbnailFactor = (size_t)atoi(argv[i]);
                    if (args->tThumbnailFactor == 0) {  // skip flexbits
                        args->tThumbnailFactor = SKIPFLEXBITS;
                    }
                    break;

                case 'O': // orientation
                    args->oOrientation = (atoi(argv[i]) < 8 ? atoi(argv[i]) : O_NONE);
                    break;

                default:
                    Call(WMP_errInvalidArgument);
                    break;
            }
        }

        i ++;
    }

    Call(WmpDecAppValidateArgs(args));

Cleanup:
    return err;
}
示例#5
0
//================================================================
// PKImageEncode_BMP
//================================================================
ERR WriteBMPHeader(
    PKImageEncode* pIE)
{
    ERR err = WMP_errSuccess;

    static U32 rguColorTable[256] = {0};
    size_t cbColorTable = 0;
    size_t cbLineS = 0;
    U32 i = 0;

    struct WMPStream* pS = pIE->pStream;
    BITMAPFILEHEADER bmpFH = { 0, };
    BITMAPINFOHEADER bmpIH = {sizeof(bmpIH), 0, };

    bmpFH.szBM[0] = 'B';
    bmpFH.szBM[1] = 'M';

    if (IsEqualGUID(&GUID_PKPixelFormat24bppRGB, &pIE->guidPixFormat) || IsEqualGUID(&GUID_PKPixelFormat24bppBGR, &pIE->guidPixFormat))
    {
        pIE->cbPixel = 3;
        cbColorTable = 0;
    }
    else if (IsEqualGUID(&GUID_PKPixelFormat32bppBGRA, &pIE->guidPixFormat) 
        || IsEqualGUID(&GUID_PKPixelFormat32bppBGR, &pIE->guidPixFormat)
        || IsEqualGUID(&GUID_PKPixelFormat32bppPBGRA, &pIE->guidPixFormat))
    {
        pIE->cbPixel = 4;
        cbColorTable = 0;
    }
    else if (IsEqualGUID(&GUID_PKPixelFormat8bppGray, &pIE->guidPixFormat))
    {
        pIE->cbPixel = 1;

        cbColorTable = sizeof(rguColorTable);
        for (i = 0; i < sizeof2(rguColorTable); ++i)
        {
            rguColorTable[i] = i | (i << 8) | (i << 16);
        }
    }
    else if (IsEqualGUID(&GUID_PKPixelFormat16bppRGB555, &pIE->guidPixFormat))
    {
        pIE->cbPixel = 2;
        bmpIH.uCompression = BI_BITFIELDS;

        cbColorTable = sizeof(rguColorTable[0]) * 3;
        rguColorTable[0] = BI_RGB555_MASK_R;
        rguColorTable[1] = BI_RGB555_MASK_G;
        rguColorTable[2] = BI_RGB555_MASK_B;
    }
    else if (IsEqualGUID(&GUID_PKPixelFormat16bppRGB565, &pIE->guidPixFormat))
    {
        pIE->cbPixel = 2;
        bmpIH.uCompression = BI_BITFIELDS;

        cbColorTable = sizeof(rguColorTable[0]) * 3;
        rguColorTable[0] = BI_RGB565_MASK_R;
        rguColorTable[1] = BI_RGB565_MASK_G;
        rguColorTable[2] = BI_RGB565_MASK_B;
    }
    else if (IsEqualGUID(&GUID_PKPixelFormat32bppRGB101010, &pIE->guidPixFormat))
    {
        pIE->cbPixel = 4;
        bmpIH.uCompression = BI_BITFIELDS;

        cbColorTable = sizeof(rguColorTable[0]) * 3;
        rguColorTable[0] = BI_RGB101010_MASK_R;
        rguColorTable[1] = BI_RGB101010_MASK_G;
        rguColorTable[2] = BI_RGB101010_MASK_B;
    }            
    else
        Call(WMP_errUnsupportedFormat);

    cbLineS = (pIE->cbPixel * pIE->uWidth + 3) / 4 * 4;

    bmpFH.uOffBits = (U32)(sizeof(bmpFH) + sizeof(bmpIH) + cbColorTable);
    bmpFH.uSize = (U32)(bmpFH.uOffBits + cbLineS * pIE->uHeight);

    bmpIH.iWidth = pIE->uWidth;
    bmpIH.iHeight = pIE->uHeight;
    bmpIH.iPlanes = 1;
    bmpIH.iBitCount = (I16)(8 * pIE->cbPixel);
    bmpIH.uImageSize = (U32)(cbLineS * pIE->uHeight);
    bmpIH.iPelsPerMeterX = (I32)(pIE->fResX * 39.37);
    bmpIH.iPelsPerMeterY = (I32)(pIE->fResY * 39.37);

    Call(pS->Write(pS, &bmpFH, sizeof(bmpFH)));
    Call(pS->Write(pS, &bmpIH, sizeof(bmpIH)));
    Call(pS->Write(pS, rguColorTable, cbColorTable));

    pIE->offPixel = pIE->offStart + bmpFH.uOffBits;
    pIE->fHeaderDone = !FALSE;

Cleanup:
    return err;
}
示例#6
0
//================================================================
// PKImageDecode_BMP
//================================================================
ERR ParseBMPHeader(
    PKTestDecode* pID,
    struct WMPStream* pWS)
{
    ERR err = WMP_errSuccess;

    BITMAPFILEHEADER bmpFH = {0};
    BITMAPINFOHEADER bmpIH = {0};
    static U32 bmpIHE[32] = {0};    // should be >= sizeof(BITMAPV5HEADER) - sizeof(BITMAPINFOHEADER)
    static U32 rguColorTable[256] = {0};
    U32 i = 0;

    Call(pWS->Read(pWS, &bmpFH, sizeof(bmpFH)));
    FailIf(bmpFH.szBM != (U8 *) strstr((char *) bmpFH.szBM, "BM"), WMP_errUnsupportedFormat);

    Call(pWS->Read(pWS, &bmpIH, sizeof(bmpIH)));

    FailIf(((sizeof(bmpIH) > bmpIH.uSize) || ((sizeof(bmpIH) + sizeof(bmpIHE)) < bmpIH.uSize)), WMP_errUnsupportedFormat);

    if (sizeof(bmpIH) < bmpIH.uSize)
        Call(pWS->Read(pWS, &bmpIHE, bmpIH.uSize - sizeof(bmpIH)));

    switch (bmpIH.iBitCount)
    {
        case 8:
            // check the color table to verify the image is actually gray scale
            Call(pWS->Read(pWS, rguColorTable, sizeof(rguColorTable)));
            for (i = 0; i < sizeof2(rguColorTable); ++i)
            {
                U32 c = i | (i << 8) | (i << 16);
                FailIf(c != rguColorTable[i], WMP_errUnsupportedFormat);
            }
            
            pID->guidPixFormat = GUID_PKPixelFormat8bppGray;
            pID->EXT.BMP.cbPixel = 1;
            break;

        case 16:
            Call(pWS->Read(pWS, rguColorTable, sizeof(rguColorTable[0]) * 3));
            if (BI_RGB555_MASK_B == rguColorTable[0] && BI_RGB555_MASK_G == rguColorTable[1] && BI_RGB555_MASK_R == rguColorTable[2])
            {
                pID->guidPixFormat = GUID_PKPixelFormat16bppRGB555;
            }
            if (BI_RGB565_MASK_B == rguColorTable[0] && BI_RGB565_MASK_G == rguColorTable[1] && BI_RGB565_MASK_R == rguColorTable[2])
            {
                pID->guidPixFormat = GUID_PKPixelFormat16bppRGB565;
            }
            else
            {
                Call(WMP_errUnsupportedFormat);
            }
            pID->EXT.BMP.cbPixel = 2;
            break;
            
        case 24:
            pID->guidPixFormat = GUID_PKPixelFormat24bppBGR;
            pID->EXT.BMP.cbPixel = 3;
            break;

        case 32:
            Call(pWS->Read(pWS, rguColorTable, sizeof(rguColorTable[0]) * 3));
            if (BI_RGB101010_MASK_B == rguColorTable[0] && BI_RGB101010_MASK_G == rguColorTable[1] && BI_RGB101010_MASK_R == rguColorTable[2])
            {
                pID->guidPixFormat = GUID_PKPixelFormat32bppRGB101010;
            }
            else
            {
                pID->guidPixFormat = GUID_PKPixelFormat32bppBGRA;
            }
            pID->EXT.BMP.cbPixel = 4;
            break;
            
        default:
            Call(WMP_errUnsupportedFormat);
            break;
    }

    pID->uWidth = (U32)bmpIH.iWidth;
    pID->uHeight = (U32)bmpIH.iHeight;

    pID->fResX = (0 == bmpIH.iPelsPerMeterX ? 96 : (Float)(bmpIH.iPelsPerMeterX * .0254));
    pID->fResY = (0 == bmpIH.iPelsPerMeterY ? 96 : (Float)(bmpIH.iPelsPerMeterY * .0254));
    
    pID->EXT.BMP.offPixel = pID->offStart + bmpFH.uOffBits;

Cleanup:
    return err;
}