source: svn/trunk/newcon3bcm2_21bu/dta/src/dcc/bapp_eia708.c @ 2

Last change on this file since 2 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 48.6 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2006, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile:  $
11 * $brcm_Revision:  $
12 * $brcm_Date: $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log:  $
19 *
20 ***************************************************************************/
21#include "bapp_eia708.h"
22#include "bapp.h"
23#include "bapp_palette.h"
24#include "bos_task_priorities.h"
25#include "bdcc.h"
26#include "bccwinlib.h"
27#include "genericlist.h"
28#include "bdccengine.h"
29//#define CONFIG_OLD_PARSER
30#ifdef CONFIG_OLD_PARSER
31#include "bcmDccTransport.h"
32#include "bcmDccTransportParse.h"
33#endif
34BDBG_MODULE(eia708);
35
36#define NUM_CC_BUF                      512
37#define CC_BUF_SIZE                     (60 * 4)
38#define MAX_TRIPLETS            (0x1f * 3)
39
40/* Number of EIA708 fonts */
41#ifdef  NEW_FONT_SET
42#define NUM_EIA_708_FONTS                               7
43#else
44#define NUM_EIA_708_FONTS                               6
45#endif
46#define EIA708_ENABLE_TIMEOUT           (g_ticks_per_second * 2)
47#define EIA708_THREAD_STACK_SIZE                512             /* changed from 1024 */
48/*
49 * Main data structure containing references to all interfaces
50 * required throughout the application.
51 */
52
53#ifdef CONFIG_8BIT_FONT
54#ifdef NEW_FONT_SET
55extern const unsigned int g_cinecavB_type_03_16_aa[];
56extern const unsigned int g_cinecavB_type_03_16_aa_size;
57extern const unsigned int g_cinecavB_type_03_18_aa[];
58extern const unsigned int g_cinecavB_type_03_18_aa_size;
59extern const unsigned int g_cinecavB_type_03_20_aa[];
60extern const unsigned int g_cinecavB_type_03_20_aa_size;
61extern const unsigned int g_cinecavB_serif_02_16_aa[];
62extern const unsigned int g_cinecavB_serif_02_16_aa_size;
63extern const unsigned int g_cinecavB_serif_02_18_aa[];
64extern const unsigned int g_cinecavB_serif_02_18_aa_size;
65extern const unsigned int g_cinecavB_serif_02_20_aa[];
66extern const unsigned int g_cinecavB_serif_02_20_aa_size;
67extern const unsigned int g_cinecavB_mono_03_16_aa[];
68extern const unsigned int g_cinecavB_mono_03_16_aa_size;
69extern const unsigned int g_cinecavB_mono_03_18_aa[];
70extern const unsigned int g_cinecavB_mono_03_18_aa_size;
71extern const unsigned int g_cinecavB_mono_03_20_aa[];
72extern const unsigned int g_cinecavB_mono_03_20_aa_size;
73extern const unsigned int g_cinecavB_sans_02_16_aa[];
74extern const unsigned int g_cinecavB_sans_02_16_aa_size;
75extern const unsigned int g_cinecavB_sans_02_18_aa[];
76extern const unsigned int g_cinecavB_sans_02_18_aa_size;
77extern const unsigned int g_cinecavB_sans_02_20_aa[];
78extern const unsigned int g_cinecavB_sans_02_20_aa_size;
79extern const unsigned int g_cinecavB_casual_02_16_aa[];
80extern const unsigned int g_cinecavB_casual_02_16_aa_size;
81extern const unsigned int g_cinecavB_casual_02_18_aa[];
82extern const unsigned int g_cinecavB_casual_02_18_aa_size;
83extern const unsigned int g_cinecavB_casual_02_20_aa[];
84extern const unsigned int g_cinecavB_casual_02_20_aa_size;
85extern const unsigned int g_cinecavB_script_02_16_aa[];
86extern const unsigned int g_cinecavB_script_02_16_aa_size;
87extern const unsigned int g_cinecavB_script_02_18_aa[];
88extern const unsigned int g_cinecavB_script_02_18_aa_size;
89extern const unsigned int g_cinecavB_script_02_20_aa[];
90extern const unsigned int g_cinecavB_script_02_20_aa_size;
91extern const unsigned int g_cinecavB_sc_02_16_aa[];
92extern const unsigned int g_cinecavB_sc_02_16_aa_size;
93extern const unsigned int g_cinecavB_sc_02_18_aa[];
94extern const unsigned int g_cinecavB_sc_02_18_aa_size;
95extern const unsigned int g_cinecavB_sc_02_20_aa[];
96extern const unsigned int g_cinecavB_sc_02_20_aa_size;
97#else
98extern const unsigned char g_SFM_20_aa[]; 
99extern const unsigned int g_SFM_20_aa_size;
100extern const unsigned char g_SFP_20_aa[]; 
101extern const unsigned int g_SFP_20_aa_size;
102extern const unsigned char g_SFM_24_aa[]; 
103extern const unsigned int g_SFM_24_aa_size;
104extern const unsigned char g_SFP_24_aa[]; 
105extern const unsigned int g_SFP_24_aa_size;
106extern const unsigned char g_SSM_20_aa[]; 
107extern const unsigned int g_SSM_20_aa_size;
108extern const unsigned char g_SSP_20_aa[]; 
109extern const unsigned int g_SSP_20_aa_size;
110extern const unsigned char g_SSM_24_aa[]; 
111extern const unsigned int g_SSM_24_aa_size;
112extern const unsigned char g_SSP_24_aa[]; 
113extern const unsigned int g_SSP_24_aa_size;
114extern const unsigned char g_SCRIPT_20_aa[]; 
115extern const unsigned int g_SCRIPT_20_aa_size;
116extern const unsigned char g_SCRIPT_24_aa[]; 
117extern const unsigned int g_SCRIPT_24_aa_size;
118extern const unsigned char g_SC_20_aa[]; 
119extern const unsigned int g_SC_20_aa_size;
120extern const unsigned char g_SC_24_aa[]; 
121extern const unsigned int g_SC_24_aa_size;
122#endif
123#else
124#ifdef NEW_FONT_SET
125extern const unsigned int g_cinecavB_type_03_16_mono[];
126extern const unsigned int g_cinecavB_type_03_16_mono_size;
127extern const unsigned int g_cinecavB_type_03_20_mono[];
128extern const unsigned int g_cinecavB_type_03_20_mono_size;
129extern const unsigned int g_cinecavB_serif_02_16_mono[];
130extern const unsigned int g_cinecavB_serif_02_16_mono_size;
131extern const unsigned int g_cinecavB_serif_02_20_mono[];
132extern const unsigned int g_cinecavB_serif_02_20_mono_size;
133extern const unsigned int g_cinecavB_mono_03_16_mono[];
134extern const unsigned int g_cinecavB_mono_03_16_mono_size;
135extern const unsigned int g_cinecavB_mono_03_20_mono[];
136extern const unsigned int g_cinecavB_mono_03_20_mono_size;
137extern const unsigned int g_cinecavB_sans_02_16_mono[];
138extern const unsigned int g_cinecavB_sans_02_16_mono_size;
139extern const unsigned int g_cinecavB_sans_02_20_mono[];
140extern const unsigned int g_cinecavB_sans_02_20_mono_size;
141extern const unsigned int g_cinecavB_casual_02_16_mono[];
142extern const unsigned int g_cinecavB_casual_02_16_mono_size;
143extern const unsigned int g_cinecavB_casual_02_20_mono[];
144extern const unsigned int g_cinecavB_casual_02_20_mono_size;
145extern const unsigned int g_cinecavB_script_02_16_mono[];
146extern const unsigned int g_cinecavB_script_02_16_mono_size;
147extern const unsigned int g_cinecavB_script_02_20_mono[];
148extern const unsigned int g_cinecavB_script_02_20_mono_size;
149extern const unsigned int g_cinecavB_sc_02_16_mono[];
150extern const unsigned int g_cinecavB_sc_02_16_mono_size;
151extern const unsigned int g_cinecavB_sc_02_20_mono[];
152extern const unsigned int g_cinecavB_sc_02_20_mono_size;
153#else
154extern const unsigned char g_SFM_20_mono[]; 
155extern const unsigned int g_SFM_20_mono_size;
156extern const unsigned char g_SFP_24_mono[]; 
157extern const unsigned int g_SFP_24_mono_size;
158extern const unsigned char g_SFM_24_mono[]; 
159extern const unsigned int g_SFM_24_mono_size;
160extern const unsigned char g_SFP_28_mono[]; 
161extern const unsigned int g_SFP_28_mono_size;
162extern const unsigned char g_SSM_20_mono[]; 
163extern const unsigned int g_SSM_20_mono_size;
164extern const unsigned char g_SSP_24_mono[]; 
165extern const unsigned int g_SSP_24_mono_size;
166extern const unsigned char g_SSM_24_mono[]; 
167extern const unsigned int g_SSM_24_mono_size;
168extern const unsigned char g_SSP_28_mono[]; 
169extern const unsigned int g_SSP_28_mono_size;
170extern const unsigned char g_SCRIPT_20_mono[]; 
171extern const unsigned int g_SCRIPT_20_mono_size;
172extern const unsigned char g_SCRIPT_24_mono[]; 
173extern const unsigned int g_SCRIPT_24_mono_size;
174extern const unsigned char g_SC_20_mono[]; 
175extern const unsigned int g_SC_20_mono_size;
176extern const unsigned char g_SC_24_mono[]; 
177extern const unsigned int g_SC_24_mono_size;
178#endif
179#endif
180
181typedef struct cc_buf_t
182{
183        LINKS_T         links;
184        unsigned int    size;
185        unsigned char   buf[CC_BUF_SIZE];
186}cc_buf_t;
187
188
189typedef struct triplets_t
190{
191        unsigned char data_0;
192        unsigned char data_1;
193        unsigned char data_2;
194}triplets_t;
195
196/* cache font size information instead of computing it each time */
197typedef struct font_size_info_t
198{
199        unsigned int    width;
200        unsigned int    height;
201} font_size_info_t;
202
203struct bapp_eia708
204{
205        bapp_t                          *p_app;
206        bool                            done;
207        bool                            enabled;
208        int                             i608_CcService;
209        int                             i708_CcService;
210        b_task_t                        thread;
211        unsigned int            *thread_stack;
212        b_mutex_t               mutex;
213#ifdef NEW_FONT_SET
214        BCCGFX_WINLIB_P_Font hFont[NUM_EIA_708_FONTS][eFONT_SIZE_MAX];
215    bgfx_font_t                 fonts[NUM_EIA_708_FONTS][eFONT_SIZE_MAX];
216#else
217        BCCGFX_WINLIB_P_Font hFont[NUM_EIA_708_FONTS][eFONT_SIZE_MAX - 1];
218    bgfx_font_t                 fonts[NUM_EIA_708_FONTS][eFONT_SIZE_MAX - 1];
219#endif
220        BDCC_ENG_Handle                 hCC708Engine ;
221        BDCC_ENG_Settings               stEngineSettings ;
222        BCCGFX_WINLIB_P_Handle  hWinLibHandle;
223        BDCC_ENG_Type                   type;
224#ifdef CONFIG_OLD_PARSER
225        DCC_TRANSPORT_OBJECT    pTransport;
226        DCC_OUTBUF_INFO                 CCBufInfo;
227        DCC_OUTBUF_INFO                 DTVCCBufInfo;
228#else
229        unsigned char                   triplets[MAX_TRIPLETS];
230#endif
231        LIST_T                                  cc_list; 
232        LIST_T                                  free_cc_list;
233        cc_buf_t                                cc_buf[NUM_CC_BUF];
234        bool                                    mode_change;
235#ifdef NEW_FONT_SET
236        font_size_info_t                font_cell_info[NUM_EIA_708_FONTS][eFONT_SIZE_MAX];
237#else
238        font_size_info_t                font_cell_info[NUM_EIA_708_FONTS][eFONT_SIZE_MAX - 1];
239#endif
240}bapp_eia708;
241
242bapp_eia708_t s_p_eia708 = NULL;
243
244static void bapp_eia708_thread(void *data);
245
246BCCGFX_WINLIB_P_ErrCode BCCGFX_WINLIB_P_Init(
247        BCCGFX_WINLIB_P_Handle *phWinLibHandle, 
248        bgfx_surf_t *p_osd_surf,
249        bccgfx_update_cb_t updateCB,
250        bccgfx_get_wide_aspect_ratio_cb_t wide_aspect_ratio_cb,
251        void *p_app);
252
253/*
254Summary:
255        Estimate the font size
256*/
257
258int bapp_eia708_font_size(bgfx_font_t *p_font)
259{
260        unsigned int uni_str[8];
261        int slen,width,height;
262        slen = c_to_uni_str("WpghjMQ",uni_str,7);
263        bgfx_string_info(p_font,(const unsigned long *)uni_str,slen,&width,&height);
264        BDBG_MSG(("%s (%d)\n",__FUNCTION__, width,height));
265        return height;
266}
267
268/*
269 * Summary:
270 *     get cached font information
271 */
272void bapp_eia708_get_cell_info(bgfx_font_t *p_font,int *width, int *height)
273{
274        int fidx,sidx;
275
276        BAPP_ASSERT(p_font);
277        for (fidx = 0; fidx < NUM_EIA_708_FONTS; ++fidx)
278        {
279#ifdef NEW_FONT_SET
280                for (sidx = 0; sidx < eFONT_SIZE_MAX; ++sidx)
281#else
282                for (sidx = 0; sidx < (eFONT_SIZE_MAX - 1); ++sidx)
283#endif
284                {
285                        if (&(s_p_eia708->fonts[fidx][sidx]) && (p_font == &(s_p_eia708->fonts[fidx][sidx]))) {
286                                /* found it */
287                                *width = s_p_eia708->font_cell_info[fidx][sidx].width;
288                                *height = s_p_eia708->font_cell_info[fidx][sidx].height;
289                                return;
290                        }
291                }
292        }
293        BDBG_WRN(("%s no match for given font pointer",__func__));
294        BAPP_ASSERT(0);
295}
296
297/*
298Summary:
299Estimate the font size
300*/
301
302void bapp_eia708_cell_info(bgfx_font_t *p_font,int *width, int *height)
303{
304        unsigned int uni_str[8];
305        char str[2] = { 0, 0};
306        static char test_str[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
307        int slen,i,h,w;
308        *width = *height = 0;
309        slen = c_to_uni_str("WpgHjMQ",uni_str,7);
310        bgfx_string_info(p_font,(const unsigned long *)uni_str,slen,&w,&h);
311#ifdef NEW_FONT_SET
312        *height = h + 4;
313#else
314        *height = h + 8;
315#endif
316
317        /* make even number */
318        *height += (*height % 2);
319
320        if (*height > DCCGFX_MAX_CELL_HEIGHT)
321                *height = DCCGFX_MAX_CELL_HEIGHT;
322
323        /* Determine max width */
324        for (i = 0; i < strlen(test_str); ++i)
325        {
326                str[0] = test_str[i];
327                slen = c_to_uni_str(str,uni_str,1);
328                bgfx_string_info(p_font,(const unsigned long *)uni_str,slen,&w,&h);
329                if (w > *width)
330                        *width = w;
331        }
332
333        *width += 6;
334        /* make even number */
335        *width += (*width % 2);
336
337        if (*width > DCCGFX_MAX_CELL_WIDTH)
338                *width = DCCGFX_MAX_CELL_WIDTH;
339        BDBG_MSG(("%s (%d,%d)\n",__FUNCTION__, *width,*height));
340}
341
342/*
343Summary:
344Initialize and allocate resources
345*/
346
347bapp_eia708_t bapp_eia708_open(void* p_opaque_app)
348{
349        bapp_t *p_app = (bapp_t *)p_opaque_app;
350        cc_buf_t *p_cc_buf;
351        b_task_params params;
352        int idx;
353
354        s_p_eia708 = (bapp_eia708_t)malloc(sizeof(struct bapp_eia708));
355        BAPP_ASSERT(s_p_eia708);
356        BDBG_ERR(("eia708 structure size (%d)\n",sizeof(struct bapp_eia708)));
357
358        memset(s_p_eia708, 0, sizeof(struct bapp_eia708));
359        s_p_eia708->p_app = p_app;
360
361        BAPP_ASSERT(bos_create_mutex(&s_p_eia708->mutex) == b_ok);
362#ifdef CONFIG_OLD_PARSER
363        s_p_eia708->CCBufInfo.OutputBufSize = 512;
364        s_p_eia708->CCBufInfo.pOutputBuf = malloc(s_p_eia708->CCBufInfo.OutputBufSize);
365        s_p_eia708->DTVCCBufInfo.OutputBufSize = 128;
366        s_p_eia708->DTVCCBufInfo.pOutputBuf = malloc(s_p_eia708->DTVCCBufInfo.OutputBufSize);
367        BAPP_ASSERT(s_p_eia708->CCBufInfo.pOutputBuf);
368        BAPP_ASSERT(s_p_eia708->DTVCCBufInfo.pOutputBuf);
369#endif
370        s_p_eia708->thread_stack = malloc(EIA708_THREAD_STACK_SIZE * sizeof(unsigned int));
371        BAPP_ASSERT(s_p_eia708->thread_stack);
372
373        initl(&s_p_eia708->cc_list);
374        initl(&s_p_eia708->free_cc_list);
375        for (idx = 0; idx < NUM_CC_BUF; idx++)
376        {
377                p_cc_buf = &(s_p_eia708->cc_buf[idx]);
378                memset(p_cc_buf,0,sizeof(cc_buf_t));
379                inslt(&(s_p_eia708->free_cc_list),p_cc_buf);
380        }
381
382        p_app->br.cnt = 0;
383#ifdef CONFIG_8BIT_FONT
384#ifdef  NEW_FONT_SET
385        p_app->br.data = (unsigned char *)g_cinecavB_type_03_16_aa;
386        p_app->br.size = g_cinecavB_type_03_16_aa_size;
387#else
388        p_app->br.data = (unsigned char *)g_SFM_20_aa;
389        p_app->br.size = g_SFM_20_aa_size;
390#endif
391#else
392#ifdef  NEW_FONT_SET
393        p_app->br.data = (unsigned char *)g_cinecavB_type_03_16_mono;
394        p_app->br.size = g_cinecavB_type_03_16_mono_size;
395#else
396        p_app->br.data = (unsigned char *)g_SFM_20_mono;
397        p_app->br.size = g_SFM_20_mono_size;
398#endif
399#endif
400        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[0][0]),&p_app->br) == 0);
401        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[0][0]), 
402                                bapp_eia708_font_size(&(s_p_eia708->fonts[0][0])), &(s_p_eia708->hFont[0][0])) == BCCGFX_WINLIB_P_SUCCESS);
403
404        p_app->br.cnt = 0;
405#ifdef CONFIG_8BIT_FONT
406#ifdef  NEW_FONT_SET
407        p_app->br.data = (unsigned char *)g_cinecavB_type_03_18_aa;
408        p_app->br.size = g_cinecavB_type_03_18_aa_size;
409#else
410        p_app->br.data = (unsigned char *)g_SFM_24_aa;
411        p_app->br.size = g_SFM_24_aa_size;
412#endif
413#else
414#ifdef  NEW_FONT_SET
415        p_app->br.data = (unsigned char *)g_cinecavB_type_03_20_mono;
416        p_app->br.size = g_cinecavB_type_03_20_mono_size;
417#else
418        p_app->br.data = (unsigned char *)g_SFM_24_mono;
419        p_app->br.size = g_SFM_24_mono_size;
420#endif
421#endif
422        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[0][1]),&p_app->br) == 0);
423        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[0][1]), 
424                                bapp_eia708_font_size(&(s_p_eia708->fonts[0][1])), &(s_p_eia708->hFont[0][1])) == BCCGFX_WINLIB_P_SUCCESS);
425
426#ifdef CONFIG_8BIT_FONT
427#ifdef  NEW_FONT_SET
428        p_app->br.cnt = 0;
429        p_app->br.data = (unsigned char *)g_cinecavB_type_03_20_aa;
430        p_app->br.size = g_cinecavB_type_03_20_aa_size;
431        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[0][2]),&p_app->br) == 0);
432        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[0][2]), 
433                                bapp_eia708_font_size(&(s_p_eia708->fonts[0][2])), &(s_p_eia708->hFont[0][2])) == BCCGFX_WINLIB_P_SUCCESS);
434#endif
435#endif
436
437        p_app->br.cnt = 0;
438#ifdef CONFIG_8BIT_FONT
439#ifdef  NEW_FONT_SET
440        p_app->br.data = (unsigned char *)g_cinecavB_serif_02_16_aa;
441        p_app->br.size = g_cinecavB_serif_02_16_aa_size;
442#else
443        p_app->br.data = (unsigned char *)g_SFP_20_aa;
444        p_app->br.size = g_SFP_20_aa_size;
445#endif
446#else
447#ifdef  NEW_FONT_SET
448        p_app->br.data = (unsigned char *)g_cinecavB_serif_02_16_mono;
449        p_app->br.size = g_cinecavB_serif_02_16_mono_size;
450#else
451        p_app->br.data = (unsigned char *)g_SFP_24_mono;
452        p_app->br.size = g_SFP_24_mono_size;
453#endif
454#endif
455        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[1][0]),&p_app->br) == 0);
456        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[1][0]), 
457                                bapp_eia708_font_size(&(s_p_eia708->fonts[1][0])), &(s_p_eia708->hFont[1][0])) == BCCGFX_WINLIB_P_SUCCESS);
458
459        p_app->br.cnt = 0;
460#ifdef CONFIG_8BIT_FONT
461#ifdef  NEW_FONT_SET
462        p_app->br.data = (unsigned char *)g_cinecavB_serif_02_18_aa;
463        p_app->br.size = g_cinecavB_serif_02_18_aa_size;
464#else
465        p_app->br.data = (unsigned char *)g_SFP_24_aa;
466        p_app->br.size = g_SFP_24_aa_size;
467#endif
468#else
469#ifdef  NEW_FONT_SET
470        p_app->br.data = (unsigned char *)g_cinecavB_serif_02_20_mono;
471        p_app->br.size = g_cinecavB_serif_02_20_mono_size;
472#else
473        p_app->br.data = (unsigned char *)g_SFP_28_mono;
474        p_app->br.size = g_SFP_28_mono_size;
475#endif
476#endif
477        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[1][1]),&p_app->br) == 0);
478        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[1][1]), 
479                                bapp_eia708_font_size(&(s_p_eia708->fonts[1][1])), &(s_p_eia708->hFont[1][1])) == BCCGFX_WINLIB_P_SUCCESS);
480
481#ifdef CONFIG_8BIT_FONT
482#ifdef  NEW_FONT_SET
483        p_app->br.cnt = 0;
484        p_app->br.data = (unsigned char *)g_cinecavB_serif_02_20_aa;
485        p_app->br.size = g_cinecavB_serif_02_20_aa_size;
486        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[1][2]),&p_app->br) == 0);
487        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[1][2]), 
488                                bapp_eia708_font_size(&(s_p_eia708->fonts[1][2])), &(s_p_eia708->hFont[1][2])) == BCCGFX_WINLIB_P_SUCCESS);
489#endif
490#endif
491
492        p_app->br.cnt = 0;
493#ifdef CONFIG_8BIT_FONT
494#ifdef  NEW_FONT_SET
495        p_app->br.data = (unsigned char *)g_cinecavB_mono_03_16_aa;
496        p_app->br.size = g_cinecavB_mono_03_16_aa_size;
497#else
498        p_app->br.data = (unsigned char *)g_SSM_20_aa;
499        p_app->br.size = g_SSM_20_aa_size;
500#endif
501#else
502#ifdef  NEW_FONT_SET
503        p_app->br.data = (unsigned char *)g_cinecavB_mono_03_16_mono;
504        p_app->br.size = g_cinecavB_mono_03_16_mono_size;
505#else
506        p_app->br.data = (unsigned char *)g_SSM_20_mono;
507        p_app->br.size = g_SSM_20_mono_size;
508#endif
509#endif
510        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[2][0]),&p_app->br) == 0);
511        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[2][0]), 
512                                bapp_eia708_font_size(&(s_p_eia708->fonts[2][0])),  &(s_p_eia708->hFont[2][0])) == BCCGFX_WINLIB_P_SUCCESS);
513
514        p_app->br.cnt = 0;
515#ifdef CONFIG_8BIT_FONT
516#ifdef  NEW_FONT_SET
517        p_app->br.data = (unsigned char *)g_cinecavB_mono_03_18_aa;
518        p_app->br.size = g_cinecavB_mono_03_18_aa_size;
519#else
520        p_app->br.data = (unsigned char *)g_SSM_24_aa;
521        p_app->br.size = g_SSM_24_aa_size;
522#endif
523#else
524#ifdef  NEW_FONT_SET
525        p_app->br.data = (unsigned char *)g_cinecavB_mono_03_20_mono;
526        p_app->br.size = g_cinecavB_mono_03_20_mono_size;
527#else
528        p_app->br.data = (unsigned char *)g_SSM_24_mono;
529        p_app->br.size = g_SSM_24_mono_size;
530#endif
531#endif
532        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[2][1]),&p_app->br) == 0);
533        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[2][1]), 
534                                bapp_eia708_font_size(&(s_p_eia708->fonts[2][1])), &(s_p_eia708->hFont[2][1])) == BCCGFX_WINLIB_P_SUCCESS);
535
536#ifdef CONFIG_8BIT_FONT
537#ifdef  NEW_FONT_SET
538        p_app->br.cnt = 0;
539        p_app->br.data = (unsigned char *)g_cinecavB_mono_03_20_aa;
540        p_app->br.size = g_cinecavB_mono_03_20_aa_size;
541        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[2][2]),&p_app->br) == 0);
542        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[2][2]), 
543                                bapp_eia708_font_size(&(s_p_eia708->fonts[2][2])), &(s_p_eia708->hFont[2][2])) == BCCGFX_WINLIB_P_SUCCESS);
544#endif
545#endif
546
547        p_app->br.cnt = 0;
548#ifdef CONFIG_8BIT_FONT
549#ifdef  NEW_FONT_SET
550        p_app->br.data = (unsigned char *)g_cinecavB_sans_02_16_aa;
551        p_app->br.size = g_cinecavB_sans_02_16_aa_size;
552#else
553        p_app->br.data = (unsigned char *)g_SSP_20_aa;
554        p_app->br.size = g_SSP_20_aa_size;
555#endif
556#else
557#ifdef  NEW_FONT_SET
558        p_app->br.data = (unsigned char *)g_cinecavB_sans_02_16_mono;
559        p_app->br.size = g_cinecavB_sans_02_16_mono_size;
560#else
561        p_app->br.data = (unsigned char *)g_SSP_24_mono;
562        p_app->br.size = g_SSP_24_mono_size;
563#endif
564#endif
565        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[3][0]),&p_app->br) == 0);
566        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[3][0]), 
567                                bapp_eia708_font_size(&(s_p_eia708->fonts[3][0])),  &(s_p_eia708->hFont[3][0])) == BCCGFX_WINLIB_P_SUCCESS);
568
569        p_app->br.cnt = 0;
570#ifdef CONFIG_8BIT_FONT
571#ifdef  NEW_FONT_SET
572        p_app->br.data = (unsigned char *)g_cinecavB_sans_02_18_aa;
573        p_app->br.size = g_cinecavB_sans_02_18_aa_size;
574#else
575        p_app->br.data = (unsigned char *)g_SSP_24_aa;
576        p_app->br.size = g_SSP_24_aa_size;
577#endif
578#else
579#ifdef  NEW_FONT_SET
580        p_app->br.data = (unsigned char *)g_cinecavB_sans_02_20_mono;
581        p_app->br.size = g_cinecavB_sans_02_20_mono_size;
582#else
583        p_app->br.data = (unsigned char *)g_SSP_28_mono;
584        p_app->br.size = g_SSP_28_mono_size;
585#endif
586#endif
587        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[3][1]),&p_app->br) == 0);
588        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[3][1]), 
589                                bapp_eia708_font_size(&(s_p_eia708->fonts[3][1])), &(s_p_eia708->hFont[3][1])) == BCCGFX_WINLIB_P_SUCCESS);
590
591#ifdef CONFIG_8BIT_FONT
592#ifdef  NEW_FONT_SET
593        p_app->br.cnt = 0;
594        p_app->br.data = (unsigned char *)g_cinecavB_sans_02_20_aa;
595        p_app->br.size = g_cinecavB_sans_02_20_aa_size;
596        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[3][2]),&p_app->br) == 0);
597        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[3][2]), 
598                                bapp_eia708_font_size(&(s_p_eia708->fonts[3][2])), &(s_p_eia708->hFont[3][2])) == BCCGFX_WINLIB_P_SUCCESS);
599#endif
600#endif
601
602        p_app->br.cnt = 0;
603#ifdef CONFIG_8BIT_FONT
604#ifdef  NEW_FONT_SET
605        p_app->br.data = (unsigned char *)g_cinecavB_casual_02_16_aa;
606        p_app->br.size = g_cinecavB_casual_02_16_aa_size;
607#else
608        p_app->br.data = (unsigned char *)g_SCRIPT_20_aa;
609        p_app->br.size = g_SCRIPT_20_aa_size;
610#endif
611#else
612#ifdef  NEW_FONT_SET
613        p_app->br.data = (unsigned char *)g_cinecavB_casual_02_16_mono;
614        p_app->br.size = g_cinecavB_casual_02_16_mono_size;
615#else
616        p_app->br.data = (unsigned char *)g_SCRIPT_20_mono;
617        p_app->br.size = g_SCRIPT_20_mono_size;
618#endif
619#endif
620        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[4][0]),&p_app->br) == 0);
621        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[4][0]), 
622                                bapp_eia708_font_size(&(s_p_eia708->fonts[4][0])), &(s_p_eia708->hFont[4][0])) == BCCGFX_WINLIB_P_SUCCESS);
623
624        p_app->br.cnt = 0;
625#ifdef CONFIG_8BIT_FONT
626#ifdef  NEW_FONT_SET
627        p_app->br.data = (unsigned char *)g_cinecavB_casual_02_18_aa;
628        p_app->br.size = g_cinecavB_casual_02_18_aa_size;
629#else
630        p_app->br.data = (unsigned char *)g_SCRIPT_24_aa;
631        p_app->br.size = g_SCRIPT_24_aa_size;
632#endif
633#else
634#ifdef  NEW_FONT_SET
635        p_app->br.data = (unsigned char *)g_cinecavB_casual_02_20_mono;
636        p_app->br.size = g_cinecavB_casual_02_20_mono_size;
637#else
638        p_app->br.data = (unsigned char *)g_SCRIPT_24_mono;
639        p_app->br.size = g_SCRIPT_24_mono_size;
640#endif
641#endif
642        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[4][1]),&p_app->br) == 0);
643        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[4][1]), 
644                                bapp_eia708_font_size(&(s_p_eia708->fonts[4][1])), &(s_p_eia708->hFont[4][1])) == BCCGFX_WINLIB_P_SUCCESS);
645
646#ifdef CONFIG_8BIT_FONT
647#ifdef  NEW_FONT_SET
648        p_app->br.cnt = 0;
649        p_app->br.data = (unsigned char *)g_cinecavB_casual_02_20_aa;
650        p_app->br.size = g_cinecavB_casual_02_20_aa_size;
651        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[4][2]),&p_app->br) == 0);
652        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[4][2]), 
653                                bapp_eia708_font_size(&(s_p_eia708->fonts[4][2])), &(s_p_eia708->hFont[4][2])) == BCCGFX_WINLIB_P_SUCCESS);
654#endif
655#endif
656
657        p_app->br.cnt = 0;
658#ifdef CONFIG_8BIT_FONT
659#ifdef  NEW_FONT_SET
660        p_app->br.data = (unsigned char *)g_cinecavB_script_02_16_aa;
661        p_app->br.size = g_cinecavB_script_02_16_aa_size;
662#else
663        p_app->br.data = (unsigned char *)g_SC_20_aa;
664        p_app->br.size = g_SC_20_aa_size;
665#endif
666#else
667#ifdef  NEW_FONT_SET
668        p_app->br.data = (unsigned char *)g_cinecavB_script_02_16_mono;
669        p_app->br.size = g_cinecavB_script_02_16_mono_size;
670#else
671        p_app->br.data = (unsigned char *)g_SC_20_mono;
672        p_app->br.size = g_SC_20_mono_size;
673#endif
674#endif
675        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[5][0]),&p_app->br) == 0);
676        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[5][0]), 
677                                bapp_eia708_font_size(&(s_p_eia708->fonts[5][0])), &(s_p_eia708->hFont[5][0])) == BCCGFX_WINLIB_P_SUCCESS);
678
679        p_app->br.cnt = 0;
680#ifdef CONFIG_8BIT_FONT
681#ifdef  NEW_FONT_SET
682        p_app->br.data = (unsigned char *)g_cinecavB_script_02_18_aa;
683        p_app->br.size = g_cinecavB_script_02_18_aa_size;
684#else
685        p_app->br.data = (unsigned char *)g_SC_24_aa;
686        p_app->br.size = g_SC_24_aa_size;
687#endif
688#else
689#ifdef  NEW_FONT_SET
690        p_app->br.data = (unsigned char *)g_cinecavB_script_02_20_mono;
691        p_app->br.size = g_cinecavB_script_02_20_mono_size;
692#else
693        p_app->br.data = (unsigned char *)g_SC_24_mono;
694        p_app->br.size = g_SC_24_mono_size;
695#endif
696#endif
697        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[5][1]),&p_app->br) == 0);
698        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[5][1]), 
699                                bapp_eia708_font_size(&(s_p_eia708->fonts[5][1])), &(s_p_eia708->hFont[5][1])) == BCCGFX_WINLIB_P_SUCCESS);
700
701#ifdef CONFIG_8BIT_FONT
702#ifdef  NEW_FONT_SET
703        p_app->br.cnt = 0;
704        p_app->br.data = (unsigned char *)g_cinecavB_script_02_20_aa;
705        p_app->br.size = g_cinecavB_script_02_20_aa_size;
706        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[5][2]),&p_app->br) == 0);
707        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[5][2]), 
708                                bapp_eia708_font_size(&(s_p_eia708->fonts[5][2])), &(s_p_eia708->hFont[5][2])) == BCCGFX_WINLIB_P_SUCCESS);
709#endif
710#endif
711
712#ifdef  NEW_FONT_SET
713        p_app->br.cnt = 0;
714#ifdef CONFIG_8BIT_FONT
715        p_app->br.data = (unsigned char *)g_cinecavB_sc_02_16_aa;
716        p_app->br.size = g_cinecavB_sc_02_16_aa_size;
717#else
718        p_app->br.data = (unsigned char *)g_cinecavB_sc_02_16_mono;
719        p_app->br.size = g_cinecavB_sc_02_16_mono_size;
720#endif
721        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[6][0]),&p_app->br) == 0);
722        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[6][0]), 
723                                bapp_eia708_font_size(&(s_p_eia708->fonts[6][0])), &(s_p_eia708->hFont[6][0])) == BCCGFX_WINLIB_P_SUCCESS);
724
725        p_app->br.cnt = 0;
726#ifdef CONFIG_8BIT_FONT
727        p_app->br.data = (unsigned char *)g_cinecavB_sc_02_18_aa;
728        p_app->br.size = g_cinecavB_sc_02_18_aa_size;
729#else
730        p_app->br.data = (unsigned char *)g_SC_24_mono;
731        p_app->br.size = g_SC_24_mono_size;
732#endif
733        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[6][1]),&p_app->br) == 0);
734        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[6][1]), 
735                                bapp_eia708_font_size(&(s_p_eia708->fonts[6][1])), &(s_p_eia708->hFont[6][1])) == BCCGFX_WINLIB_P_SUCCESS);
736#endif  /*NEW_FONT_SET*/
737
738#ifdef CONFIG_8BIT_FONT
739#ifdef  NEW_FONT_SET
740        p_app->br.cnt = 0;
741        p_app->br.data = (unsigned char *)g_cinecavB_sc_02_20_aa;
742        p_app->br.size = g_cinecavB_sc_02_20_aa_size;
743        BAPP_ASSERT(bgfx_load_font(&(s_p_eia708->fonts[6][2]),&p_app->br) == 0);
744        BAPP_ASSERT(BCCGFX_WINLIB_P_LoadFont(s_p_eia708->hWinLibHandle, (const char *)&(s_p_eia708->fonts[6][2]), 
745                                bapp_eia708_font_size(&(s_p_eia708->fonts[6][2])), &(s_p_eia708->hFont[6][2])) == BCCGFX_WINLIB_P_SUCCESS);
746#endif
747#endif
748
749#ifdef CONFIG_NOCC_SD
750        BAPP_ASSERT(BCCGFX_WINLIB_P_Init(&(s_p_eia708->hWinLibHandle),&(p_app->surf),
751                                (bccgfx_update_cb_t)bapp_flush_screen_partial,(bccgfx_get_wide_aspect_ratio_cb_t)bapp_get_wide_aspect_ratio_cb, p_app) == BCCGFX_WINLIB_P_SUCCESS);
752#else
753        BAPP_ASSERT(BCCGFX_WINLIB_P_Init(&(s_p_eia708->hWinLibHandle),&(p_app->surf),
754                                (bccgfx_update_cb_t)bapp_flush_screen,(bccgfx_get_wide_aspect_ratio_cb_t)bapp_get_wide_aspect_ratio_cb, p_app) == BCCGFX_WINLIB_P_SUCCESS);
755#endif
756        BAPP_ASSERT(BDCC_ENG_GetDefaultSettings(&(s_p_eia708->stEngineSettings)) == BCCGFX_WINLIB_P_SUCCESS);
757        s_p_eia708->stEngineSettings.iSafeTitleX = 100;         /* 40 + (3 * 20) */
758        s_p_eia708->stEngineSettings.iSafeTitleY = 48;
759        s_p_eia708->stEngineSettings.iEdgeWidth = 1;
760        s_p_eia708->stEngineSettings.Columns = 32;
761        s_p_eia708->stEngineSettings.uiTimeOutMilliSecs = 30 * 1000;
762        s_p_eia708->type = BDCC_ENG_Type_e708;
763        s_p_eia708->i708_CcService = (p_app->settings.dcc.captions_basic < 1) ? 1 : p_app->settings.dcc.captions_basic;
764        s_p_eia708->i608_CcService = (p_app->settings.dcc.captions_analog < 1) ? 1 : p_app->settings.dcc.captions_analog;
765        if (s_p_eia708->i608_CcService>4) s_p_eia708->i608_CcService -= 4;
766
767        /* cache all font cell information */
768        {
769                bgfx_font_t         *p_font;
770                int fidx,sidx,w,h;
771                for (fidx = 0; fidx < NUM_EIA_708_FONTS; ++fidx)
772                {
773#ifdef NEW_FONT_SET
774                        for (sidx = 0; sidx < eFONT_SIZE_MAX; ++sidx)
775#else
776                        for (sidx = 0; sidx < (eFONT_SIZE_MAX - 1); ++sidx)
777#endif
778                        {
779                                p_font = &(s_p_eia708->fonts[fidx][sidx]);
780                                if (p_font) {
781                                        bapp_eia708_cell_info(p_font,&w,&h);
782                                        s_p_eia708->font_cell_info[fidx][sidx].width = w;
783                                        s_p_eia708->font_cell_info[fidx][sidx].height = h;
784                                        if (0 == s_p_eia708->stEngineSettings.iCharCellWidth) {
785                                                s_p_eia708->stEngineSettings.iCharCellWidth = w;
786                                                s_p_eia708->stEngineSettings.iCharCellHeight = h;
787                                        }
788                                } else {
789                                        s_p_eia708->font_cell_info[fidx][sidx].width = s_p_eia708->font_cell_info[fidx][sidx].height = 0;
790                                }
791                                BDBG_MSG(("Font[%d][%d] cell: w = %d, h = %d\n", fidx,sidx,w,h));
792                        }
793                }
794        }
795        /*s_p_eia708->type = BDCC_ENG_Type_e608; */
796        BAPP_ASSERT(BDCC_ENG_Open(&(s_p_eia708->hCC708Engine), s_p_eia708->hWinLibHandle) == BCCGFX_WINLIB_P_SUCCESS);
797        BDCC_ENG_SetSettings(s_p_eia708->hCC708Engine,&(s_p_eia708->stEngineSettings));
798        BAPP_ASSERT(BDCC_ENG_Init( s_p_eia708->hCC708Engine, s_p_eia708->i708_CcService, s_p_eia708->type ) == BCCGFX_WINLIB_P_SUCCESS);
799
800        params.name="EIA708";
801        params.priority = EIA_708_PRIORITY;
802        params.stack_size = EIA708_THREAD_STACK_SIZE;
803        params.stack = s_p_eia708->thread_stack;
804        s_p_eia708->done = false;
805        bos_start_task(&s_p_eia708->thread,&params,bapp_eia708_thread,&s_p_eia708->thread);
806        BAPP_ASSERT(s_p_eia708->thread);
807
808        return s_p_eia708;
809}
810
811/*
812Summary:
813adjust cell size
814*/
815void bapp_eia708_adjust_cell_size(bgfx_font_t *p_font)
816{
817        BDCC_ENG_GetSettings( s_p_eia708->hCC708Engine, &s_p_eia708->stEngineSettings);
818        bapp_eia708_get_cell_info(p_font,&(s_p_eia708->stEngineSettings.iCharCellWidth),&(s_p_eia708->stEngineSettings.iCharCellHeight));
819        BDBG_MSG(("Change cell size (%d,%d)\n",s_p_eia708->stEngineSettings.iCharCellWidth,s_p_eia708->stEngineSettings.iCharCellHeight));
820        BDCC_ENG_SetSettings( s_p_eia708->hCC708Engine, &s_p_eia708->stEngineSettings );
821}
822
823/*
824Summary:
825select user selected font
826*/
827BCCGFX_WINLIB_P_Font bapp_eia708_select_font(BDCC_FontStyle style,
828                BDCC_PenSize pensize )
829{
830        BCCGFX_WINLIB_P_Font hFont;
831        bgfx_font_t *p_font;
832        static bgfx_font_t *p_last_font = NULL;
833        BDBG_MSG(("%s(%d,%d)\n",__FUNCTION__,style,pensize));
834
835#ifdef NEW_FONT_SET
836#ifdef CONFIG_8BIT_FONT
837        /* currently 3 font sets */
838#else
839        /* currently 2 font sets */
840        if (pensize >= BDCC_PenSize_Large)
841                pensize = BDCC_PenSize_Standard;
842#endif
843        pensize += 1;           /* compensite the -1 below */
844#else
845        if ((pensize == BDCC_PenSize_Small) || (pensize > BDCC_PenSize_Large))
846                pensize = BDCC_PenSize_Standard;
847
848#endif
849
850        switch (style)
851        {
852                default:
853                case BDCC_FontStyle_Default:
854                case BDCC_FontStyle_MonoSerifs:
855                        hFont = s_p_eia708->hFont[0][pensize - 1];
856                        p_font = &s_p_eia708->fonts[0][pensize - 1];
857                        break;
858                case BDCC_FontStyle_PropSerifs:         
859                        hFont = s_p_eia708->hFont[1][pensize - 1];
860                        p_font = &s_p_eia708->fonts[1][pensize - 1];
861                        break;
862                case BDCC_FontStyle_Mono:
863                        hFont = s_p_eia708->hFont[2][pensize - 1];
864                        p_font = &s_p_eia708->fonts[2][pensize - 1];
865                        break;
866                case BDCC_FontStyle_Prop:                       
867                        hFont = s_p_eia708->hFont[3][pensize - 1];
868                        p_font = &s_p_eia708->fonts[3][pensize - 1];
869                        break;
870#ifdef NEW_FONT_SET
871                case BDCC_FontStyle_Casual:
872                        hFont = s_p_eia708->hFont[4][pensize - 1];
873                        p_font = &s_p_eia708->fonts[4][pensize - 1];
874                        break;
875                case BDCC_FontStyle_Cursive:           
876                        hFont = s_p_eia708->hFont[5][pensize - 1];
877                        p_font = &s_p_eia708->fonts[5][pensize - 1];
878                        break;
879                case BDCC_FontStyle_SmallCaps:         
880                        hFont = s_p_eia708->hFont[6][pensize - 1];
881                        p_font = &s_p_eia708->fonts[6][pensize - 1];
882                        break;
883#else
884                case BDCC_FontStyle_Casual:
885                case BDCC_FontStyle_Cursive:           
886                        hFont = s_p_eia708->hFont[4][pensize - 1];
887                        p_font = &s_p_eia708->fonts[4][pensize - 1];
888                        break;
889                case BDCC_FontStyle_SmallCaps:         
890                        hFont = s_p_eia708->hFont[5][pensize - 1];
891                        p_font = &s_p_eia708->fonts[5][pensize - 1];
892                        break;
893#endif
894        }
895
896        if ((hFont == NULL) || (p_font == NULL))
897        {
898                BDBG_WRN(("%s ERROR hFont = 0x%08x, p_font = 0x%08x\n",__FUNCTION__,hFont,p_font));
899                hFont = s_p_eia708->hFont[0][0];
900                p_font = &s_p_eia708->fonts[0][0];
901        }
902        if (p_font != p_last_font)
903        {
904                bapp_eia708_adjust_cell_size(p_font);
905                p_last_font = p_font;
906        }
907        return hFont;
908}
909
910/*
911Summary:
912Release all resources
913*/
914
915void bapp_eia708_close(bapp_eia708_t p_eia708)
916{
917        BAPP_ASSERT(s_p_eia708);
918        bos_delete_mutex(&p_eia708->mutex);
919#ifdef CONFIG_OLD_PARSER
920        if (s_p_eia708->CCBufInfo.pOutputBuf)
921                free(s_p_eia708->CCBufInfo.pOutputBuf);
922        if (s_p_eia708->CCBufInfo.pOutputBuf)
923                free(s_p_eia708->CCBufInfo.pOutputBuf);
924        if (s_p_eia708->CCBufInfo.pOutputBuf)
925                free(s_p_eia708->CCBufInfo.pOutputBuf);
926#endif
927        if (s_p_eia708->thread_stack)
928                free(s_p_eia708->thread_stack);
929
930        free(s_p_eia708);
931}
932/*
933 * Callback to process CC data
934 */
935extern bapp_t *s_p_app;
936void  bapp_eia708_cb(unsigned char* data,          /* the data buffer, containing data_len valid bytes */
937                int data_len,                      /* the number of valid bytes in data */
938                bool banalog
939                )
940{
941        cc_buf_t *p_cc_buf;
942        unsigned int flags;
943        BAPP_ASSERT(s_p_eia708);
944        BAPP_ASSERT((unsigned int)s_p_eia708 == (unsigned int)s_p_app->eia708);
945
946        if (s_p_eia708->enabled)
947        {
948                if (data_len > CC_BUF_SIZE)
949                {
950                        BDBG_WRN(("%s:%d data_len %d > %d\n",__FUNCTION__,__LINE__,data_len,CC_BUF_SIZE));
951                        return;
952                }
953                if (banalog && (s_p_eia708->type != BDCC_ENG_Type_e608) ) { /* 608 CC */
954                        /* enable also call RESET. */
955                        BDBG_WRN(("Reset DCC as 608 mode"));
956                        s_p_eia708->type = BDCC_ENG_Type_e608; 
957                        s_p_eia708->mode_change = true;
958                }
959                else if (!banalog && (s_p_eia708->type != BDCC_ENG_Type_e708) ) {
960                        BDBG_WRN(("Reset DCC as 708 mode"));
961                        s_p_eia708->type = BDCC_ENG_Type_e708;
962                        s_p_eia708->mode_change = true;
963                }
964                flags = bos_enter_critical();
965                p_cc_buf = (cc_buf_t*)remlh(&(s_p_eia708->free_cc_list));
966                bos_exit_critical(flags);
967                if (!p_cc_buf)
968                {
969                        BDBG_WRN(("%s:%d no free CC buffers\n",__FUNCTION__,__LINE__));
970                        return;
971                }
972                p_cc_buf->size = data_len;
973                memcpy(p_cc_buf->buf,data,p_cc_buf->size);
974                flags = bos_enter_critical();
975                inslt(&(s_p_eia708->cc_list),p_cc_buf);
976                bos_exit_critical(flags);
977        }
978        else {
979                /* actual reset will be at bapp_eia708_enable */
980                if (banalog && (s_p_eia708->type != BDCC_ENG_Type_e608)) {
981                        s_p_eia708->type = BDCC_ENG_Type_e608;
982                }
983                else if (!banalog && (s_p_eia708->type != BDCC_ENG_Type_e708)) {
984                        s_p_eia708->type = BDCC_ENG_Type_e708;
985                }
986        }
987}
988
989/* implemented in bdccengine.c */
990extern uint32_t BDCC_ENG_GetPktSeqNumErrorCount(BDCC_ENG_Handle hEngine);
991extern void BDCC_ENG_ResetPktSeqNumErrorCount(BDCC_ENG_Handle hEngine);
992
993/*
994 * Callback to get some DCC internal information, current PKT sequence number error counts
995 */
996void  bapp_eia708_dcc_status_cb(uint32_t *pkt_sequence_num_errors)
997{
998        BAPP_ASSERT(s_p_eia708);
999        BAPP_ASSERT((unsigned int)s_p_eia708 == (unsigned int)s_p_app->eia708);
1000
1001        if (pkt_sequence_num_errors)
1002        {
1003                *pkt_sequence_num_errors = BDCC_ENG_GetPktSeqNumErrorCount(s_p_eia708->hCC708Engine);
1004        }
1005}
1006
1007/*
1008 * Callback to get some DCC internal information, current PKT sequence number error counts
1009 */
1010void  bapp_eia708_dcc_reset_pkt_error_count(void)
1011{
1012        BAPP_ASSERT(s_p_eia708);
1013        BAPP_ASSERT((unsigned int)s_p_eia708 == (unsigned int)s_p_app->eia708);
1014
1015        BDCC_ENG_ResetPktSeqNumErrorCount(s_p_eia708->hCC708Engine);
1016}
1017
1018/*
1019Summary:
1020override the settings from the user
1021*/
1022void bapp_eia708_overrides(bapp_eia708_t p_eia708)
1023{
1024        BDCC_ENG_OverRides overrides;
1025        unsigned int overrideMask = BDCC_ATTR_MASK_NONE;
1026
1027        memset(&overrides, 0, sizeof(BDCC_ENG_OverRides));
1028        //if (p_eia708->p_app->settings.dcc.captions_font > 0)
1029        {
1030                overrides.FontStyle = p_eia708->p_app->settings.dcc.captions_font;
1031                /* it is kind of misleading to use FONTSTYLE for font */
1032                overrideMask |= BDCC_ATTR_MASK_FONTSTYLE;
1033                bapp_eia708_select_font(overrides.FontStyle, 0 == p_eia708->p_app->settings.dcc.captions_font_size ? 
1034                                BDCC_PenSize_Standard : p_eia708->p_app->settings.dcc.captions_font_size - 1);
1035                BDBG_MSG(("%s:%d font = %d\n",__FUNCTION__,__LINE__,overrides.FontStyle));
1036        }
1037        if (p_eia708->p_app->settings.dcc.captions_font_size > 0)
1038        {
1039                overrides.PenSize = p_eia708->p_app->settings.dcc.captions_font_size - 1 ;
1040                overrideMask |= BDCC_ATTR_MASK_PENSIZE;
1041                bapp_eia708_select_font(overrides.FontStyle,
1042                                overrides.PenSize );
1043                BDBG_MSG(("%s:%d font = %d\n",__FUNCTION__,__LINE__,overrides.PenSize));
1044        }
1045        if (p_eia708->p_app->settings.dcc.captions_font_style == 2)
1046        {
1047                overrideMask |= BDCC_ATTR_MASK_ITALICS;
1048                overrides.Italics = 1;
1049                BDBG_MSG(("%s:%d captions_font_style = %d\n",__FUNCTION__,__LINE__,p_eia708->p_app->settings.dcc.captions_font_style));
1050        }
1051
1052        if (p_eia708->p_app->settings.dcc.captions_font_style == 3)
1053        {
1054                overrideMask |= BDCC_ATTR_MASK_UNDERLINE;
1055                overrides.Underline = 1;
1056                BDBG_MSG(("%s:%d captions_font_style = %d\n",__FUNCTION__,__LINE__,p_eia708->p_app->settings.dcc.captions_font_style));
1057        }
1058
1059        if ((p_eia708->p_app->settings.dcc.captions_font_color > 0) || (p_eia708->p_app->settings.dcc.captions_font_opacity > 0))
1060        {
1061                switch (p_eia708->p_app->settings.dcc.captions_font_color)
1062                {
1063                        case 0: overrides.FgColor = 0x3F; break;
1064                        case 1: overrides.FgColor = 0x3F; break;
1065                        case 2: overrides.FgColor = 0; break;
1066                        case 3: overrides.FgColor = 0x30; break;
1067                        case 4: overrides.FgColor = 0x0C; break;
1068                        case 5: overrides.FgColor = 0x03; break;
1069                        case 6: overrides.FgColor = 0x3C; break;
1070                        case 7: overrides.FgColor = 0x33; break;
1071                        case 8: overrides.FgColor = 0x0F; break;
1072                }
1073
1074                switch (p_eia708->p_app->settings.dcc.captions_font_opacity)
1075                {
1076                        case 3: overrides.FgOpacity = BDCC_Opacity_Solid; break;
1077                        case 4: overrides.FgOpacity = BDCC_Opacity_Flash; break;
1078                        case 2: overrides.FgOpacity = BDCC_Opacity_Translucent; break;
1079                        case 1: overrides.FgOpacity = BDCC_Opacity_Transparent; break;
1080                        case 0: overrides.FgOpacity = BDCC_Opacity_Solid; break;
1081                } 
1082                overrideMask |= BDCC_ATTR_MASK_PENFG;
1083                BDBG_MSG(("%s:%d font color = %d\n",__FUNCTION__,__LINE__,overrides.FgColor));
1084                BDBG_MSG(("%s:%d font effect = %d\n",__FUNCTION__,__LINE__,overrides.FgOpacity));
1085        }
1086
1087        if ((p_eia708->p_app->settings.dcc.captions_back_color > 0) || (p_eia708->p_app->settings.dcc.captions_back_opacity > 0))
1088        {
1089                switch (p_eia708->p_app->settings.dcc.captions_back_color)
1090                {
1091                        case 0: overrides.BgColor = 0; break;
1092                        case 1: overrides.BgColor = 0x3F; break;
1093                        case 2: overrides.BgColor = 0; break;
1094                        case 3: overrides.BgColor = 0x30; break;
1095                        case 4: overrides.BgColor = 0x0C; break;
1096                        case 5: overrides.BgColor = 0x03; break;
1097                        case 6: overrides.BgColor = 0x3C; break;
1098                        case 7: overrides.BgColor = 0x33; break;
1099                        case 8: overrides.BgColor = 0x0F; break;
1100                } 
1101                switch (p_eia708->p_app->settings.dcc.captions_back_opacity)
1102                {
1103                        case 3: overrides.BgOpacity = BDCC_Opacity_Solid; break;
1104                        case 4: overrides.BgOpacity = BDCC_Opacity_Flash; break;
1105                        case 2: overrides.BgOpacity = BDCC_Opacity_Translucent; break;
1106                        case 1: overrides.BgOpacity = BDCC_Opacity_Transparent; break;
1107                        case 0: overrides.BgOpacity = BDCC_Opacity_Solid; break;
1108                } 
1109                overrideMask |= BDCC_ATTR_MASK_PENBG;
1110                BDBG_MSG(("%s:%d bg color = %d\n",__FUNCTION__,__LINE__,overrides.BgColor));
1111                BDBG_MSG(("%s:%d bg effect = %d\n",__FUNCTION__,__LINE__,overrides.BgOpacity));
1112        }
1113
1114        if (p_eia708->p_app->settings.dcc.captions_edge_color > 0)
1115        {
1116                switch (p_eia708->p_app->settings.dcc.captions_edge_color)
1117                {
1118                        case 0: overrides.EdgeColor = 0x3F; break;
1119                        case 1: overrides.EdgeColor = 0x3F; break;
1120                        case 2: overrides.EdgeColor = 0; break;
1121                        case 3: overrides.EdgeColor = 0x30; break;
1122                        case 4: overrides.EdgeColor = 0x0C; break;
1123                        case 5: overrides.EdgeColor = 0x03; break;
1124                        case 6: overrides.EdgeColor = 0x3C; break;
1125                        case 7: overrides.EdgeColor = 0x33; break;
1126                        case 8: overrides.EdgeColor = 0x0F; break;
1127                } 
1128                overrideMask |= BDCC_ATTR_MASK_EDGECOLOR;
1129        }
1130
1131
1132        if (p_eia708->p_app->settings.dcc.captions_edge_type > 0)
1133        {
1134                overrides.EdgeType = (BDCC_Edge)p_eia708->p_app->settings.dcc.captions_edge_type;
1135                overrideMask |= BDCC_ATTR_MASK_EDGETYPE;
1136        }
1137
1138        BDBG_MSG(("%s:%d service = %d\n",__FUNCTION__,__LINE__,
1139                                (s_p_eia708->type==BDCC_ENG_Type_e608)?s_p_eia708->i608_CcService:s_p_eia708->i708_CcService));
1140
1141        BDCC_ENG_Override( s_p_eia708->hCC708Engine, overrideMask, &overrides );
1142
1143        BDCC_ENG_Reset( s_p_eia708->hCC708Engine, false,  s_p_eia708->type, 
1144                        (s_p_eia708->type==BDCC_ENG_Type_e608)?s_p_eia708->i608_CcService:s_p_eia708->i708_CcService );
1145}
1146
1147
1148/*
1149Summary:
1150reset 708 engine if needed
1151*/
1152void bapp_eia708_reset(bapp_eia708_t p_eia708)
1153{
1154        if (bos_acquire_mutex(&(p_eia708->mutex),EIA708_ENABLE_TIMEOUT) != b_ok)
1155        {
1156                BDBG_ERR(("%s bos_acquire_mutex failed\n",__FUNCTION__));
1157                return;
1158        }
1159
1160        if (p_eia708 && p_eia708->enabled) {
1161                BDCC_ENG_Reset( s_p_eia708->hCC708Engine, false,  s_p_eia708->type, 
1162                                (s_p_eia708->type==BDCC_ENG_Type_e608)?s_p_eia708->i608_CcService:s_p_eia708->i708_CcService );
1163        }
1164        bos_release_mutex(&(p_eia708->mutex));
1165}
1166
1167/*
1168Summary:
1169Check Enable/Disable CC
1170*/
1171bool bapp_eia708_enabled(bapp_eia708_t p_eia708)
1172{
1173        if (!p_eia708)
1174                return 0;
1175
1176        return p_eia708->enabled;
1177}
1178
1179/*
1180Summary:
1181Enable/Disable CC
1182*/
1183void bapp_eia708_enable(bapp_eia708_t p_eia708, bool enable)
1184{
1185        cc_buf_t *p_cc_buf;
1186        BAPP_ASSERT(s_p_eia708);
1187
1188        if (!p_eia708)
1189                return;
1190        BDBG_WRN(("%s:%d enable = %d - current %d (type:%d)\n",__FUNCTION__,__LINE__,enable,p_eia708->enabled,p_eia708->type));
1191
1192        if (p_eia708->p_app->pin_limit_timeout && p_eia708->p_app->pin_limit_override
1193                        && bapp_get_block_status(p_eia708->p_app)) {
1194                BDBG_WRN(("shouldn't update screen (pin_limit_timeout:%d)",p_eia708->p_app->pin_limit_timeout));
1195                return;
1196        }
1197
1198        if (bos_acquire_mutex(&(p_eia708->mutex),EIA708_ENABLE_TIMEOUT) != b_ok)
1199        {
1200                BDBG_ERR(("%s bos_acquire_mutex failed(enable = %d)\n",__FUNCTION__,enable));
1201                return;
1202        }
1203
1204        if (p_eia708->enabled == enable)
1205        {
1206                bos_release_mutex(&(p_eia708->mutex));
1207                BDBG_MSG(("%s:%d release\n",__FUNCTION__,__LINE__));
1208                BDBG_MSG(("708 already enabled eia708->enabled = %d = enable = %d)\n",p_eia708->enabled,enable));
1209                return;
1210        }
1211
1212        p_eia708->enabled = enable;
1213        while ((p_cc_buf = (cc_buf_t*)remlh(&(s_p_eia708->cc_list))))
1214        {
1215                inslt(&(s_p_eia708->free_cc_list),p_cc_buf);
1216        }
1217
1218        if (p_eia708->enabled)
1219        {
1220                bapp_eia708_overrides(p_eia708);
1221                bgfx_fill_rect(&p_eia708->p_app->surf,0,0,p_eia708->p_app->surf.surface.width,p_eia708->p_app->surf.surface.height,eCOLOR_CLEAR);
1222                bapp_set_palette(p_eia708->p_app,ePALETTE_EIA_708);
1223#ifdef CONFIG_NOCC_SD
1224                bapp_flush_screen_partial(p_eia708->p_app, eGRAPHICS_HD);
1225#else
1226                bapp_flush_screen(p_eia708->p_app);
1227#endif
1228        }
1229        else
1230        {
1231                bgfx_fill_rect(&p_eia708->p_app->surf,0,0,p_eia708->p_app->surf.surface.width,p_eia708->p_app->surf.surface.height,eCOLOR_CLEAR);
1232                bapp_set_palette(p_eia708->p_app,ePALETTE_APP);
1233#ifdef CONFIG_NOCC_SD
1234                bapp_flush_screen_partial(p_eia708->p_app, eGRAPHICS_HD);
1235#else
1236                bapp_flush_screen(p_eia708->p_app);
1237#endif
1238        }
1239
1240        bos_release_mutex(&(p_eia708->mutex));
1241        if (!p_eia708->enabled)
1242        {
1243                static chm_event_t         evt;
1244       
1245                evt.type = eCHM_EVT_REDRAW;
1246                evt.id = 0;
1247                evt.ticks = 0;
1248                /* JPF TODO evt.id = p_eia708->p_app->cur_ch_num; */
1249                bos_post_event(p_eia708->p_app->msg_queue,(b_event_t*)&evt);
1250        }
1251        BDBG_MSG(("%s:%d release\n",__FUNCTION__,__LINE__));
1252}
1253/*
1254Summary:
1255EIA 708 Processing Thread
1256*/
1257
1258static void bapp_eia708_thread(void *data)
1259{
1260#ifdef CONFIG_OLD_PARSER
1261        DCCERR dccerr; 
1262#endif
1263        unsigned int start_ticks,flags;
1264        int delta,bytes_produced;
1265        unsigned char dumby;            /* we need this to do periodic update of the screen for scrolling */
1266        unsigned char* triplets = NULL;
1267        cc_buf_t *p_cc_buf;
1268
1269        BAPP_ASSERT(s_p_eia708);
1270#if 0
1271        BDBG_SetModuleLevel("eia708",BDBG_eWrn);
1272        BDBG_SetModuleLevel("bdcc_winlib",BDBG_eWrn);
1273        BDBG_SetModuleLevel("bdccgfx",BDBG_eMsg);
1274        BDBG_SetModuleLevel("bdcc_608trans",BDBG_eMsg);
1275        BDBG_SetModuleLevel("bdccengine",BDBG_eMsg);
1276        BDBG_SetModuleLevel("bdccservice",BDBG_eMsg);
1277        BDBG_SetModuleLevel("bdccpacket",BDBG_eMsg);
1278        BDBG_SetModuleLevel("bdcc_coding",BDBG_eMsg);
1279        BDBG_SetModuleLevel("bdccintgfx",BDBG_eMsg);
1280
1281        BDBG_SetModuleLevel("bdcc_608trans",BDBG_eMsg);
1282#endif
1283
1284        while (!s_p_eia708->done)
1285        {
1286                if (!s_p_eia708->enabled)
1287                {
1288                        bos_sleep(100);
1289                        continue;                       
1290                }
1291                if (s_p_eia708->mode_change) {
1292                        BDCC_ENG_Reset( s_p_eia708->hCC708Engine, false,  s_p_eia708->type, 
1293                                        (s_p_eia708->type==BDCC_ENG_Type_e608)?s_p_eia708->i608_CcService:s_p_eia708->i708_CcService);
1294                        s_p_eia708->mode_change = false;
1295                }
1296                flags = bos_enter_critical();
1297                p_cc_buf = (cc_buf_t*)remlh(&(s_p_eia708->cc_list));
1298                bos_exit_critical(flags);
1299
1300                if (p_cc_buf)
1301                {
1302                        bytes_produced = 0;
1303                        if (!s_p_eia708->enabled)
1304                        {
1305                                flags = bos_enter_critical();
1306                                inslt(&(s_p_eia708->free_cc_list),p_cc_buf);
1307                                bos_exit_critical(flags);
1308                                //bos_sleep(500);
1309                                bos_sleep(100);
1310                                continue;                       
1311                        }
1312
1313                        start_ticks = bos_getticks();
1314
1315#ifdef CONFIG_OLD_PARSER
1316                        s_p_eia708->DTVCCBufInfo.OutputBytesProduced = 0;
1317                        dccerr = DccTransport_Process(&s_p_eia708->pTransport, p_cc_buf->buf, p_cc_buf->size, 
1318                                        &s_p_eia708->CCBufInfo, &s_p_eia708->DTVCCBufInfo);
1319
1320                        bytes_produced = s_p_eia708->DTVCCBufInfo.OutputBytesProduced;
1321                        triplets = (unsigned char *)s_p_eia708->DTVCCBufInfo.pOutputBuf;
1322#else
1323                        bytes_produced = p_cc_buf->size;
1324                        triplets = p_cc_buf->buf;
1325#endif
1326
1327                        flags = bos_enter_critical();
1328                        inslt(&(s_p_eia708->free_cc_list),p_cc_buf);
1329                        bos_exit_critical(flags);
1330
1331                        delta = bos_getticks() - start_ticks;
1332                        if (delta > MS_TO_TICKS(16))
1333                        {
1334                                BDBG_WRN(("### DccTransport_Process %d ms\n",TICKS_TO_MS(delta)));
1335                                //printf("?\n");
1336                        }
1337                        //start_ticks = bos_getticks();
1338                }
1339                else
1340                {
1341                        triplets = NULL;
1342                        bytes_produced = 0;
1343                }
1344
1345                //BDBG_MSG(("BDCC_ENG_Process %d bytes\n",bytes_produced));
1346                //BDBG_MSG(("%s:%d acquire\n",__FUNCTION__,__LINE__));
1347                start_ticks = bos_getticks();
1348                if (bos_acquire_mutex(&(s_p_eia708->mutex),EIA708_ENABLE_TIMEOUT) == b_ok)
1349                {
1350            if (triplets == NULL)
1351                triplets = &dumby;
1352                        if (BDCC_ENG_Process(s_p_eia708->hCC708Engine, 
1353                                                triplets, bytes_produced/3) != BCCGFX_WINLIB_P_SUCCESS)
1354                        {
1355                                BDBG_MSG(("BDCC_ENG_Process failed to process %d bytes\n",bytes_produced));
1356                        }
1357
1358                        bos_release_mutex(&(s_p_eia708->mutex));
1359                        //BDBG_MSG(("%s:%d release\n",__FUNCTION__,__LINE__));
1360                }
1361
1362                delta = bos_getticks() - start_ticks;
1363                if (delta > MS_TO_TICKS(32))
1364                {
1365                        BDBG_MSG(("### %d ms\n",TICKS_TO_MS(delta)));
1366                        //printf("?\n");
1367                }
1368                //if (bytes_produced)
1369                {
1370                        bos_sleep(5);
1371                }
1372        } /* while (!s_p_eia708->done) */
1373}
1374
1375
1376void bapp_eia708_get_cc_info(bapp_eia708_t p_eia708, int *type, int *service)
1377{
1378        BAPP_ASSERT(s_p_eia708);
1379        *type = (s_p_eia708->type == BDCC_ENG_Type_e608)?0:1;
1380        *service = (*type==0)?s_p_eia708->i608_CcService:s_p_eia708->i708_CcService;
1381}
1382
1383void bapp_eia708_set_cc_service(bapp_eia708_t p_eia708, int type, int service)
1384{
1385        BAPP_ASSERT(s_p_eia708);
1386        if (type == 0) {
1387                if (service>4) service -= 4;
1388                s_p_eia708->i608_CcService = service;
1389        }
1390        else
1391                s_p_eia708->i708_CcService = service;
1392}
1393
1394static int bapp_eia708_p_color2index(uint32_t ARGB)
1395{
1396        int ColorIndex = 2;
1397        static unsigned int ColorLookup[] = {0,128,192,255} ;
1398        unsigned int red, grn, blu, i;
1399        unsigned char RGB;
1400
1401        red = ((ARGB) >> 16) & 0xFF ;
1402        grn = ((ARGB) >> 8) & 0xFF ;
1403        blu = ((ARGB) >> 0) & 0xFF ;
1404
1405        for (i = 0; i<4; i++) {
1406                if(red == ColorLookup[i])
1407                        break;
1408        }
1409        RGB = (i << 4) & 0x30;
1410
1411        for (i = 0; i<4; i++) {
1412                if(grn == ColorLookup[i])
1413                        break;
1414        }
1415        RGB |= (i << 2) & 0x0C;
1416
1417        for (i = 0; i<4; i++) {
1418                if(blu == ColorLookup[i])
1419                        break;
1420        }
1421        RGB |= (i << 0) & 0x03;
1422
1423        switch (RGB)
1424        {
1425                case 0x00: ColorIndex = 2; break;
1426                case 0x2a: case 0x3F: ColorIndex = 1; break;
1427                case 0x30: ColorIndex = 3; break;
1428                case 0x0C: ColorIndex = 4; break;
1429                case 0x03: ColorIndex = 5; break;
1430                case 0x3C: ColorIndex = 6; break;
1431                case 0x33: ColorIndex = 7; break;
1432                case 0x0F: ColorIndex = 8; break;
1433        }
1434        return ColorIndex;
1435}
1436
1437static int bapp_eia708_p_color2alpha(uint32_t ARGB)
1438{
1439        unsigned char alpha;
1440        alpha = (ARGB>>24)&0xFF;       
1441
1442        switch (alpha)
1443        {
1444                case 0x00: return 1; /* transparent */
1445                case 0x50: return 2; /* transfluent */
1446                case 0xFF:
1447                default:
1448                                   return 3; /* solid */
1449        }
1450}
1451
1452int bapp_eia708_get_dcc_settings(bapp_eia708_t p_eia708, void *psettings)
1453{
1454        unsigned int colors[3];
1455        unsigned int style=0;
1456        dcc_settings_t *settings = (dcc_settings_t *)psettings;
1457
1458        memset(settings, 0, sizeof(dcc_settings_t));   
1459        if (BDCC_WINLIB_P_GetActiveWindowSettings(p_eia708->hWinLibHandle, colors, &style))
1460        {
1461                settings->captions_edge_color = bapp_eia708_p_color2index(colors[2]);
1462                settings->captions_edge_type = (style>>8)&0xFF;
1463                settings->captions_font_color = bapp_eia708_p_color2index(colors[0]);
1464                settings->captions_back_color = bapp_eia708_p_color2index(colors[1]);
1465
1466                if (style&0x02) settings->captions_font_style = 3; /* underline */     
1467                else if (style&0x01) settings->captions_font_style = 2; /* italic */
1468                else settings->captions_font_style = 1; /* solid */
1469
1470                if (style & 0x04) settings->captions_font_opacity = 4; /* flashsing */
1471                else settings->captions_font_opacity = bapp_eia708_p_color2alpha(colors[0]);
1472                if (style & 0x08) settings->captions_back_opacity = 4;
1473                else settings->captions_back_opacity = bapp_eia708_p_color2alpha(colors[1]);
1474                return 1;
1475        }
1476        else 
1477        {
1478                return 0;
1479        }
1480}
1481
Note: See TracBrowser for help on using the repository browser.