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

📄 ig_graphics.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                                           *DataPtr++,  //cb
                                           *DataPtr++); //t
        }
        else
        {
            Color = IGMakeARGBfromYCrCb601(*DataPtr++,  // y
                                           *DataPtr++,  //cr
                                           *DataPtr++,  //cb
                                           *DataPtr++); //t
        }

        CurPal->Colors[PalColor].a = ClrBytes[0];
        CurPal->Colors[PalColor].r = ClrBytes[1];
        CurPal->Colors[PalColor].g = ClrBytes[2];
        CurPal->Colors[PalColor].b = ClrBytes[3];
    }

    return IG_STATUS_SUCCESS;
}


/**
 * IGGraphicsCreateAllPalettes - create all the ig palettes
 *
 * @return IG_STATUS
 */
IG_STATUS IGGraphicsCreateAllPalettes()
{
    DFBPaletteDescription PalDesc;
    PALETTE *CurPal;

    /* loop and create all the dfb palettes but with clear as their colors */
    for (int i=0; i<IG_MAX_PALETTES; i++)
    {
        CurPal = &IGPalettes[i];
        for (int j=0; j<IG_MAX_PALETTE_COLORS; j++)
        {
            CurPal->Colors[j].a = 0;
            CurPal->Colors[j].r = 0;
            CurPal->Colors[j].g = 0;
            CurPal->Colors[j].b = 0;
        }

        /* setup the description */
        PalDesc.flags = (DFBPaletteDescriptionFlags) (DPDESC_SIZE | DPDESC_ENTRIES);
        PalDesc.size = IG_MAX_PALETTE_COLORS;
        PalDesc.entries = CurPal->Colors;

        /* call create palette with the entries we give here */
        if (IGInfo.IGDFBInfo.pDFBHandle->CreatePalette(IGInfo.IGDFBInfo.pDFBHandle, &PalDesc, &CurPal->DFBPal) != DFB_OK)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("IGGraphicsCreateAllPalettes(): Failed CreatePalette\n"));
            return IG_STATUS_ERROR;
        }
    }

    return (IG_STATUS_SUCCESS);
}

/**
 * IGGraphicsDeleteAllPalettes - release the surface memory
 *
 * @return IG_STATUS
 */
IG_STATUS IGGraphicsDeleteAllPalettes()
{
    PALETTE *CurPal;

    /* loop and create all the dfb palettes but with clear as their colors */
    for (int i=0; i<IG_MAX_PALETTES; i++)
    {
        CurPal = &IGPalettes[i];

        /* call create palette with the entries we give here */
        if (CurPal->DFBPal->Release(CurPal->DFBPal) != DFB_OK)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("IGGraphicsDeleteAllPalettes(): Failed Release Palette\n"));
            return (IG_STATUS_ERROR);
        }
    }

    return (IG_STATUS_SUCCESS);
}


/**
 * IGGraphicsRenderButton - render a button to the plane
 *
 * @param BUTTON *Button - Take the given button and render it based on it's state
 *
 * @return IG_STATUS
 */
