source: svn/trunk/zasc/app/DST_CC708.cpp @ 2

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

1.phkim

  1. revision copy newcon3sk r27
File size: 61.2 KB
Line 
1#include "DST_WinManager.h"
2#include "DST_CC_Setup.h"
3#include "DST_CCTask.h"
4#include "DST_HostInterface.h"
5#include "DST_FontEngine.h"
6
7extern DS_U16 DMW_KSX2UniSub(DS_U8 high, DS_U8 low);
8#define COLOR_TRANSPARENT       0
9#if 0
10____CC_708_Font_Size_Decide__()
11#endif
12
13static int debug_cc = 0;
14
15extern "C" void DST_708Debug(bool bOn)
16{
17        debug_cc = bOn ? 1 : 0;
18}
19
20#define MAX_708_ROW 15
21#define MAX_708_COL 52 // korean 708 cc ¿¡ µû¸§
22
23static int DST_708_FontSize[3] = {0,0,0}; // 0 = small, 1 = standard, 2 = large
24
25int DST_708_GetFontSize(int n) // 0 = min, 1 = std, 2 = max
26{
27        if (DST_708_FontSize[0] == 0)
28        {
29                DST_708_FontSize[0] = DST_DecideFontSize(13); // ½ºÅ©¸° ³ôÀÌ¿¡ 15ÁÙ ±×¸±¼ö ÀÖÀ¸¸é Samll
30                DST_708_FontSize[1] = DST_DecideFontSize(12); // ½ºÅ©¸° ³ôÀÌ¿¡ 12ÁÙ ±×¸±¼ö ÀÖÀ¸¸é Standard
31                DST_708_FontSize[2] = DST_DecideFontSize(11); // ½ºÅ©¸° ³ôÀÌ¿¡ 9ÁÙ ±×¸±¼ö ÀÖÀ¸¸é Large
32                DST_Printf("708 Font Size = %d %d %d\n", DST_708_FontSize[0], DST_708_FontSize[1], DST_708_FontSize[2]);
33        }
34        return DST_708_FontSize[n];
35}
36
37#if 0
38____CC_708_Region_Process___()
39#endif
40
41static DST_RECT rect = { 0,0,0,0};
42static void DST_UpdateRegionReset()
43{
44    memset(&rect, 0, sizeof(DST_RECT));
45}
46
47static void DST_UpdateRegionAdd(DST_RECT rectNew)
48{
49  if (rectNew.w == 0 || rectNew.h == 0) return;
50        // Çå¹Ú½ºÀÇ Å©±â°¡ 0ÀÌ¸é »õ¹Ú½ºÀÇ Å©±â·Î ´ëüÇÑ´Ù.
51        if (rect.w == 0 || rect.h == 0)
52        {
53                rect = rectNew;
54                return;
55        }
56        DST_RECT rectTemp = rect;
57#ifndef min
58        #define min(a,b) ((a)>(b)?(b):(a))
59#endif
60#ifndef max
61        #define max(a,b) ((a)>(b)?(a):(b))
62#endif
63        rect.x = min(rectTemp.x, rectNew.x );
64        rect.y = min(rectTemp.y, rectNew.y );
65        rect.w = max(rectTemp.x + rectTemp.w, rectNew.x + rectNew.w) - rect.x;
66        rect.h = max(rectTemp.y + rectTemp.h, rectNew.y + rectNew.h) - rect.y;
67
68        if (rect.x < 0) rect.x = 0;
69        if (rect.y < 0) rect.y = 0;
70        int nScreenHeight = DST_GetCCScreenHeight();
71        int nScreenWidth = DST_GetCCScreenWidth();
72        if (rect.w > nScreenWidth - rect.x) rect.w = nScreenWidth - rect.x;
73        if (rect.h > nScreenHeight - rect.y) rect.h = nScreenHeight - rect.y;
74}
75
76static DST_RECT DST_UpdateRegionGet()
77{
78        return rect;
79}
80
81#if 0
82____CC_708_Queue____()
83#endif
84
85#define QUEUE_LENGTH 2048
86
87class CCCircularQueue
88{
89private:
90        int head;
91        int tail;
92        int nLength;
93        unsigned char buffer[QUEUE_LENGTH];
94public:
95        CCCircularQueue()
96        {
97                Reset();
98        }
99        void Reset()
100        {
101                head = 0;
102                tail = 0;
103                nLength = 0;
104        }
105        int GetSize()
106        {
107                return nLength;
108        }
109        int GetFreeSize()
110        {
111                return QUEUE_LENGTH - GetSize();
112        }
113        bool Add(unsigned char  *Buff, int nSize)
114        {
115                if (GetFreeSize() < nSize) return false;
116                while (nSize--) Add(*(Buff++));
117                return true;
118        }
119        bool Add(unsigned char  ucBuff)
120        {
121                if (GetFreeSize() < 1) return false;
122                buffer[head] = ucBuff;
123                head = (head == QUEUE_LENGTH-1) ? 0 : head + 1;
124                nLength++;
125                return true;
126        }
127        unsigned char  GetByte()
128        {
129                if (GetSize() < 1) return 0;
130                return buffer[tail];
131        }
132        unsigned char  GetNextByte()
133        {
134                if (GetSize() < 2) return 0;
135                switch (tail)
136                {
137                        case QUEUE_LENGTH - 1:
138                                return buffer [0];
139                }
140                return buffer[tail+1];
141        }
142        unsigned char  GetNextNextByte()
143        {
144                if (GetSize() < 3) return 0;
145                switch (tail)
146                {
147                        case QUEUE_LENGTH - 2:
148                                return buffer [0];
149                        case QUEUE_LENGTH - 1:
150                                return buffer [1];
151                }
152                return buffer[tail+2];
153        }
154        bool Get(unsigned char  *data, int nSize)
155        {
156                if (GetSize() < nSize) return false;
157                for (int i = 0; i < nSize; i++)
158                {
159                        data[i] = GetByte();
160                        RemoveByte();
161                }
162                return true;
163        }
164        void RemoveByte()
165        {
166                if (GetSize() < 1) return;
167                tail = (tail == QUEUE_LENGTH-1) ? 0 : tail+1;
168                nLength--;
169        }
170};
171
172#if 0
173____CC_708_Window____()
174#endif
175
176struct DST_708_Color
177{
178   DS_U8 red;
179   DS_U8 green;
180   DS_U8 blue;
181};
182
183struct DST_708_Window
184{
185    // Define Window
186   DS_U8 priority; // 0 ~ 7
187   DS_U8 anchor_point; // 0 ~8
188   DS_U8 relative_positioning; // 0 ~ 1
189   DS_U8 anchor_vertical;
190   DS_U8 anchor_horizontal;
191   DS_U8 row_count;
192   DS_U8 column_count;
193   DS_U8 row_lock;
194   DS_U8 column_lock;
195   DS_U8 visible;
196   DS_U8 window_styleID;
197   DS_U8 pen_styleID;
198    // Set Window Attributes
199   DS_U8 justify;
200   DS_U8 print_direction;
201   DS_U8 scroll_direction;
202   DS_U8 wordwrap;
203   DS_U8 display_effect;
204   DS_U8 effect_direction;
205   DS_U8 effect_speed;
206    DST_708_Color fill_color;
207   DS_U8 fill_opacity;
208   DS_U8 border_type;
209    DST_708_Color border_color;
210};
211
212struct DST_708_Pen
213{
214    // Set Pen Attributes
215   DS_U8 pen_size;
216   DS_U8 font_style;
217   DS_U8 text_tag;
218   DS_U8 offset;
219   DS_U8 italics;
220   DS_U8 underline;
221   DS_U8 edge_type;
222    // Set Pen Color
223    DST_708_Color fg_color;
224   DS_U8 fg_opacity;
225    DST_708_Color bg_color;
226   DS_U8 bg_opacity;
227    DST_708_Color edge_color;
228};
229
230struct DST_708_Char
231{
232    DS_U16 nCode;
233    DST_708_Pen pen;
234};
235
236
237class CC708Window
238{
239private:
240        DST_708_Window window_data;
241        DST_708_Pen pen_data;
242        DST_708_Char strText[MAX_708_COL][MAX_708_ROW]; // ¹öÆÛ¿¡ µé¾î¿Â µ¥ÀÌÅÍ
243        bool bDefined;
244        int pos_x; // Ä¿¼­ÀÇ À§Ä¡
245        int pos_y;
246
247        DST_RECT rect;
248        OSD_PIXEL_T *imgBuff;
249        bool bNeedDraw;
250        bool bKorean;
251        bool bWideScreen;
252        DS_U8 nID;
253
254        int nLineWidth[MAX_708_ROW];
255        int nLineHeight[MAX_708_ROW];
256
257        bool bHide; // HDW DSW TGW ¸í·É¿¡ ÀÇÇØ¼­ »óŰ¡ º¯°æµÈ´Ù.
258                                                        // true°¡ µÇ¸é ¹®ÀÚ¿­À» ´õ ÀÌ»ó ¹Þ¾ÆµéÀÌÁö ¾Ê´Â´Ù.
259public:
260        void SetID(DS_U8 id)
261        {
262                nID = id;
263        }
264        void SetKorean(bool bVal)
265        {
266                bKorean = bVal;
267        }
268        bool GetNeedRedraw()
269        {
270                return bNeedDraw;
271        }
272        void SetNeedRedraw(bool bValue)
273        {
274                bNeedDraw = bValue;
275        }
276        bool GetVisible()
277        {
278                return window_data.visible == 0 ? false : true;
279        }
280        int GetPriority()
281        {
282                return window_data.priority;
283        }
284        OSD_PIXEL_T *GetImgBuff()
285        {
286                return imgBuff;
287        }
288        DST_RECT GetSize()
289        {
290                return rect;
291        }
292        CC708Window(bool bKorea, bool bWide)
293        {
294                imgBuff = 0;
295                for (int i = 0; i < MAX_708_ROW; i++)
296                {
297                        nLineWidth[i] = 0;
298                        nLineHeight[i] = 0;
299                }
300                Initialize();
301                bKorean = bKorea;
302                bWideScreen = bWide;
303        }
304        void Initialize()
305        {
306                bHide = false;
307                memset(&window_data, 0, sizeof(DST_708_Window));
308                memset(&pen_data, 0, sizeof(DST_708_Pen));
309                memset(&rect, 0, sizeof(DST_RECT));
310                ClearWindow();
311                if (imgBuff) DST_OS_Free(&imgBuff);
312                imgBuff = 0;
313                for (int i = 0; i < MAX_708_ROW; i++)
314                {
315                        nLineWidth[i] = 0;
316                        nLineHeight[i] = 0;
317                }
318                bDefined = false;
319                bNeedDraw = false;
320        }
321        virtual ~CC708Window()
322        {
323                if (imgBuff) DST_OS_Free(&imgBuff);
324                imgBuff = 0;
325                for (int i = 0; i < MAX_708_ROW; i++)
326                {
327                        nLineWidth[i] = 0;
328                        nLineHeight[i] = 0;
329                }
330        }
331        void DefineWindow(DS_U8 priority,
332                           DS_U8 anchor_point,
333                           DS_U8 relative_positioning,
334                           DS_U8 anchor_vertical,
335                           DS_U8 anchor_horizontal,
336                           DS_U8 row_count,
337                           DS_U8 column_count,
338                           DS_U8 row_lock,
339                           DS_U8 column_lock,
340                           DS_U8 visible,
341                           DS_U8 window_styleID,
342                           DS_U8 pen_styleID )
343        {
344                if (debug_cc)
345                {
346                        DST_Printf("Define Window[%d]", nID);
347                        DST_Printf(" p(%d)", priority);
348                        DST_Printf(" a(%d)", anchor_point);
349                        DST_Printf(" r(%d)", relative_positioning);
350                        DST_Printf(" v(%d)", anchor_vertical);
351                        DST_Printf(" h(%d)", anchor_horizontal);
352                        DST_Printf(" row(%d)", row_count);
353                        DST_Printf(" col(%d)", column_count);
354                        DST_Printf(" rl(%d)", row_lock);
355                        DST_Printf(" cl(%d)", column_lock);
356                        DST_Printf(" v(%d)", visible);
357                        DST_Printf(" s(%d)", window_styleID);
358                        DST_Printf(" pen(%d)", pen_styleID);
359                        DST_Printf("\n");
360                }
361                // 608 ¹ø¿ª ¿À·ù ´ëÀÀ 4¹ø ½ºÅ¸ÀÏ·Î ¿À¸é row_count¸¦ 2ÁÙ ÁÙÀδÙ.
362                //  football.trp
363                if (bKorean == false && window_data.window_styleID == 4)
364                {
365                        if (row_count > 0) row_count--;
366                }
367                // 4-Line Roll-Up ¸ðµå 608 ¹ø¿ª ¿À·ù ´ëÀÀ
368                // 2¹ø ½ºÅ¸ÀÏ·Î ¿À¸é¼­  row_count°¡ 2,3,4·Î ¿À´Âµ¥ 1,2,3À¸·Î ¿Í¾ß ¸Â´Â °ªÀÌ´Ù.
369                // DTVCC1080 v1.1_8-08-01.trp 2ºÐ 50ÃÊ
370                // SPLÀº ³×¹øÂ° ÁÙ·Î ¿À°í ¹®ÀÚ¿­ÀÌ ¿À°í ÁٹٲÞÀÌ ¿Â´Ù.
371                // c41misccÀÇ 10.2ä³Î ¹®Á¦·Î ¾Æ·¡ ·çƾÀº »ç¿ëÇÒ¼ö ¾ø½¿
372                if (bKorean == false && window_data.window_styleID == 2 && column_count == 32)
373                {
374                        if (row_count == 2) row_count = 1;
375                        if (row_count == 3) row_count = 2;
376                        if (row_count == 4) row_count = 3;
377                }
378                if ( bDefined == true &&
379                        window_data.priority ==   priority &&
380                        window_data.anchor_point ==   anchor_point &&
381                        window_data.relative_positioning ==   relative_positioning &&
382                        window_data.anchor_vertical ==   anchor_vertical &&
383                        window_data.anchor_horizontal ==   anchor_horizontal &&
384                        window_data.row_count ==   row_count &&
385                        window_data.column_count ==   column_count &&
386                        window_data.row_lock ==   row_lock &&
387                        window_data.column_lock ==   column_lock &&
388                        window_data.visible ==   visible &&
389                        window_data.window_styleID ==   window_styleID &&
390                        window_data.pen_styleID ==   pen_styleID )
391                {
392                        if (debug_cc) DST_Printf("Same Define Window. Ignore\n");
393                        return;
394                }
395    // PBS_CCD  row_count°¡ Á¡Á¡ ÁÙ¾îµå´Â °æ¿ì ´ëÀÀ
396    if (window_data.row_count >   row_count)
397    {
398        for (int i = 0; i < window_data.row_count - row_count; i++)
399        {
400                ScrollUp();
401                if (pos_y > 0) pos_y--;
402        }
403        }
404                window_data.priority =   priority;
405                window_data.anchor_point =   anchor_point;
406                window_data.relative_positioning =   relative_positioning;
407                window_data.anchor_vertical =   anchor_vertical;
408                window_data.anchor_horizontal =   anchor_horizontal;
409                window_data.row_count =   row_count;
410                window_data.column_count =   column_count;
411                window_data.row_lock =   row_lock;
412                window_data.column_lock =   column_lock;
413                window_data.visible =   visible;
414                window_data.window_styleID =   window_styleID;
415                window_data.pen_styleID =   pen_styleID;
416
417                // À©µµ¿ì ½ºÅ¸ÀÏÀÌ 1~7 »çÀÌÀÇ °ªÀ̶ó¸é Àû¿ëÇÑ´Ù.
418                // ¸¸¾à 0À̶ó¸é »ý¼º½Ã¿¡¸¸ Àû¿ëÇÏÀÚ.
419                if (window_data.window_styleID == 0)
420                {
421                        if (bDefined == false) SetPredefinedWindowStyleID(1);
422                }
423                else
424                {
425                        SetPredefinedWindowStyleID(window_data.window_styleID);
426                }
427                // À©µµ¿ì ½ºÅ¸ÀÏÀÌ 1~7 »çÀÌÀÇ °ªÀ̶ó¸é Àû¿ëÇÑ´Ù.
428                // ¸¸¾à 0À̶ó¸é »ý¼º½Ã¿¡¸¸ Àû¿ëÇÏÀÚ.
429                if (window_data.pen_styleID == 0)
430                {
431                        if (bDefined == false) SetPredefinedPenStyleID(1);
432                }
433                else
434                {
435                        SetPredefinedPenStyleID(window_data.pen_styleID);
436                }
437                bDefined = true;
438                bNeedDraw = true;
439        }
440        // ÀÌ¹Ì Á¤ÀÇµÈ Ææ ½ºÅ¸ÀÏ °ªÀ¸·Î ¼³Á¤ÇÑ´Ù.
441        void SetPredefinedPenStyleID(unsigned char StyleID)
442        {
443                pen_data.pen_size = 1;
444                pen_data.font_style = 0;
445                pen_data.text_tag = 0;
446                pen_data.offset = 1;
447                pen_data.italics = 0;
448                pen_data.underline = 0;
449                pen_data.edge_type = 0;
450                // Set Pen Color
451                pen_data.fg_color.red = 2;
452                pen_data.fg_color.green = 2;
453                pen_data.fg_color.blue = 2;
454                pen_data.fg_opacity = 0;
455                pen_data.bg_color.red = 0;
456                pen_data.bg_color.green = 0;
457                pen_data.bg_color.blue = 0;
458                pen_data.bg_opacity = 0;
459                pen_data.edge_color.red = 0;
460                pen_data.edge_color.green = 0;
461                pen_data.edge_color.blue = 0;
462
463                switch (StyleID)
464                {
465                        case 2: pen_data.font_style = 1; break;
466                        case 3: pen_data.font_style = 2; break;
467                        case 4: pen_data.font_style = 3; break;
468                        case 5: pen_data.font_style = 4; break;
469                        case 6: pen_data.font_style = 3; pen_data.edge_type = 3; pen_data.bg_opacity = 3; break;
470                        case 7: pen_data.font_style = 4; pen_data.edge_type = 3; pen_data.bg_opacity = 3; break;
471                }
472        }
473        // ÀÌ¹Ì Á¤ÀÇµÈ À©µµ¿ì ½ºÅ¸ÀϷΠä¿î´Ù.
474        void SetPredefinedWindowStyleID(unsigned char StyleID)
475        {
476                window_data.justify = 0;
477                window_data.print_direction = 0;
478                window_data.scroll_direction = 3;
479                window_data.wordwrap = 1;
480                window_data.display_effect = 0;
481                window_data.effect_direction = 0;
482                window_data.effect_speed = 0;
483                window_data.fill_color.red = 0;
484                window_data.fill_color.green = 0;
485                window_data.fill_color.blue = 0;
486                window_data.fill_opacity = 0;
487                window_data.border_type = 0;
488                window_data.border_color.red = 0;
489                window_data.border_color.green = 0;
490                window_data.border_color.blue = 0;
491
492                switch (StyleID)
493                {
494                        case 2:
495                                 window_data.fill_opacity = 3;
496                                 break;
497                        case 3: window_data.justify = 2; break;
498                        case 4: window_data.wordwrap = 0; break;
499                        case 5: window_data.wordwrap = 0;
500                                window_data.fill_opacity = 3;
501                                break;
502                        case 6: window_data.wordwrap = 0; window_data.justify = 2; break;
503                        case 7: window_data.print_direction = 2; window_data.scroll_direction = 1; break;
504                }
505        }
506        void ClearWindow()
507        {
508                memset(&strText, 0, sizeof(DST_708_Char) * MAX_708_ROW * MAX_708_COL);
509                pos_x = 0;
510                pos_y = 0;
511                bNeedDraw = true;
512        }
513        void DeleteWindow()
514        {
515                if (bDefined == false) return;
516                UpdateScreen(); // ÃʱâÈ­Çϸé visible ¼Ó¼ºÀÌ ²¨Áö¹Ç·Î ¹Ì¸® ¾÷µ¥ÀÌÆ®¸¦ ÇÑ´Ù.
517                Initialize();
518        }
519        void DisplayWindow()
520        {
521                if (bDefined == false) return;
522                window_data.visible = true;
523                bNeedDraw = true;
524                bHide = false;
525                UpdateScreen();
526        }
527        void HideWindow()
528        {
529                if (bDefined == false) return;
530                window_data.visible = false;
531                bNeedDraw = true;
532                bHide = true;
533                UpdateScreen();
534        }
535        void ToggleWindow()
536        {
537                if (bDefined == false) return;
538                window_data.visible = !window_data.visible;
539                //bHide = !bHide;
540                bNeedDraw = true;
541                UpdateScreen();
542        }
543        void SetWindowAttribute(DS_U8 justify,
544                               DS_U8 print_direction,
545                               DS_U8 scroll_direction,
546                               DS_U8 wordwrap,
547                               DS_U8 display_effect,
548                               DS_U8 effect_direction,
549                               DS_U8 effect_speed,
550                               DS_U8 fill_color_red, //DST_708_Color fill_color,
551                               DS_U8 fill_color_green,
552                               DS_U8 fill_color_blue,
553                               DS_U8 fill_opacity,
554                               DS_U8 border_type,
555                               DS_U8 border_color_red, //DST_708_Color border_color
556                               DS_U8 border_color_green,
557                               DS_U8 border_color_blue)
558        {
559                if (bDefined == false) return;
560                window_data.justify =   justify;
561                window_data.print_direction =   print_direction;
562                window_data.scroll_direction =   scroll_direction;
563                window_data.wordwrap =   wordwrap;
564                window_data.display_effect =   display_effect;
565                window_data.effect_direction =   effect_direction;
566                window_data.effect_speed =   effect_speed;
567                window_data.fill_color.red =   fill_color_red;
568                window_data.fill_color.green =   fill_color_green;
569                window_data.fill_color.blue =   fill_color_blue;
570                window_data.fill_opacity =   fill_opacity;
571                window_data.border_type =   border_type;
572                window_data.border_color.red =   border_color_red;
573                window_data.border_color.green =   border_color_green;
574                window_data.border_color.blue =   border_color_blue;
575                bNeedDraw = true;
576                if (debug_cc)
577                {
578                        DST_Printf("SetWindowAttribute[%d]", nID);
579                        DST_Printf(" j(%d)", justify);
580                        DST_Printf(" p(%d)", print_direction);
581                        DST_Printf(" s(%d)", scroll_direction);
582                        DST_Printf(" w(%d)", wordwrap);
583                        DST_Printf(" e(%d)", display_effect);
584                        DST_Printf(" ed(%d)", effect_direction);
585                        DST_Printf(" es(%d)", effect_speed);
586                        DST_Printf(" fill(%d,%d,%d)", fill_color_red, fill_color_green, fill_color_blue);
587                        DST_Printf(" o(%d)", fill_opacity);
588                        DST_Printf(" b(%d)", border_type);
589                        DST_Printf(" border(%d,%d,%d)", border_color_red, border_color_green, border_color_blue);
590                        DST_Printf("\n");
591                }
592        }
593        void SetPenAttribute(   unsigned char pen_size,
594                                                                                unsigned char font_style,
595                                                                                unsigned char text_tag,
596                                                                                unsigned char offset,
597                                                                                unsigned char italics,
598                                                                                unsigned char underline,
599                                                                                unsigned char edge_type)
600        {
601                if (bDefined == false) return;
602                pen_data.pen_size =  pen_size;
603                pen_data.font_style =  font_style;
604                pen_data.text_tag =  text_tag;
605//              pen_data.offset =  offset;                2013.02.20 ±¹³»Çâ YTN ¹®Á¦·Î OFFSET Áö¿øÇÏÁö ¾Êµµ·Ï ÇÔ
606                pen_data.italics =  italics;
607                pen_data.underline =  underline;
608                pen_data.edge_type =  edge_type;
609                if (debug_cc)
610                {
611                        DST_Printf("SetPenAttribute[%d]", nID);
612                        DST_Printf(" size(%d)", pen_size);
613                        DST_Printf(" style(%d)", font_style);
614                        DST_Printf(" tt(%d)", text_tag);
615                        DST_Printf(" o(%d)", offset);
616                        DST_Printf(" i(%d)", italics);
617                        DST_Printf(" u(%d)", underline);
618                        DST_Printf(" b(%d)", edge_type);
619                        DST_Printf("\n");
620                }
621        }
622        void SetPenColor(       unsigned char fg_color_red,
623                                                   DS_U8 fg_color_green,
624                                                   DS_U8 fg_color_blue,
625                                                   DS_U8 fg_opacity,
626                                                   DS_U8 bg_color_red,
627                                                   DS_U8 bg_color_green,
628                                                   DS_U8 bg_color_blue,
629                                                   DS_U8 bg_opacity,
630                                                   DS_U8 edge_color_red,
631                                                   DS_U8 edge_color_green,
632                                                        unsigned char edge_color_blue)
633        {
634                if (bDefined == false) return;
635                // Set Pen Color
636                pen_data.fg_color.red = fg_color_red;
637                pen_data.fg_color.green = fg_color_green;
638                pen_data.fg_color.blue = fg_color_blue;
639                pen_data.fg_opacity = fg_opacity;
640                pen_data.bg_color.red = bg_color_red;
641                pen_data.bg_color.green = bg_color_green;
642                pen_data.bg_color.blue = bg_color_blue;
643                pen_data.bg_opacity = bg_opacity;
644                pen_data.edge_color.red = edge_color_red;
645                pen_data.edge_color.green = edge_color_green;
646                pen_data.edge_color.blue = edge_color_blue;
647                if (debug_cc)
648                {
649                        DST_Printf("SetPenColor[%d]", nID);
650                        DST_Printf(" fg_color(%d,%d,%d)", fg_color_red, fg_color_green, fg_color_blue);
651                        DST_Printf(" fg_o(%d)", fg_opacity);
652                        DST_Printf(" bg_color(%d,%d,%d)", bg_color_red, bg_color_green, bg_color_blue);
653                        DST_Printf(" bg_opacity(%d)", bg_opacity);
654                        DST_Printf(" edge_color(%d,%d,%d)", edge_color_red, edge_color_green, edge_color_blue);
655                        DST_Printf("\n");
656                }
657        }
658        void SetPenLocation(unsigned char x,DS_U8 y)
659        {
660                if (bDefined == false) return;
661                if (x > window_data.column_count) return;
662                if (y > window_data.row_count) return;
663                // 608 ¹®¹ýÀ» 708·Î ¿Å±â´Ù°¡ ¹ß»ýÇÏ´Â ¿À·ù¿¡ ´ëÀÀÇÑ´Ù.
664                // À©µµ¿ì ½ºÅ¸ÀÏÀÌ 2¹øÀÎ °æ¿ì CRÀÌ ¿ÀÁö¾Ê°í SPL ¸¸ ¹Ýº¹Çؼ­ ¿À´Â °æ¿ì ´ëÀÀ PBS_CCD
665                // kcsm43.trp
666                pos_y = y;
667                // ¿ÞÂÊ Á¤·ÄÀÏ ¶§¸¸ x À§Ä¡¸¦ º¯°æÇÑ´Ù.
668//              if (window_data.justify != 0) return;
669                // ÇÑ±Û CCÀÎ °æ¿ì ¹ÝÀÚ󸮿¡ ´ëÇÑ Ã³¸® ´õ ÇÊ¿äÇÔ
670                if (bKorean == true)
671                {
672                        int nLineLength = GetStingLength(pos_y);
673                        int nCount = 0;
674                        for (int i = 0; i < nLineLength; i++)
675                        {
676                                nCount = IsFullCharater(strText[i][pos_y].nCode) ? nCount+2 : nCount+1;
677                                if (nCount < x) continue;
678                                // ÇöÀç ±ÛÀÚ µ¥ÀÌÅÍ ¾È¿¡ ÀÏÄ¡ÇÏ´Â À§Ä¡°¡ ÀÖ´Â °æ¿ì
679                                pos_x = i;
680                                return;
681                        }
682                        pos_x = nLineLength + x - nCount;
683                }
684                else
685                {
686                        if (window_data.justify == 0)
687                        {
688                                pos_x = x;
689                        }
690                        else
691                        {
692                                for (int x = 0; x < MAX_708_COL; x++) strText[x][pos_y].nCode = 0; // ÇöÀç ÁÙÀÇ Á¤º¸¸¦ Áö¿î´Ù.
693                                pos_x = 0;
694                        }
695                }
696        }
697        void Reset()
698        {
699                window_data.visible = false;
700                if (bDefined == false) return;
701                DeleteWindow();
702        }
703        // 1-Line Scroll Up
704        void ScrollUp()
705        {
706                for (int y = 0; y < MAX_708_ROW - 1; y++) for (int x = 0; x < MAX_708_COL; x++) strText[x][y] = strText[x][y+1];
707                for (int x = 0; x < MAX_708_COL; x++) memset(&strText[x][MAX_708_ROW-1], 0, sizeof(DST_708_Char));
708        }
709        // Multi-Line Scroll Up
710        void ScrollUp(int nLines)
711        {
712                for (int i = 0; i < nLines; i++)  ScrollUp();
713        }
714        // 1-Line Scroll Down
715        void ScrollDown()
716        {
717                for (int y = 0; y < MAX_708_ROW - 1; y++) for (int x = 0; x < MAX_708_COL; x++) strText[x][y+1] = strText[x][y];
718                for (int x = 0; x < MAX_708_COL; x++) memset(&strText[x][0], 0, sizeof(DST_708_Char));
719        }
720        // Multi-Line Scroll Down
721        void ScrollDown(int nLines)
722        {
723                for (int i = 0; i < nLines; i++)  ScrollDown();
724        }
725
726        // ÇÑ±Û ÀüÀÚÀÎÁö ¹ÝÀÚÀÎÁö ÀüÀÚ¶ó¸é true¸¦ return ÇÑ´Ù.
727        bool IsFullCharater(DS_U16 nCode) // ÄÚµå´Â À¯´ÏÄÚµåÀÌ´Ù.
728        {
729                if (0x1100 <= nCode && nCode < 0x1200) return true; // ÇÑ±Û ÀÚ¸ð
730                if (0x2113 <= nCode && nCode < 0x2127) return true; //  Tel, TM µî
731                if (0x2E80 <= nCode && nCode < 0xA500) return true; //  È÷¶ó°¡³ª, °¡Å¸Ä«³ª
732                if (0xAC00 <= nCode && nCode < 0xD800) return true; //  ÇѱÛ
733                if (0xF900 <= nCode && nCode < 0xFB00) return true; //  CJK compatibility ideographs
734                if (0xFE30 <= nCode && nCode < 0xFE50) return true; //  CJK compatibility forms
735                return false;
736        }
737
738        void AddChar(DS_U16 data)
739        {
740//              if (bHide == true) return; // C16S6Pkc 10.3
741#if 0 // 080703_dfa_buick_csd
742                if (window_data.scroll_direction == 2)
743                {
744                        AddCharTopToBottom(data); // À§¿¡¼­ ¾Æ·¡·Î ½ºÅ©·Ñ ´Ù¿î
745                }
746                else
747#endif
748                {
749                        AddCharBottomToTop(data); // ¾Æ·¡¿¡¼­ À§·Î ½ºÅ©·Ñ ¾÷
750                }
751        }
752        // Bottom to Top
753        void AddCharBottomToTop(DS_U16 data)
754        {
755                int nOverLines = GetStringLines() - window_data.row_count - 1;
756                if (nOverLines > 0) ScrollUp(nOverLines);
757                if (data == 0x08) // Back Space
758                {
759                        if (pos_x == 0) return;
760                        strText[pos_x][pos_y].nCode = 0;
761                        pos_x--;
762                        bNeedDraw = true;
763                        return;
764                }
765                if (data == 0x0C) // FF À©µµ¿ìÀÇ ¸Ç óÀ½ À§Ä¡·Î µ¹¾Æ°£´Ù.
766                {
767                        ClearWindow(); // c67gsetaÀÇ 10.3ä³Î È­¸éÀ» Áö¿ì°í óÀ½À¸·Î µ¹¾Æ°£´Ù.
768                        return;
769                }
770                if (data == 0x0E) // HCR ÇØ´çÁÙÀÇ Á¤º¸¸¦ Áö¿ì°í óÀ½ À§Ä¡·Î µ¹¾Æ°£´Ù.
771                {
772                        for (int x = 0; x < MAX_708_COL; x++) memset(&strText[x][pos_y], 0, sizeof(DST_708_Char));
773                        pos_x = 0;
774                        bNeedDraw = true;
775                        return;
776                }
777                if (data == 0x0D) // °³Çà ¹®ÀÚ
778                {
779                        // 608 ¹ø¿ª ¿À·ù ´ëÀÀ WindowStyleÀÌ 5ÀÎ °æ¿ì´Â CRÀÌ ¿À¸é ¹«Á¶°Ç ÁÙ¹Ù²Þ ¼öÇà
780                        // PBS CCD.trp
781                        if ( /*window_data.window_styleID == 4 || */
782                                (bKorean == false && window_data.window_styleID == 5 && pos_y != 0) ||
783                                pos_y >= window_data.row_count ||
784                                pos_y >= MAX_708_ROW-1)
785                        {
786                                ScrollUp(); // ÇÑÁÙ Á¦°Å
787                                bNeedDraw = true;
788                        }
789                        else
790                        {
791                                pos_y++;
792                        }
793                        pos_x = 0;
794                        return;
795                }
796                // ¹®ÀÚ¿­ÀÌ Column Count º¸´Ù Å« °æ¿ì ´ÙÀ½ ÁÙ·Î º¸³½´Ù.
797                if (bKorean == true)
798                {
799                        int nLineLength = GetStingLength(pos_y);
800                        int nCount = 0;
801                        for (int i = 0; i < nLineLength; i++)
802                        {
803                                nCount = IsFullCharater(strText[i][pos_y].nCode) ? nCount+2 : nCount+1;
804                        }
805                        if (nCount >= window_data.column_count + 1 || nCount >= MAX_708_COL)
806                        {
807                                pos_y++;
808                                pos_x = 0;
809                        }
810                }
811                else
812                {
813                        if (pos_x > window_data.column_count + 1 || pos_x >= MAX_708_COL)
814                        {
815                                pos_y++;
816                                pos_x = 0;
817                        }
818                }
819                // ¹®ÀÚ¿­ÀÌ Row Count º¸´Ù Å« °æ¿ì ½ºÅ©·Ñ ¾÷ÇÑ´Ù.
820                if (pos_y >= window_data.row_count + 1 || pos_y >= MAX_708_ROW)
821                {
822                        ScrollUp(); // ÇÑÁÙ Á¦°Å
823                        pos_y--;
824                }
825                strText[pos_x][pos_y].nCode = data;
826                strText[pos_x][pos_y].pen = pen_data;
827                pos_x++;
828                bNeedDraw = true;
829                //DST_Printf("%d %d %d\n", pos_x, pos_y, data);
830        }
831        // Top to Bottom
832        void AddCharTopToBottom(DS_U16 data)
833        {
834                int nOverLines = GetStringLines() - window_data.row_count - 1;
835                if (nOverLines > 0) ScrollDown(nOverLines);
836                if (data == 0x08) // Back Space
837                {
838                        if (pos_x == 0) return;
839                        strText[pos_x][pos_y].nCode = 0;
840                        pos_x--;
841                        bNeedDraw = true;
842                        return;
843                }
844                if (data == 0x0C) // FF À©µµ¿ìÀÇ ¸Ç óÀ½ À§Ä¡·Î µ¹¾Æ°£´Ù.
845                {
846                        ClearWindow(); // c67gsetaÀÇ 10.3ä³Î È­¸éÀ» Áö¿ì°í óÀ½À¸·Î µ¹¾Æ°£´Ù.
847                        return;
848                }
849                if (data == 0x0E) // HCR ÇØ´çÁÙÀÇ Ã³À½ À§Ä¡·Î µ¹¾Æ°£´Ù.
850                {
851                        for (int x = 0; x < MAX_708_COL; x++) memset(&strText[x][pos_y], 0, sizeof(DST_708_Char));
852                        pos_x = 0;
853                        bNeedDraw = true;
854                        return;
855                }
856                if (data == 0x0D) // °³Çà ¹®ÀÚ
857                {
858                        ScrollDown(); // ÇÑÁÙ Á¦°Å
859                        bNeedDraw = true;
860                        pos_y = 0;
861                        pos_x = 0;
862                        return;
863                }
864                // ¹®ÀÚ¿­ÀÌ Column Count º¸´Ù Å« °æ¿ì ´ÙÀ½ ÁÙ·Î º¸³½´Ù.
865                if (bKorean == true)
866                {
867                        int nLineLength = GetStingLength(pos_y);
868                        int nCount = 0;
869                        for (int i = 0; i < nLineLength; i++)
870                        {
871                                nCount = IsFullCharater(strText[i][pos_y].nCode) ? nCount+2 : nCount+1;
872                        }
873                        if (nCount >= window_data.column_count + 1 || nCount >= MAX_708_COL)
874                        {
875                                ScrollDown(); // ÇÑÁÙ Á¦°Å
876                                pos_y = 0;
877                                pos_x = 0;
878                        }
879                }
880                else
881                {
882                if (pos_x >= window_data.column_count || pos_x >= MAX_708_COL-1)
883                {
884                        ScrollDown(); // ÇÑÁÙ Á¦°Å
885                        pos_y = 0;
886                        pos_x = 0;
887                }
888                }
889                strText[pos_x][pos_y].nCode = data;
890                strText[pos_x][pos_y].pen = pen_data;
891                pos_x++;
892                bNeedDraw = true;
893        }
894        // ARGB °ªÀ» 8ºñÆ®·Î º¯È¯
895        unsigned char ARGB(unsigned char alpha,DS_U8 red,DS_U8 green,DS_U8 blue)
896        {
897                if (alpha == 0 || alpha > 2) return 0;
898                return (alpha & 0x03) * 64 + (red & 0x03) * 16 + (green & 0x03) * 4  + (blue & 0x03);
899        }
900        // ºÒÅõ¸í »öÀ» 8ºñÆ®·Î º¯È¯
901        unsigned char S_RGB(DST_708_Color color)
902        {
903                return ARGB(2, color.red, color.green, color.blue);
904        }
905        // ¹ÝÅõ¸í »öÀ» 8ºñÆ®·Î º¯È¯
906        unsigned char T_RGB(DST_708_Color color)
907        {
908                return ARGB(1, color.red, color.green, color.blue);
909        }
910        // Border Size¸¦ ¹ÝȯÇÑ´Ù.
911        int GetBorderSize()
912        {
913                return DST_GetCCScreenHeight() / 200;
914        }
915
916        OSD_PIXEL_T ColorConvert(DS_U8 c)
917        {
918                DS_U32 color = 0;
919                switch (c & 0xC0)
920                {
921                        case 0x40: // ¹ÝÅõ¸í
922                                color = 0x7F000000 + (c & 0x30) * 348160 + (c & 0x0C) * 5440 + (c & 0x03) * 85;
923                                break;
924                        case 0x80: // ºÒÅõ¸í
925                                color = 0xFF000000 + (c & 0x30) * 348160 + (c & 0x0C) * 5440 + (c & 0x03) * 85;;
926                                break;
927                }
928                return CONV32_16(color);
929        }
930        DS_U8 GetBackGroundColor(bool bFlash)
931        {
932                if (window_data.fill_opacity == 3) return COLOR_TRANSPARENT;
933                if (bFlash && window_data.fill_opacity == 1) return COLOR_TRANSPARENT;
934                if (window_data.fill_opacity == 2) return T_RGB(window_data.fill_color);
935                return S_RGB(window_data.fill_color);
936        }
937        void DrawBackGround(bool bFlash)
938        {
939                if (imgBuff == 0) return;
940                OSD_PIXEL_T color = ColorConvert(GetBackGroundColor(bFlash));
941                int nSize = rect.w * rect.h;
942                if (color == 0)
943                {
944                        memset(imgBuff, 0, nSize * sizeof(OSD_PIXEL_T));
945                }
946                else
947                {
948                        OSD_PIXEL_T* buff = imgBuff;
949                        while (nSize--) *buff++ = color;
950                }
951        }
952        // ÇØ´ç ÁÙ¿¡´Â ¸î ±ÛÀÚÀÇ Á¤º¸°¡ ÀÖ´ÂÁö
953        int GetStingLength(int nLine)
954        {
955                for (int x = MAX_708_COL - 1; x >= 0; x--) if (strText[x][nLine].nCode != 0) return x+1;
956                return 0;
957        }
958        // ¸î ÁÙÀÇ µ¥ÀÌÅͰ¡ ÀÖ´ÂÁö
959        int GetStringLines()
960        {
961                for (int y = MAX_708_ROW - 1; y >= 0; y--) if (GetStingLength(y) != 0) return y+1;
962                return 0;
963        }
964
965        void DrawStrings(bool bFlash)
966        {
967                int y_pos = 0;
968                int nLines = GetStringLines();
969                int nOldHeight = GetCharHeight();
970                        for (int y = 0; y < nLines; y++)
971                        {
972                                int x_pos = 0;
973                                OSD_PIXEL_T *LineBuff = GetLineImage(y, &nLineWidth[y], &nLineHeight[y], bFlash);
974                                switch (window_data.justify)
975                                {
976                                        case 1: x_pos = rect.w - nLineWidth[y]; break; // right justify
977                                        case 2: x_pos = (rect.w - nLineWidth[y])/2; break;// center justify
978                                }
979                                DrawImage(x_pos, y_pos, nLineWidth[y], nLineHeight[y], LineBuff);
980                                DST_OS_Free(&LineBuff);
981                                if (nLineHeight[y] == 0) nLineHeight[y] = nOldHeight;
982                                y_pos+=nLineHeight[y];
983                                nLineWidth[y] = 0;
984                                nLineHeight[y] = 0;
985                        }
986                }
987
988        void DrawImage(int x_pos, int y_pos, int w, int h, OSD_PIXEL_T *buff)
989        {
990                if (imgBuff == 0) return;
991                if (x_pos + w > rect.w) // È­¸é¿¡ ±×·ÁÁú À̹ÌÁö°¡ È­¸éº¸´Ù Å« °æ¿ì µÞºÎºÐÀ» ¹ö¸°´Ù.
992                {
993                        int ww = rect.w - x_pos;
994                        if (ww <= 0) return;
995                        for (int y = 0; y < h; y++)
996                        {
997                                for (int x = 0; x < ww; x++) buff[y*ww+x] = buff[y*w+x];
998                        }
999                        DrawImage(x_pos, y_pos, ww, h, buff);
1000                        return;
1001                }
1002                       
1003                OSD_PIXEL_T *src = buff;
1004                OSD_PIXEL_T *des = imgBuff + y_pos * rect.w + x_pos;
1005                int des_delta = rect.w - w;
1006                int y = h;
1007                while (y--)
1008                {
1009                        int x = w;
1010                        while (x--)
1011                        {
1012                                if (*src != 0) *des = *src;
1013                                src++;
1014                                des++;
1015                        }
1016                        des +=  des_delta;
1017                }
1018        }
1019
1020        int GetCharHeight()
1021        {
1022                int nFontSize = DST_708_GetFontSize(1); // Default, Medium
1023                switch (DST_CC_GetSize())
1024                {
1025                        case 1: nFontSize = DST_708_GetFontSize(0); break;// Small
1026                        case 3: nFontSize =  DST_708_GetFontSize(2); break;// Large
1027                }
1028                return DST_GetFontHeight(nFontSize);
1029        }
1030
1031        int GetCharWidth()
1032        {
1033                if (bKorean)
1034                {
1035                        return GetCharHeight() * 45 / 100; // ±ÛÀÚ ³ôÀÌÀÇ 40%¸¦ ±âº» ÆøÀ¸·Î ÇÑ´Ù.
1036                }
1037                return GetCharHeight() * 45 / 100; // ±ÛÀÚ ³ôÀÌÀÇ 40%¸¦ ±âº» ÆøÀ¸·Î ÇÑ´Ù.
1038        }
1039        // CC Á¤º¸ÀÇ ÆùÆ® »çÀÌÁ ÆùÆ®¿£ÁøÀÇ ÆùÆ® »çÀÌÁî °ªÀ¸·Î ¹Ù²Û´Ù.
1040        unsigned char ConvertFontSize(unsigned char nSize)
1041        {
1042          return DST_708_GetFontSize((DST_CC_GetSize() == 0) ? nSize : DST_CC_GetSize() - 1);
1043        }
1044        // CC Á¤º¸ÀÇ ÆùÆ® ½ºÅ¸Àϸ¦ ÆùÆ®¿£ÁøÀÇ ÆùÆ® ½ºÅ¸ÀÏ °ªÀ¸·Î ¹Ù²Û´Ù.
1045        unsigned char ConvertFontStyle(unsigned char nStyle)
1046        {
1047                if (bKorean == true) return 0; // Çѱ¹ÇâÀÎ °æ¿ì Ç×»ó ±âº» ÆùÆ®¸¦ ¾´´Ù.
1048                return (nStyle == 0) ? 4 : nStyle; // ¹ÌÁÖÇâÀÇ ±âº» ÆùÆ®´Â 4.Proportionally without serifs.ttf
1049        }
1050        // CC Á¤º¸ÀÇ ÆùÆ® italic¸¦ ÆùÆ®¿£ÁøÀÇ italic °ªÀ¸·Î ¹Ù²Û´Ù.
1051        bool ConvertFontItalic(unsigned char italics)
1052        {
1053                switch (DST_CC_GetItalic())
1054                {
1055                        case 0: return italics == 0 ? false : true;// default
1056                        case 1: return true; // Italic on
1057                }
1058                return false;
1059        }
1060        // CC Á¤º¸ÀÇ ÆùÆ® edge style¸¦ ÆùÆ®¿£ÁøÀÇ edge style °ªÀ¸·Î ¹Ù²Û´Ù.
1061        unsigned char ConvertFontEdgeStyle(unsigned char edge_type)
1062        {
1063                return (DST_CC_GetEdge() == 0) ? edge_type : DST_CC_GetEdge() - 1;
1064        }
1065        // CC Á¤º¸ÀÇ ÆùÆ® Underline¸¦ ÆùÆ®¿£ÁøÀÇ underline °ªÀ¸·Î ¹Ù²Û´Ù.
1066        bool ConvertFontUnderLine(unsigned char underline)
1067        {
1068                switch (DST_CC_GetUnderline())
1069                {
1070                        case 0: return underline == 0 ? false : true; // default
1071                        case 1: return true; // underline on
1072                }
1073                return false;
1074        }
1075        // CC Á¤º¸ÀÇ ÆùÆ® Offset¸¦ ÆùÆ®¿£ÁøÀÇ Offset °ªÀ¸·Î ¹Ù²Û´Ù.
1076        unsigned char ConvertFontOffset(unsigned char offset)
1077        {
1078                switch (offset)
1079                {
1080                        case 0: return 1; // Sub Script
1081                        case 1: return 0; // normal
1082                        case 2: return 2; // Super Script
1083                }
1084                return 0;
1085        }
1086        // CC Á¤º¸ÀÇ Font Color¸¦ ÆùÆ®¿£ÁøÀÇ Font Color °ªÀ¸·Î ¹Ù²Û´Ù.
1087        //  0=Auto 1=Solid 2=TransParent 3=translucent 4=flashing
1088        // opacity 0 = solid 1=flahing 2= translucent 4 = transparent
1089        unsigned char ConvertFontColor(unsigned char opacity, DST_708_Color color, bool bFlash)
1090        {
1091                switch (DST_CC_GetColor())
1092                {
1093                        case 1: color.red = 0; color.green = 0; color.blue = 0; break; // black
1094                        case 2: color.red = 3; color.green = 3; color.blue = 3; break; // white
1095                        case 3: color.red = 3; color.green = 0; color.blue = 0; break; // red
1096                        case 4: color.red = 0; color.green = 3; color.blue = 0; break; // green
1097                        case 5: color.red = 0; color.green = 0; color.blue = 3; break; // blue
1098                        case 6: color.red = 3; color.green = 3; color.blue = 0; break; // yellow
1099                        case 7: color.red = 3; color.green = 0; color.blue = 3; break; // magenta
1100                        case 8: color.red = 0; color.green = 3; color.blue = 3; break; // cyan
1101                }
1102
1103                switch (DST_CC_GetOpacity())
1104                {
1105                        case 0: // default
1106                                switch (opacity)
1107                                {
1108                                        case 0: return S_RGB(color); // Solid
1109                                        case 1: return (bFlash) ? COLOR_TRANSPARENT : S_RGB(color);// Flash
1110                                        case 2: return T_RGB(color);// TransLucent
1111                                        case 3: return COLOR_TRANSPARENT;
1112                                }
1113                                break;
1114                        case 1: // Solid
1115                                return S_RGB(color);
1116                        case 2: // TransParent
1117                                return COLOR_TRANSPARENT;
1118                        case 3: // Translucent
1119                                return T_RGB(color);
1120                        case 4: // Flashing
1121                                return (bFlash) ? COLOR_TRANSPARENT : S_RGB(color);
1122                }
1123                return S_RGB(color);
1124        }
1125        // CC Á¤º¸ÀÇ edge Color¸¦ ÆùÆ®¿£ÁøÀÇ edge Color °ªÀ¸·Î ¹Ù²Û´Ù.
1126        //  0=Auto 1=Solid 2=TransParent 3=translucent 4=flashing
1127        // opacity 0 = solid 1=flahing 2= translucent 4 = transparent
1128        unsigned char ConvertFontEdgeColor(unsigned char opacity, DST_708_Color color, bool bFlash)
1129        {
1130                switch (DST_CC_GetEdgeColor())
1131                {
1132                        case 1: color.red = 0; color.green = 0; color.blue = 0; break; // black
1133                        case 2: color.red = 3; color.green = 3; color.blue = 3; break; // white
1134                        case 3: color.red = 3; color.green = 0; color.blue = 0; break; // red
1135                        case 4: color.red = 0; color.green = 3; color.blue = 0; break; // green
1136                        case 5: color.red = 0; color.green = 0; color.blue = 3; break; // blue
1137                        case 6: color.red = 3; color.green = 3; color.blue = 0; break; // yellow
1138                        case 7: color.red = 3; color.green = 0; color.blue = 3; break; // magenta
1139                        case 8: color.red = 0; color.green = 3; color.blue = 3; break; // cyan
1140                }
1141                switch (DST_CC_GetOpacity())
1142                {
1143                        case 0: // default
1144                                switch (opacity)
1145                                {
1146                                        case 0: return S_RGB(color); // Solid
1147                                        case 1: return (bFlash) ? COLOR_TRANSPARENT : S_RGB(color);// Flash
1148                                        case 2: return T_RGB(color);// TransLucent
1149                                        case 3: return COLOR_TRANSPARENT;
1150                                }
1151                                break;
1152                        case 1: // Solid
1153                                return S_RGB(color);
1154                        case 2: // TransParent
1155                                return COLOR_TRANSPARENT;
1156                        case 3: // Translucent
1157                                return T_RGB(color);
1158                        case 4: // Flashing
1159                                return (bFlash) ? COLOR_TRANSPARENT : S_RGB(color);
1160                }
1161                return S_RGB(color);
1162        }
1163
1164        // CC Á¤º¸ÀÇ back Color¸¦ ÆùÆ®¿£ÁøÀÇ back Color °ªÀ¸·Î ¹Ù²Û´Ù.
1165        //  0=Auto 1=Solid 2=TransParent 3=translucent 4=flashing
1166        // opacity 0 = solid 1=flahing 2= translucent 4 = transparent
1167        unsigned char ConvertFontBackColor(unsigned char opacity, DST_708_Color color, bool bFlash)
1168        {
1169                switch (DST_CC_GetBackColor())
1170                {
1171                        case 1: color.red = 0; color.green = 0; color.blue = 0; break; // black
1172                        case 2: color.red = 3; color.green = 3; color.blue = 3; break; // white
1173                        case 3: color.red = 3; color.green = 0; color.blue = 0; break; // red
1174                        case 4: color.red = 0; color.green = 3; color.blue = 0; break; // green
1175                        case 5: color.red = 0; color.green = 0; color.blue = 3; break; // blue
1176                        case 6: color.red = 3; color.green = 3; color.blue = 0; break; // yellow
1177                        case 7: color.red = 3; color.green = 0; color.blue = 3; break; // magenta
1178                        case 8: color.red = 0; color.green = 3; color.blue = 3; break; // cyan
1179                }
1180
1181                switch (DST_CC_GetBackOpacity())
1182                {
1183                        case 0: // default
1184                                switch (opacity)
1185                                {
1186                                case 0: return S_RGB(color); // Solid
1187                                case 1: return (bFlash) ? COLOR_TRANSPARENT : S_RGB(color);// Flash
1188                                case 2: return T_RGB(color);// TransLucent
1189                                case 3: return COLOR_TRANSPARENT;
1190                                }
1191                                break;
1192                        case 1: // Solid
1193                                return S_RGB(color);
1194                        case 2: // TransParent
1195                                return COLOR_TRANSPARENT;
1196                        case 3: // Translucent
1197                                return T_RGB(color);
1198                        case 4: // Flashing
1199                                return (bFlash) ? COLOR_TRANSPARENT : S_RGB(color);
1200                }
1201                return S_RGB(color);
1202        }
1203        DS_U8 CalcColor(DS_U8 foreColor, DS_U8 backColor)
1204        {
1205                switch (foreColor & 0xC0)
1206                {
1207                        case 0x40: // ¹ÝÅõ¸í
1208                        case 0x80: // ºÒÅõ¸í
1209                                return foreColor;
1210                }
1211                return backColor; // Åõ¸í
1212        }
1213        FONT_CC ConvertCCStyleToFontStyle(DST_708_Char cc, bool bFlash)
1214        {
1215                FONT_CC font;
1216                font.nCode = cc.nCode;
1217                font.nSize = ConvertFontSize(cc.pen.pen_size);
1218                font.nStyle = ConvertFontStyle(cc.pen.font_style);
1219                font.bItalic = ConvertFontItalic(cc.pen.italics);
1220                font.nEdgeType = ConvertFontEdgeStyle(cc.pen.edge_type);
1221                font.bUnderLine = ConvertFontUnderLine(cc.pen.underline);
1222                font.nOffset = ConvertFontOffset(cc.pen.offset);
1223
1224                DS_U8 backWindowColor = GetBackGroundColor(bFlash);
1225                DS_U8 foreGroundColor = ConvertFontColor(cc.pen.fg_opacity, cc.pen.fg_color, bFlash);
1226                DS_U8 edgeColor = ConvertFontEdgeColor(cc.pen.fg_opacity, cc.pen.edge_color, bFlash);
1227                DS_U8 backGroundColor = ConvertFontBackColor(cc.pen.bg_opacity, cc.pen.bg_color, bFlash);
1228
1229                font.Color = ColorConvert(CalcColor(foreGroundColor, backWindowColor));
1230                font.EdgeColor = ColorConvert(CalcColor(edgeColor, backWindowColor));
1231                font.BackColor = ColorConvert(CalcColor(backGroundColor, backWindowColor));
1232                return font;
1233        }
1234
1235        // È£ÃâÀÚ¿¡¼­ ¸Þ¸ð¸® ÇØÁ¦
1236        OSD_PIXEL_T * GetLineImage(int nLine, int *nWidth, int *nHeight, bool bFlash)
1237        {
1238                int nStrLen = GetStingLength(nLine);
1239                if (nStrLen == 0)
1240                {
1241                        *nWidth = 0;
1242                        *nHeight = 0;
1243                        return 0;
1244                }
1245
1246                static FONT_CC strFont[MAX_708_COL];
1247                for (int x = 0; x < nStrLen; x++)
1248                {
1249                        strFont[x] = ConvertCCStyleToFontStyle(strText[x][nLine], bFlash);
1250                }
1251
1252                // Åõ¸í °ø¹é ¹®ÀÚÀÇ Å©±â´Â Åõ¸í °ø¹é¹®ÀÚ°¡ ¾Æ´Ñ ù ±ÛÀÚ¿Í °°°Ô ÇÑ´Ù.
1253                int nDefaultSize = strFont[0].nSize;
1254                for (int x = 0; x < nStrLen; x++)
1255                {
1256                        if (strFont[x].nCode == 0) continue;
1257                        nDefaultSize = strFont[x].nSize;
1258                        break;
1259                }
1260                //  Åõ¸í °ø¹é ¹®ÀÚ Ã¤¿ì±â
1261                for (int x = 0; x < nStrLen; x++)
1262                {
1263                        if (strFont[x].nCode != 0) continue;
1264                        strFont[x].nCode = ' ';
1265                        strFont[x].nSize = nDefaultSize;
1266                        strFont[x].nStyle = 0;
1267                        strFont[x].bItalic = false;
1268                        strFont[x].nEdgeType = 0;
1269                        strFont[x].bUnderLine = false;
1270                        strFont[x].nOffset = 0;
1271                        strFont[x].Color = COLOR_TRANSPARENT;
1272                        strFont[x].EdgeColor = COLOR_TRANSPARENT;
1273                        strFont[x].BackColor = COLOR_TRANSPARENT;
1274                }
1275
1276                *nWidth = DST_GetFontWidthCC(strFont, nStrLen);
1277                *nHeight = DST_GetFontHeightCC(strFont, nStrLen);
1278                OSD_PIXEL_T *LineBuff = (OSD_PIXEL_T *)DST_OS_Malloc(*nWidth * *nHeight * sizeof(OSD_PIXEL_T));
1279                DST_GetFontImageCC(strFont, nStrLen, LineBuff);
1280                return LineBuff;
1281        }
1282
1283        void Resize(bool bFlash) // À©µµ¿ìÀÇ »çÀÌÁ Àç Á¶Á¤ÇÑ´Ù.
1284        {
1285                // define window ¿¡ ÀÇÇÑ ±âº» Å©±â
1286                int default_width = GetCharWidth() * (window_data.column_count+1);
1287                int default_height =  GetCharHeight() * (window_data.row_count+1);
1288
1289                // È­¸é¿¡ Ç¥½ÃµÈ ±ÛÀÚ¿¡ ÀÇÇÑ Å©±â Á¶Á¤
1290                int nMaxWidth = 0;
1291                int nTotalHeight = 0;
1292                int nOldHeight = GetCharHeight();
1293                int nLines = GetStringLines();
1294                bool bReachMaxColumn = false; // column count¸¦ ³Ñ¾ú´ÂÁö
1295                // °¢ ¶óÀκ°·Î À̹ÌÁö¸¦ ±×·Áº»´Ù.
1296                for (int y = 0; y < nLines; y++)
1297                {
1298                        if (GetStingLength(y) >= window_data.column_count+1) bReachMaxColumn = true;
1299                        OSD_PIXEL_T* LineBuff = GetLineImage(y, &nLineWidth[y], &nLineHeight[y], bFlash);
1300                        DST_OS_Free(&LineBuff);
1301                        if (nMaxWidth < nLineWidth[y]) nMaxWidth = nLineWidth[y];
1302                        if (nLineHeight[y] == 0) nLineHeight[y] = nOldHeight; // ºóÁÙÀÌ¸é ŸÁÙÀÇ ³ôÀ̸¦ ¾´´Ù.
1303                        nOldHeight = nLineHeight[y];
1304                        nTotalHeight += nLineHeight[y];
1305                }
1306
1307                if (bReachMaxColumn)
1308                {
1309                        rect.w = nMaxWidth;
1310                }
1311                else
1312                {
1313                        rect.w =  (nMaxWidth > default_width) ? nMaxWidth : default_width;
1314                }
1315                if (rect.w == 0) return;
1316                rect.h = (nTotalHeight > default_height) ? nTotalHeight : default_height;
1317                if (rect.h == 0) return;
1318
1319                int nScreenHeight = DST_GetCCScreenHeight();
1320                int nScreenWidth = DST_GetCCScreenWidth();
1321
1322                if (rect.w > nScreenWidth) rect.w = nScreenWidth;
1323                if (rect.h > nScreenHeight) rect.h = nScreenHeight;
1324
1325                // ¸¸¾à ³ôÀ̰¡ ³ÑÃļ­ º¸Á¤ÀÌ µÇ¾ú´Ù¸é °¢ ¶óÀκ°·Îµµ º¸Á¤ÀÌ ÀÌ·ç¾îÁ®¾Æ ÇÑ´Ù.
1326                int nDataEmptyHeight = 0;
1327                int nDataHeight = 0;
1328                int nEmptyLineCount = 0;
1329                for (int y = 0; y < nLines; y++)
1330                {
1331                        nDataEmptyHeight += nLineHeight[y];
1332                        if (nLineWidth[y] == 0)
1333                        {
1334                                nEmptyLineCount++;
1335                        }
1336                        else
1337                        {
1338                                nDataHeight += nLineHeight[y];
1339                        }
1340                }
1341
1342                if (nDataHeight > rect.h)
1343                {
1344                        DST_Printf("Error || OVER HEIGHT\n");
1345                }
1346                else
1347                {
1348                        if (nDataEmptyHeight > rect.h)
1349                        {
1350                                int nCompensation = (rect.h - nDataHeight) / nEmptyLineCount;
1351                                DST_Printf("nCompensation = %d\n", nCompensation);
1352                                for (int y = 0; y < nLines; y++)
1353                                {
1354                                        if (nLineWidth[y] != 0) continue;
1355                                        nLineHeight[y] = nCompensation;
1356                                }
1357                        }
1358                }
1359
1360
1361                // À©µµ¿ìÀÇ ½ÃÀÛ À§Ä¡¸¦ ±¸ÇÑ´Ù.
1362                int default_x = 0;
1363                int default_y = 0;
1364
1365
1366                int max_x = nScreenWidth - 1;
1367                int max_y = nScreenHeight - 1;
1368                if (window_data.relative_positioning == 1)
1369                {
1370                        default_x = max_x * window_data.anchor_horizontal / 99;
1371                        default_y = max_y * window_data.anchor_vertical / 99;
1372                }
1373                else
1374                {
1375                        if (bWideScreen)
1376                        {
1377                                default_x = max_x * window_data.anchor_horizontal / 209;
1378                                default_y = max_y * window_data.anchor_vertical / 74;
1379                        }
1380                        else
1381                        {
1382                                default_x = max_x * (window_data.anchor_horizontal + 25) / 209;
1383                                default_y = max_y * window_data.anchor_vertical / 74;
1384                        }
1385                }
1386                if (default_x < 0) default_x = 0;
1387                if (default_y < 0) default_y = 0;
1388                if (default_x > max_x) default_x = max_x;
1389                if (default_y > max_y) default_y = max_y;
1390
1391                switch (window_data.anchor_point)
1392                {
1393                        case 0: break;
1394                        case 1: default_x -= (rect.w/2); break;
1395                        case 2: default_x -= rect.w; break;
1396                        case 3: default_y -= (rect.h/2); break;
1397                        case 4: default_y -= (rect.h/2); default_x -= (rect.w/2); break;
1398                        case 5: default_y -= (rect.h/2); default_x -= rect.w; break;
1399                        case 6: default_y -= rect.h; break;
1400                        case 7: default_y -= rect.h; default_x -= (rect.w/2); break;
1401                        case 8: default_y -= rect.h; default_x -= rect.w; break;
1402                }
1403
1404                if (default_x + rect.w > nScreenWidth) default_x = nScreenWidth - rect.w;
1405                if (default_y + rect.h > nScreenHeight) default_y = nScreenHeight - rect.h;
1406
1407                if (default_x < 0) default_x = 0;
1408                if (default_y < 0) default_y = 0;
1409                if (default_x >= nScreenWidth) default_x = nScreenWidth - 1;
1410                if (default_y >= nScreenHeight) default_y = nScreenHeight - 1;
1411
1412                rect.x = default_x;
1413                rect.y = default_y;
1414        }
1415
1416        void Draw(bool bFlash)
1417        {
1418                if (GetVisible() == false || GetNeedRedraw() == false) return;
1419                UpdateScreen();
1420                Resize(bFlash);
1421                UpdateScreen();
1422                if (imgBuff) DST_OS_Free(&imgBuff);
1423                imgBuff = 0;
1424                if (rect.w == 0 || rect.h == 0) return;
1425                imgBuff = (OSD_PIXEL_T*)DST_OS_Malloc(rect.w * rect.h * sizeof(OSD_PIXEL_T));
1426                DrawBackGround(bFlash);
1427                DrawStrings(bFlash);
1428                SetNeedRedraw(false);
1429        }
1430
1431        void UpdateScreen()
1432        {
1433                DST_UpdateRegionAdd(rect);
1434        }
1435
1436        void UpdateScreen(int x, int y, int w, int h)
1437        {
1438                DST_RECT rectTemp;
1439                rectTemp.x = rect.x + x;
1440                rectTemp.y = rect.y + y;
1441                rectTemp.w = w;
1442                rectTemp.h = h;
1443                DST_UpdateRegionAdd(rectTemp);
1444        }
1445
1446        // Ç÷¡½Ã ŸÀ̸ӿ¡ ÀÇÇØ¼­ ÁÖ±âÀûÀ¸·Î È£ÃâµÈ´Ù.
1447        void OnFlash()
1448        {
1449                if (GetVisible() == false || bNeedDraw == true) return;
1450                if (window_data.fill_opacity == 1) // ¹è°æ»öÀÌ Flash ¼Ó¼ºÀ̶ó¸é ´Ù½Ã ±×¸°´Ù.
1451                {
1452                        bNeedDraw = true;
1453                        return;
1454                }
1455                // ±ÛÀÚÁß¿¡ Flash ¼Ó¼ºÀÌ ÀÖ´Â ±ÛÀÚ°¡ 1±ÛÀÚ¶óµµ ÀÖÀ¸¸é ´Ù½Ã ±×¸°´Ù.
1456                int nLines = GetStringLines();
1457                for (int y = 0; y < nLines; y++)
1458                {
1459                        int nColumn = GetStingLength(y);
1460                        for (int x = 0; x < nColumn; x++)
1461                        {
1462                                if (DST_CC_GetOpacity() == CC_FLASHING) bNeedDraw = true;
1463                                if (DST_CC_GetBackOpacity() == CC_FLASHING) bNeedDraw = true;
1464                                if (strText[x][y].pen.fg_opacity == 1) bNeedDraw = true;
1465                                if (strText[x][y].pen.bg_opacity == 1) bNeedDraw = true;
1466                                if (bNeedDraw == true) return;
1467                        }
1468                }
1469        }
1470};
1471
1472// µÎ ¹Ú½ºÀÇ °øÅë ¿µ¿ªÀ» ±¸ÇÑ´Ù.
1473static bool DST_GetCommonRect(DST_RECT A, DST_RECT B, DST_RECT *C)
1474{
1475        C->x= (A.x > B.x) ? A.x : B.x;
1476        C->y= (A.y > B.y) ? A.y : B.y;
1477        C->w= (A.x + A.w < B.x + B.w) ? (A.x + A.w - C->x) : (B.x + B.w - C->x);
1478        C->h= (A.y + A.h < B.y + B.h) ? (A.y + A.h - C->y) : (B.y + B.h - C->y);
1479        if (C->w <= 0 || C->h <= 0) return false;
1480        return true;
1481}
1482
1483#if 0
1484____CC_708_Decoder____()
1485#endif
1486
1487// EIA 708 ¸í·É¾î Á¤ÀÇ
1488#define CW0  0x80
1489#define CW1  0x81
1490#define CW2  0x82
1491#define CW3  0x83
1492#define CW4  0x84
1493#define CW5  0x85
1494#define CW6  0x86
1495#define CW7  0x87
1496
1497#define DF0  0x98
1498#define DF1  0x99
1499#define DF2  0x9A
1500#define DF3  0x9B
1501#define DF4  0x9C
1502#define DF5  0x9D
1503#define DF6  0x9E
1504#define DF7  0x9F
1505
1506#define CLW  0x88
1507#define DLW  0x8C
1508#define DSW  0x89
1509#define HDW  0x8A
1510#define TGW  0x8B
1511#define SWA  0x97
1512#define SPA  0x90
1513#define SPC  0x91
1514#define SPL  0x92
1515#define DLY  0x8D
1516#define DLC  0x8E
1517#define RST  0x8F
1518
1519#define EXT1 0x10
1520#define BS   0x08
1521#define CR       0x0D
1522#define ETX  0x03
1523
1524class CC708Decoder : public CWindow
1525{
1526private:
1527        int nCurrentWindow;
1528        CC708Window *win[8];
1529        bool bKorean;
1530        bool bWideScreen;
1531        bool bUnicode;
1532        DS_U8 nServiceNumber;
1533        CCCircularQueue Queue;
1534        bool bFlashDraw;
1535        DS_U32 LastShowTime;
1536public:
1537        CC708Decoder(SWinEventMsg event):CWindow(event)
1538        {
1539                LastShowTime = 0;
1540                //DST_Printf("CC708Decoder Create start\n");
1541                bFlashDraw = false;
1542                nCurrentWindow = -1;
1543                nServiceNumber = event.data[2]; /*1~6 »çÀÌÀÇ °ª*/
1544                DST_CheckCCDescription(nServiceNumber, &bKorean, &bWideScreen, &bUnicode);
1545                //DST_Printf("!!!!!!!!![nServiceNumber: %d][bKorean: %d][bWideScreen: %d][bUnicode: %d]!!!!!!!!!\n",nServiceNumber, bKorean, bWideScreen, bUnicode);
1546                for (DS_U8 i = 0; i < 8; i++)
1547                {
1548                        win[i] = new CC708Window(bKorean, bWideScreen);
1549                        win[i]->SetID(i);
1550                }
1551                rect.w = DST_GetCCScreenWidth();
1552                rect.h = DST_GetCCScreenHeight();
1553                rect.x = (DST_GetScreenWidth() - rect.w) / 2;
1554                rect.y = (DST_GetScreenHeight() - rect.h) / 2;
1555                //DST_Printf("RECT %d %d %d %d\n", rect.x, rect.y, rect.w, rect.h);
1556                SetTimeOut(16); // 16ÃÊ ¾È¿¡ »õ·Î¿î Á¤º¸°¡ ¾ø´Ù¸é Áö¿î´Ù. TTAK.KO-07.0093 5.7.22. ÀÚ¸· À©µµ¿ì ÀÚµ¿ »èÁ¦ ±â´É
1557                SetTimer(1, 500); // Flashing
1558                bTransparentWindow = false;
1559                //DST_Printf("CC708Decoder Create end\n");
1560        }
1561        virtual ~CC708Decoder()
1562        {
1563                //DST_Printf("CC708Decoder Delete start\n");
1564                for (DS_U8 i = 0; i < 8; i++) delete win[i];
1565                //DST_Printf("CC708Decoder Delete end\n");
1566        }
1567
1568        virtual void OnTimer(char nID)
1569        {
1570                switch (nID)
1571                {
1572                        case 1: // Flashing
1573                                bFlashDraw = !bFlashDraw;
1574                                OnFlash();
1575                                Show();
1576                                break;
1577                        case 2: // ½Ã½ºÅÛ ¼º´ÉÀÌ ºÎÁ·Çϸé Áö¿¬Çؼ­ ShowÇϱâ
1578                                Show(); // Show ¾È¿¡¼­ Kill ŸÀ̸簡 È£ÃâµÊ
1579                                break;
1580                }
1581        }
1582
1583        void Delay(unsigned char /*TenthsOfSeconds*/)
1584        {
1585                // TO DO
1586        }
1587
1588        void DelayCancel()
1589        {
1590                // TO DO
1591        }
1592
1593        void Reset()
1594        {
1595                for (int i = 0; i < 8; i++) win[i]->Reset();
1596                nCurrentWindow = -1;
1597        }
1598
1599        bool ProcessC01Byte(CCCircularQueue *Q)
1600        {
1601                switch (Q->GetByte())
1602                {
1603                        case 0x0C: PrintChar(0x0C); if (debug_cc) DST_Printf("FF\n"); break; // FF À©µµ¿ìÀÇ ¸Ç óÀ½ À§Ä¡·Î µ¹¾Æ°£´Ù.
1604                        case 0x0E: PrintChar(0x0E); if (debug_cc) DST_Printf("HCR\n"); break;// HCR ÇöÀç ÁÙÀÇ Ã³À½ À§Ä¡·Î µ¹¾Æ°£´Ù.
1605                        case 0x0D: PrintChar(0x0D); if (debug_cc) DST_Printf("CR\n"); break;// CR µ¥ÀÌÅ͸¦ ÇÑ ÁÙ ¿Ã¸°´Ù.
1606                        case 0x08: PrintChar(0x08); if (debug_cc) DST_Printf("Back Space\n"); break; // Back Space
1607                        case ETX: if (debug_cc) DST_Printf("End Of Text\n"); break;// End Of Text
1608                        default: /*if (debug_cc) DST_Printf("Unknown C0 Code 0x%02X\n", Q->GetByte());*/ break;
1609                }
1610                Q->RemoveByte();
1611                return true;
1612        }
1613
1614        bool ProcessC2(CCCircularQueue *Q)
1615        {
1616                unsigned char ucNext = Q->GetNextByte();
1617                unsigned char buff[5];
1618                if (ucNext < 0x08)  // C2 0-Additional bytes
1619                {
1620                        Q->Get(buff, 2);
1621                        if (debug_cc)
1622                        {
1623                                DST_Printf("C2 0-Additional bytes 0x%02X 0x%02X\n", buff[0], buff[1]);
1624                        }
1625                        return true;
1626                }
1627                if (ucNext < 0x10)  // C2 1-Additional bytes
1628                {
1629                        if (Q->GetSize() < 3) return false;
1630                        Q->Get(buff, 3);
1631                        if (debug_cc)
1632                        {
1633                                DST_Printf("C2 1-Additional bytes 0x%02X 0x%02X 0x%02X\n", buff[0], buff[1], buff[2]);
1634                        }
1635                        return true;
1636                }
1637                if (ucNext < 0x18) // C2 2-Additional bytes
1638                {
1639                        if (Q->GetSize() < 4) return false;
1640                        Q->Get(buff, 4);
1641                        if (debug_cc)
1642                        {
1643                                DST_Printf("C2 2-Additional bytes 0x%02X 0x%02X 0x%02X 0x%02X\n", buff[0], buff[1], buff[2], buff[3]);
1644                        }
1645                        return true;
1646                }
1647                // C2 3-Additional bytes
1648                if (Q->GetSize() < 5) return false;
1649                Q->Get(buff, 5);
1650                if (debug_cc)
1651                {
1652                        DST_Printf("C2 3-Additional bytes 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
1653                                buff[0], buff[1], buff[2], buff[3], buff[4]);
1654                }
1655                return true;
1656        }
1657
1658        bool ProcessG2(CCCircularQueue *Q)
1659        {
1660                switch (Q->GetNextByte())
1661                {
1662                        case 0x20: PrintChar(0); break; // TSP
1663                        case 0x21: PrintChar(0); break; // NBTSP
1664                        case 0x25: PrintChar(0x0125); break;
1665                        case 0x2A: PrintChar(0x012A); break;
1666                        case 0x2C: PrintChar(0x012C); break;
1667                        case 0x30: PrintChar(0x0130); break;
1668                        case 0x31: PrintChar(0x0131); break;
1669                        case 0x32: PrintChar(0x0132); break;
1670                        case 0x33: PrintChar(0x0133); break;
1671                        case 0x34: PrintChar(0x0134); break;
1672                        case 0x35: PrintChar(0x0135); break;
1673                        case 0x39: PrintChar(0x0139); break;
1674                        case 0x3A: PrintChar(0x013A); break;
1675                        case 0x3C: PrintChar(0x013C); break;
1676                        case 0x3D: PrintChar(0x013D); break;
1677                        case 0x3F: PrintChar(0x013F); break;
1678                        case 0x76: PrintChar(0x0176); break;
1679                        case 0x77: PrintChar(0x0177); break;
1680                        case 0x78: PrintChar(0x0178); break;
1681                        case 0x79: PrintChar(0x0179); break;
1682                        case 0x7A: PrintChar(0x017A); break;
1683                        case 0x7B: PrintChar(0x017B); break;
1684                        case 0x7C: PrintChar(0x017C); break;
1685                        case 0x7D: PrintChar(0x017D); break;
1686                        case 0x7E: PrintChar(0x017E); break;
1687                        case 0x7F: PrintChar(0x017F); break;
1688                }
1689                unsigned char buff[2];
1690                Q->Get(buff, 2);
1691                if (debug_cc)
1692                {
1693                        DST_Printf("G2 0x%02X 0x%02X\n", buff[0], buff[1]);
1694                }
1695                return true;
1696        }
1697
1698        bool ProcessC3(CCCircularQueue *Q)
1699        {
1700                unsigned char ucNext = Q->GetNextByte();
1701                unsigned char buff[256];
1702                if (ucNext < 0x88) // C3 4-Additional bytes
1703                {
1704                        if (Q->GetSize() < 6) return false;
1705                        Q->Get(buff, 6);
1706                        if (debug_cc)
1707                        {
1708                                DST_Printf("C3 4-Additional bytes 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
1709                                        buff[0], buff[1], buff[2], buff[3], buff[4], buff[5]);
1710                        }
1711                        return true;
1712                }
1713                if (ucNext < 0x90) // C3 5-Additional bytes
1714                {
1715                        if (Q->GetSize() < 7) return false;
1716                        Q->Get(buff, 7);
1717                        if (debug_cc)
1718                        {
1719                                DST_Printf("C3 5-Additional bytes 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
1720                                        buff[0], buff[1], buff[2], buff[3], buff[4], buff[5], buff[6]);
1721                        }
1722                        return true;
1723                }
1724                // C3 Variable Length Additional bytes
1725                if (Q->GetSize() < 3) return false;
1726                unsigned char ucNextNext = Q->GetNextNextByte() & 0x3F; // ÇÏÀ§ 6ºñÆ®°¡ ±æÀÌ ºñÆ®ÀÌ´Ù.
1727                if (Q->GetSize() < 3 + ucNextNext) return false;
1728                Q->Get(buff, 3 + ucNextNext);
1729                if (debug_cc)  DST_Printf("C3 Variable Length Additional bytes\n");
1730                return true;
1731        }
1732
1733        bool ProcessG3(CCCircularQueue *Q)
1734        {
1735                if (Q->GetNextByte() == 0xA0) PrintChar(0x01A0); // [CC] ¹®ÀÚ
1736                unsigned char buff[2];
1737                Q->Get(buff, 2);
1738                if (debug_cc) DST_Printf("G3 0x%02X 0x%02X\n", buff[0], buff[1]);
1739                return true;
1740        }
1741
1742        bool ProcessExt1(CCCircularQueue *Q)
1743        {
1744                unsigned char ucData = Q->GetNextByte();
1745                if (ucData < 0x20)
1746                {
1747                        return ProcessC2(Q);
1748                }
1749                if (ucData < 0x80)
1750                {
1751                        return ProcessG2(Q);
1752                }
1753                if (ucData < 0xA0)
1754                {
1755                        return ProcessC3(Q);
1756                }
1757                return ProcessG3(Q);
1758        }
1759        // C0 ¿µ¿ª ó¸®
1760        bool ProcessC0(CCCircularQueue *Q)
1761        {
1762                unsigned char buff[4] = {0,0,0,0};
1763                unsigned char ucData = Q->GetByte();
1764                if (ucData < 0x10) // 1¹ÙÀÌÆ® ¸í·É¾î
1765                {
1766                        return ProcessC01Byte(Q);
1767                }
1768                if (ucData < 0x18) // 2¹ÙÀÌÆ® ¸í·É¾î
1769                {
1770                        if (Q->GetSize() < 2) return false;
1771                        if (ucData == EXT1)
1772                        {
1773                                return ProcessExt1(Q);
1774                        }
1775                        Q->Get(buff, 2);
1776                        if (debug_cc) DST_Printf("C0 0x%02X 0x%02X\n", buff[0], buff[1]);
1777                        return true;
1778                }
1779                // 3¹ÙÀÌÆ® ¸í·É¾î
1780                if (Q->GetSize() < 3) return false;
1781
1782                Q->Get(buff, 3);
1783                if (ucData == 0x18 && bKorean == true)
1784                {
1785                        // ASC ¹®ÀÚ Áß »ç¿ëÇÒ ¼ö ¾ø´Â ¹®ÀÚ¿­Àº ¹èÁ¦ÇÑ´Ù.
1786                        if (buff[1] == 0 && (buff[2] < 0x20 || (buff[2] >= 0x80 && buff[2] < 0xA0)))
1787                        {
1788                                if (debug_cc) DST_Printf("P16 Not supported ascii 0x%02X\n", buff[2]);
1789                                return true;
1790                        }
1791                        if (debug_cc)
1792                        {
1793                                if (buff[1] == 0)
1794                                {
1795                                        DST_Printf("P16 0x%04X [%s]\n", (buff[1]*256)+buff[2], &buff[2]);
1796                                }
1797                                else
1798                                {
1799                                        DST_Printf("P16 0x%04X [%s]\n", (buff[1]*256)+buff[2], &buff[1]);
1800                                }
1801                        }
1802                        if (buff[1] == 0) // 0x007F¿Í 0x00A0´Â °ø¹é¹®ÀڷΠġȯÇÑ´Ù.
1803                        {
1804                                switch (buff[2])
1805                                {
1806                                        case 0x7F:
1807                                        case 0xA0:
1808                                                buff[2] = 0x20;
1809                                                break;
1810                                }
1811                        }
1812                        PrintChar(bUnicode ? (DS_U16)(buff[1]*256+buff[2]) : DMW_KSX2UniSub(buff[1], buff[2]));
1813                        return true;
1814                }
1815                return true;
1816        }
1817
1818        bool ProcessC1(CCCircularQueue *Q)
1819        {
1820                unsigned char ucData = Q->GetByte();
1821                unsigned char buff[10];
1822                switch (ucData)
1823                {
1824                        case CW0: // Current Window
1825                        case CW1:
1826                        case CW2:
1827                        case CW3:
1828                        case CW4:
1829                        case CW5:
1830                        case CW6:
1831                        case CW7:
1832                                nCurrentWindow = ucData & 0x07;
1833                                Q->RemoveByte();
1834                                if (debug_cc)  DST_Printf("CW%d 0x%02X\n", nCurrentWindow, ucData);
1835                                return true;
1836
1837                        case DF0: // Define Window
1838                        case DF1:
1839                        case DF2:
1840                        case DF3:
1841                        case DF4:
1842                        case DF5:
1843                        case DF6:
1844                        case DF7:
1845                                if (Q->GetSize() < 7) return false;
1846                                Q->Get(buff, 7);
1847                                if (debug_cc)  DST_Printf("DF 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
1848                                        buff[0], buff[1], buff[2], buff[3], buff[4], buff[5], buff[6]);
1849                                        nCurrentWindow = buff[0] & 0x07; // test code
1850                                win[buff[0] & 0x07]->DefineWindow(// Window ID
1851                                        buff[1] & 0x07, // Priority
1852                                        (buff[4] >> 4) & 0x0F, // Anchor Point
1853                                        (buff[2] & 0x80) ? 1 : 0, // Relative Position
1854                                        buff[2] & 0x7F, // Anchor Vertical
1855                                        buff[3], // Anchor Horizontal
1856                                        buff[4] & 0x0F, // Row Count
1857                                        buff[5] & 0x3F, // Column Count
1858                                        (buff[1] & 0x10) ? 1 : 0, // Row Lock
1859                                        (buff[1] & 0x08) ? 1 : 0, // Column Lock
1860                                        (buff[1] & 0x20) ? 1 : 0, // Visible
1861                                        (buff[6] >> 3) & 0x07, // Window Style ID
1862                                        buff[6] & 0x07 // Pen Style ID
1863                                );
1864                                return true;
1865
1866                        case CLW: // Clear Window
1867                                if (Q->GetSize() < 2) return false;
1868                                Q->Get(buff, 2);
1869                                if (debug_cc)  DST_Printf("CLW 0x%02X 0x%02X\n", buff[0], buff[1]);
1870                                if (buff[1] & 0x01) win[0]->ClearWindow();
1871                                if (buff[1] & 0x02) win[1]->ClearWindow();
1872                                if (buff[1] & 0x04) win[2]->ClearWindow();
1873                                if (buff[1] & 0x08) win[3]->ClearWindow();
1874                                if (buff[1] & 0x10) win[4]->ClearWindow();
1875                                if (buff[1] & 0x20) win[5]->ClearWindow();
1876                                if (buff[1] & 0x40) win[6]->ClearWindow();
1877                                if (buff[1] & 0x80) win[7]->ClearWindow();
1878                                return true;
1879
1880                        case DLW: // Delete Window
1881                                if (Q->GetSize() < 2) return false;
1882                                Q->Get(buff, 2);
1883                                if (debug_cc)  DST_Printf("DLW 0x%02X 0x%02X\n", buff[0], buff[1]);
1884                                if (buff[1] & 0x01) win[0]->DeleteWindow();
1885                                if (buff[1] & 0x02) win[1]->DeleteWindow();
1886                                if (buff[1] & 0x04) win[2]->DeleteWindow();
1887                                if (buff[1] & 0x08) win[3]->DeleteWindow();
1888                                if (buff[1] & 0x10) win[4]->DeleteWindow();
1889                                if (buff[1] & 0x20) win[5]->DeleteWindow();
1890                                if (buff[1] & 0x40) win[6]->DeleteWindow();
1891                                if (buff[1] & 0x80) win[7]->DeleteWindow();
1892                                return true;
1893
1894                        case DSW: // Display Window
1895                                if (Q->GetSize() < 2) return false;
1896                                Q->Get(buff, 2);
1897                                if (debug_cc)  DST_Printf("DSW 0x%02X 0x%02X\n", buff[0], buff[1]);
1898                                if (buff[1] & 0x01) win[0]->DisplayWindow();
1899                                if (buff[1] & 0x02) win[1]->DisplayWindow();
1900                                if (buff[1] & 0x04) win[2]->DisplayWindow();
1901                                if (buff[1] & 0x08) win[3]->DisplayWindow();
1902                                if (buff[1] & 0x10) win[4]->DisplayWindow();
1903                                if (buff[1] & 0x20) win[5]->DisplayWindow();
1904                                if (buff[1] & 0x40) win[6]->DisplayWindow();
1905                                if (buff[1] & 0x80) win[7]->DisplayWindow();
1906                                return true;
1907
1908                        case HDW: // Hide Window
1909                                if (Q->GetSize() < 2) return false;
1910                                Q->Get(buff, 2);
1911                                if (debug_cc)  DST_Printf("HDW 0x%02X 0x%02X\n", buff[0], buff[1]);
1912                                if (buff[1] & 0x01) win[0]->HideWindow();
1913                                if (buff[1] & 0x02) win[1]->HideWindow();
1914                                if (buff[1] & 0x04) win[2]->HideWindow();
1915                                if (buff[1] & 0x08) win[3]->HideWindow();
1916                                if (buff[1] & 0x10) win[4]->HideWindow();
1917                                if (buff[1] & 0x20) win[5]->HideWindow();
1918                                if (buff[1] & 0x40) win[6]->HideWindow();
1919                                if (buff[1] & 0x80) win[7]->HideWindow();
1920                                return true;
1921
1922                        case TGW: // Toggle Window
1923                                if (Q->GetSize() < 2) return false;
1924                                Q->Get(buff, 2);
1925                                if (debug_cc)  DST_Printf("TGW 0x%02X 0x%02X\n", buff[0], buff[1]);
1926                                if (buff[1] & 0x01) win[0]->ToggleWindow();
1927                                if (buff[1] & 0x02) win[1]->ToggleWindow();
1928                                if (buff[1] & 0x04) win[2]->ToggleWindow();
1929                                if (buff[1] & 0x08) win[3]->ToggleWindow();
1930                                if (buff[1] & 0x10) win[4]->ToggleWindow();
1931                                if (buff[1] & 0x20) win[5]->ToggleWindow();
1932                                if (buff[1] & 0x40) win[6]->ToggleWindow();
1933                                if (buff[1] & 0x80) win[7]->ToggleWindow();
1934                                return true;
1935
1936                        case SWA: // Set Window Attributes
1937                                if (Q->GetSize() < 5) return false;
1938                                Q->Get(buff, 5);
1939                                if (debug_cc)  DST_Printf("SWA 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
1940                                        buff[0], buff[1], buff[2], buff[3], buff[4]);
1941                                if (nCurrentWindow == -1) return true;
1942                                win[nCurrentWindow]->SetWindowAttribute(
1943                                        buff[3] & 0x03, // Justify
1944                                        (buff[3] >> 4) & 0x03, // Print Direction
1945                                        (buff[3] >> 2) & 0x03, // Scroll Direction
1946                                        ((buff[3] >> 5) & 0x01) ? true : false, // Word Wrap
1947                                        buff[4] & 0x03, // Display Effect
1948                                        (buff[4] >> 2) & 0x03, // Effect Direction
1949                                        (buff[4] >> 4) & 0x0F, // Effect Speed
1950                                        (buff[1] >> 4) & 0x03, // Fill Color Red
1951                                        (buff[1] >> 2) & 0x03, // Fill Color Green
1952                                        buff[1] & 0x03, // Fill Color Blue
1953                                        (buff[1] >> 6) & 0x03, // Fill Color Opacity
1954                                        ((buff[3] >> 5) & 0x04) | ((buff[2] >> 6) & 0x03), // Border Type
1955                                        (buff[2] >> 4) & 0x03, // Border Color Red
1956                                        (buff[2] >> 2) & 0x03, // Border Color Green
1957                                        buff[2] & 0x03 // Border Color Blue
1958                                );
1959                                return true;
1960
1961                        case SPA: // Set Pen Attributes
1962                                if (Q->GetSize() < 3) return false;
1963                                Q->Get(buff, 3);
1964                                if (debug_cc)  DST_Printf("SPA 0x%02X 0x%02X 0x%02X\n", buff[0], buff[1], buff[2]);
1965                                if (nCurrentWindow < 0) return true;
1966                                win[nCurrentWindow]->SetPenAttribute
1967                                (
1968                                        buff[1] & 0x03, // Pen Size
1969                                        buff[2] & 0x07, // Font Style
1970                                        (buff[1] >> 4) & 0x0F, // Text Tag
1971                                        (buff[1] >> 2) & 0x03, // Offset
1972                                        (buff[2] & 0x80) ? 1 : 0, // Italics
1973                                        (buff[2] & 0x40) ? 1 : 0, // UnderLine
1974                                        (buff[2] >> 3) & 0x07   // Edge Type
1975                                );
1976                                return true;
1977
1978                        case SPC: // Set Pen Color
1979                                if (Q->GetSize() < 4) return false;
1980                                Q->Get(buff, 4);
1981                                if (debug_cc)  DST_Printf("SPC 0x%02X 0x%02X 0x%02X 0x%02X\n", buff[0], buff[1], buff[2], buff[3]);
1982                                if (nCurrentWindow < 0) return true;
1983                                win[nCurrentWindow]->SetPenColor
1984                                (
1985                                        (buff[1] >> 4) & 0x03, // Foreground Body Color Red
1986                                        (buff[1] >> 2) & 0x03, // Foreground Body Color Green
1987                                        (buff[1] >> 0) & 0x03, // Foreground Body Color Blue
1988                                        (buff[1] >> 6) & 0x03, // Foreground Body Opacity
1989                                        (buff[2] >> 4) & 0x03, // BackGround Body Color Red
1990                                        (buff[2] >> 2) & 0x03, // BackGround Body Color Green
1991                                        (buff[2] >> 0) & 0x03, // BackGround Body Color Blue
1992                                        (buff[2] >> 6) & 0x03, // BackGround Body Opacity
1993                                        (buff[3] >> 4) & 0x03, // Edgeground Body Color Red
1994                                        (buff[3] >> 2) & 0x03, // Edgeground Body Color Green
1995                                        (buff[3] >> 0) & 0x03  // Edgeground Body Color Blue
1996                                );
1997                                return true;
1998
1999                        case SPL: // Set Pen Location
2000                                if (Q->GetSize() < 3) return false;
2001                                Q->Get(buff, 3);
2002                                if (debug_cc)  DST_Printf("SPL 0x%02X 0x%02X 0x%02X\n", buff[0], buff[1], buff[2]);
2003                                if (nCurrentWindow == -1) return true;
2004                                win[nCurrentWindow]->SetPenLocation(
2005                                        buff[2] & 0x3F, // Column
2006                                        buff[1] & 0x0F // Row
2007                                );
2008                                if (debug_cc)  DST_Printf("SPL %d %d\n", buff[2] & 0x3F, buff[1] & 0x0F);
2009                                return true;
2010
2011                        case DLY:
2012                                if (Q->GetSize() < 2) return false;
2013                                Q->Get(buff, 2);
2014                                if (debug_cc)  DST_Printf("DLY 0x%02X 0x%02X\n", buff[0], buff[1]);
2015                                Delay (buff[1]);
2016                                return true;
2017
2018                        case DLC:
2019                                if (debug_cc)  DST_Printf("DLC 0x%02X\n", ucData);
2020                                DelayCancel();
2021                                Q->RemoveByte();
2022                                DST_Printf("DLC\n");
2023                                return true;
2024
2025                        case RST:
2026                                if (debug_cc)  DST_Printf("RST 0x%02X\n", ucData);
2027                                Q->RemoveByte();
2028                                Reset();
2029                                return true;
2030                }
2031                if (debug_cc)  DST_Printf("Unknown C1 Command 0x%02X\n", ucData);
2032                Q->RemoveByte(); // Undefined Command.
2033                return true;
2034        }
2035
2036        void PrintChar(DS_U16 code)
2037        {
2038                if (nCurrentWindow == -1) return;
2039                win[nCurrentWindow]->AddChar(code);
2040        }
2041
2042        bool DecodeSub(CCCircularQueue *Q)
2043        {
2044                if (Q->GetSize() < 1) return false;
2045                unsigned char ucData = Q->GetByte();
2046                if (ucData < 0x20) // C0 ¿µ¿ª
2047                {
2048                        return ProcessC0(Q);
2049                }
2050                if (ucData < 0x80) // G0 ¿µ¿ª
2051                {
2052                        if (debug_cc)  DST_Printf("G0 %c 0x%02X\n", ucData, ucData);
2053                        //if (bKorean == false) // JTBC¿¡¼­ G0ÀÇ 0x20À» »ç¿ëÇÏ´Â ¹®Á¦·Î ±¹³»Çâ¿¡¼­µµ G0 Áö¿ø 2013.03.13
2054                        {
2055                                PrintChar((DS_U16)ucData);
2056                        }
2057                        Q->RemoveByte();
2058                        return true;
2059                }
2060                if (ucData < 0xA0) // C1 ¿µ¿ª
2061                {
2062                        return ProcessC1(Q);
2063                }
2064                // G1 ¿µ¿ª
2065                if (debug_cc)  DST_Printf("G1 %c0x%02X\n", ucData, ucData);
2066                if (bKorean == false)
2067                {
2068                PrintChar((DS_U16)ucData);
2069                }
2070                Q->RemoveByte();
2071                return true;
2072        }
2073        virtual void Show()
2074        {
2075                if (imgBuff == 0) return;
2076                KillTimer(2); // Áö¿¬Çؼ­ ±×¸®´Â ŸÀ̸Ӹ¦ ²ö´Ù.
2077                // EIT³ª PMTÀÇ CC descriptionÀÌ º¯°æµÇ¾ú´Ù¸é ´Ý´Â´Ù.
2078                bool _bKorean, _bWideScreen, _bUnicode;
2079                DST_CheckCCDescription(nServiceNumber, &_bKorean, &_bWideScreen, &_bUnicode);
2080                if (bKorean != _bKorean || bWideScreen != _bWideScreen)
2081                {
2082                        Close();
2083                        return;
2084                }
2085                if (bKorean == true && bUnicode != _bUnicode)
2086                {
2087                        Close();
2088                        return;
2089                }
2090
2091                for (int i = 0; i < 8; i++) win[i]->Draw(bFlashDraw);// º¯°æ»çÇ×ÀÌ ÀÖ´Ù¸é ±×¸°´Ù.
2092                // ´Ù ±×·ÈÀ¸¸é È­¸é¿¡ ±×¸®ÀÚ.
2093                DST_RECT rectUpdate = DST_UpdateRegionGet();
2094                if (rectUpdate.w == 0 || rectUpdate.h == 0) return;
2095                //DST_Printf("rectUpdate %d %d %d %d \n", rectUpdate.x, rectUpdate.y, rectUpdate.w, rectUpdate.h);
2096                UpdateScreen(rectUpdate.x, rectUpdate.y, rectUpdate.w, rectUpdate.h);
2097
2098                //DrawBox(rectUpdate.x, rectUpdate.y, rectUpdate.w, rectUpdate.h, COLOR_TRANSPARENT);
2099                { // ¾÷µ¥ÀÌÆ® ÇÒ ¿µ¿ªÀ» Åõ¸í»öÀ¸·Î ä¿î´Ù
2100                        OSD_PIXEL_T *tmp_buff = imgBuff + rect.w * rectUpdate.y + rectUpdate.x;
2101                        int nSize = rectUpdate.w * sizeof(OSD_PIXEL_T);
2102                        int y = rectUpdate.h;
2103                        while (y--)
2104                        {
2105                                memset(tmp_buff, 0, nSize);
2106                                tmp_buff += rect.w;
2107                        }
2108                }
2109
2110                bool bFirst = true;
2111                for (int priority = 7; priority >= 0; priority--)
2112                {
2113                        // 2013.05.16 µ¿ÀÏ priority¶ó¸é nCurrentWindow¸¦ °¡Àå ¸¶Áö¸·¿¡ ±×¸®µµ·Ï ÇÑ´Ù.
2114                        int order_table[8] = {0,1,2,3,4,5,6,7};
2115                        order_table[0] = (nCurrentWindow > -1) ? nCurrentWindow : 0;
2116                        for (int i = 1; i < 8; i++) order_table[i] = (i <= order_table[0]) ? i-1 : i;   
2117                        for (int j = 7; j >= 0; j--)
2118                        {
2119                                int i = order_table[j];
2120                                if (priority != win[i]->GetPriority()) continue;
2121                                if (win[i]->GetVisible() == false) continue;
2122                                OSD_PIXEL_T *srcBuff = win[i]->GetImgBuff();
2123                                if (srcBuff == 0) continue;
2124                                DST_RECT rectCommon;
2125                                DST_RECT rectSrc = win[i]->GetSize();
2126                                if (DST_GetCommonRect(rectUpdate, rectSrc, &rectCommon ) == false) continue;
2127                                int srcStartX = rectCommon.x - rectSrc.x;
2128                                if (srcStartX < 0) srcStartX = 0;
2129                                int srcStartY = rectCommon.y - rectSrc.y;
2130                                if (srcStartY < 0) srcStartY = 0;
2131                                //DS_U8* des1 = imgBuff + rect.w * rectCommon.y + rectCommon.x;
2132                                //DS_U8* src1 = srcBuff + rectSrc.w * srcStartY + srcStartX;
2133                                if (bFirst == true)
2134                                {
2135                                        bFirst = false;
2136
2137                                        OSD_PIXEL_T* src = srcBuff + rectSrc.w * srcStartY + srcStartX;
2138                                        OSD_PIXEL_T* des = imgBuff + rectCommon.y * rect.w + rectCommon.x;
2139                                        int y = rectCommon.h;
2140                                        int nSize = rectCommon.w * sizeof(OSD_PIXEL_T);
2141                                        while (y--)
2142                                        {
2143                                                memcpy(des, src, nSize);
2144                                                src += rectSrc.w;
2145                                                des += rect.w;
2146                                        }
2147                                }
2148                                else
2149                                {
2150                                        OSD_PIXEL_T* src = srcBuff + rectSrc.w * srcStartY + srcStartX;
2151                                        OSD_PIXEL_T* des = imgBuff + rectCommon.y * rect.w + rectCommon.x;
2152                                        int src_delta = rectSrc.w-rectCommon.w;
2153                                        int des_delta = rect.w-rectCommon.w;
2154                                        int y = rectCommon.h;
2155                                        while (y--)
2156                                        {
2157                                                int x = rectCommon.w;
2158                                                while (x--)
2159                                                {
2160                                                        if (*src) *des = *src;
2161                                                        src++;
2162                                                        des++;
2163                                                }
2164                                                src+=src_delta;
2165                                                des+=des_delta;
2166                                        }
2167                                }
2168                        }
2169                }
2170                DST_UpdateRegionReset();
2171                LastShowTime = DST_OS_GetTickCount();
2172        }
2173
2174        void OnFlash()
2175        {
2176                for (int i = 0; i < 8; i++) win[i]->OnFlash(); // Ç÷¡½Ã »óŰ¡ ¹Ù²î¸é ±×¸±°Ô ÀÖ´ÂÁö ¾÷µ¥ÀÌÆ®ÇÑ´Ù.
2177        }
2178        virtual void OnMessage(SWinEventMsg event)
2179        {
2180                int i = 0;
2181                switch (event.cmd)
2182                {
2183                        case WM_SEQ_ERROR:
2184                                Close();
2185                                break;
2186
2187                        case WM_CS1:
2188                                if (GetState() != 1) break;
2189                                ResetTimer(0); // À©µµ¿ìÀÇ Å¸ÀӾƿô °ªÀ» ¿¬ÀåÇÑ´Ù.
2190                                for (i = 0 ; i < event.data[0]; i++) 
2191                                {
2192                                        if (debug_cc) DST_Printf("%02X ", event.data[i+1]);
2193                                        Queue.Add(event.data[i+1]);
2194                                }
2195                                if (debug_cc) DST_Printf("\n");
2196                                while (1)
2197                                {
2198                                        if (DecodeSub(&Queue)== false) break;
2199                                }
2200                                if (LastShowTime > DST_OS_GetTickCount()) LastShowTime = DST_OS_GetTickCount();
2201                                if (DST_OS_GetTickCount() - LastShowTime < DST_OS_GetTicksPerSecond()/10)
2202                                {
2203                                        SetTimer(2, 100); // 100ms ÈÄ¿¡ ±×¸®±â
2204                                }
2205                                else
2206                                {
2207                                        Show();
2208                                }
2209                                break;
2210
2211                        case WM_CC_CLOSE:
2212//                              T();
2213                                Close();
2214                                break;
2215                }
2216        }
2217};
2218
2219void DST_CreateCC708Win(SWinEventMsg event)
2220{
2221        DST_AddWin((WinID)(event.data[0]), new CC708Decoder(event));
2222}
Note: See TracBrowser for help on using the repository browser.