static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)

{

    char *tx3g_ptr = avctx->extradata;

    int i, box_size, font_length;

    int8_t v_align, h_align;

    int style_fontID;

    StyleBox s_default;



    m->count_f = 0;

    m->ftab_entries = 0;

    box_size = BOX_SIZE_INITIAL; /* Size till ftab_entries */

    if (avctx->extradata_size < box_size)

        return -1;



    // Display Flags

    tx3g_ptr += 4;

    // Alignment

    h_align = *tx3g_ptr++;

    v_align = *tx3g_ptr++;

    if (h_align == 0) {

        if (v_align == 0)

            m->d.alignment = TOP_LEFT;

        if (v_align == 1)

            m->d.alignment = MIDDLE_LEFT;

        if (v_align == -1)

            m->d.alignment = BOTTOM_LEFT;

    }

    if (h_align == 1) {

        if (v_align == 0)

            m->d.alignment = TOP_CENTER;

        if (v_align == 1)

            m->d.alignment = MIDDLE_CENTER;

        if (v_align == -1)

            m->d.alignment = BOTTOM_CENTER;

    }

    if (h_align == -1) {

        if (v_align == 0)

            m->d.alignment = TOP_RIGHT;

        if (v_align == 1)

            m->d.alignment = MIDDLE_RIGHT;

        if (v_align == -1)

            m->d.alignment = BOTTOM_RIGHT;

    }

    // Background Color

    m->d.back_color = AV_RB24(tx3g_ptr);

    tx3g_ptr += 4;

    // BoxRecord

    tx3g_ptr += 8;

    // StyleRecord

    tx3g_ptr += 4;

    // fontID

    style_fontID = AV_RB16(tx3g_ptr);

    tx3g_ptr += 2;

    // face-style-flags

    s_default.style_flag = *tx3g_ptr++;

    m->d.bold = s_default.style_flag & STYLE_FLAG_BOLD;

    m->d.italic = s_default.style_flag & STYLE_FLAG_ITALIC;

    m->d.underline = s_default.style_flag & STYLE_FLAG_UNDERLINE;

    // fontsize

    m->d.fontsize = *tx3g_ptr++;

    // Primary color

    m->d.color = AV_RB24(tx3g_ptr);

    tx3g_ptr += 4;

    // FontRecord

    // FontRecord Size

    tx3g_ptr += 4;

    // ftab

    tx3g_ptr += 4;



    m->ftab_entries = AV_RB16(tx3g_ptr);

    tx3g_ptr += 2;



    for (i = 0; i < m->ftab_entries; i++) {



        box_size += 3;

        if (avctx->extradata_size < box_size) {

            mov_text_cleanup_ftab(m);

            m->ftab_entries = 0;

            return -1;

        }

        m->ftab_temp = av_malloc(sizeof(*m->ftab_temp));

        if (!m->ftab_temp) {

            mov_text_cleanup_ftab(m);

            return AVERROR(ENOMEM);

        }

        m->ftab_temp->fontID = AV_RB16(tx3g_ptr);

        tx3g_ptr += 2;

        font_length = *tx3g_ptr++;



        box_size = box_size + font_length;

        if (avctx->extradata_size < box_size) {

            mov_text_cleanup_ftab(m);

            m->ftab_entries = 0;

            return -1;

        }

        m->ftab_temp->font = av_malloc(font_length + 1);

        if (!m->ftab_temp->font) {

            mov_text_cleanup_ftab(m);

            return AVERROR(ENOMEM);

        }

        memcpy(m->ftab_temp->font, tx3g_ptr, font_length);

        m->ftab_temp->font[font_length] = '\0';

        av_dynarray_add(&m->ftab, &m->count_f, m->ftab_temp);

        if (!m->ftab) {

            mov_text_cleanup_ftab(m);

            return AVERROR(ENOMEM);

        }

        tx3g_ptr = tx3g_ptr + font_length;

    }

    for (i = 0; i < m->ftab_entries; i++) {

        if (style_fontID == m->ftab[i]->fontID)

            m->d.font = m->ftab[i]->font;

    }

    return 0;

}

static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)