IG_STATUS IGGraphicsRenderButton(BUTTON *Button, int ClearButton)
{
    /* use the button's x,y to put the button down */
    OBJECT_DEFINITION_SEGMENT *Img=NULL;
    USHORT DrawX, DrawY, DrawW, DrawH;
    USHORT ScreenMaxX, ScreenMaxY;
    int imgsize;
#ifdef ALLOW_IG_PROFILING
    ULONG TickStart = 0;
#endif

    if (NULL == Button)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("IGGraphicsRenderButton(): Null Button\n"));
        return IG_STATUS_ERROR;
    }

    DBGPRINT(DBG_ON(DBG_TRACE), ("IGGraphicsRenderButton(): ButtonID %d\n", Button->ButtonID));

    /* if the button calls out an image that doesn't exist clear it */
    if (Button->CurrentDisplayObjectIDRef > IG_MAX_ODS)
    {
        IGGraphicsClearButton(Button);
        return IG_STATUS_SUCCESS;
    }

    /* grab the object from the list */
    Img = &IGObjList[Button->CurrentDisplayObjectIDRef];
    if (0 == Img->InUse)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("IGGraphicsRenderButton(): Could not render object id %d\n", Button->CurrentDisplayObjectIDRef));
        return IG_STATUS_ERROR;
    }

    imgsize = Img->ObjData.Width * Img->ObjData.Height;
    if (0 == imgsize)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("IGGraphicsRenderButton(): imgsize is zero!\n"));
        return IG_STATUS_ERROR;
    }

    /* check to see if the image is big enough to render */
    if ((Img->ObjData.Width < 8) || (Img->ObjData.Height < 8))
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("IGGraphicsRenderButton(): Could not render object id %d, too small\n",
            Button->CurrentDisplayObjectIDRef));
        return IG_STATUS_ERROR;
    }

    /* if the clear button flag is set we clear the image area */
    if (ClearButton == 1)
    {
        IGGraphicsClearButton(Button);
        return IG_STATUS_SUCCESS;
    }

    /* load drawing params, if we are drawing half width cut all x coords in half */
    DrawY = Button->YPosition;
    DrawH = Img->ObjData.Height;
    ScreenMaxY = MAX_GRFX_HEIGHT;

    if (IGInfo.CoordsHalfWidth == 0)
    {
        DrawX = Button->XPosition;
        DrawW = Img->ObjData.Width;
        ScreenMaxX = MAX_GRFX_WIDTH;
    }
    else
    {
        DrawX = Button->XPosition/2;
        DrawW = (Img->ObjData.Width+1)/2;
        ScreenMaxX = MAX_GRFX_WIDTH/2;
    }

    /* Blit */
    if ((DrawX <= ScreenMaxX) && (DrawY <= ScreenMaxY) &&
       ((DrawX + DrawW) <= ScreenMaxX) && ((DrawY + DrawH) <= ScreenMaxY))
    {
#ifdef ALLOW_IG_PROFILING
        if (IGStats.Profiling == 1)
        {
            TickStart = OS_GetTicks();
        }
#endif
        DBGPRINT(DBG_ON(DBG_TRACE), ("IGGraphicsRenderButton(): ButtonID %d x=%d y=%d w=%d h=%d\n", Button->ButtonID,
            DrawX, DrawY, DrawW, DrawH));

        if (IGInfo.IGDFBInfo.PrimarySurface->Blit(IGInfo.IGDFBInfo.PrimarySurface, Img->SurfaceLUT8,
            NULL, DrawX, DrawY) == DFB_OK)
        {
#ifdef ALLOW_IG_PROFILING
            if (IGStats.Profiling == 1)
            {
                IGStats.TotalBlitTicks += OS_GetTicks() - TickStart;
            }
#endif
            IGAddtoCleanupList(DrawX, DrawY, DrawW, DrawH);
        }
    }
    else
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("IGGraphicsRenderButton(): image tried to draw out of bounds %d %d %d %d\n",
            DrawX, DrawY, DrawX + DrawW, DrawY + DrawH));
     }

    return (IG_STATUS_SUCCESS);
}

/**
 * IGGraphicsClearButton - clear a button area using the clear color
 *
 * @param BUTTON *Button - The button that contains an area to clear
 *
 * @return IG_STATUS
 */
