Skip to content

Commit

Permalink
Fixed DRCS parser bug
Browse files Browse the repository at this point in the history
  • Loading branch information
scimmia9286 committed Apr 22, 2021
1 parent 5e9be27 commit 58a34b8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,9 +1139,10 @@ static int decoder_handle_time( arib_decoder_t *decoder )
return 1;
break;
default:
if( i_mode == 1 && c >= 0x40 && c <= 0x7F )
if( i_mode == 1 && c >= 0x40 && c <= 0x7F ) {
decoder->i_control_time += c & 0x3f;
return 1;
}
return 0;
}
if( i_mode == 0 )
Expand Down
12 changes: 8 additions & 4 deletions src/drcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,19 @@ static void save_drcs_pattern_data_image(
void save_drcs_pattern(
arib_instance_t *p_instance,
int i_width, int i_height,
int i_depth, const int8_t* p_patternData )
int i_depth, const int8_t* p_patternData,
int16_t i_CharacterCode )
{
// int i_drcsPage = (i_CharacterCode >> 16) & 0xff;
int i_code = (i_CharacterCode & 0xff) - 0x20;
char* psz_hash = get_drcs_pattern_data_hash( p_instance,
i_width, i_height, i_depth, p_patternData );

strncpy( p_instance->p->drcs_hash_table[p_instance->p->i_drcs_num], psz_hash, 32 );
p_instance->p->drcs_hash_table[p_instance->p->i_drcs_num][32] = '\0';
strncpy( p_instance->p->drcs_hash_table[i_code-1], psz_hash, 32 );
p_instance->p->drcs_hash_table[i_code-1][32] = '\0';

p_instance->p->i_drcs_num++;
p_instance->p->i_drcs_num = i_code > p_instance->p->i_drcs_num ?
i_code : p_instance->p->i_drcs_num;

save_drcs_pattern_data_image( p_instance, psz_hash,
i_width, i_height, i_depth, p_patternData );
Expand Down
2 changes: 1 addition & 1 deletion src/drcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ typedef struct drcs_data_s

bool apply_drcs_conversion_table( arib_instance_t * );
bool load_drcs_conversion_table( arib_instance_t * );
void save_drcs_pattern( arib_instance_t *, int, int, int, const int8_t* );
void save_drcs_pattern( arib_instance_t *, int, int, int, const int8_t*, int16_t );

#endif
25 changes: 21 additions & 4 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ static void parse_data_unit_DRCS( arib_parser_t *p_parser, bs_t *p_bs,
uint8_t i_data_unit_parameter,
uint32_t i_data_unit_size )
{
p_parser->p_instance->p->i_drcs_num = 0;
#ifdef ARIBSUB_GEN_DRCS_DATA
if( p_parser->p_drcs_data != NULL )
{
Expand Down Expand Up @@ -119,7 +118,7 @@ static void parse_data_unit_DRCS( arib_parser_t *p_parser, bs_t *p_bs,

for( int i = 0; i < i_NumberOfCode; i++ )
{
bs_skip( p_bs, 16 ); /* i_character_code */
int16_t i_CharacterCode = bs_read( p_bs, 16 ); /* i_character_code */
p_parser->i_data_unit_size += 2;
uint8_t i_NumberOfFont = bs_read( p_bs, 8 );
p_parser->i_data_unit_size += 1;
Expand All @@ -139,7 +138,11 @@ static void parse_data_unit_DRCS( arib_parser_t *p_parser, bs_t *p_bs,

for( int j = 0; j < i_NumberOfFont; j++ )
{
#ifdef ARIBSUB_GEN_DRCS_DATA
int8_t i_fontId = bs_read( p_bs, 4 ); /* i_fontID */
#else
bs_skip( p_bs, 4 ); /* i_fontID */
#endif //ARIBSUB_GEN_DRCS_DATA
uint8_t i_mode = bs_read( p_bs, 4 );
p_parser->i_data_unit_size += 1;

Expand Down Expand Up @@ -206,18 +209,26 @@ static void parse_data_unit_DRCS( arib_parser_t *p_parser, bs_t *p_bs,

#ifdef ARIBSUB_GEN_DRCS_DATA
save_drcs_pattern( p_parser->p_instance, i_width, i_height, i_depth + 2,
p_drcs_pattern_data->p_patternData );
p_drcs_pattern_data->p_patternData, i_CharacterCode );
#else
save_drcs_pattern( p_parser->p_instance, i_width, i_height, i_depth + 2,
p_patternData );
p_patternData, i_CharacterCode);
free( p_patternData );
#endif //ARIBSUB_GEN_DRCS_DATA
}
else
{
#ifdef ARIBSUB_GEN_DRCS_DATA
int8_t i_regionX = bs_read( p_bs, 8 ); /* i_regionX */
#else
bs_skip( p_bs, 8 ); /* i_regionX */
#endif //ARIBSUB_GEN_DRCS_DATA
p_parser->i_data_unit_size += 1;
#ifdef ARIBSUB_GEN_DRCS_DATA
int8_t i_regionY = bs_read( p_bs, 8 ); /* i_regionY */
#else
bs_skip( p_bs, 8 ); /* i_regionY */
#endif //ARIBSUB_GEN_DRCS_DATA
p_parser->i_data_unit_size += 1;
uint16_t i_geometricData_length = bs_read( p_bs, 16 );
p_parser->i_data_unit_size += 2;
Expand Down Expand Up @@ -245,7 +256,11 @@ static void parse_data_unit_DRCS( arib_parser_t *p_parser, bs_t *p_bs,

for( int k = 0; k < i_geometricData_length ; k++ )
{
#ifdef ARIBSUB_GEN_DRCS_DATA
int8_t i_geometricData = bs_read( p_bs, 8 ); /* i_geometric_data */
#else
bs_skip( p_bs, 8 ); /* i_geometric_data */
#endif //ARIBSUB_GEN_DRCS_DATA
p_parser->i_data_unit_size += 1;

#ifdef ARIBSUB_GEN_DRCS_DATA
Expand Down Expand Up @@ -344,6 +359,8 @@ static void parse_caption_management_data( arib_parser_t *p_parser, bs_t *p_bs )
p_parser->i_data_unit_size = 0;
p_parser->i_subtitle_data_size = 0;
p_parser->psz_subtitle_data = NULL;
p_parser->p_instance->p->i_drcs_num = 0;
memset(p_parser->p_instance->p->drcs_hash_table, 0, sizeof(p_parser->p_instance->p->drcs_hash_table));
if( i_data_unit_loop_length > 0 )
{
p_parser->psz_subtitle_data = (unsigned char*) calloc(
Expand Down

0 comments on commit 58a34b8

Please sign in to comment.