read_sdram.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:10k
- /* Include files */
- #include "Includesysdefs.h"
- #include "PlaycoreCaptureLogompeg_encenc.h"
- #include "PlaycoreCoremainCoreGDef.h"
- #ifdef SUPPORT_CAPTURE_LOGO
- // defines
- #define BANK1 0
- #define BANK2 1
- /* functions */
- void read_Y_pixels( unsigned char *buff, int line, int start_index, int num_of_pixs , int bank );
- unsigned long get_line_start_offset( int line , int start_index, int bank , int *pix_2_line_end);
- void read_C_pixels( unsigned char *buff, int line, int start_index , int num_of_pixs , int bank );
- void get_Y_pixels( unsigned char *buff , int line , int start_index , int num_of_pix);
- void get_C_pixels( unsigned char *buff , int line , int start_index , int num_of_pix);
- void read_Y_data( UINT16 *buff , unsigned long offset, int num_of_pixs );
- void read_C_data( UINT16 *buff , unsigned long offset, int num_of_pixs );
- BOOL write_2_sdram( unsigned short x);
- /**********************************************************************************
- Purpose : request to get pixels from Y buffer
- Input Parameters : buff - buffer to fill with data
- line - line of picture
- start_index - pixel index in line
- num_of_pix - number of pixels to get
- Return Value :
- Comment: :
- **********************************************************************************/
- void get_Y_pixels( unsigned char *buff , int line , int start_index , int num_of_pix)
- {
-
- if( line % 2 == 0 )
- {
- // first bank
- line = line /2;
- read_Y_pixels( buff, line, start_index, num_of_pix, BANK1 );
- }
- else
- { // second bank
- line = (line - 1)/2;
- read_Y_pixels( buff, line, start_index, num_of_pix, BANK2 );
- }
- }
- /**********************************************************************************
- Purpose : read pixels from Y buffer specific bank in SDRAM
- Input Parameters : buff - buffer to fill with data
- line - line of picture
- start_index - pixel index in line
- num_of_pix - number of pixels to get
- bank - which bank of SDRAM to read from
- Return Value :
- Comment: :
- **********************************************************************************/
- void read_Y_pixels( unsigned char *buff, int line, int start_index , int num_of_pixs , int bank )
- {
- int pix_2_end;
- unsigned long start_line_offset = get_line_start_offset( line, start_index, bank, &pix_2_end );
- if( pix_2_end >= num_of_pixs )
- {
- // enouph pixels in current bank line
- read_Y_data((UINT16*)buff, start_line_offset, num_of_pixs );
- }
- else
- {
- int left_2_read = num_of_pixs - pix_2_end;
- read_Y_data((UINT16*)buff, start_line_offset, pix_2_end );
- // start_line_offset = get_line_start_offset( line+1, start_index, bank, &pix_2_end );
- start_line_offset = get_line_start_offset( line, start_index + pix_2_end, bank, &pix_2_end );
- read_Y_data((UINT16*)buff, start_line_offset, left_2_read );
- }
- }
- /**********************************************************************************
- Purpose : request to get pixels from C buffer
- Input Parameters : buff - buffer to fill with data
- line - line of picture
- start_index - pixel index in line
- num_of_pix - number of pixels to get
- Return Value :
- Comment: :
- **********************************************************************************/
- void get_C_pixels( unsigned char *buff , int line , int start_index , int num_of_pix)
- {
- if( line % 2 == 0 )
- {
- // first bank
- line = line /2;
- read_C_pixels( buff, line, start_index, num_of_pix, BANK1 );
- }
- else
- { // second bank
- line = (line - 1)/2;
- read_C_pixels( buff, line, start_index, num_of_pix, BANK2 );
- }
- }
- /**********************************************************************************
- Purpose : read pixels from C buffer specific bank in SDRAM
- Input Parameters : buff - buffer to fill with data
- line - line of picture
- start_index - pixel index in line
- num_of_pix - number of pixels to get
- bank - which bank of SDRAM to read from
- Return Value :
- Comment: :
- **********************************************************************************/
- void read_C_pixels( unsigned char *buff, int line, int start_index , int num_of_pixs , int bank )
- {
- int pix_2_end;
- unsigned long start_line_offset = get_line_start_offset( line, start_index, bank, &pix_2_end );
- if( pix_2_end >= num_of_pixs )
- {
- // enouph pixels in current bank line
- read_C_data( (UINT16*)buff, start_line_offset , num_of_pixs );
- }
- else
- {
- int left_2_read = num_of_pixs - pix_2_end;
- read_C_data( (UINT16*)buff, start_line_offset , pix_2_end );
- // start_line_offset = get_line_start_offset( line+1, start_index, bank, &pix_2_end );
- start_line_offset = get_line_start_offset( line, start_index + pix_2_end, bank, &pix_2_end );
- read_C_data( (UINT16*)buff, start_line_offset , left_2_read );
- }
- }
- /**********************************************************************************
- Purpose : get the offset in SDRAM for the specif line and specifix pixel index
- of the picture
- Input Parameters : line - the line of the picture
- start_index - the pixel index in the line of the picture
- bank - the bank used in SDRAM
- *pix_2_line_end - pointer to return number of pixel that left until
- the end of the line.
- Return Value : return the offset in SDRAM of the start line + pixel index
- Comment: :
- **********************************************************************************/
- unsigned long get_line_start_offset( int line , int start_index , int bank , int *pix_2_line_end)
- {
- unsigned long h_size = pLogoCapture->Hsize;
- unsigned long sum_of_pix = h_size * line;
- unsigned long line_index = sum_of_pix / (256*2);
- unsigned long pixel_index = sum_of_pix % (256*2) ;
- unsigned long pics2end;
- unsigned long left;
- pics2end = (256*2) - pixel_index;
- if( pics2end > start_index )
- {
- pixel_index += start_index;
- pics2end = (256*2) - pixel_index;
- }
- else
- {
- left = start_index - pics2end;
- line_index ++;
- if( left >= (256*2) )
- {
- line_index ++;
- left = left - (256*2) ;
- }
- pixel_index = left;
- pics2end = (256*2) - left;
- }
- *pix_2_line_end = (int)pics2end;
- if( bank == BANK1 )
- {
- return ((line_index * (512UL*2)) + pixel_index);
- }
- else
- {
- return((line_index * (512UL*2)) + pixel_index + (256UL*2));
- }
- }
- /**********************************************************************************
- Purpose : get MB data
- Input Parameters : mb -
- h_offset -
- v_offset -
- Output Parameters:
- Return Value :
- Comment: :
- **********************************************************************************/
- int get_mb(short mb[6][8][8],int h_offset,int v_offset)
- {
- unsigned int block_index;
- unsigned int mb_line;
- unsigned int i, start_pix, start_line;
- unsigned char buffer[16];
- unsigned char str[20];
- if(pLogoCapture->Vsize<=288)
- {
- if( pLogoCapture->line != v_offset )
- {
- pLogoCapture->line = v_offset;
- //sprintf( str , "%d", v_offset );
- //ui_tmp_string(str);
- cl_inc_progress_bar();
- }
- else
- if(h_offset==pLogoCapture->Hsize/32)
- cl_inc_progress_bar();
- }
- else
- if( pLogoCapture->line != v_offset )
- {
- pLogoCapture->line = v_offset;
- //sprintf( str , "%d", v_offset );
- //ui_tmp_string(str);
- cl_inc_progress_bar();
- }
-
- h_offset = h_offset*16;
- v_offset = v_offset*16;
- // fill mb[0...3] - for Y
- for( block_index=0; block_index<4; block_index++)
- for( mb_line=0; mb_line<8; mb_line++)
- {
- if( mb_line %2 == 0 ) // even line
- pLogoCapture->TopFld = 1;
- else // odd line
- pLogoCapture->TopFld = 0;
- if( block_index %2 == 0 ) //for block index 0 , 2
- start_pix = h_offset;
- else
- start_pix = h_offset+8;
- if( block_index < 2 ) // for block index 0 , 1
- start_line = v_offset/2 + mb_line/2;
- else
- start_line = v_offset/2 + (mb_line/2) + 4;
- if(pLogoCapture->bSingleField)
- {
- pLogoCapture->TopFld = 1;
- if( block_index < 2 ) // for block index 0 , 1
- start_line = v_offset + mb_line;
- else
- start_line = v_offset + mb_line + 8;
- }
- get_Y_pixels( buffer, start_line, start_pix , 8 );
- for(i=0; i<8;i++)
- mb[block_index][mb_line][i] = (short)(buffer[i]);
- }
- // fill mb[4,5] for UV
- for( mb_line=0; mb_line<8; mb_line++)
- {
- if( mb_line %2 == 0 ) // even line
- pLogoCapture->TopFld = 1;
- else // odd line
- pLogoCapture->TopFld = 0;
- start_pix = h_offset;
- start_line = v_offset/4 + mb_line/2;
- if(pLogoCapture->bSingleField)
- {
- pLogoCapture->TopFld = 1;
- start_line = v_offset/2 + mb_line;
- }
- get_C_pixels( buffer, start_line, start_pix , 16 );
- for(i=0; i<16;i+=2)
- {
- mb[4][mb_line][i/2] = buffer[i];
- mb[5][mb_line][i/2] = buffer[i+1];
- }
- }
- //mikex debug
- if(g_disc_type==DEC_DISC_TYPE_DVD_VIDEO)
- for(block_index=0;block_index<4;block_index++)
- {
- for(mb_line=1;mb_line<7;mb_line+=2)
- for(i=0;i<8;i++)
- {
- mb[block_index][mb_line][i]=(mb[block_index][mb_line-1][i]+mb[block_index][mb_line+1][i])/2;
- }
- if( block_index %2 == 0 ) //for block index 0 , 2
- start_pix = h_offset;
- else
- start_pix = h_offset+8;
- if( block_index < 2 ) // for block index 0 , 1
- start_line = v_offset/2 + 4;
- else
- start_line = v_offset/2 + 8;
- if(pLogoCapture->bSingleField)
- {
- pLogoCapture->TopFld = 1;
- if( block_index < 2 ) // for block index 0 , 1
- start_line = v_offset + 8;
- else
- start_line = v_offset + 16;
- }
- pLogoCapture->TopFld = 1;
- if(start_line<pLogoCapture->Vsize/2)
- {
- get_Y_pixels( buffer, start_line, start_pix , 8 );
- for(i=0;i<8;i++)
- {
- mb[block_index][7][i]=(mb[block_index][6][i]+(short)(buffer[i]))/2;
- }
- }
- }
- //mikex debug
- return 1;
- }
- #endif