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

📄 tidtv_gammactrl.c

📁 ti的数字电视芯片 tvp9000的源码
💻 C
字号:
/*******************************************************************************
*  @ModuleName :: TiDTV_GammaCtrl.c
*
*	@Copyright	::	Copyright 2005- Texas Instruments, Inc.
*
*  @Description:: Functions for TI DTV Gamma Correction APIs
*
*	@History	::
*---------------------------------------
*	07-14-2005	Paul Hunt	Created
*******************************************************************************/

#include <stdio.h>
#include <math.h>
#include <string.h>

#include "Tvp9000.h"
#include "TvpError.h"
#include "TvpEncoder.h"
#include "TvpEncoderMem.h"

#include "TiDTV_DataType.h"
#include "ucos_ii.h"
#include "TiDTV_UART.h"
#include "TiDTV_GammaCtrl.h"

// Buffers for Encoder LUTs
static unsigned char TiDTV_EncRedLUT[256];
static unsigned char TiDTV_EncGreenLUT[256];
static unsigned char TiDTV_EncBlueLUT[256];

/*******************************************************************************
*  @RoutineName:: tvpEncGammaTableGen
*
*  @Description:: Generate and update one or more Gamma tables using
*                 the supplied parameters
*
*  @Input      :: channelFlags specifies which channel(s) to populate
*
*  @Output     :: none
*
*  @Return     :: none
*******************************************************************************/
void tvpEncGammaTableGen(unsigned char channelFlags, unsigned short gamma_fix)
{
    unsigned short i;
   unsigned char gamma_entry;
   short short_entry;
   float float_entry;
   float gamma_float;

#if	0
   char fstring[80];
  unsigned long          enc_cfg_tmp;
   volatile unsigned long *enc_cfg_p = (volatile unsigned long *) 0x50000;

   static unsigned char UartInitd = 0;

   if (!UartInitd) // initialize uart
   {
      TiDTV_InitUART();
      UartInitd = 1;

////////////////////////////////////////////////////////////////////////
///////////// Configure Gamma Correction into output path //////////////
////////////////////////////////////////////////////////////////////////
      // print current encoder cfg reg
      enc_cfg_tmp = *enc_cfg_p; // get enc cfg
      sprintf(fstring, "%lX\n", enc_cfg_tmp);
      TiDTV_UartWrite(strlen(fstring), fstring, 0);

      // modify encoder cfg reg to select after gamma correction block
      enc_cfg_tmp &= ~TVP_ENC_DVO_OUT_MASK; // clear DVO source select bits
      enc_cfg_tmp |= TVP_ENC_DVO_GC; // DVO source after gamma correction
      // print new encoder cfg reg
      sprintf(fstring, "%lX\n", enc_cfg_tmp);
      TiDTV_UartWrite(strlen(fstring), fstring, 0);

      *enc_cfg_p = enc_cfg_tmp; // set enc cfg
////////////////////////////////////////////////////////////////////////
   }
#endif
   
   gamma_float = ((float) gamma_fix) / ENC_GAMMA_DIVISOR;
//   sprintf(fstring, "gamma_float = %5.3f\n", gamma_float);
//   TiDTV_UartWrite((strlen(fstring), fstring, 0);
   
   

   for (i = 0; i < TVP_NUM_LUT_ENTRIES; i++)
   {
      // compute gamma for index i as a function of parms
      float_entry = 255.0 * pow( i/255.0, gamma_float );
      //sprintf(fstring, "float_entry = %f", float_entry);
      //TiDTV_UartWrite(strlen(fstring), fstring, 0);
      
      //if (channelFlags & 0x08) gamma_fix = i; else gamma_fix = 0; // hack for testing
      short_entry = (short) float_entry;
      if (short_entry > 255) short_entry = 255;
      gamma_entry = (unsigned char) short_entry;
      //sprintf(fstring, ", gamma_entry = %d\n", gamma_entry);
      //TiDTV_UartWrite(strlen(fstring), fstring, 0);

      // store in selected table(s)

      if (channelFlags & ENC_GAMMA_GEN_GREEN) TiDTV_EncGreenLUT[i] = gamma_entry;
      if (channelFlags & ENC_GAMMA_GEN_BLUE ) TiDTV_EncBlueLUT[i]  = gamma_entry;
      if (channelFlags & ENC_GAMMA_GEN_RED  ) TiDTV_EncRedLUT[i]   = gamma_entry;

   }
}

/*******************************************************************************
*  @RoutineName:: tvpEncLutWrite
*
*  @Description:: Update the LUT data of Encoder
*
*  @Input      :: channelFlags specifies which channel(s) to write to Encoder
*
*  @Output     :: none
*
*  @Return     :: none
*******************************************************************************/
void tvpEncLutWrite(unsigned char channelFlags)
{
   volatile unsigned long *dst_p;
   volatile unsigned char *src_p;
   unsigned long i;

   //char fstring[20];

   if (channelFlags & ENC_LUT_WRITE_GREEN)
   {
      dst_p = TVP_ENC_LUT0_BASE;
      src_p = TiDTV_EncGreenLUT;

      // Load the new gamma LUT conversion table for Green
      for (i=0; i<TVP_NUM_LUT_ENTRIES; i++)
      {
           //sprintf(fstring, "%d\n", (unsigned long) *src_p);
           //TiDTV_UartWrite(strlen(fstring), fstring, 0);
           *dst_p++ = (unsigned long) *src_p++;
      }
   }

   if (channelFlags & ENC_LUT_WRITE_BLUE)
   {
      dst_p = TVP_ENC_LUT1_BASE;
      src_p = TiDTV_EncBlueLUT;

      // Load the new gamma LUT conversion table for Blue
      for (i=0; i<TVP_NUM_LUT_ENTRIES; i++)
           *dst_p++ = (unsigned long) *src_p++;
   }

   if (channelFlags & ENC_LUT_WRITE_RED)
   {
      dst_p = TVP_ENC_LUT2_BASE;
      src_p = TiDTV_EncRedLUT;

      // Load the new gamma LUT conversion table for Red
      for (i=0; i<TVP_NUM_LUT_ENTRIES; i++)
           *dst_p++ = (unsigned long) *src_p++;
   }
}

⌨️ 快捷键说明

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