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

📄 pg_util.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
******************************************************************************
**                                                                          **
**  Copyright (c) 2005-2006 Videon Central, Inc.                            **
**  All rights reserved.                                                    **
**                                                                          **
**  The computer program contained herein contains proprietary information  **
**  which is the property of Videon Central, Inc.  The program may be used  **
**  and/or copied only with the written permission of Videon Central, Inc.  **
**  or in accordance with the terms and conditions stipulated in the        **
**  agreement/contract under which the programs have been supplied.         **
**                                                                          **
******************************************************************************
*****************************************************************************/
/**
 * @file pg_util.cpp
 *
 * $Revision: 1.3 $ 
 *
 * PG utility functions
 *
 */

#include "vdvd_types.h"
#include "pg_defs.h"
#include "pg_api.h"
#include "pg_util.h"

#define DEBUG_PG_UTIL   DBG_ERROR
#define DBG_ON(x)       (DEBUG_PG_UTIL >= x)

PG_STATUS PGUtilHalfDecode(BYTE *Input, ULONG InputSize, BYTE *Output, ULONG OutputSize, ULONG Pitch, ULONG OutputWidth);

/**
 * MakeARGBfromYCrCb601 - color space conversion from YCrCbT to RGB
 *
 * @param y - y component
 * @param cr - cr component
 * @param cb - cb component
 *
 * @return
 * int - 32 bit pixel code with byte position in RGB0 format
 */
ULONG MakeARGBfromYCrCb601(BYTE y, BYTE cr, BYTE cb, BYTE t)
{
    ULONG pixel32;
    BYTE *pixel = (BYTE *)&pixel32;
    int r, g, b;

    r = y + (int)(1.370705 * (cr-128));
    g = y - (int)((0.698001 * (cr-128)) - (0.337633 * (cb-128)));
    b = y + (int)(1.732446 * (cb-128));

    r = (t * r + 127) / 255;
    b = (t * b + 127) / 255;
    g = (t * g + 127) / 255;

    if (r > 255) r = 255;
    if (g > 255) g = 255;
    if (b > 255) b = 255;

    if (r < 0) r = 0;
    if (g < 0) g = 0;
    if (b < 0) b = 0;

    pixel[0] = t;
    pixel[1] = r;
    pixel[2] = g;
    pixel[3] = b;

    return pixel32;
}

/**
 * MakeARGBfromYCrCb709 - color space conversion from YCrCbT to RGB
 *
 * @param y - y component
 * @param cr - cr component
 * @param cb - cb component
 *
 * @return
 * int - 32 bit pixel code with byte position in RGB0 format
 */
ULONG MakeARGBfromYCrCb709(BYTE y, BYTE cr, BYTE cb, BYTE t)
{
    ULONG pixel32;
    BYTE *pixel = (BYTE *)&pixel32;
    int r, g, b;

    r = y + (int)(1.540 * (cr-128));
    g = y - (int)((0.459 * (cr-128)) - (0.183 * (cb-128)));
    b = y + (int)(1.816 * (cb-128));

    r = (t * r + 127) / 255;
    b = (t * b + 127) / 255;
    g = (t * g + 127) / 255;

    if (r > 255) r = 255;
    if (g > 255) g = 255;
    if (b > 255) b = 255;

    if (r < 0) r = 0;
    if (g < 0) g = 0;
    if (b < 0) b = 0;

    pixel[0] = t;
    pixel[1] = r;
    pixel[2] = g;
    pixel[3] = b;

    return pixel32;
}

/**
 * RleDecode - Decode Run Length Encoded data according to BDROM spec, if the data sizes
 *              do not match what is expected, return an error
 *
 * @param BYTE *InData - the data to convert
 * @param ULONG InputSize - the size of the input data in bytes
 * @param PALETTE *Pal - the palette used for conversion
 * @param BYTE *OutData - the output data (24 bit), this is 3/4 the InputSize in length
 *
 * @return PG_STATUS
 */