IG_STATUS IGGraphicsClearButton(BUTTON *Button)
{
    OBJECT_DEFINITION_SEGMENT *Img=NULL;
    int fImgValid = 0;

    if (Button == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("IGGraphicsClearButton: Null Pointer!\n"));
        return (IG_STATUS_ERROR);
    }

    /* find any button coordinates that are valid and use them to clear the space */
    if (Button->NormalStartObjectIDRef < IG_MAX_ODS)
    {
        Img = &IGObjList[Button->NormalStartObjectIDRef];
        if (Img->InUse == 1)
        {
            fImgValid = 1;
        }
    }

    if ((Button->SelectedStartObjectIDRef < IG_MAX_ODS) && (fImgValid == 0))
    {
        Img = &IGObjList[Button->SelectedStartObjectIDRef];
        if (Img->InUse == 1)
        {
            fImgValid = 1;
        }
    }

    if ((Button->ActivatedStartObjectIDRef < IG_MAX_ODS) && (fImgValid == 0))
    {
        Img = &IGObjList[Button->ActivatedStartObjectIDRef];
        if (Img->InUse == 1)
        {
            fImgValid = 1;
        }
    }

    /* if our image is valid we clear the area */
    if (fImgValid)
    {
        IGInfo.IGDFBInfo.PrimarySurface->SetColorIndex(IGInfo.IGDFBInfo.PrimarySurface, 0xff);  // all transparent

        DFBRectangle r;
        if (IGInfo.CoordsHalfWidth == 0)
        {
            r.x = Button->XPosition;
            r.y = Button->YPosition;
            r.w = Img->ObjData.Width;
            r.h = Img->ObjData.Height;
        }
        else
        {
            r.x = Button->XPosition/2;
            r.y = Button->YPosition;
            r.w = (Img->ObjData.Width+1)/2;
            r.h = Img->ObjData.Height;
        }

        IGInfo.IGDFBInfo.PrimarySurface->FillRectangle(IGInfo.IGDFBInfo.PrimarySurface, r.x, r.y, r.w, r.h);

        IGAddtoCleanupList(r.x, r.y, r.w, r.h);

        return (IG_STATUS_SUCCESS);
    }

    DBGPRINT(DBG_ON(DBG_TRACE), ("IGGraphicsClearButton: Could not clear button, no objects valid\n"));

    return (IG_STATUS_ERROR);
}

/**
 * IGGraphicsCreateLUT8Surface - create a directfb surface for the LUT8 member of an ODS
 *
 * @param DFBSurfaceDescription *desc = Description pointer describing the new surface
 * @param OBJECT_DEFINITION_SEGMENT *Obj = The object that contains the LUT8 DFB Surface to create
 *
 * @return IG_STATUS
 */
IG_STATUS IGGraphicsCreateLUT8Surface(DFBSurfaceDescription *desc, OBJECT_DEFINITION_SEGMENT *Obj)
{
#ifdef ALLOW_IG_PROFILING
    ULONG TickStart = 0;
    if (IGStats.Profiling == 1)
    {
        TickStart = OS_GetTicks();
    }
#endif
    /* create the palettized surface of the object passed in */
    DFBResult Result;
    Result = IGInfo.IGDFBInfo.SurfaceManager->CreateSurface(IGInfo.IGDFBInfo.SurfaceManager, desc, &Obj->SurfaceLUT8);

    if (Result != DFB_OK)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("CreateSurface failed error %d\n", Result));
        return IG_STATUS_ERROR;
    }
#ifdef ALLOW_IG_PROFILING
    if (IGStats.Profiling == 1)
    {
        IGStats.TotalCreateSurfaceTicks += OS_GetTicks() - TickStart;
    }
#endif
    return IG_STATUS_SUCCESS;
}

/**
 * IGGraphicsFlip - present the backbuffer on screen
 *
 * @param void
 *
 * @return IG_STATUS
 */
IG_STATUS IGGraphicsFlip()
{
    OS_SemTake(IGInfo.BlitLock, OS_WAIT_FOREVER);
    DFBRegion TempRegion;

#ifdef ALLOW_IG_PROFILING
    ULONG TickStart = 0;
#endif

    if ((gIGFlipRegion.x2 > gIGFlipRegion.x1) && (gIGFlipRegion.y2 > gIGFlipRegion.y1))
    {
#ifdef ALLOW_IG_PROFILING
        if (IGStats.Profiling == 1)
        {
            TickStart = OS_GetTicks();
        }
#endif

        /* copy the flipping region */
        memcpy(&TempRegion, &gIGFlipRegion, sizeof(DFBRegion));

        /* make the region one bigger in each direction, this is 
           to account for the conversion of rectangle areas to regions */
        TempRegion.x2++;
        TempRegion.y2++;

        /* check width */
        if (IGInfo.CoordsHalfWidth == 1)
        {
            if (TempRegion.x2 > ((IGInfo.IGDFBInfo.ScreenWidth/2)-1))
            {
                TempRegion.x2 = ((IGInfo.IGDFBInfo.ScreenWidth/2)-1);
            }

⌨️ 快捷键说明

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