read_sdram.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:10k
源码类别:

DVD

开发平台:

Others

  1. /* Include files */
  2. #include "Includesysdefs.h"
  3. #include "PlaycoreCaptureLogompeg_encenc.h"
  4. #include "PlaycoreCoremainCoreGDef.h"
  5. #ifdef SUPPORT_CAPTURE_LOGO
  6. // defines
  7. #define BANK1 0
  8. #define BANK2 1
  9. /* functions */
  10. void read_Y_pixels( unsigned char *buff, int line, int start_index, int num_of_pixs , int bank );
  11. unsigned long get_line_start_offset( int line , int start_index, int bank , int *pix_2_line_end);
  12. void read_C_pixels( unsigned char *buff, int line, int start_index , int num_of_pixs , int bank );
  13. void get_Y_pixels( unsigned char *buff , int line , int start_index , int num_of_pix);
  14. void get_C_pixels( unsigned char *buff , int line , int start_index , int num_of_pix);
  15. void read_Y_data( UINT16 *buff , unsigned long offset, int num_of_pixs );
  16. void read_C_data( UINT16 *buff , unsigned long offset, int num_of_pixs );
  17. BOOL write_2_sdram( unsigned short x);  
  18. /**********************************************************************************
  19.  Purpose          :  request to get pixels from Y buffer
  20.  Input Parameters :  buff - buffer to fill with data
  21.  line - line of picture
  22.  start_index - pixel index in line
  23.  num_of_pix - number of pixels to get
  24.  Return Value     :
  25.  Comment:   :
  26. **********************************************************************************/
  27. void get_Y_pixels( unsigned char *buff , int line , int start_index , int num_of_pix)
  28. {
  29. if( line % 2 == 0 )
  30. {
  31. // first bank
  32. line = line /2;
  33. read_Y_pixels( buff, line, start_index, num_of_pix, BANK1 );
  34. }
  35. else
  36. { // second bank
  37. line = (line - 1)/2;
  38. read_Y_pixels( buff, line, start_index, num_of_pix, BANK2 );
  39. }
  40. }
  41. /**********************************************************************************
  42.  Purpose          :  read pixels from Y buffer specific bank in SDRAM
  43.  Input Parameters :  buff - buffer to fill with data
  44.  line - line of picture
  45.  start_index - pixel index in line
  46.  num_of_pix - number of pixels to get
  47.  bank - which bank of SDRAM to read from 
  48.  Return Value     :
  49.  Comment:   :
  50. **********************************************************************************/
  51. void read_Y_pixels( unsigned char *buff, int line, int start_index , int num_of_pixs , int bank )
  52. {
  53. int pix_2_end;
  54. unsigned long start_line_offset =  get_line_start_offset( line, start_index, bank, &pix_2_end );
  55. if( pix_2_end >= num_of_pixs )
  56. {
  57. // enouph pixels in current bank line
  58. read_Y_data((UINT16*)buff, start_line_offset, num_of_pixs );
  59. }
  60. else
  61. {
  62. int left_2_read = num_of_pixs - pix_2_end;
  63. read_Y_data((UINT16*)buff, start_line_offset, pix_2_end );
  64. // start_line_offset =  get_line_start_offset( line+1, start_index, bank, &pix_2_end );
  65. start_line_offset =  get_line_start_offset( line, start_index + pix_2_end, bank, &pix_2_end );
  66. read_Y_data((UINT16*)buff, start_line_offset, left_2_read );
  67. }
  68. }
  69. /**********************************************************************************
  70.  Purpose          :  request to get pixels from C buffer
  71.  Input Parameters :  buff - buffer to fill with data
  72.  line - line of picture
  73.  start_index - pixel index in line
  74.  num_of_pix - number of pixels to get
  75.  Return Value     :
  76.  Comment:   :
  77. **********************************************************************************/
  78. void get_C_pixels( unsigned char *buff , int line , int start_index , int num_of_pix)
  79. {
  80. if( line % 2 == 0 )
  81. {
  82. // first bank
  83. line = line /2;
  84. read_C_pixels( buff, line, start_index, num_of_pix, BANK1 );
  85. }
  86. else
  87. { // second bank
  88. line = (line - 1)/2;
  89. read_C_pixels( buff, line, start_index, num_of_pix, BANK2 );
  90. }
  91. }
  92. /**********************************************************************************
  93.  Purpose          :  read pixels from C buffer specific bank in SDRAM
  94.  Input Parameters :  buff - buffer to fill with data
  95.  line - line of picture
  96.  start_index - pixel index in line
  97.  num_of_pix - number of pixels to get
  98.  bank - which bank of SDRAM to read from
  99.  Return Value     :
  100.  Comment:   :
  101. **********************************************************************************/
  102. void read_C_pixels( unsigned char *buff, int line, int start_index , int num_of_pixs , int bank )
  103. {
  104. int pix_2_end;
  105. unsigned long start_line_offset =  get_line_start_offset( line, start_index, bank, &pix_2_end );
  106. if( pix_2_end >= num_of_pixs )
  107. {
  108. // enouph pixels in current bank line
  109. read_C_data( (UINT16*)buff, start_line_offset , num_of_pixs );
  110. }
  111. else
  112. {
  113. int left_2_read = num_of_pixs - pix_2_end;
  114. read_C_data( (UINT16*)buff, start_line_offset , pix_2_end );
  115. // start_line_offset =  get_line_start_offset( line+1, start_index, bank, &pix_2_end );
  116. start_line_offset =  get_line_start_offset( line, start_index + pix_2_end, bank, &pix_2_end );
  117. read_C_data( (UINT16*)buff, start_line_offset , left_2_read );
  118. }
  119. }
  120. /**********************************************************************************
  121.  Purpose          : get the offset in SDRAM for the specif line and specifix pixel index
  122. of the picture
  123.  Input Parameters : line - the line of the picture
  124. start_index - the pixel index in the line of the picture
  125. bank - the bank used in SDRAM
  126. *pix_2_line_end - pointer to return number of pixel that left until
  127. the end of the line.
  128.  Return Value     : return the offset in SDRAM of the start line + pixel index 
  129.  Comment:   :
  130. **********************************************************************************/
  131. unsigned long get_line_start_offset( int line , int start_index , int bank , int *pix_2_line_end)
  132. {
  133. unsigned long h_size = pLogoCapture->Hsize;
  134. unsigned long sum_of_pix = h_size * line;
  135. unsigned long line_index = sum_of_pix / (256*2);
  136. unsigned long pixel_index = sum_of_pix % (256*2) ;
  137.    unsigned long pics2end;
  138. unsigned long left;
  139. pics2end =  (256*2) - pixel_index;
  140. if( pics2end > start_index )
  141. {
  142. pixel_index += start_index;
  143. pics2end =  (256*2) - pixel_index;
  144. }
  145. else
  146. {
  147. left = start_index - pics2end;
  148. line_index ++;
  149. if( left >= (256*2) )
  150. {
  151. line_index ++;
  152. left = left - (256*2) ;
  153. }
  154. pixel_index = left;
  155. pics2end =  (256*2) - left;
  156. }
  157. *pix_2_line_end = (int)pics2end;
  158. if( bank == BANK1 )
  159. {
  160. return ((line_index * (512UL*2)) + pixel_index);
  161. }
  162. else
  163. {
  164. return((line_index * (512UL*2)) + pixel_index + (256UL*2));
  165. }
  166. }
  167. /**********************************************************************************
  168.  Purpose          :  get MB data
  169.  Input Parameters :  mb - 
  170.    h_offset - 
  171.  v_offset - 
  172.  Output Parameters:
  173.  Return Value     :
  174.  Comment:   :
  175. **********************************************************************************/   
  176. int get_mb(short mb[6][8][8],int h_offset,int v_offset)
  177. {
  178. unsigned int block_index;
  179. unsigned int mb_line;
  180. unsigned int i, start_pix, start_line;
  181. unsigned char buffer[16];
  182. unsigned char str[20];
  183. if(pLogoCapture->Vsize<=288)
  184. {
  185. if( pLogoCapture->line != v_offset )
  186. {
  187. pLogoCapture->line = v_offset;
  188. //sprintf( str , "%d", v_offset );
  189. //ui_tmp_string(str);
  190. cl_inc_progress_bar();
  191. }
  192. else
  193. if(h_offset==pLogoCapture->Hsize/32)
  194. cl_inc_progress_bar();
  195. }
  196. else
  197. if( pLogoCapture->line != v_offset )
  198. {
  199. pLogoCapture->line = v_offset;
  200. //sprintf( str , "%d", v_offset );
  201. //ui_tmp_string(str);
  202. cl_inc_progress_bar();
  203. }
  204.    
  205.     h_offset = h_offset*16;
  206. v_offset = v_offset*16;
  207. // fill mb[0...3] - for Y
  208. for( block_index=0; block_index<4; block_index++)
  209. for( mb_line=0; mb_line<8; mb_line++)
  210. {
  211. if( mb_line %2 == 0 ) // even line
  212. pLogoCapture->TopFld = 1;
  213. else   // odd line
  214. pLogoCapture->TopFld = 0;
  215. if( block_index %2 == 0 ) //for block index 0 , 2
  216. start_pix = h_offset;
  217. else
  218. start_pix = h_offset+8;
  219. if( block_index < 2 ) // for block index 0 , 1
  220. start_line = v_offset/2 + mb_line/2;
  221. else
  222. start_line = v_offset/2 + (mb_line/2) + 4;
  223. if(pLogoCapture->bSingleField)
  224. {
  225. pLogoCapture->TopFld = 1;
  226. if( block_index < 2 ) // for block index 0 , 1
  227. start_line = v_offset + mb_line;
  228. else
  229. start_line = v_offset + mb_line + 8;
  230. }
  231. get_Y_pixels( buffer, start_line, start_pix , 8 );
  232. for(i=0; i<8;i++)
  233. mb[block_index][mb_line][i] = (short)(buffer[i]);
  234. }
  235. // fill mb[4,5] for UV
  236. for( mb_line=0; mb_line<8; mb_line++)
  237. {
  238. if( mb_line %2 == 0 ) // even line
  239. pLogoCapture->TopFld = 1;
  240. else   // odd line
  241. pLogoCapture->TopFld = 0;
  242. start_pix = h_offset;
  243. start_line = v_offset/4 + mb_line/2;
  244. if(pLogoCapture->bSingleField)
  245. {
  246. pLogoCapture->TopFld = 1;
  247. start_line = v_offset/2 + mb_line;
  248. }
  249. get_C_pixels( buffer, start_line, start_pix , 16 );
  250. for(i=0; i<16;i+=2)
  251. {
  252. mb[4][mb_line][i/2] = buffer[i];
  253. mb[5][mb_line][i/2] = buffer[i+1];
  254. }
  255. }
  256. //mikex debug
  257. if(g_disc_type==DEC_DISC_TYPE_DVD_VIDEO)
  258. for(block_index=0;block_index<4;block_index++)
  259. {
  260. for(mb_line=1;mb_line<7;mb_line+=2)
  261. for(i=0;i<8;i++)
  262. {
  263. mb[block_index][mb_line][i]=(mb[block_index][mb_line-1][i]+mb[block_index][mb_line+1][i])/2;
  264. }
  265. if( block_index %2 == 0 ) //for block index 0 , 2
  266. start_pix = h_offset;
  267. else
  268. start_pix = h_offset+8;
  269. if( block_index < 2 ) // for block index 0 , 1
  270. start_line = v_offset/2 + 4;
  271. else
  272. start_line = v_offset/2 + 8;
  273. if(pLogoCapture->bSingleField)
  274. {
  275. pLogoCapture->TopFld = 1;
  276. if( block_index < 2 ) // for block index 0 , 1
  277. start_line = v_offset + 8;
  278. else
  279. start_line = v_offset + 16;
  280. }
  281. pLogoCapture->TopFld = 1;
  282. if(start_line<pLogoCapture->Vsize/2)
  283. {
  284. get_Y_pixels( buffer, start_line, start_pix , 8 );
  285. for(i=0;i<8;i++)
  286. {
  287. mb[block_index][7][i]=(mb[block_index][6][i]+(short)(buffer[i]))/2;
  288. }
  289. }
  290. }
  291. //mikex debug
  292. return 1;
  293. }
  294. #endif