PG_STATUS RLEDecode(BYTE *Input, ULONG InputSize, BYTE *Output, ULONG OutputSize, ULONG Pitch,
    ULONG OutputWidth, ULONG HalfWidth)
{
    BYTE PixelCode = 0;
    ULONG Index = 0;
    int RunLength = 0;
    ULONG OutputIndex = 0;
    ULONG PitchDelta = 0;
    ULONG PixelsOutput = 0;

    if (HalfWidth)
    {
        return PGUtilHalfDecode(Input, InputSize, Output, OutputSize, Pitch, OutputWidth);
    }

    /*  check the pitch, if it's greater we have more memory
        allocated then needs and need to skip some space*/
    if (Pitch >= OutputWidth)
    {
        PitchDelta = Pitch - OutputWidth;
    }
    else
    {
        DbgPrint(("RLEDecode(): INVALID PITCH, pitch=%d, image=%d\n", Pitch, OutputWidth));
        return PG_STATUS_RLE_ERROR;
    }

    /* while we still have data left */
    while (Index < InputSize)
    {
        while (1) /* till we get an end of line */
        {
            if (Input[Index] != 0)
            {
                /* if we get a pixel write it out */
                PixelCode = Input[Index];
                if ((PixelsOutput+1) > OutputSize)
                {
                    DBGPRINT(DBG_ON(DBG_ERROR), ("rle decode error, output size too big PixelsOutput %d OutputSize %d\n", PixelsOutput, OutputSize));
                    return PG_STATUS_RLE_ERROR;
                }
                Output[OutputIndex++] = PixelCode;
                PixelsOutput++;
            }
            else
            {
                Index++;

                /* check switches */
                if (SWITCH_1(Input[Index]) == 0)
                {
                    if (SWITCH_2(Input[Index]) == 0)
                    {
                        if (RLZERO(Input[Index]) != 0)
                        {
                            /* write out this many zero's */
                            RunLength = RLZERO(Input[Index]);

                            if ((PixelsOutput + RunLength) > OutputSize)
                            {
                                DBGPRINT(DBG_ON(DBG_ERROR), ("rle decode error, output size too big PixelsOutput %d OutputSize %d\n", PixelsOutput, OutputSize));
                                return PG_STATUS_RLE_ERROR;
                            }

                            memset(&Output[OutputIndex], 0, RunLength);
                            OutputIndex += RunLength;
                            PixelsOutput += RunLength;
                        }
                        else
                        {
                            /* add any pitch delta that exists or just 0 */
                            OutputIndex += PitchDelta;
                            break;  /* got end of line */
                        }
                    }
                    else
                    {
                        RunLength = (RL64TO16K_TOP(Input[Index]) << 8) | Input[Index+1];

                        if ((PixelsOutput + RunLength) > OutputSize)
                        {
                            DBGPRINT(DBG_ON(DBG_ERROR), ("rle decode error, output size too big PixelsOutput %d OutputSize %d\n", PixelsOutput, OutputSize));
                            return PG_STATUS_RLE_ERROR;
                        }

                        memset(&Output[OutputIndex], 0, RunLength);
                        OutputIndex += RunLength;
                        PixelsOutput += RunLength;
                        Index++;
                    }
                }
                else /* non zero pixelcode run */
                {
                    if (SWITCH_2(Input[Index]) == 0)
                    {
                        RunLength = RL3TO63(Input[Index]);
                        Index++;
                    }
                    else
                    {
                        RunLength = (RL64TO16K_TOP(Input[Index]) << 8) | Input[Index+1];
                        Index += 2;
                    }

                    /* get the next pixel code */
                    PixelCode = Input[Index];

                    if ((PixelsOutput + RunLength) > OutputSize)
                    {
                        DBGPRINT(DBG_ON(DBG_ERROR), ("rle decode error, output size too big PixelsOutput %d OutputSize %d\n", PixelsOutput, OutputSize));
                        return PG_STATUS_RLE_ERROR;
                    }

                    /* write out the current pixel code */
                    memset(&Output[OutputIndex], PixelCode, RunLength);

                    OutputIndex += RunLength;
                    PixelsOutput += RunLength;
                }
            }

            /* move to the next byte */
            Index++;
        }

        /* move to the next byte */
        Index++;
    }

    if (PixelsOutput != OutputSize)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("RLEDecode(): incorrect rle decode, data size does not match, %d %d\n",
            PixelsOutput, OutputSize));
        return PG_STATUS_RLE_ERROR;
    }

⌨️ 快捷键说明

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