60 #ifdef STB_SUB_DRIVER_PRINT_REQUIRED 61 #ifdef STB_SUB_DRIVER_CHANNEL_DEBUG_REQUIRED 62 #define STB_SUB_DRIVER_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_OSD) x 64 #define STB_SUB_DRIVER_PRINT(x) STB_SPDebugWrite x 67 #define STB_SUB_DRIVER_PRINT(x) 72 #ifdef STB_SEGMENT_PRINT_REQUIRED 73 #ifdef STB_SUB_DRIVER_CHANNEL_DEBUG_REQUIRED 74 #define STB_SEGMENT_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_OSD) x 76 #define STB_SEGMENT_PRINT(x) STB_SPDebugWrite x 79 #define STB_SEGMENT_PRINT(x) 83 #ifdef STB_SUMMARY_PRINT_REQUIRED 84 #ifdef STB_SUB_DRIVER_CHANNEL_DEBUG_REQUIRED 85 #define STB_SUMMARY_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_OSD) x 87 #define STB_SUMMARY_PRINT(x) STB_SPDebugWrite x 90 #define STB_SUMMARY_PRINT(x) 94 #ifdef STB_REGION_PRINT_REQUIRED 95 #ifdef STB_REGION_CHANNEL_DEBUG_REQUIRED 96 #define STB_REGION_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_OSD) x 98 #define STB_REGION_PRINT(x) STB_SPDebugWrite x 101 #define STB_REGION_PRINT(x) 104 #ifdef STB_CDS_PRINT_REQUIRED 105 #ifdef STB_CLUT_CHANNEL_DEBUG_REQUIRED 106 #define STB_CDS_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_OSD) x 108 #define STB_CDS_PRINT(x) STB_SPDebugWrite x 111 #define STB_CDS_PRINT(x) 114 #ifdef STB_CLUT_PRINT_REQUIRED 115 #ifdef STB_CLUT_CHANNEL_DEBUG_REQUIRED 116 #define STB_CLUT_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_OSD) x 118 #define STB_CLUT_PRINT(x) STB_SPDebugWrite x 121 #define STB_CLUT_PRINT(x) 124 #ifdef STB_ODS_PRINT_REQUIRED 125 #ifdef STB_ODS_CHANNEL_DEBUG_REQUIRED 126 #define STB_ODS_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_OSD) x 128 #define STB_ODS_PRINT(x) STB_SPDebugWrite x 131 #define STB_ODS_PRINT(x) 134 #ifdef STB_OBJECT_PRINT_REQUIRED 135 #ifdef STB_OBJECT_CHANNEL_DEBUG_REQUIRED 136 #define STB_OBJECT_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_OSD) x 138 #define STB_OBJECT_PRINT(x) STB_SPDebugWrite x 141 #define STB_OBJECT_PRINT(x) 144 #ifdef STB_PIXMAP_PRINT_REQUIRED 145 #ifdef STB_PIXMAP_CHANNEL_DEBUG_REQUIRED 146 #define STB_PIXMAP_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_OSD) x 148 #define STB_PIXMAP_PRINT(x) STB_SPDebugWrite x 151 #define STB_PIXMAP_PRINT(x) 154 #ifdef STB_END_PRINT_REQUIRED 155 #ifdef STB_END_CHANNEL_DEBUG_REQUIRED 156 #define STB_END_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_OSD) x 158 #define STB_END_PRINT(x) STB_SPDebugWrite x 161 #define STB_END_PRINT(x) 165 #define TEMP_BUFFER_SIZE (1024 * 2) 166 #define SCAN_LINE_WIDTH 1950 168 #define MAX_REGION_WIDTH 1920 169 #define MAX_REGION_HEIGHT 1080 171 #define FIELD_SCAN_LINES (MAX_REGION_HEIGHT / 2) // this is a half value because on interlacing 174 #define STB_GetMemory(x) STB_DSGetMemory(x) 175 #define STB_FreeMemory(x) STB_DSFreeMemory(x) 184 U16BIT max_line_size;
185 U16BIT line_size[FIELD_SCAN_LINES];
186 U8BIT *data_line[FIELD_SCAN_LINES];
193 static S_DISPLAY_SET subtitle_display_set = {NULL, NULL, NULL, NULL, NULL};
196 static U8BIT *temp_buffer;
203 static U32BIT default_2_bit_clut[4] =
205 0xff108080, 0x00478080, 0x00108080, 0x002b8080
209 static U32BIT default_4_bit_clut[16] =
211 0xff108080, 0x00209c76, 0x0030686d, 0x00418463, 0x00167b9c, 0x00279792, 0x00376389, 0x00478080,
212 0x00108080, 0x00188e7b, 0x00207476, 0x00288271, 0x00137d8e, 0x001b8b89, 0x00237184, 0x002b8080
216 static U32BIT default_8_bit_clut[256] =
218 0xff108080, 0xbf209c76, 0xbf30686d, 0xbf418463, 0xbf167b9c, 0xbf279792, 0xbf376389, 0xbf478080,
219 0x7f108080, 0x7f15897c, 0x7f1a7879, 0x7f208176, 0x7f127e89, 0x7f178786, 0x7f1c7683, 0x7f228080,
220 0x001b9379, 0x00209c76, 0x00258b73, 0x002b9470, 0x001d9182, 0x00229a7f, 0x0028897c, 0x002d9379,
221 0x7f1b9379, 0x7f209c76, 0x7f258b73, 0x7f2b9470, 0x7f1d9182, 0x7f229a7f, 0x7f28897c, 0x7f2d9379,
222 0x00257073, 0x002b7970, 0x0030686d, 0x00367169, 0x00276e7c, 0x002d7779, 0x00326676, 0x00387073,
223 0x7f257073, 0x7f2b7970, 0x7f30686d, 0x7f367169, 0x7f276e7c, 0x7f2d7779, 0x7f326676, 0x7f387073,
224 0x0030836c, 0x00368c69, 0x003b7b66, 0x00418463, 0x00338176, 0x00388a73, 0x003d7970, 0x0043836c,
225 0x7f30836c, 0x7f368c69, 0x7f3b7b66, 0x7f418463, 0x7f338176, 0x7f388a73, 0x7f3d7970, 0x7f43836c,
226 0x00147c93, 0x0019868f, 0x001f758c, 0x00247e89, 0x00167b9c, 0x001b8499, 0x00217396, 0x00267c93,
227 0x7f147c93, 0x7f19868f, 0x7f1f758c, 0x7f247e89, 0x7f167b9c, 0x7f1b8499, 0x7f217396, 0x7f267c93,
228 0x001f8f8c, 0x00249989, 0x002a8886, 0x002f9183, 0x00218e96, 0x00269792, 0x002c868f, 0x00318f8c,
229 0x7f1f8f8c, 0x7f249989, 0x7f2a8886, 0x7f2f9183, 0x7f218e96, 0x7f269792, 0x7f2c868f, 0x7f318f8c,
230 0x002a6c86, 0x002f7683, 0x00346580, 0x003a6e7d, 0x002c6b8f, 0x0031748c, 0x00366389, 0x003c6c86,
231 0x7f2a6c86, 0x7f2f7683, 0x7f346580, 0x7f3a6e7d, 0x7f2c6b8f, 0x7f31748c, 0x7f366389, 0x7f3c6c86,
232 0x00358080, 0x003a897c, 0x00407879, 0x00458176, 0x00377e89, 0x003c8786, 0x00427683, 0x00478080,
233 0x7f358080, 0x7f3a897c, 0x7f407879, 0x7f458176, 0x7f377e89, 0x7f3c8786, 0x7f427683, 0x7f478080,
234 0x00108080, 0x0012847e, 0x00157c7c, 0x0018807b, 0x00117f84, 0x00138383, 0x00167b81, 0x00198080,
235 0x00108080, 0x0012847e, 0x00157c7c, 0x0018807b, 0x00117f84, 0x00138383, 0x00167b81, 0x00198080,
236 0x0015897c, 0x00188e7b, 0x001a8579, 0x001d8a78, 0x00168881, 0x00198d7f, 0x001b847e, 0x001e897c,
237 0x0015897c, 0x00188e7b, 0x001a8579, 0x001d8a78, 0x00168881, 0x00198d7f, 0x001b847e, 0x001e897c,
238 0x001a7879, 0x001d7c78, 0x00207476, 0x00227875, 0x001b777e, 0x001e7c7c, 0x0021737b, 0x00237879,
239 0x001a7879, 0x001d7c78, 0x00207476, 0x00227875, 0x001b777e, 0x001e7c7c, 0x0021737b, 0x00237879,
240 0x00208176, 0x00238675, 0x00257d73, 0x00288271, 0x0021807b, 0x00248579, 0x00267c78, 0x00298176,
241 0x00208176, 0x00238675, 0x00257d73, 0x00288271, 0x0021807b, 0x00248579, 0x00267c78, 0x00298176,
242 0x00127e89, 0x00148387, 0x00177a86, 0x001a7f84, 0x00137d8e, 0x0015828c, 0x0018798a, 0x001b7e89,
243 0x00127e89, 0x00148387, 0x00177a86, 0x001a7f84, 0x00137d8e, 0x0015828c, 0x0018798a, 0x001b7e89,
244 0x00178786, 0x001a8c84, 0x001c8383, 0x001f8881, 0x0018878a, 0x001b8b89, 0x001e8387, 0x00208786,
245 0x00178786, 0x001a8c84, 0x001c8383, 0x001f8881, 0x0018878a, 0x001b8b89, 0x001e8387, 0x00208786,
246 0x001c7683, 0x001f7b81, 0x00227280, 0x0025777e, 0x001d7587, 0x00207a86, 0x00237184, 0x00267683,
247 0x001c7683, 0x001f7b81, 0x00227280, 0x0025777e, 0x001d7587, 0x00207a86, 0x00237184, 0x00267683,
248 0x00228080, 0x0025847e, 0x00277c7c, 0x002a807b, 0x00237f84, 0x00268383, 0x00287b81, 0x002b8080,
249 0x00228080, 0x0025847e, 0x00277c7c, 0x002a807b, 0x00237f84, 0x00268383, 0x00287b81, 0x002b8080
252 static U8BIT default_2_bit_4_bit_map[4] =
254 0x00, 0x07, 0x08, 0x0f
257 static U8BIT default_2_bit_8_bit_map[4] =
259 0x00, 0x77, 0x88, 0xff
262 static U8BIT default_4_bit_8_bit_map[16] =
264 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
267 #define TOP_FIELD_ONLY 1 268 #define BOTTOM_FIELD_ONLY 2 269 #define BOTH_FIELDS 0 274 static BOOLEAN ProcessObjectCodingMethod(U8BIT *data,
S_OBJECT *
object, U16BIT coding_method, U16BIT seg_len);
275 static BOOLEAN ProcessPixelDataSubBlock(U8BIT *data,
S_OBJECT *
object, U16BIT field_data_block_length, U8BIT field,
S_PIXEL_SUB_DATA_BLOCK *decoded_data_block);
276 static BOOLEAN Process2BitPixelCodeString(U16BIT *run_length, U8BIT *colour,
277 U8BIT *my2_u8p, U16BIT *my2_u16, U8BIT *my2_u8);
278 static BOOLEAN Process4BitPixelCodeString(U16BIT *run_length, U8BIT *colour,
279 U8BIT *my4_u8p, U16BIT *my4_u16, U8BIT *my4_u8);
280 static BOOLEAN Process8BitPixelCodeString(U16BIT *run_length, U8BIT *colour,
281 U8BIT *data, U16BIT *byte_count);
282 static BOOLEAN Process2To4BitMapTable(U8BIT *data, U16BIT *processed_bits, U8BIT *decoded_data);
283 static BOOLEAN Process2To8BitMapTable(U8BIT *data, U16BIT *processed_bits, U8BIT *decoded_data);
284 static BOOLEAN Process4To8BitMapTable(U8BIT *data, U16BIT *processed_bits, U8BIT *decoded_data);
285 static BOOLEAN MakeClutEntry(
S_CLUT *
clut, U16BIT clut_id, U8BIT clut_entry_id, U8BIT clut_bit_entry_flags, U32BIT palette_entry);
286 #ifdef STB_REGION_PRINT_REQUIRED 288 U16BIT region_level_of_compatability, U16BIT region_depth, U16BIT clut_id);
290 static void DestroyObject(
S_OBJECT **obj, BOOLEAN del_obj);
291 static void DeleteObjectList(
S_OBJECT **obj);
292 static void DeleteClutList(
S_CLUT **clut);
294 static void DeletePageCompositionRegions(
S_REGION **comp_pg);
295 static void STB_DSDumpPageState(
const char *label);
297 extern void dump_physical_regions(
const char *label);
299 static void Get2Bit_Initialise(
const U8BIT *new_root, U8BIT **my2_u8p, U16BIT *my2_u16, U8BIT *my2_u8);
300 static void Get2Bit_SetAlignment(U16BIT *my2_u16, U8BIT *my2_u8);
301 static U16BIT Get2Bit_Offset(U16BIT my2_u16);
302 static U8BIT Get2Bit_Get(U8BIT *my2_u8p, U16BIT *my2_u16, U8BIT *my2_u8);
304 static void Get4Bit_Initialise(
const U8BIT *new_root, U8BIT **my4_u8p, U16BIT *my4_u16, U8BIT *my4_u8);
305 static void Get4Bit_SetAlignment(U16BIT *my4_u16, U8BIT *my4_u8);
306 static U16BIT Get4Bit_Offset(U16BIT my4_u16);
307 static U8BIT Get4Bit_Get(U8BIT *my4_u8p, U16BIT *my4_u16, U8BIT *my4_u8);
311 static void Get2Bit_Initialise(
const U8BIT *new_root, U8BIT **my_root, U16BIT *my_offset, U8BIT *my_counter)
313 *my_root = (U8BIT *) new_root;
318 static void Get2Bit_SetAlignment(U16BIT *my_offset, U8BIT *my_counter)
321 if (*my_counter != 0)
332 static U16BIT Get2Bit_Offset(U16BIT my_offset)
337 static U8BIT Get2Bit_Get(U8BIT *my_root, U16BIT *my_offset, U8BIT *my_counter)
344 retval = (my_root[*my_offset]) >> 6;
347 retval = (((my_root[*my_offset]) >> 4) & 0x03);
350 retval = (((my_root[*my_offset]) >> 2) & 0x03);
353 retval = ((my_root[*my_offset]) & 0x03);
362 *my_counter = (*my_counter + 1) % 4;
367 static void Get4Bit_Initialise(
const U8BIT *new_root, U8BIT **my_root, U16BIT *my_offset, U8BIT *my_counter)
369 *my_root = (U8BIT *) new_root;
374 static void Get4Bit_SetAlignment(U16BIT *my_offset, U8BIT *my_counter)
377 if (*my_counter != 0)
388 static U16BIT Get4Bit_Offset(U16BIT my_offset)
393 static U8BIT Get4Bit_Get(U8BIT *my_root, U16BIT *my_offset, U8BIT *my_counter)
400 retval = (my_root[*my_offset]) >> 4;
405 retval = ((my_root[*my_offset]) & 0x0f);
416 *my_counter = (*my_counter + 1) % 2;
437 static BOOLEAN ProcessObjectCodingMethod(U8BIT *data,
S_OBJECT *
object, U16BIT coding_method, U16BIT seg_len)
441 U16BIT top_field_data_block_length;
442 U16BIT bottom_field_data_block_length;
445 FUNCTION_START(ProcessObjectCodingMethod);
447 ASSERT(data != NULL);
448 ASSERT(
object != NULL);
452 switch (coding_method)
460 top_field_data_block_length = (data[0] << 8) + data[1];
461 bottom_field_data_block_length = (data[2] << 8) + data[3];
463 if ((top_field_data_block_length + bottom_field_data_block_length) < seg_len)
468 if (object->bitmap != NULL)
471 object->bitmap = NULL;
474 if (bottom_field_data_block_length == 0)
478 STB_OBJECT_PRINT((
"bottom_field_data_block not present"));
480 retval = ProcessPixelDataSubBlock(&data[0],
object, top_field_data_block_length, BOTH_FIELDS, &top_field);
484 retval = ProcessPixelDataSubBlock(&data[0],
object, top_field_data_block_length, TOP_FIELD_ONLY, &top_field);
485 retval &= ProcessPixelDataSubBlock(&data[top_field_data_block_length],
object, bottom_field_data_block_length, BOTTOM_FIELD_ONLY, &bottom_field);
494 object->num_chars = data[9];
495 object->character_code = (U8BIT *)
STB_GetMemory((object->num_chars * 2));
496 if (object->character_code != NULL)
498 STB_OBJECT_PRINT((
"object_coding_method string of %d characters", object->num_chars));
499 memcpy((
void *)object->character_code, (
void *)&data[10], (
size_t)(object->num_chars * 2));
503 STB_OBJECT_PRINT((
"object_coding_method char malloc fail"));
504 object->num_chars = 0;
514 STB_OBJECT_PRINT((
"object_coding_method INVALID"));
520 FUNCTION_FINISH(ProcessObjectCodingMethod);
543 static BOOLEAN ProcessPixelDataSubBlock(U8BIT *data,
545 U16BIT field_data_block_length,
551 U16BIT processed_length;
552 U16BIT decode_data_size;
557 BOOLEAN end_of_string;
558 BOOLEAN terminate = FALSE;
571 static BOOLEAN error_flag;
572 static BOOLEAN error_line;
574 FUNCTION_START(ProcessPixelDataSubBlock);
576 ASSERT(data != NULL);
577 ASSERT(
object != NULL);
578 ASSERT(decoded_data_block != NULL);
580 USE_UNWANTED_PARAM(decoded_data_block);
582 STB_OBJECT_PRINT((
" Pixel-data_sub-block %d bytes", field_data_block_length));
589 decode_data_size = 0;
590 processed_length = 0;
593 decoded_data = temp_buffer;
595 end_of_string = FALSE;
607 case BOTTOM_FIELD_ONLY:
630 while (!terminate && (processed_length < field_data_block_length))
632 data_type = data[processed_length];
634 STB_OBJECT_PRINT((
" data_type %02x @ %x / %d", data_type, data + processed_length, processed_length));
644 processed_length += 6;
651 Get2Bit_Initialise((
const U8BIT *) (data + processed_length), &my2_u8p, &my2_u16, &my2_u8);
655 end_of_string = Process2BitPixelCodeString(&run_length, &colour, my2_u8p, &my2_u16, &my2_u8 );
657 if (((decode_data_size + run_length) > SCAN_LINE_WIDTH) ||
658 (processed_length + Get2Bit_Offset(my2_u16) > field_data_block_length))
666 static U8BIT lastcolin = 0xff;
668 if ((lastcolin != colour) && (run_length > 12))
675 if (object->map_table_2_to_8_bit != default_2_bit_8_bit_map)
678 colour =
object->map_table_2_to_8_bit[colour];
684 colour =
object->map_table_2_to_4_bit[colour];
685 colour =
object->map_table_4_to_8_bit[colour];
688 memset((
void *)&decoded_data[decode_data_size], colour, run_length);
689 decode_data_size += run_length;
693 while (!end_of_string);
696 Get2Bit_SetAlignment(&my2_u16, &my2_u8);
699 processed_length += Get2Bit_Offset(my2_u16);
706 Get4Bit_Initialise((
const U8BIT *) (data + processed_length), &my4_u8p, &my4_u16, &my4_u8);
710 end_of_string = Process4BitPixelCodeString(&run_length, &colour, my4_u8p, &my4_u16, &my4_u8 );
712 if (((decode_data_size + run_length) > SCAN_LINE_WIDTH) ||
713 (processed_length + Get4Bit_Offset(my4_u16) > field_data_block_length))
715 if ((decode_data_size + run_length) > SCAN_LINE_WIDTH)
717 STB_OBJECT_PRINT((
" !! Decoded + run length > scan line width %d + %d > %d",
718 decode_data_size, run_length, SCAN_LINE_WIDTH));
720 if (processed_length + Get4Bit_Offset(my4_u16) > field_data_block_length)
722 STB_OBJECT_PRINT((
" !! processed_length + Get4Bit_Offset(my4_u16) > field_data_block_length %d + %d > %d",
723 processed_length, Get4Bit_Offset(my4_u16), field_data_block_length));
732 static U8BIT lastcolin = 0xff;
734 if ((lastcolin != colour) && (run_length > 12))
742 colour =
object->map_table_4_to_8_bit[colour];
743 memset((
void *)&decoded_data[decode_data_size], colour, run_length);
744 decode_data_size += run_length;
748 while (!end_of_string);
751 Get4Bit_SetAlignment(&my4_u16, &my4_u8);
754 processed_length += Get4Bit_Offset(my4_u16);
763 end_of_string = Process8BitPixelCodeString(&run_length, &colour, data, &processed_length);
765 if (((decode_data_size + run_length) > SCAN_LINE_WIDTH) || (processed_length > field_data_block_length))
773 static U8BIT lastcolin = 0xff;
775 if ((lastcolin != colour) && (run_length > 12))
780 memset((
void *)&decoded_data[decode_data_size], colour, run_length);
781 decode_data_size += run_length;
785 while (!end_of_string);
792 Process2To4BitMapTable(data, &processed_length, decoded_data);
793 if (object->map_table_2_to_4_bit != (U8BIT *)default_2_bit_4_bit_map)
798 if (object->map_table_2_to_4_bit != NULL)
800 memcpy((
void *)object->map_table_2_to_4_bit, (
void *)decoded_data, (
size_t)4);
802 STB_OBJECT_PRINT((
" 20> 2To4Map %02x %02x %02x %02x",
803 decoded_data[0], decoded_data[1], decoded_data[2], decoded_data[3]));
807 object->map_table_2_to_4_bit = default_2_bit_4_bit_map;
815 Process2To8BitMapTable(data, &processed_length, decoded_data);
817 if (object->map_table_2_to_8_bit != (U8BIT *)default_2_bit_8_bit_map)
822 if (object->map_table_2_to_8_bit != NULL)
824 memcpy((
void *)object->map_table_2_to_8_bit, (
void *)decoded_data, (
size_t)4);
826 STB_OBJECT_PRINT((
" 21> 2To8Map %02x %02x %02x %02x",
827 decoded_data[0], decoded_data[1], decoded_data[2], decoded_data[3]));
831 object->map_table_2_to_8_bit = default_2_bit_8_bit_map;
839 Process4To8BitMapTable(data, &processed_length, decoded_data);
841 if (object->map_table_4_to_8_bit != (U8BIT *)default_4_bit_8_bit_map)
846 if (object->map_table_4_to_8_bit != NULL)
848 memcpy((
void *)object->map_table_4_to_8_bit, (
void *)decoded_data, (
size_t)16);
849 STB_OBJECT_PRINT((
" 22> 4To8Map %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
850 decoded_data[ 0], decoded_data[ 1], decoded_data[ 2], decoded_data[ 3],
851 decoded_data[ 4], decoded_data[ 5], decoded_data[ 6], decoded_data[ 7],
852 decoded_data[ 8], decoded_data[ 9], decoded_data[10], decoded_data[11],
853 decoded_data[12], decoded_data[13], decoded_data[14], decoded_data[15]));
857 object->map_table_4_to_8_bit = default_4_bit_8_bit_map;
864 STB_OBJECT_PRINT((
" End of Line after %d pixels", decode_data_size));
865 if (decode_data_size != 0)
868 scanline, decode_data_size, 1);
871 if (field == BOTTOM_FIELD_ONLY)
876 if ((scanline + 1) >= error_line)
879 if (decode_data_size != 0)
882 scanline, decode_data_size, 1);
899 if (decode_data_size != 0)
902 scanline, decode_data_size, 1);
906 decode_data_size = 0;
907 decoded_data = temp_buffer;
913 STB_OBJECT_PRINT((
"Unknown data_type 0x%02x", data_type));
916 if (field == TOP_FIELD_ONLY)
919 error_line = scanline;
920 STB_OBJECT_PRINT((
"ERR Detected TOP %d", scanline));
924 STB_OBJECT_PRINT((
"ERR Detected BOT %d", scanline));
938 STB_OBJECT_PRINT((
"PIXPARSE TERMINATE @ %d", __LINE__));
939 if (object->map_table_2_to_4_bit != (U8BIT *)default_2_bit_4_bit_map)
942 object->map_table_2_to_4_bit = (U8BIT *)default_2_bit_4_bit_map;
945 if (object->map_table_2_to_8_bit != (U8BIT *)default_2_bit_8_bit_map)
948 object->map_table_2_to_8_bit = (U8BIT *)default_2_bit_8_bit_map;
951 if (object->map_table_4_to_8_bit != (U8BIT *)default_4_bit_8_bit_map)
954 object->map_table_4_to_8_bit = (U8BIT *)default_4_bit_8_bit_map;
958 if (!terminate && (processed_length == field_data_block_length))
963 FUNCTION_FINISH(ProcessPixelDataSubBlock);
983 static BOOLEAN Process2BitPixelCodeString(U16BIT *run_length, U8BIT *colour,
984 U8BIT *my2_u8p, U16BIT *my2_u16, U8BIT *my2_u8)
987 BOOLEAN end_of_2_bit_pixel_code_string = FALSE;
990 FUNCTION_START(Process2BitPixelCodeString);
992 ASSERT(run_length != NULL);
993 ASSERT(colour != NULL);
995 bit_pattern = Get2Bit_Get(my2_u8p, my2_u16, my2_u8);
997 if (bit_pattern != 0x00)
1001 *colour = bit_pattern;
1006 bit_pattern = Get2Bit_Get(my2_u8p, my2_u16, my2_u8);
1007 if (bit_pattern == 0x01)
1015 if (bit_pattern >= 0x2)
1018 *run_length = ((bit_pattern & 1) << 2) + Get2Bit_Get(my2_u8p, my2_u16, my2_u8) + 3;
1019 *colour = Get2Bit_Get(my2_u8p, my2_u16, my2_u8);
1023 if (bit_pattern == 0)
1026 bit_pattern = Get2Bit_Get(my2_u8p, my2_u16, my2_u8);
1027 if (bit_pattern == 0x1)
1035 if (bit_pattern == 0x2)
1038 *run_length = (Get2Bit_Get(my2_u8p, my2_u16, my2_u8) << 2) +
1039 Get2Bit_Get(my2_u8p, my2_u16, my2_u8) + 12;
1040 *colour = Get2Bit_Get(my2_u8p, my2_u16, my2_u8);
1044 if (bit_pattern == 0x3)
1047 *run_length = (Get2Bit_Get(my2_u8p, my2_u16, my2_u8) << 6) +
1048 (Get2Bit_Get(my2_u8p, my2_u16, my2_u8) << 4) +
1049 (Get2Bit_Get(my2_u8p, my2_u16, my2_u8) << 2) +
1050 Get2Bit_Get(my2_u8p, my2_u16, my2_u8) + 29;
1051 *colour = Get2Bit_Get(my2_u8p, my2_u16, my2_u8);
1058 end_of_2_bit_pixel_code_string = TRUE;
1067 if (!end_of_2_bit_pixel_code_string)
1069 STB_PIXMAP_PRINT((
" <2> col %d x %3d", *colour, *run_length));
1073 STB_PIXMAP_PRINT((
" <2> End of String"));
1076 FUNCTION_FINISH(Process2BitPixelCodeString);
1078 return(end_of_2_bit_pixel_code_string);
1096 static BOOLEAN Process4BitPixelCodeString(U16BIT *run_length, U8BIT *colour,
1097 U8BIT *my4_u8p, U16BIT *my4_u16, U8BIT *my4_u8)
1100 BOOLEAN end_of_4_bit_pixel_code_string = FALSE;
1103 FUNCTION_START(Process4BitPixelCodeString);
1105 ASSERT(run_length != NULL);
1106 ASSERT(colour != NULL);
1108 bit_pattern = (U8BIT)Get4Bit_Get(my4_u8p, my4_u16, my4_u8);
1110 if (bit_pattern > 0x00)
1114 *colour = bit_pattern;
1118 bit_pattern = (U8BIT)Get4Bit_Get(my4_u8p, my4_u16, my4_u8);
1120 if (bit_pattern == 0x00)
1125 end_of_4_bit_pixel_code_string = TRUE;
1129 if (bit_pattern <= 0x07)
1132 *run_length = (bit_pattern + 2);
1137 if (bit_pattern <= 0x0b)
1140 *run_length = ((bit_pattern & 0x03) + 4);
1141 *colour = (U8BIT)Get4Bit_Get(my4_u8p, my4_u16, my4_u8);
1145 if (bit_pattern <= 0x0d)
1147 *run_length = ((bit_pattern & 0x03) + 1);
1152 if (bit_pattern == 0x0e)
1155 *run_length = ((U8BIT)Get4Bit_Get(my4_u8p, my4_u16, my4_u8) + 9);
1156 *colour = (U8BIT)Get4Bit_Get(my4_u8p, my4_u16, my4_u8);
1160 if (bit_pattern == 0x0f)
1163 *run_length = (((U8BIT)Get4Bit_Get(my4_u8p, my4_u16, my4_u8) << 4) & 0xf0);
1164 *run_length += (U8BIT)Get4Bit_Get(my4_u8p, my4_u16, my4_u8);
1166 *colour = (U8BIT)Get4Bit_Get(my4_u8p, my4_u16, my4_u8);
1175 if (!end_of_4_bit_pixel_code_string)
1177 STB_PIXMAP_PRINT((
" <4> col %2d x %3d", *colour, *run_length));
1181 STB_PIXMAP_PRINT((
" <4> End of String"));
1184 FUNCTION_FINISH(Process4BitPixelCodeString);
1186 return(end_of_4_bit_pixel_code_string);
1203 static BOOLEAN Process8BitPixelCodeString(U16BIT *run_length, U8BIT *colour, U8BIT *data, U16BIT *byte_count)
1206 BOOLEAN end_of_8_bit_pixel_code_string;
1209 FUNCTION_START(Process8BitPixelCodeString);
1211 ASSERT(data != NULL);
1212 ASSERT(byte_count != NULL);
1213 ASSERT(run_length != NULL);
1214 ASSERT(colour != NULL);
1216 end_of_8_bit_pixel_code_string = FALSE;
1218 bit_pattern = data[(*byte_count)];
1220 if (bit_pattern != 0x00)
1224 *colour = bit_pattern;
1229 bit_pattern = data[(*byte_count)];
1231 if (bit_pattern == 0x00)
1236 end_of_8_bit_pixel_code_string = TRUE;
1240 if (bit_pattern <= 0x7f)
1244 *run_length = bit_pattern;
1250 *run_length = (bit_pattern & 0x7f);
1251 *colour = data[(*byte_count)];
1257 if (!end_of_8_bit_pixel_code_string)
1259 STB_PIXMAP_PRINT((
" <8> col %d x %3d", *colour, *run_length));
1263 STB_PIXMAP_PRINT((
" <8> End of String"));
1266 FUNCTION_FINISH(Process8BitPixelCodeString);
1268 return(end_of_8_bit_pixel_code_string);
1284 static BOOLEAN Process2To4BitMapTable(U8BIT *data, U16BIT *processed_bytes, U8BIT *decoded_data)
1286 FUNCTION_START(Process2To4BitMapTable);
1288 ASSERT(data != NULL);
1289 ASSERT(processed_bytes != NULL);
1290 ASSERT(decoded_data != NULL);
1293 decoded_data[0] = (data[*processed_bytes] & 0xf0) >> 4;
1294 decoded_data[1] = (data[*processed_bytes] & 0x0f);
1295 decoded_data[2] = (data[(*processed_bytes) + 1] & 0xf0) >> 4;
1296 decoded_data[3] = (data[(*processed_bytes) + 1] & 0x0f);
1297 *processed_bytes += 2;
1299 FUNCTION_FINISH(Process2To4BitMapTable);
1319 static BOOLEAN Process2To8BitMapTable(U8BIT *data, U16BIT *processed_bytes, U8BIT *decoded_data)
1321 FUNCTION_START(Process2To8BitMapTable);
1323 ASSERT(data != NULL);
1324 ASSERT(processed_bytes != NULL);
1325 ASSERT(decoded_data != NULL);
1328 decoded_data[0] = data[*processed_bytes];
1329 decoded_data[1] = data[(*processed_bytes) + 1];
1330 decoded_data[2] = data[(*processed_bytes) + 2];
1331 decoded_data[3] = data[(*processed_bytes) + 3];
1332 *processed_bytes += 4;
1334 FUNCTION_FINISH(Process2To8BitMapTable);
1353 static BOOLEAN Process4To8BitMapTable(U8BIT *data, U16BIT *processed_bytes, U8BIT *decoded_data)
1355 FUNCTION_START(Process4To8BitMapTable);
1357 ASSERT(data != NULL);
1358 ASSERT(processed_bytes != NULL);
1359 ASSERT(decoded_data != NULL);
1361 memcpy(decoded_data, data + *processed_bytes, 16);
1363 *processed_bytes += 16;
1365 FUNCTION_FINISH(Process4To8BitMapTable);
1386 static BOOLEAN MakeClutEntry(
S_CLUT *clut, U16BIT clut_id, U8BIT clut_entry_id, U8BIT clut_bit_entry_flags, U32BIT palette_entry)
1391 FUNCTION_START(MakeClutEntry);
1393 ASSERT(clut != NULL);
1395 USE_UNWANTED_PARAM(clut_id);
1399 if (clut_bit_entry_flags & 0x4)
1401 if (clut_entry_id < 4)
1403 if (clut->default_2_bit)
1406 if (clut->clut_2_bit == NULL)
1408 clut->clut_2_bit = default_2_bit_clut;
1413 memcpy((
void *)clut->clut_2_bit, (
void *)default_2_bit_clut, (
size_t)(4 * 4));
1414 clut->default_2_bit = FALSE;
1415 clut->clut_2_bit[clut_entry_id] = palette_entry;
1420 clut->clut_2_bit[clut_entry_id] = palette_entry;
1425 if (clut_bit_entry_flags & 0x2)
1427 if (clut_entry_id < 16)
1429 if (clut->default_4_bit)
1432 if (clut->clut_4_bit == NULL)
1434 clut->clut_4_bit = default_4_bit_clut;
1439 memcpy((
void *)clut->clut_4_bit, (
void *)default_4_bit_clut, (
size_t)(16 * 4));
1440 clut->default_4_bit = FALSE;
1441 clut->clut_4_bit[clut_entry_id] = palette_entry;
1446 clut->clut_4_bit[clut_entry_id] = palette_entry;
1451 if (clut_bit_entry_flags & 0x1)
1453 if (clut->default_8_bit)
1456 if (clut->clut_8_bit == NULL)
1458 clut->clut_8_bit = default_8_bit_clut;
1463 memcpy((
void *)clut->clut_8_bit, (
void *)default_8_bit_clut, (
size_t)(256 * 4));
1464 clut->default_8_bit = FALSE;
1465 clut->clut_8_bit[clut_entry_id] = palette_entry;
1470 clut->clut_8_bit[clut_entry_id] = palette_entry;
1474 FUNCTION_FINISH(MakeClutEntry);
1479 #ifdef STB_REGION_PRINT_REQUIRED 1498 void CheckRegionFootPrint(
S_EPOCH_REGION *region, U16BIT region_width, U16BIT region_height,
1499 U16BIT region_level_of_compatability, U16BIT region_depth, U16BIT clut_id)
1501 FUNCTION_START(CheckRegionFootPrint);
1504 if (region->region_width != region_width)
1506 STB_REGION_PRINT((
"Attempt to redefine width"));
1508 if (region->region_height != region_height)
1510 STB_REGION_PRINT((
"Attempt to redefine height"));
1512 if (region->region_level_of_compatibilty != region_level_of_compatability)
1514 STB_REGION_PRINT((
"Attempt to redefine compatibilty"));
1516 if (region->region_colour_depth != region_depth)
1518 STB_REGION_PRINT((
"Attempt to redefine depth"));
1520 if (region->region_clut_id != clut_id)
1522 STB_REGION_PRINT((
"Attempt to redefine clut id"));
1525 FUNCTION_FINISH(CheckRegionFootPrint);
1543 static void DestroyObject(
S_OBJECT **obj, BOOLEAN del_obj)
1545 FUNCTION_START(DestroyObject);
1547 ASSERT(*obj != NULL);
1553 if ((*obj)->character_code)
1557 if ((*obj)->map_table_2_to_4_bit != (U8BIT *)default_2_bit_4_bit_map)
1561 if ((*obj)->map_table_2_to_8_bit != (U8BIT *)default_2_bit_8_bit_map)
1565 if ((*obj)->map_table_4_to_8_bit != (U8BIT *)default_4_bit_8_bit_map)
1577 memset((
void *)*obj, 0x00,
sizeof(
S_OBJECT));
1578 (*obj)->map_table_2_to_4_bit = (U8BIT *)default_2_bit_4_bit_map;
1579 (*obj)->map_table_2_to_8_bit = (U8BIT *)default_2_bit_8_bit_map;
1580 (*obj)->map_table_4_to_8_bit = (U8BIT *)default_4_bit_8_bit_map;
1583 FUNCTION_FINISH(DestroyObject);
1597 static void DeleteObjectList(
S_OBJECT **obj)
1603 FUNCTION_START(DeleteObjectList);
1607 while (ptr_1 != NULL)
1609 ptr_2 = ptr_1->next;
1610 DestroyObject(&ptr_1, TRUE);
1616 FUNCTION_FINISH(DeleteObjectList);
1630 static void DeleteClutList(
S_CLUT **clut)
1636 FUNCTION_START(DeleteClutList);
1640 while (ptr_1 != NULL)
1642 if (!ptr_1->default_2_bit)
1647 if (!ptr_1->default_4_bit)
1652 if (!ptr_1->default_8_bit)
1657 ptr_2 = ptr_1->next;
1664 FUNCTION_FINISH(DeleteClutList);
1686 FUNCTION_START(DeleteEpochRegionList);
1688 ptr_r1 = *region_list;
1690 while (ptr_r1 != NULL)
1692 ptr_o1 = ptr_r1->region_object_list;
1693 while (ptr_o1 != NULL)
1696 ptr_o2 = ptr_o1->next;
1702 ptr_r2 = ptr_r1->next;
1707 *region_list = NULL;
1709 FUNCTION_FINISH(DeleteEpochRegionList);
1724 static void DeletePageCompositionRegions(
S_REGION **comp_pg)
1730 FUNCTION_START(DeletePageCompositionRegions);
1734 while (ptr_1 != NULL)
1736 ptr_2 = ptr_1->next;
1743 FUNCTION_FINISH(DeletePageCompositionRegions);
1765 if (temp_buffer == NULL)
1767 STB_SUB_DRIVER_PRINT((
"Initialation failure!!!"));
1771 STB_SUB_DRIVER_PRINT((
"Initialised OK"));
1773 memset((
void *)&subtitle_display_set, 0x00,
sizeof(
S_DISPLAY_SET));
1778 page_1.dds_present = FALSE;
1779 page_1.dds_version = 0xff;
1780 page_1.display_width = 719;
1781 page_1.display_height = 575;
1782 page_1.display_window = FALSE;
1783 page_1.page_version_number = 0xff;
1785 page_2.dds_present = FALSE;
1786 page_2.dds_version = 0xff;
1787 page_2.display_width = 719;
1788 page_2.display_height = 575;
1789 page_2.display_window = FALSE;
1790 page_2.page_version_number = 0xff;
1792 subtitle_display_set.page_display_buffer = &page_1;
1793 subtitle_display_set.page_composition_buffer = &page_2;
1823 while (clut != NULL)
1825 if (clut->clut_id == clut_id)
1837 STB_CDS_PRINT((
" +c%d", clut_id));
1839 clut->clut_id = clut_id;
1841 clut->clut_2_bit = default_2_bit_clut;
1842 clut->clut_4_bit = default_4_bit_clut;
1843 clut->clut_8_bit = default_8_bit_clut;
1844 clut->default_2_bit = TRUE;
1845 clut->default_4_bit = TRUE;
1846 clut->default_8_bit = TRUE;
1847 clut->clut_version_number = 0xff;
1850 clut->next = subtitle_display_set.clut_list;
1851 subtitle_display_set.clut_list = clut;
1855 STB_CDS_PRINT((
"CLUT %d malloc fail", clut_id));
1879 U16BIT segment_length;
1880 U16BIT processed_length;
1882 BOOLEAN display_window;
1883 U16BIT display_width, display_height;
1888 ASSERT(data != NULL);
1895 segment_length = (data[4] << 8) + data[5];
1897 STB_SEGMENT_PRINT((
"DDS: segment_length=%u", segment_length));
1899 if ((processed_bytes + segment_length + 5) > pes_len)
1901 STB_SEGMENT_PRINT((
"\n\nABORT DDS processing - pes too short"));
1905 dds_version = (data[6] & 0xf0) >> 4;
1907 display_window = ((data[6] & 0x08) != 0);
1908 display_width = (data[7] << 8) + data[8];
1909 display_height = (data[9] << 8) + data[10];
1911 processed_length = 10;
1913 STB_SEGMENT_PRINT((
"DDS: display %ux%u", display_width, display_height));
1917 processed_length += 8;
1920 if (subtitle_display_set.page_composition_buffer != NULL)
1922 subtitle_display_set.page_composition_buffer->dds_present = TRUE;
1924 if (dds_version != subtitle_display_set.page_composition_buffer->dds_version)
1926 subtitle_display_set.page_composition_buffer->dds_version = dds_version;
1928 subtitle_display_set.page_composition_buffer->display_width = display_width;
1929 subtitle_display_set.page_composition_buffer->display_height = display_height;
1930 subtitle_display_set.page_composition_buffer->display_window = display_window;
1934 subtitle_display_set.page_composition_buffer->window_x = (data[11] << 8) + data[12];
1935 subtitle_display_set.page_composition_buffer->window_width = ((data[13] << 8) + data[14]) -
1936 subtitle_display_set.page_composition_buffer->window_x + 1;
1937 subtitle_display_set.page_composition_buffer->window_y = (data[15] << 8) + data[16];
1938 subtitle_display_set.page_composition_buffer->window_height = ((data[17] << 8) + data[18]) -
1939 subtitle_display_set.page_composition_buffer->window_y + 1;
1941 STB_SEGMENT_PRINT((
"DDS: window %u,%u : %ux%u",
1942 subtitle_display_set.page_composition_buffer->window_x,
1943 subtitle_display_set.page_composition_buffer->window_y,
1944 subtitle_display_set.page_composition_buffer->window_width,
1945 subtitle_display_set.page_composition_buffer->window_height));
1951 retval = (processed_length == (segment_length + 5));
1972 BOOLEAN
STB_DSSegmentPCS(U8BIT *data, U16BIT pes_len, U16BIT processed_bytes, BOOLEAN external_force_acquisition)
1975 U16BIT segment_length;
1976 U16BIT processed_length;
1978 U8BIT page_time_out;
1979 U8BIT page_version_number;
1981 BOOLEAN retval = FALSE;
1983 static BOOLEAN force_acquisition = TRUE;
1987 ASSERT(data != NULL);
1995 force_acquisition |= external_force_acquisition;
1998 external_force_acquisition = force_acquisition;
2000 segment_length = (data[4] << 8) + data[5];
2002 if ((processed_bytes + segment_length + 6) > pes_len)
2004 STB_SEGMENT_PRINT((
"\n\nABORT PCS processing - pes too short"));
2009 page_time_out = data[6];
2010 page_version_number = (data[7] & 0xf0) >> 4;
2011 page_state = (data[7] & 0x0c) >> 2;
2013 processed_length = 2;
2016 if ((subtitle_display_set.page_composition_buffer != NULL) && (page_state != RES_PAGE_STATE))
2019 if (!subtitle_display_set.page_composition_buffer->dds_present)
2022 subtitle_display_set.page_composition_buffer->display_width = 719;
2023 subtitle_display_set.page_composition_buffer->display_height = 575;
2024 subtitle_display_set.page_composition_buffer->display_window = FALSE;
2028 if ((subtitle_display_set.page_display_buffer->page_version_number != page_version_number) || force_acquisition)
2030 STB_SEGMENT_PRINT((
"\n\nPCS <state %d> Ver v%d ( Comp v%d / Disp v%d ) timeout %d",
2031 page_state, page_version_number,
2032 subtitle_display_set.page_composition_buffer->page_version_number,
2033 subtitle_display_set.page_display_buffer->page_version_number,
2039 if ((page_state == MODE_CHANGE) ||
2040 ((page_state == ACQUISITION_POINT) && force_acquisition))
2042 page_state = MODE_CHANGE;
2044 force_acquisition = FALSE;
2051 STB_SEGMENT_PRINT((
"pcs NORMAL_CASE"));
2057 case ACQUISITION_POINT:
2061 STB_SEGMENT_PRINT((
"pcs ACQUISITION_POINT - treating as mode change"));
2062 page_state = MODE_CHANGE;
2070 if (external_force_acquisition)
2072 STB_SEGMENT_PRINT((
"pcs FORCED Reset display region list + Obj + CLUT ++ EPOCH"));
2076 STB_SEGMENT_PRINT((
"pcs Reset display region list + Obj + CLUT ++ EPOCH"));
2082 DeleteEpochRegionList(&subtitle_display_set.region_list);
2083 DeleteObjectList(&subtitle_display_set.object_list);
2084 DeleteClutList(&subtitle_display_set.clut_list);
2092 subtitle_display_set.page_composition_buffer->page_time_out = page_time_out;
2093 subtitle_display_set.page_composition_buffer->page_version_number = page_version_number;
2094 subtitle_display_set.page_composition_buffer->page_state = page_state;
2111 while (processed_length < segment_length)
2117 region->region_id = data[0];
2118 region->region_horizontal_address = (data[2] << 8) + data[3];
2119 region->region_vertical_address = (data[4] << 8) + data[5];
2121 if (subtitle_display_set.page_composition_buffer->display_window)
2123 region->region_horizontal_address += subtitle_display_set.page_composition_buffer->window_x;
2124 region->region_vertical_address += subtitle_display_set.page_composition_buffer->window_y;
2126 if (region->region_horizontal_address > subtitle_display_set.page_composition_buffer->display_width)
2128 region->region_horizontal_address = subtitle_display_set.page_composition_buffer->display_width;
2131 if (region->region_vertical_address > subtitle_display_set.page_composition_buffer->display_height)
2133 region->region_vertical_address = subtitle_display_set.page_composition_buffer->display_height;
2138 if (region->region_horizontal_address > subtitle_display_set.page_composition_buffer->display_width)
2140 region->region_horizontal_address = subtitle_display_set.page_composition_buffer->display_width;
2143 if (region->region_vertical_address > subtitle_display_set.page_composition_buffer->display_height)
2145 region->region_vertical_address = subtitle_display_set.page_composition_buffer->display_height;
2150 region->next = subtitle_display_set.page_composition_buffer->region_list;
2151 subtitle_display_set.page_composition_buffer->region_list = region;
2153 STB_SEGMENT_PRINT((
" +r%d @ (%3d, %3d)",
2155 region->region_horizontal_address, region->region_vertical_address));
2160 processed_length += 6;
2167 STB_SEGMENT_PRINT((
"\n\nPCS <state %d> Ver v%d ( Comp v%d / Disp v%d ) -- Unchanged version - IGNORING (force_acquisition=%s)",
2168 page_state, page_version_number,
2169 subtitle_display_set.page_composition_buffer->page_version_number,
2170 subtitle_display_set.page_display_buffer->page_version_number,
2171 force_acquisition ?
"TRUE" :
"FALSE"));
2173 subtitle_display_set.page_composition_buffer->page_state = page_state;
2178 retval &= (processed_length == segment_length);
2183 STB_SEGMENT_PRINT((
"\n\nPCS -- Not processed, illegal state %s@%d", __FILE__, __LINE__));
2209 U16BIT segment_length;
2210 U16BIT processed_length;
2212 U8BIT region_version_number;
2220 ASSERT(data != NULL);
2227 segment_length = (data[4] << 8) + data[5];
2229 if ((processed_bytes + segment_length + 6) > pes_len)
2231 STB_SEGMENT_PRINT((
"\n\nABORT RCS processing - pes too short"));
2236 region_id = data[6];
2237 region_version_number = (data[7] & 0xf0) >> 4;
2239 processed_length = 10;
2242 region = subtitle_display_set.region_list;
2244 while (region != NULL)
2246 if (region->region_id == region_id)
2250 region = region->next;
2257 if (region->region_version_number != region_version_number)
2263 STB_SEGMENT_PRINT((
"RCS Region r%d (existing version %d) new ver %d c%d %s 8_%d 4_%d 2_%d",
2264 region_id, region->region_version_number, region_version_number,
2266 ((data[7] & 0x08) >> 3) ?
"FILL" :
"no fill",
2267 data[14], (data[15] & 0xf0) >> 4, (data[15] & 0x0c) >> 2));
2269 object_1 = region->region_object_list;
2270 while (object_1 != NULL)
2273 object_2 = object_1->next;
2275 object_1 = object_2;
2277 region->region_object_list = NULL;
2282 STB_SEGMENT_PRINT((
"RCS Region r%d version number %d unchanged -- IGNORING",
2283 region_id, region->region_version_number, region_version_number));
2290 else if (subtitle_display_set.page_composition_buffer->page_state == MODE_CHANGE)
2299 region->region_id = region_id;
2300 region->region_version_number = region_version_number;
2301 region->region_object_list = NULL;
2304 region->region_width = (data[8] << 8) + data[9];
2306 region->region_height = (data[10] << 8) + data[11];
2307 region->region_level_of_compatibilty = (data[12] & 0xe0) >> 5;
2308 region->region_level_of_compatibilty = 1 << region->region_level_of_compatibilty;
2309 region->region_clut_id = data[13];
2310 region->region_colour_depth = (data[12] & 0x1c) >> 2;
2311 region->region_colour_depth = 1 << region->region_colour_depth;
2314 region->region_fill_flag = (data[7] & 0x08) >> 3;
2315 region->region_8_bit_pixel_code = data[14];
2316 region->region_4_bit_pixel_code = (data[15] & 0xf0) >> 4;
2317 region->region_2_bit_pixel_code = (data[15] & 0x0c) >> 2;
2319 STB_SEGMENT_PRINT((
"RCS r%d NEW ver %d (%dx%d(x%d)) compat %x c%d %s 8_%d 4_%d 2_%d",
2321 region->region_version_number,
2322 region->region_width,
2323 region->region_height,
2324 region->region_colour_depth,
2325 region->region_level_of_compatibilty,
2327 ((data[7] & 0x08) >> 3) ?
"FILL" :
"no fill",
2328 data[14], (data[15] & 0xf0) >> 4, (data[15] & 0x0c) >> 2));
2331 region->next = subtitle_display_set.region_list;
2332 subtitle_display_set.region_list = region;
2335 STB_DSGetClut(subtitle_display_set.clut_list, region->region_clut_id);
2337 #ifdef STB_REGION_PRINT_REQUIRED 2338 if (subtitle_display_set.page_composition_buffer->page_state != MODE_CHANGE)
2340 CheckRegionFootPrint(region,
2341 region->region_width,
2342 region->region_height,
2343 region->region_level_of_compatibilty,
2344 region->region_colour_depth,
2345 region->region_clut_id);
2353 STB_SEGMENT_PRINT((
"RCS Region r%d (No pre-existing vn) new ver %d - CANNOT CREATE - page state %d",
2354 region_id, region_version_number,
2355 subtitle_display_set.page_composition_buffer->page_state));
2365 region->region_version_number = region_version_number;
2368 region->region_fill_flag = (data[7] & 0x08) >> 3;
2369 region->region_8_bit_pixel_code = data[14];
2370 region->region_4_bit_pixel_code = (data[15] & 0xf0) >> 4;
2371 region->region_2_bit_pixel_code = (data[15] & 0x0c) >> 2;
2375 subtitle_display_set.page_composition_buffer->page_state);
2380 while (processed_length < segment_length)
2382 object_id = (data[0] << 8) + data[1];
2383 object_type = (data[2] & 0xc0) >> 6;
2385 existing_region_object = region->region_object_list;
2386 while (existing_region_object != NULL)
2388 if (existing_region_object->object_id == object_id)
2390 object = existing_region_object;
2393 existing_region_object = existing_region_object->next;
2396 if (existing_region_object == NULL)
2404 object->object_id = object_id;
2405 object->object_type = (data[2] & 0xc0) >> 6;
2406 object->object_provider_flag = (data[2] & 0x30) >> 4;
2407 object->object_horizontal_position = ((data[2] & 0x0f) << 8) + data[3];
2408 object->object_vertical_position = ((data[4] & 0x0f) << 8) + data[5];
2410 if ((object->object_type == 0x01) || (
object->object_type == 0x02))
2412 object->object_foreground_pixel_code = data[6];
2413 object->object_background_pixel_code = data[7];
2416 if (existing_region_object == NULL)
2418 object->next = region->region_object_list;
2419 region->region_object_list = object;
2420 STB_SEGMENT_PRINT((
" +o%d @(%d,%d)",
2422 object->object_horizontal_position,
2423 object->object_vertical_position));
2427 STB_SEGMENT_PRINT((
" ~o%d @(%d,%d)",
2429 object->object_horizontal_position,
2430 object->object_vertical_position));
2440 if ((object_type == 0x01) || (object_type == 0x02))
2444 processed_length += 8;
2450 processed_length += 6;
2456 retval = (processed_length == segment_length);
2478 U32BIT palette_entry;
2479 U16BIT segment_length;
2480 U16BIT processed_length;
2482 U8BIT clut_version_number;
2483 U8BIT display_version_number;
2484 U16BIT clut_entries = 0;
2486 U8BIT clut_entry_id;
2487 U8BIT clut_2_4_8_bit_entry_flags;
2488 U8BIT full_range_flag;
2500 ASSERT(data != NULL);
2507 segment_length = (data[4] << 8) + data[5];
2509 if ((processed_bytes + segment_length + 6) > pes_len)
2516 clut_version_number = (data[7] & 0xf0) >> 4;
2519 processed_length = 2;
2521 clut =
STB_DSGetClut(subtitle_display_set.clut_list, clut_id);
2523 display_version_number = clut->clut_version_number;
2525 if (display_version_number == clut_version_number)
2535 STB_SEGMENT_PRINT((
"CDS c%d version number %d unchanged - ignoring",
2536 clut_id, clut_version_number));
2541 processed_length = segment_length;
2547 STB_CLUT_PRINT((
"CDS c%d v%d", clut_id, clut_version_number));
2548 while (processed_length < segment_length)
2550 clut_entry_id = data[0];
2551 clut_2_4_8_bit_entry_flags = (data[1] & 0xe0) >> 5;
2552 full_range_flag = data[1] & 0x01;
2554 if (full_range_flag)
2561 processed_length += 6;
2567 y = (data[2] & 0xfc);
2568 cr = ((data[2] & 0x03) << 6) + ((data[3] & 0xc0) >> 2);
2569 cb = (data[3] & 0x3c) << 2;
2570 t = (data[3] & 0x03) << 6;
2572 processed_length += 4;
2583 palette_entry = 0xff000000;
2587 palette_entry = (t << 24) + (y << 16) + (cr << 8) + cb;
2590 MakeClutEntry(clut, clut_id, clut_entry_id, clut_2_4_8_bit_entry_flags, palette_entry);
2591 STB_CLUT_PRINT((
" %3d> p%08x f%02x ", clut_entry_id, palette_entry, clut_2_4_8_bit_entry_flags));
2595 STB_SEGMENT_PRINT((
"CDS c%d v%d -- %d entries", clut_id, clut_version_number, clut_entries));
2596 clut->clut_version_number = clut_version_number;
2599 if (processed_length == segment_length)
2628 U16BIT segment_length;
2630 U8BIT object_version_number;
2631 U8BIT object_coding_method;
2632 U8BIT non_modifying_colour_flag;
2637 ASSERT(data != NULL);
2646 segment_length = (data[4] << 8) + data[5];
2648 if ((processed_bytes + segment_length + 6) > pes_len)
2653 object_id = (data[6] << 8) + data[7];
2655 object_version_number = (data[8] & 0xf0) >> 4;
2656 object_coding_method = (data[8] & 0x0c) >> 2;
2657 non_modifying_colour_flag = (data[8] & 0x02) >> 1;
2659 object = subtitle_display_set.object_list;
2662 while (
object != NULL)
2664 if (object->object_id == object_id)
2668 object =
object->next;
2673 if (object->object_version_number != object_version_number)
2676 STB_SEGMENT_PRINT((
"ODS o%d (existing version v%d) new ver v%d",
2678 object->object_version_number,
2679 object_version_number));
2683 STB_SEGMENT_PRINT((
"ODS o%d version number v%d unchanged -- IGNORING",
2684 object_id, object_version_number));
2707 STB_SEGMENT_PRINT((
"ODS o%d ver v%d", object_id, object_version_number));
2709 memset((
void *)
object, 0x00,
sizeof(
S_OBJECT));
2711 object->next = subtitle_display_set.object_list;
2712 subtitle_display_set.object_list = object;
2716 STB_SEGMENT_PRINT((
"ODS o%d ver v%d malloc fail", object_id, object_version_number));
2722 object->object_id = object_id;
2723 object->object_version_number = object_version_number;
2724 object->object_coding_method = object_coding_method;
2725 object->non_modifying_colour_flag = non_modifying_colour_flag;
2726 object->map_table_2_to_4_bit = default_2_bit_4_bit_map;
2727 object->map_table_2_to_8_bit = default_2_bit_8_bit_map;
2728 object->map_table_4_to_8_bit = default_4_bit_8_bit_map;
2730 if (ProcessObjectCodingMethod(data + 9,
object, object_coding_method, segment_length))
2762 U16BIT segment_length;
2768 ASSERT(data != NULL);
2770 STB_SEGMENT_PRINT((
"EDS - End of Page"));
2777 segment_length = (data[4] << 8) + data[5];
2779 if ((processed_bytes + segment_length + 6) > pes_len)
2784 if (segment_length == 0)
2793 STB_DSDumpPageState(
"post-EDS");
2820 pts[0] = (data[0] & 0x08) >> 3;
2821 pts[1] = ((data[0] & 0x06) << 5) + ((data[1] & 0xfc) >> 2);
2822 pts[2] = ((data[1] & 0x03) << 6) + ((data[2] & 0xfc) >> 2);
2823 pts[3] = ((data[2] & 0x02) << 6) + ((data[3] & 0xfe) >> 1);
2824 pts[4] = ((data[3] & 0x01) << 7) + ((data[4] & 0xfe) >> 1);
2826 retval = (data[0] & 0x01) & (data[2] & 0x01) & (data[4] & 0x01);
2848 U32BIT stc_timestamp;
2849 U32BIT pts_timestamp;
2856 ASSERT(pts != NULL);
2861 stc_timestamp = ((stc[0] << 24) + (stc[1] << 16) + (stc[2] << 8) + stc[3]);
2862 pts_timestamp = ((pts[0] << 24) + (pts[1] << 16) + (pts[2] << 8) + pts[3]);
2864 memcpy((
void *)subtitle_display_set.page_composition_buffer->pts, (
void *)pts, (
size_t)5);
2866 if (pts_timestamp > stc_timestamp)
2868 stc_timestamp = ((stc[1] << 24) + (stc[2] << 16) + (stc[3] << 8) + stc[4]);
2869 pts_timestamp = ((pts[1] << 24) + (pts[2] << 16) + (pts[3] << 8) + pts[4]);
2871 stc_delay = pts_timestamp - stc_timestamp;
2872 ms_delay = stc_delay / 90;
2874 subtitle_display_set.page_composition_buffer->presentation_time_ms = time_ms + ms_delay;
2878 subtitle_display_set.page_composition_buffer->presentation_time_ms = time_ms;
2901 return(&subtitle_display_set);
2919 DeletePageCompositionRegions(&subtitle_display_set.page_composition_buffer->region_list);
2920 DeletePageCompositionRegions(&subtitle_display_set.page_display_buffer->region_list);
2921 DeleteEpochRegionList(&subtitle_display_set.region_list);
2922 DeleteObjectList(&subtitle_display_set.object_list);
2923 DeleteClutList(&subtitle_display_set.clut_list);
2925 memset((
void *)&subtitle_display_set, 0x00,
sizeof(
S_DISPLAY_SET));
2930 page_1.dds_present = FALSE;
2931 page_1.dds_version = 0xff;
2932 page_1.display_width = 719;
2933 page_1.display_height = 575;
2934 page_1.display_window = FALSE;
2935 page_1.page_version_number = 0xff;
2937 page_2.dds_present = FALSE;
2938 page_2.dds_version = 0xff;
2939 page_2.display_width = 719;
2940 page_2.display_height = 575;
2941 page_2.display_window = FALSE;
2942 page_2.page_version_number = 0xff;
2944 subtitle_display_set.page_display_buffer = &page_1;
2945 subtitle_display_set.page_composition_buffer = &page_2;
2965 DeletePageCompositionRegions(&subtitle_display_set.page_composition_buffer->region_list);
2967 subtitle_display_set.page_composition_buffer->pts[0] = 0x00;
2968 subtitle_display_set.page_composition_buffer->pts[1] = 0x00;
2969 subtitle_display_set.page_composition_buffer->pts[2] = 0x00;
2970 subtitle_display_set.page_composition_buffer->pts[3] = 0x00;
2971 subtitle_display_set.page_composition_buffer->pts[4] = 0x00;
2973 subtitle_display_set.page_composition_buffer->display_set_shown = FALSE;
2974 subtitle_display_set.page_composition_buffer->display_set_removed = FALSE;
2975 subtitle_display_set.page_composition_buffer->dds_present = FALSE;
2980 static void STB_DSDumpPageState(
const char *label)
2984 #ifdef STB_CLUT_PRINT_REQUIRED 2987 #ifdef STB_OBJECT_PRINT_REQUIRED 2992 #ifdef STB_SUMMARY_PRINT_REQUIRED 2993 STB_SUMMARY_PRINT((
"\nPage state dump \"%s\"\n EPOCH Reg", label));
2995 USE_UNWANTED_PARAM(label);
3000 regione = subtitle_display_set.region_list;
3002 while (regione != NULL)
3004 STB_SUMMARY_PRINT((
" r%d (v%d) (w%d, h%d, d%d) c%d",
3006 regione->region_version_number,
3007 regione->region_width,
3008 regione->region_height,
3009 regione->region_colour_depth,
3010 regione->region_clut_id));
3011 #ifdef STB_OBJECT_PRINT_REQUIRED 3012 region_object = regione->region_object_list;
3013 while (region_object != NULL)
3015 STB_SUMMARY_PRINT((
" o%3d @(%d,%d)",
3016 region_object->object_id,
3017 region_object->object_horizontal_position,
3018 region_object->object_vertical_position));
3019 region_object = region_object->next;
3022 regione = regione->next;
3025 STB_SUMMARY_PRINT((
" <END>\n Composition"));
3028 region = subtitle_display_set.page_composition_buffer->region_list;
3030 while (region != NULL)
3032 STB_SUMMARY_PRINT((
" r%d @ (%dx%d)",
3034 region->region_horizontal_address,
3035 region->region_vertical_address));
3036 region = region->next;
3039 STB_SUMMARY_PRINT((
" <END>\n Display"));
3042 region = subtitle_display_set.page_display_buffer->region_list;
3044 while (region != NULL)
3046 STB_SUMMARY_PRINT((
" r%d @ (%dx%d)",
3048 region->region_horizontal_address,
3049 region->region_vertical_address));
3051 region = region->next;
3054 #ifdef STB_OBJECT_PRINT_REQUIRED 3056 STB_SUMMARY_PRINT((
" <END>\n Objects"));
3058 object = subtitle_display_set.object_list;
3060 while (
object != NULL)
3062 STB_SUMMARY_PRINT((
" o%3d v%2d (%dx%d) coding %d %s",
3064 object->object_version_number,
3065 object->width, object->height,
3066 object->object_coding_method,
3067 (object->non_modifying_colour_flag) ?
"nonmod" :
"MODIFY"));
3068 object =
object->next;
3072 #ifdef STB_CLUT_PRINT_REQUIRED 3073 STB_SUMMARY_PRINT((
" <END>\n Clut"));
3075 clut = subtitle_display_set.clut_list;
3077 while (clut != NULL)
3079 STB_SUMMARY_PRINT((
" c%d v%3d 2-%s 4-%s 8-%s",
3081 clut->clut_version_number,
3082 (clut->default_2_bit) ?
"default" :
"CHANGED",
3083 (clut->default_4_bit) ?
"default" :
"CHANGED",
3084 (clut->default_8_bit) ?
"default" :
"CHANGED"));
3089 STB_SUMMARY_PRINT((
" <END>"));
S_CLUT * STB_DSGetClut(S_CLUT *clut_list, U16BIT clut_id)
Finds or malloc's a new CLUT and assigns the family pointers to the default data. version_id is set t...
void STB_DSCreateCompositionRegion(S_EPOCH_REGION *region, BOOLEAN page_reset)
By end of call ensures that the specified region has a suitable physical region waiting in the physic...
void * STB_GetMemory(U32BIT bytes)
Attempts to allocate memory from the heap.
BOOLEAN STB_DSSegmentPCS(U8BIT *data, U16BIT pes_len, U16BIT processed_bytes, BOOLEAN external_force_acquisition)
Processes the Page Composition segment in accordance with ETSI document ETS 300 743.
BOOLEAN STB_DSSegmentCDS(U8BIT *data, U16BIT pes_len, U16BIT processed_bytes)
Processes the CLUT Definition segment in accordance with ETSI document ETS 300 743.
BOOLEAN STB_DSSegmentDDS(U8BIT *data, U16BIT pes_len, U16BIT processed_bytes)
Processes the Display Definition segment in accordance with ETSI document ETS 300 743...
Header file - macros and function prototypes for public use.
void STB_DSClearDisplaySetStruct(void)
Clears all information from the display set structure.
BOOLEAN STB_DSSegmentRCS(U8BIT *data, U16BIT pes_len, U16BIT processed_bytes)
Processes the Region Composition segment in accordance with ETSI document ETS 300 743...
Header file - Function prototypes for OSD control.
void STB_DSClearCompositionPageDetails(void)
Clears all information from the display set composition page.
void STB_AVGetSTC(U8BIT path, U8BIT stc[5])
Returns the current 33-bit System Time Clock from the PCR PES. On some systems, this information may ...
U8BIT STB_DPGetPathVideoDecoder(U8BIT path)
Returns the video decoder ID acquired by the given decode path.
Header file - Function prototypes for A/V control.
Header file - Function prototypes for DVB subtitles.
void STB_FreeMemory(void *addr)
Releases previously allocated heap memory.
BOOLEAN STB_DSSegmentEDS(U8BIT *data, U16BIT pes_len, U16BIT processed_bytes)
DTG - Digital Terrestrial Television Requirements for Interoperability Subtitling: 28 August 1998: Ve...
Debug functions header file.
BOOLEAN STB_DSGetPesPts(U8BIT *data, U8BIT *pts)
Extracts the PTS from the PES packet header.
void STB_DSRenderBitmapToRegion(S_EPOCH_REGION *region_list, S_OBJECT *object, U8BIT *scan_line, U16BIT y, U16BIT w, U16BIT h)
For the passed region list [PCS specified] get region handle, load the region with the correct CLUT...
BOOLEAN STB_DSSetDisplaySetPts(U8BIT path, U8BIT *pts)
Copies the passed PTS into the display set structure.
Header file - Function prototypes for operating system.
System Wide Global Technical Data Type Definitions.
S_DISPLAY_SET * STB_DSGetDetails(void)
Gets a pointer to the display set structure.
BOOLEAN STB_DSInitialiseDVBSubtitlesProcessing(void)
Initilises DVB subtitles, allocates a temporary buffer for use as a scratchpad and zero's the display...
void STB_DSResetPhysicalCompositionRegions(void)
Deletes all regions and clears serice_aquired flag.
Header file - Function prototypes for heap memory.
BOOLEAN STB_DSSegmentODS(U8BIT *data, U16BIT pes_len, U16BIT processed_bytes)
Processes the Object Data segment in accordance with ETSI document ETS 300 743.
U32BIT STB_OSGetClockMilliseconds(void)
Get Current Computer Clock Time.