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

📄 l2_cdsp.c

📁 台湾凌阳方案300万数码相机源代码
💻 C
📖 第 1 页 / 共 5 页
字号:

    //get low byte
    if(WinNum==0) //BY window value
      WinVal = (((LONG)RegVal*PseudoHwdSize*PseudoVwdSize)<<5)/((LONG)HwdSize*VwdSize*25);
    else
      WinVal = ((LONG)RegVal*PseudoHwdSize*PseudoVwdSize)/((LONG)HwdSize*VwdSize);

    *BYValPt = WinVal;

    if((status0!=0) || (status1!=0)) status = 0x01;

//    PRINT_CDSP("        L2_ReadBYWindow: WinNum = %bu, BYVal = %d\n", WinNum, *BYValPt);
  }

  // return
  PRINT_L2("        L2_ReadBYWindow: Exit\n");

  return(status);
}

//-----------------------------------------------------------------------------
//L2_ConfigAFWindow
//-----------------------------------------------------------------------------
/*
routine description:
  Define the AF window (1).

arguments:
  AFWinHoff: the horizontal offset of AF window
  AFWinVoff: the vertical offset of AF window
  AFWinHsize: the horizontal size of AF window
  AFWinVsize: the vertical size of AF window

return value:
  0x00   - success
  0x01   - general error
  0x02   - parameter error
  others - error
*/

UCHAR L2_ConfigAFWindow(USHORT AFWinHoff, USHORT AFWinVoff, USHORT AFWinHsize,
                        USHORT AFWinVsize) USING_0
{
  USHORT stmp0, stmp1;
  UCHAR tmp0, tmp1;
  UCHAR status;

  status = L2K_SUCCESS;

  //body
  PRINT_L2("        L2_ConfigAFWindow: Enter\n");

  //offset
  stmp0 = AFWinHoff+17; //pipe line delay
  stmp1 = AFWinVoff+7; //pipe line delay
  XBYTE[0x2210] = M_LoByteOfWord(stmp0);
  XBYTE[0x2211] = M_LoByteOfWord(stmp1);

  tmp0 = M_HiByteOfWord(stmp0);
  tmp1 = M_HiByteOfWord(stmp1);
  XBYTE[0x2212] = (tmp1<<4)|tmp0;

  //size
  XBYTE[0x2213] = M_LoByteOfWord(AFWinHsize);
  XBYTE[0x2214] = M_LoByteOfWord(AFWinVsize);

  tmp0 = M_HiByteOfWord(AFWinHsize);
  tmp1 = M_HiByteOfWord(AFWinVsize);
  XBYTE[0x2215] = (tmp1<<4)|tmp0;

  //pseudo window size
  if(((AFWinHsize>>8)!=0) && (AFWinHsize!=256))      tmp0 = 0x06;
  else if(((AFWinHsize>>7)!=0) && (AFWinHsize!=128)) tmp0 = 0x05;
  else if(((AFWinHsize>>6)!=0) && (AFWinHsize!= 64)) tmp0 = 0x04;
  else if(((AFWinHsize>>5)!=0) && (AFWinHsize!= 32)) tmp0 = 0x03;
  else if(((AFWinHsize>>4)!=0) && (AFWinHsize!= 16)) tmp0 = 0x02;
  else if(((AFWinHsize>>3)!=0) && (AFWinHsize!=  8)) tmp0 = 0x01;
  else                                               tmp0 = 0x00;

  if(((AFWinVsize>>11)!=0) && (AFWinVsize!=2048))      tmp1 = 0x90;
  else if(((AFWinVsize>>10)!=0) && (AFWinVsize!=1024)) tmp1 = 0x80;
  else if(((AFWinVsize>>9)!=0) && (AFWinVsize!=512))   tmp1 = 0x70;
  else if(((AFWinVsize>>8)!=0) && (AFWinVsize!=256))   tmp1 = 0x60;
  else if(((AFWinVsize>>7)!=0) && (AFWinVsize!=128))   tmp1 = 0x50;
  else if(((AFWinVsize>>6)!=0) && (AFWinVsize!= 64))   tmp1 = 0x40;
  else if(((AFWinVsize>>5)!=0) && (AFWinVsize!= 32))   tmp1 = 0x30;
  else if(((AFWinVsize>>4)!=0) && (AFWinVsize!= 16))   tmp1 = 0x20;
  else if(((AFWinVsize>>3)!=0) && (AFWinVsize!=  8))   tmp1 = 0x10;
  else                                                 tmp1 = 0x00;

  XBYTE[0x2216] = tmp0|tmp1;

  // return
  PRINT_L2("        L2_ConfigAFWindow: Exit\n");

  return(status);
}

