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

📄 l2_dram.c

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

        //body
        XBYTE[0x2880] = QTableIndex;
		XBYTE[0x2882] = 0x01;
        if(ChangeQ==1)
        {
         switch(QTableIndex)
          {
           case K_Q95:
              for (i = 0; i < 0x80; i++)
                XBYTE[0x2800 + i] = QTable95[i];
              break;
           case K_Q92:
              for (i = 0; i < 0x80; i++)
                XBYTE[0x2800 + i] = QTable92[i];
              break;
           case K_Q90:
              for (i = 0; i < 0x80; i++)
                XBYTE[0x2800 + i] = QTable90[i];
              break;
           case K_Q88:
              for (i = 0; i < 0x80; i++)
                XBYTE[0x2800 + i] = QTable88[i];
              break;
           case K_Q85:
              for (i = 0; i < 0x80; i++)
                XBYTE[0x2800 + i] = QTable85[i];
              break;
           case K_Q80:
              for (i = 0; i < 0x80; i++)
                XBYTE[0x2800 + i] = QTable80[i];
              break;
           case K_Q70:
              for (i = 0; i < 0x80; i++)
                XBYTE[0x2800 + i] = QTable70[i];
              break;
           case K_Q50:
              for (i = 0; i < 0x80; i++)
                XBYTE[0x2800 + i] = QTable50[i];
              break;
           case 0xf0:
              for (i = 0; i < 0x80; i++)
                XBYTE[0x2800 + i] = QTable[i];
              break;
           case 0xf1:
              for (i = 0; i < 64; i++)
                  {
                   j = zigzagTable[i];
                   XBYTE[0x2800 + j] = QTable[i];
                  }
              for (i = 64; i < 128; i++)
                  {
                   j = zigzagTable[i-64];
                   XBYTE[0x2840 + j] = QTable[i];
                  }
              break;
           default:
              break;
          }
        }

        if(QTableIndex==K_Q1)
           XBYTE[0x2881]=0x01;
        else
           XBYTE[0x2881]=0x00;

        XBYTE[0x2882] = 0x00;
        //return
        return(status);
}

//-----------------------------------------------------------------------------
//L2_ReadQTable
//-----------------------------------------------------------------------------
/*
routine description:
                Fill the Q table
arguments:
                GetArray    - 0: only read the quantizatin table index
                              1: read the quantizatin table index and array in raster scan
                              2: read the quantizatin table index and array in zigzag scan
                QTableIndex - The quantization table index
                QTable      - The quantization table array in raster scan sequence
return value:
                0x00          - success
                others        - error
*/

UCHAR L2_ReadQTable(UCHAR GetArray, UCHAR *QTableIndex, UCHAR *QTable) USING_0
{
        UCHAR status = L2K_SUCCESS;
        UCHAR i;
                UCHAR j;

        //body
        *QTableIndex=XBYTE[0x2880];
        XBYTE[0x2882] = 0x01;

        if(GetArray)
		  {
           if(GetArray == 1)
             {
              for(i=0;i<128;i++)
                  QTable[i]=XBYTE[0x2800+i];
             }
           else
             {
              for(i=0;i<64;i++)
                 {
                  j = zigzagTable[i];
                  QTable[i]=XBYTE[0x2800+j];
                 }
              for(i=64;i<128;i++)
                 {
                  j = zigzagTable[i-64];
                  QTable[i]=XBYTE[0x2840+j];
                 }
              }
          }
        XBYTE[0x2882] = 0x00;
        //return
        return(status);
}