{

    char *tx3g_ptr = avctx->extradata;

    int i, box_size, font_length;

    int8_t v_align, h_align;

    int style_fontID;

    StyleBox s_default;



    m->count_f = 0;

    m->ftab_entries = 0;

    box_size = BOX_SIZE_INITIAL; 

    if (avctx->extradata_size < box_size)

        return -1;



    

    tx3g_ptr += 4;

    

    h_align = *tx3g_ptr++;

    v_align = *tx3g_ptr++;

    if (h_align == 0) {

        if (v_align == 0)

            m->d.alignment = TOP_LEFT;

        if (v_align == 1)

            m->d.alignment = MIDDLE_LEFT;

        if (v_align == -1)

            m->d.alignment = BOTTOM_LEFT;

    }

    if (h_align == 1) {

        if (v_align == 0)

            m->d.alignment = TOP_CENTER;

        if (v_align == 1)

            m->d.alignment = MIDDLE_CENTER;

        if (v_align == -1)

            m->d.alignment = BOTTOM_CENTER;

    }

    if (h_align == -1) {

        if (v_align == 0)

            m->d.alignment = TOP_RIGHT;

        if (v_align == 1)

            m->d.alignment = MIDDLE_RIGHT;

        if (v_align == -1)

            m->d.alignment = BOTTOM_RIGHT;

    }

    

    m->d.back_color = AV_RB24(tx3g_ptr);

    tx3g_ptr += 4;

    

    tx3g_ptr += 8;

    

    tx3g_ptr += 4;

    

    style_fontID = AV_RB16(tx3g_ptr);

    tx3g_ptr += 2;

    

    s_default.style_flag = *tx3g_ptr++;

    m->d.bold = s_default.style_flag & STYLE_FLAG_BOLD;

    m->d.italic = s_default.style_flag & STYLE_FLAG_ITALIC;

    m->d.underline = s_default.style_flag & STYLE_FLAG_UNDERLINE;

    

    m->d.fontsize = *tx3g_ptr++;

    

    m->d.color = AV_RB24(tx3g_ptr);

    tx3g_ptr += 4;

    

     Size

    tx3g_ptr += 4;

    

    tx3g_ptr += 4;



    m->ftab_entries = AV_RB16(tx3g_ptr);

    tx3g_ptr += 2;



    for (i = 0; i < m->ftab_entries; i++) {



        box_size += 3;

        if (avctx->extradata_size < box_size) {

            mov_text_cleanup_ftab(m);

            m->ftab_entries = 0;

            return -1;

        }

        m->ftab_temp = av_malloc(sizeof(*m->ftab_temp));

        if (!m->ftab_temp) {

            mov_text_cleanup_ftab(m);

            return AVERROR(ENOMEM);

        }

        m->ftab_temp->fontID = AV_RB16(tx3g_ptr);

        tx3g_ptr += 2;

        font_length = *tx3g_ptr++;



        box_size = box_size + font_length;

        if (avctx->extradata_size < box_size) {

            mov_text_cleanup_ftab(m);

            m->ftab_entries = 0;

            return -1;

        }

        m->ftab_temp->font = av_malloc(font_length + 1);

        if (!m->ftab_temp->font) {

            mov_text_cleanup_ftab(m);

            return AVERROR(ENOMEM);

        }

        memcpy(m->ftab_temp->font, tx3g_ptr, font_length);

        m->ftab_temp->font[font_length] = '\0';

        av_dynarray_add(&m->ftab, &m->count_f, m->ftab_temp);

        if (!m->ftab) {

            mov_text_cleanup_ftab(m);

            return AVERROR(ENOMEM);

        }

        tx3g_ptr = tx3g_ptr + font_length;

    }

    for (i = 0; i < m->ftab_entries; i++) {

        if (style_fontID == m->ftab[i]->fontID)

            m->d.font = m->ftab[i]->font;

    }

    return 0;

}

    char *tx3g_ptr = avctx->extradata;
static int FUNC_0(AVCodecContext *VAR_0, MovTextContext *VAR_1)