//-----------------------------------------------------------------------------
//L2_ReadAFWindow
//-----------------------------------------------------------------------------
/*
routine description:
  Read the average of edge value of AF window.

arguments:
  AFvalPt: the pointer of the average of edge value on the AF window

return value:
  0x00   - success
  0x01   - general error
  0x02   - parameter error
  others - error
*/

void L2_ReadAFWindow(PUSHORT AFValPt) USING_0
{
  UCHAR tmp0, tmp1;
  USHORT AFHwdSize, AFVwdSize, AFPseudoHwdSize, AFPseudoVwdSize;
  ULONG WinVal;

  //body
  PRINT_L2("        L2_ReadAFWindow: Enter\n");

  tmp0 = XBYTE[0x2215];
  tmp1 = tmp0&0x0F;
  AFHwdSize = ((USHORT)tmp1<<8)|XBYTE[0x2213]; //horizontal size of AF window

  tmp1 = tmp0>>4;
  AFVwdSize = ((USHORT)tmp1<<8)|XBYTE[0x2214]; //vertical size of AF window

  tmp0 = XBYTE[0x2216];
  tmp1 = tmp0&0x0F;
  AFPseudoHwdSize = 8;
  AFPseudoHwdSize = AFPseudoHwdSize<<tmp1; //pseudo horizontal size of AF window

  tmp1 = tmp0>>4;
  AFPseudoVwdSize = 8;
  AFPseudoVwdSize = AFPseudoVwdSize<<tmp1; //pseudo vertical size of AF window

  tmp0 = XBYTE[0x2218];

  WinVal = ((USHORT)tmp0<<8)|XBYTE[0x2217];
  WinVal = (WinVal*AFPseudoHwdSize*AFPseudoVwdSize)/((ULONG)AFHwdSize*AFVwdSize);

  *AFValPt = WinVal;

//  PRINT_CDSP("        L2_ReadAFWindow: AFVal = %u\n", *AFValPt);

  // return
  PRINT_L2("        L2_ReadAFWindow: Exit\n");

  return;
}

//-----------------------------------------------------------------------------
//L2_ConfigOB
//-----------------------------------------------------------------------------
/*
routine description:
  Define the configuration of optical black compensation.

arguments:
  OBWinHoff: the horizontal offset of OB window
  OBWinVoff: the vertical offset of OB window
  OBWinType: the type of OB window
          0: 1x256
          1: 2x256
          2: 4x256
          3: 8x256
          4: 256x1
          5: 256x2
          6: 256x4
          7: 256x8
 OBMode:
      Bit 0: the enable of manual OB
      Bit 1: the enable of auto OB
      Bit 2: when set, the auto OB value is directly calculated from the current frame;
             when clear, the auto OB value is calculated from the previous frame.

return value:
  0x00   - success
  0x01   - general error
  0x02   - parameter error
  others - error
*/

UCHAR L2_ConfigOB(USHORT OBWinHoff, USHORT OBWinVoff, UCHAR OBWinType, UCHAR OBMode,
                  USHORT ManuOB) USING_0
{
  UCHAR tmp0, tmp1;
  UCHAR status;

  status = L2K_SUCCESS;

  //body
  PRINT_L2("        L2_ConfigOB: Enter\n");

  //offset
  XBYTE[0x210C] = M_LoByteOfWord(OBWinHoff);
  XBYTE[0x210D] = M_LoByteOfWord(OBWinVoff);

  tmp0 = M_HiByteOfWord(OBWinHoff);
  tmp1 = M_HiByteOfWord(OBWinVoff);
  XBYTE[0x210B] = (tmp1<<4)|tmp0;

  //manual OB
  XBYTE[0x210E] = M_LoByteOfWord(ManuOB);
  XBYTE[0x210F] = M_HiByteOfWord(ManuOB);

  //type
  tmp0 = OBWinType<<4;
  tmp1 = OBMode&0X07;
  XBYTE[0x210A] = tmp1|tmp0;

  // return
  PRINT_L2("        L2_ConfigOB: Exit\n");

  return(status);
}