//-----------------------------------------------------------------------------
//L2_Compress
//-----------------------------------------------------------------------------
/*
routine description:
                Compress an image that already resides in the SDRAM
arguments:
                Camode            - Camera operation mode
                SrcAddr           - Image starting address
                SrcHsize          - Image width
                SrcVsize          - Image height
                VLCAddr           - The address to write the VLC stream to
                DCTDCAddr         - The address to store the DCT DC value to
                Option bit[1:0] 0 - YUV422
                                1 - YUV420
                                2 - Black/White
                       bit[2]     - JPEG rotation function is turned on if set to 1
                       bit[3]   0 - rotate clockwise
                                1 - rotate counterclockwise
                       bit[4]     - JFIF compatible VLC data is generated if set to 1
                       bit[5]     - DCT DC value is generated if set to 1
return value:
                0x00              - success
                others            - error
*/
UCHAR L2_Compress(UCHAR CamMode, ULONG SrcAddr, USHORT SrcHsize, USHORT SrcVsize,
                  ULONG VLCAddr, ULONG DCTDCAddr, UCHAR Option) USING_0
{
        UCHAR status = L2K_SUCCESS;
        UCHAR error;
        UCHAR imgtype, jpgroten, clockwise, jfif, dctdcen;
        UCHAR compdone;

        //body
        imgtype   = Option&0x03;
        jpgroten  = (Option>>2)&0x01;
        clockwise = (Option>>3)&0x01;
        jfif      = (Option>>4)&0x01;
        dctdcen   = (Option>>5)&0x01;



        if(CamMode!=0x02) XBYTE[0x2883]=0x00;         //disable the thumbnail(DCT DC value)

        error = L2_SetAFBAddr(SrcAddr);               //set image starting address to AFR

        if(jpgroten==1) error = L2_SetAFBSize(SrcVsize, SrcHsize);
        else            error = L2_SetAFBSize(SrcHsize, SrcVsize);

        if(jpgroten==1)
         {
          if(clockwise==0) XBYTE[0x2786]=0x02;
          else             XBYTE[0x2786]=0x03;
         }

        XBYTE[0x274a] = 0x00;                         //set jpgsrcidx to AFB

        XBYTE[0x2730] = (UCHAR)(VLCAddr)&0xff;        //set VLCStart[7:0]
        XBYTE[0x2731] = (UCHAR)(VLCAddr>>8)&0xff;     //set VLCStart[15:8]
        XBYTE[0x2732] = (UCHAR)(VLCAddr>>16)&0xff;    //set VLCStart[23:16]

        if(imgtype==0)      XBYTE[0x270e]=0x02;       //set to YUV422
        else if(imgtype==1) XBYTE[0x270e]=0x05;       //set to YUV420

        if(jfif==1) XBYTE[0x2884]=0x01;               //set JFIF compatible format
        else        XBYTE[0x2884]=0x00;


        if(dctdcen==1)                                //set collect DCT DC value
          {
           XBYTE[0x2883]=1;
           XBYTE[0x2736]=(UCHAR)(DCTDCAddr)&0xff;
           XBYTE[0x2737]=(UCHAR)(DCTDCAddr>>8)&0xff;
           XBYTE[0x2738]=(UCHAR)(DCTDCAddr>>16)&0xff;
          }
        else
        {
          XBYTE[0x2883]=0;
        }

        //PRINT_L2("            L2_Compress: start to compress....\n");
        XBYTE[0x2000]=0x00;
        XBYTE[0x2000]=0x02;                           //set CamMode to DSC
        XBYTE[0x27a1]=0x01;                           //trigger compress action
        compdone=0x00;
        do                                            //wait till compress done
        {
         compdone=XBYTE[0x27b0]&0x20;
        }while(compdone==0x00);

        //PRINT_L2("            L2_Compress: compress done....\n");

        //return
        return(status);
}