{

    char *VAR_2 = VAR_0->extradata;

    int VAR_3, VAR_4, VAR_5;

    int8_t v_align, h_align;

    int VAR_6;

    StyleBox s_default;



    VAR_1->count_f = 0;

    VAR_1->ftab_entries = 0;

    VAR_4 = BOX_SIZE_INITIAL; 

    if (VAR_0->extradata_size < VAR_4)

        return -1;



    

    VAR_2 += 4;

    

    h_align = *VAR_2++;

    v_align = *VAR_2++;

    if (h_align == 0) {

        if (v_align == 0)

            VAR_1->d.alignment = TOP_LEFT;

        if (v_align == 1)

            VAR_1->d.alignment = MIDDLE_LEFT;

        if (v_align == -1)

            VAR_1->d.alignment = BOTTOM_LEFT;

    }

    if (h_align == 1) {

        if (v_align == 0)

            VAR_1->d.alignment = TOP_CENTER;

        if (v_align == 1)

            VAR_1->d.alignment = MIDDLE_CENTER;

        if (v_align == -1)

            VAR_1->d.alignment = BOTTOM_CENTER;

    }

    if (h_align == -1) {

        if (v_align == 0)

            VAR_1->d.alignment = TOP_RIGHT;

        if (v_align == 1)

            VAR_1->d.alignment = MIDDLE_RIGHT;

        if (v_align == -1)

            VAR_1->d.alignment = BOTTOM_RIGHT;

    }

    

    VAR_1->d.back_color = AV_RB24(VAR_2);

    VAR_2 += 4;

    

    VAR_2 += 8;

    

    VAR_2 += 4;

    

    VAR_6 = AV_RB16(VAR_2);

    VAR_2 += 2;

    

    s_default.style_flag = *VAR_2++;

    VAR_1->d.bold = s_default.style_flag & STYLE_FLAG_BOLD;

    VAR_1->d.italic = s_default.style_flag & STYLE_FLAG_ITALIC;

    VAR_1->d.underline = s_default.style_flag & STYLE_FLAG_UNDERLINE;

    

    VAR_1->d.fontsize = *VAR_2++;

    

    VAR_1->d.color = AV_RB24(VAR_2);

    VAR_2 += 4;

    

     Size

    VAR_2 += 4;

    

    VAR_2 += 4;



    VAR_1->ftab_entries = AV_RB16(VAR_2);

    VAR_2 += 2;



    for (VAR_3 = 0; VAR_3 < VAR_1->ftab_entries; VAR_3++) {



        VAR_4 += 3;

        if (VAR_0->extradata_size < VAR_4) {

            mov_text_cleanup_ftab(VAR_1);

            VAR_1->ftab_entries = 0;

            return -1;

        }

        VAR_1->ftab_temp = av_malloc(sizeof(*VAR_1->ftab_temp));

        if (!VAR_1->ftab_temp) {

            mov_text_cleanup_ftab(VAR_1);

            return AVERROR(ENOMEM);

        }

        VAR_1->ftab_temp->fontID = AV_RB16(VAR_2);

        VAR_2 += 2;

        VAR_5 = *VAR_2++;



        VAR_4 = VAR_4 + VAR_5;

        if (VAR_0->extradata_size < VAR_4) {

            mov_text_cleanup_ftab(VAR_1);

            VAR_1->ftab_entries = 0;

            return -1;

        }

        VAR_1->ftab_temp->font = av_malloc(VAR_5 + 1);

        if (!VAR_1->ftab_temp->font) {

            mov_text_cleanup_ftab(VAR_1);

            return AVERROR(ENOMEM);

        }

        memcpy(VAR_1->ftab_temp->font, VAR_2, VAR_5);

        VAR_1->ftab_temp->font[VAR_5] = '\0';

        av_dynarray_add(&VAR_1->ftab, &VAR_1->count_f, VAR_1->ftab_temp);

        if (!VAR_1->ftab) {

            mov_text_cleanup_ftab(VAR_1);

            return AVERROR(ENOMEM);

        }

        VAR_2 = VAR_2 + VAR_5;

    }

    for (VAR_3 = 0; VAR_3 < VAR_1->ftab_entries; VAR_3++) {

        if (VAR_6 == VAR_1->ftab[VAR_3]->fontID)

            VAR_1->d.font = VAR_1->ftab[VAR_3]->font;

    }

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, MovTextContext *VAR_1)
{ char *VAR_2 = VAR_0->extradata; int VAR_3, VAR_4, VAR_5; int8_t v_align, h_align; int VAR_6; StyleBox s_default; VAR_1->count_f = 0; VAR_1->ftab_entries = 0; VAR_4 = BOX_SIZE_INITIAL; if (VAR_0->extradata_size < VAR_4)
return -1; VAR_2 += 4; h_align = *VAR_2++; v_align = *VAR_2++; if (h_align == 0) { if (v_align == 0)
VAR_1->d.alignment = TOP_LEFT; if (v_align == 1)
VAR_1->d.alignment = MIDDLE_LEFT; if (v_align == -1)
VAR_1->d.alignment = BOTTOM_LEFT; } if (h_align == 1) { if (v_align == 0)
VAR_1->d.alignment = TOP_CENTER; if (v_align == 1)
VAR_1->d.alignment = MIDDLE_CENTER; if (v_align == -1)
VAR_1->d.alignment = BOTTOM_CENTER; } if (h_align == -1) { if (v_align == 0)
VAR_1->d.alignment = TOP_RIGHT; if (v_align == 1)
VAR_1->d.alignment = MIDDLE_RIGHT; if (v_align == -1)
VAR_1->d.alignment = BOTTOM_RIGHT; } VAR_1->d.back_color = AV_RB24(VAR_2); VAR_2 += 4; VAR_2 += 8; VAR_2 += 4; VAR_6 = AV_RB16(VAR_2); VAR_2 += 2; s_default.style_flag = *VAR_2++; VAR_1->d.bold = s_default.style_flag & STYLE_FLAG_BOLD; VAR_1->d.italic = s_default.style_flag & STYLE_FLAG_ITALIC; VAR_1->d.underline = s_default.style_flag & STYLE_FLAG_UNDERLINE; VAR_1->d.fontsize = *VAR_2++; VAR_1->d.color = AV_RB24(VAR_2); VAR_2 += 4; Size
VAR_2 += 4; VAR_2 += 4; VAR_1->ftab_entries = AV_RB16(VAR_2); VAR_2 += 2; for (VAR_3 = 0; VAR_3 < VAR_1->ftab_entries; VAR_3++) { VAR_4 += 3; if (VAR_0->extradata_size < VAR_4) { mov_text_cleanup_ftab(VAR_1); VAR_1->ftab_entries = 0; return -1; } VAR_1->ftab_temp = av_malloc(sizeof(*VAR_1->ftab_temp)); if (!VAR_1->ftab_temp) { mov_text_cleanup_ftab(VAR_1); return AVERROR(ENOMEM); } VAR_1->ftab_temp->fontID = AV_RB16(VAR_2); VAR_2 += 2; VAR_5 = *VAR_2++; VAR_4 = VAR_4 + VAR_5; if (VAR_0->extradata_size < VAR_4) { mov_text_cleanup_ftab(VAR_1); VAR_1->ftab_entries = 0; return -1; } VAR_1->ftab_temp->font = av_malloc(VAR_5 + 1); if (!VAR_1->ftab_temp->font) { mov_text_cleanup_ftab(VAR_1); return AVERROR(ENOMEM); } memcpy(VAR_1->ftab_temp->font, VAR_2, VAR_5); VAR_1->ftab_temp->font[VAR_5] = '\0'; av_dynarray_add(&VAR_1->ftab, &VAR_1->count_f, VAR_1->ftab_temp); if (!VAR_1->ftab) { mov_text_cleanup_ftab(VAR_1); return AVERROR(ENOMEM); } VAR_2 = VAR_2 + VAR_5; } for (VAR_3 = 0; VAR_3 < VAR_1->ftab_entries; VAR_3++) { if (VAR_6 == VAR_1->ftab[VAR_3]->fontID)
VAR_1->d.font = VAR_1->ftab[VAR_3]->font; } return 0; }