//-----------------------------------------------------------------------------
//L2_ReadAutoOB
//-----------------------------------------------------------------------------
/*
routine description:
  Read the value of auto OB.

arguments:
  *AutoOB : the average of edge value on the AF window

return value:
  0x00   - success
  0x01   - general error
  0x02   - parameter error
  others - error
*/

void L2_ReadAutoOB(PUSHORT AutoOBPt) USING_0
{
  UCHAR tmp0;
  USHORT tmp1;

  //body
  PRINT_L2("        L2_ReadAutoOB: Enter\n");

  tmp0 = XBYTE[0x211E];
  tmp1 = XBYTE[0x211F];

  *AutoOBPt = (tmp1<<8)|tmp0;

//  PRINT_CDSP("        L2_ReadAutoOB: AutoOB = %u\n", *AutoOBPt);

  // return
  PRINT_L2("        L2_ReadAutoOB: Exit\n");

  return;
}

//-----------------------------------------------------------------------------
//L2_ConfigSPW
//-----------------------------------------------------------------------------
/*
routine description:
  Define one of the special window (SPW).

arguments:
  RegNum: the region number of the special window to be configured (0 ~ 3).
  LumLThr: lumiance low threshold
  LumHThr: lumiance high threshold
  PSCLThr: Cb-Cr low threshold
  PSCHThr: Cb-Cr high threshold
  NSCLThr: Cb+Cr low threshold
  NSCHThr: Cb+Cr high threshold

return value:
  0x00   - success
  0x01   - general error
  0x02   - parameter error
  others - error
*/

UCHAR L2_ConfigSPW(UCHAR RegNum, UCHAR LumLThr, UCHAR LumHThr, UCHAR PSCLThr,
                   UCHAR PSCHThr, UCHAR NSCLThr, UCHAR NSCHThr) USING_0
{
  USHORT addr;
  UCHAR status;

  //body
  PRINT_L2("        L2_ConfigSPW: Enter\n");

  if(RegNum>4)
  {
    status = L2K_ERROR_PARAMETER;
  }
  else
  {
    status = L2K_SUCCESS;

    //luminance
    addr = 0x221B+RegNum;
    XBYTE[addr++] = LumLThr;
    XBYTE[addr] = LumHThr;

    //chrominance
    addr = 0x2220+RegNum*4;
    XBYTE[addr++] = PSCLThr;
    XBYTE[addr++] = PSCHThr;
    XBYTE[addr++] = NSCLThr;
    XBYTE[addr] = NSCHThr;
  }

  // return
  PRINT_L2("        L2_ConfigSPW: Exit\n");

  return(status);
}

//-----------------------------------------------------------------------------
//L2_ReadSPW
//-----------------------------------------------------------------------------
/*
routine description:
  Read the total number of the pixel that is in the defined special region.
  The average of the luminance, R-Y and B-Y are also be read.

arguments:
  RegNum: the region number of the special window to be configured (0 ~ 3).
  *NumSPWPt: the total number of pixel.
  *YAvgSPWPt: the average of luminace .
  *RYAvgSPWPt: the average of R-Y.
  *BYAvgSPWPt: the average of B-Y.

return value:
  0x00   - success
  0x01   - general error
  0x02   - parameter error
  others - error
*/