//-----------------------------------------------------------------------------
//L2_DeCompress
//-----------------------------------------------------------------------------
/*
routine description:
                Decompress a VLC stream that already resides in the SDRAM
arguments:
                SrcAddr   - VLC stream starting address
                SrcHsize  - Image width
                SrcVsize  - Image height
                DstAddr   - The address to write the decompressed image to
                PbRescalSize - JPEG decompress rescale factor
                           0 -
                           1 -
                           2 -
                           3 -
                           4 -
                           5 -
                           6 -
                           7 -
                Option bit[1:0] 0 - YUV422
                                1 - YUV420
                                2 - Black/White
                       bit[2]     - JFIF compatible VLC data
                       bit[3]   0 - not exit this function till decompress done
                                1 - hit and run
                MCURstNo : If the VLC stream include MCU restart code, fill the restart MCU number
				           (MCU number shows after JFIF marker "FFDD")
						   Notice : MCU restart code decompression works when MCURstNo > 0
						            and Option[2] is turn on (JFIF compatibl VLC data)
return value:
                0x00          - success
                others        - error
*/
UCHAR L2_DeCompress(ULONG SrcAddr, USHORT SrcHsize, USHORT SrcVsize,
                    ULONG DstAddr, UCHAR PbRescalSize, UCHAR Option, USHORT MCURstNo) USING_0
{
        UCHAR status = L2K_SUCCESS;
        UCHAR error, imgtype, jfif, hitrun;
        UCHAR decompdone;

        //body
        imgtype   = Option&0x03;
        jfif      = (Option>>2)&0x01;
        hitrun    = (Option>>3)&0x01;

        XBYTE[0x2730] = (UCHAR)(SrcAddr)&0xff;        //set VLCStart[7:0]
        XBYTE[0x2731] = (UCHAR)(SrcAddr>>8)&0xff;     //set VLCStart[15:8]
        XBYTE[0x2732] = (UCHAR)(SrcAddr>>16)&0xff;    //set VLCStart[23:16]

        error = L2_SetAFBAddr(DstAddr);               //set decompress to AFR
        error = L2_SetAFBSize(SrcHsize, SrcVsize);    //set width and height

        XBYTE[0x2720] = 0xff;                         //set VLCsize to maximum
        XBYTE[0x2721] = 0xff;                         //set VLCsize to maximum
        XBYTE[0x2722] = 0xff;                         //set VLCsize to maximum

        switch(PbRescalSize)
         {
          case 1:  XBYTE[0x2745]=0x01;
                   break;
          case 2:  XBYTE[0x2745]=0x02;
                   break;
          case 3:  XBYTE[0x2745]=0x03;
                   break;
          case 4:  XBYTE[0x2745]=0x04;
                   break;
          case 5:  XBYTE[0x2745]=0x05;
                   break;
          case 6:  XBYTE[0x2745]=0x06;
                   break;
          case 7:  XBYTE[0x2745]=0x07;
                   break;
          default: XBYTE[0x2745]=0x00;
                   break;
         }

        if(imgtype==0x00)      XBYTE[0x270e]=0x02;    //set to YUV422
        else if(imgtype==0x01) XBYTE[0x270e]=0x05;    //set to YUV420

        if(jfif==1) XBYTE[0x2884]=0x01;               //set JFIF compatible format
        else        XBYTE[0x2884]=0x00;

		if(jfif==1 && MCURstNo !=0)
		  {
		  XBYTE[0x2888] = (UCHAR)MCURstNo;
		  XBYTE[0x2889] = (UCHAR)(MCURstNo>>8);
          }
   	    else
		  {
		  XBYTE[0x2888] = 0;
		  XBYTE[0x2889] = 0;
		  }

        //PRINT_L2("            L2_DeCompress: start to decompress....\n");
        XBYTE[0x2000]=0x00;
        XBYTE[0x2000]=0x05;                           //set cammode to playback
        XBYTE[0x27a1]=0x02;                           //trigger decompress action
        if(hitrun==0)
         {
          do                                          //wait till decompress done
          {
           decompdone=XBYTE[0x27b0]&0x40;
          }while(decompdone==0x00);
          //PRINT_L2("            L2_DeCompress: decompress done....\n");
         }
        else
        {
          //PRINT_L2("            L2_DeCompress: exit the L2_DeCompress....\n");
        }

        //return
        return(status);
}


//-----------------------------------------------------------------------------
//L2_ReadCompSize
//-----------------------------------------------------------------------------
/*
routine description:
                Read the compression size
arguments:
                Compsize - Compression size
return value:
                0x00     - success
                others   - error
*/
UCHAR L2_ReadCompSize(ULONG *Compsize) USING_0
{
        UCHAR status = L2K_SUCCESS;

        //body
         *Compsize=(((ULONG)XBYTE[0x2722])<<16)|(((ULONG)XBYTE[0x2721])<<8)|((ULONG)XBYTE[0x2720]);

        //return
        return(status);
}

//-----------------------------------------------------------------------------
//L2_CheckDecompress

⌨️ 快捷键说明

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