UCHAR L2_ReadSPW(UCHAR RegNum, PULONG NumSPWPt, PUCHAR YAvgSPWPt,
                PCHAR RYAvgSPWPt, PCHAR BYAvgSPWPt) USING_0
{
  USHORT addr;
  UCHAR tmp0, tmp1, tmp2, tmp3;
  ULONG ltmp0;
  ULONG YSumSPW;
  LONG  RYSumSPW, BYSumSPW;
  UCHAR status;

  //body
  PRINT_L2("        L2_ReadSPW: Enter\n");

  if(RegNum>4)
  {
    status = L2K_ERROR_PARAMETER;
  }
  else
  {
    status = L2K_SUCCESS;

    //pixel number
    addr = 0x2230+RegNum*16;
    tmp0 = XBYTE[addr++];
    tmp1 = XBYTE[addr++];
    tmp2 = XBYTE[addr++];

    *NumSPWPt = (ULONG)((USHORT)tmp2<<8|tmp1)<<8|tmp0;

    addr++;

    //average of luminance
    tmp0 = XBYTE[addr++];
    tmp1 = XBYTE[addr++];
    tmp2 = XBYTE[addr++];
    tmp3 = XBYTE[addr++];

    YSumSPW = ((ULONG)((USHORT)tmp3<<8|tmp2)<<8|tmp1)<<8|tmp0;

    if(*NumSPWPt==0) *YAvgSPWPt = 0;
    else             *YAvgSPWPt = YSumSPW / *NumSPWPt;

    //average of R-Y
    tmp0 = XBYTE[addr++];
    tmp1 = XBYTE[addr++];
    tmp2 = XBYTE[addr++];
    tmp3 = XBYTE[addr++];
    ltmp0 = ((ULONG)((USHORT)tmp3<<8|tmp2)<<8|tmp1)<<8|tmp0;

    if(tmp3<32) RYSumSPW = (LONG)ltmp0;
    else        RYSumSPW = (LONG)ltmp0-0x40000000;

    if(*NumSPWPt==0) *RYAvgSPWPt = 0;
    else             *RYAvgSPWPt = RYSumSPW / (LONG)*NumSPWPt;

    //sum of B-Y
    tmp0 = XBYTE[addr++];
    tmp1 = XBYTE[addr++];
    tmp2 = XBYTE[addr++];
    tmp3 = XBYTE[addr];
    ltmp0 = ((ULONG)((USHORT)tmp3<<8|tmp2)<<8|tmp1)<<8|tmp0;

    if(tmp3<32) BYSumSPW = (LONG)ltmp0;
    else        BYSumSPW = (LONG)ltmp0-0x40000000;

    if(*NumSPWPt==0) *BYAvgSPWPt = 0;
    else             *BYAvgSPWPt = BYSumSPW / (LONG)*NumSPWPt;

//    PRINT_CDSP("        L2_ReadSPW: RegNum = %bu, NumSPW = %lu\n", RegNum, *NumSPWPt);
//    PRINT_CDSP("        L2_ReadSPW: RegNum = %bu, YAvgSPW = %bu\n", RegNum, *YAvgSPWPt);
//    PRINT_CDSP("        L2_ReadSPW: RegNum = %bu, RYAvgSPW = %bd\n", RegNum, *RYAvgSPWPt);
//    PRINT_CDSP("        L2_ReadSPW: RegNum = %bu, BYAvgSPW = %bd\n", RegNum, *BYAvgSPWPt);
  }

  // return
  PRINT_L2("        L2_ReadSPW: Exit\n");

  return(status);
}

//-----------------------------------------------------------------------------
//L2_InitCDSP
//-----------------------------------------------------------------------------
/*
routine description:
  Initialize the CDSP module.

arguments:
  CamMode:
    	0: power-on mode initialization
        1: for preview mode initialization
        2: for still camera mode initialization (snap a still image)
        3: for video clip mode initialization
        4: for PC-camera mode initialization
        5: for playback mode initialization

return value:
  0x00   - success
  0x01   - general error
  0x02   - parameter error
  others - error
*/

UCHAR L2_InitCDSP(UCHAR CamMode) USING_0
{
  UCHAR status;

  status = L2K_SUCCESS;
  //body
  PRINT_L2("        L2_InitCDSP: Enter\n");

  switch(CamMode)
  {
    case 0:
    {

⌨️ 快捷键说明

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